using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
+using Nito.AsyncEx;
using System.Threading;
using System.Threading.Tasks;
using Slusser.Collections.Generic;
GapBuffer<char> buf = new GapBuffer<char>();
const int MaxSemaphoreCount = 1;
SemaphoreSlim Semaphore = new SemaphoreSlim(MaxSemaphoreCount);
- ReaderWriterLockSlim rwlock = new ReaderWriterLockSlim();
+ AsyncReaderWriterLock rwlock = new AsyncReaderWriterLock();
public StringBuffer()
{
public string ToString(int index, int length)
{
- this.rwlock.EnterReadLock();
-
StringBuilder temp = new StringBuilder();
temp.Clear();
- for (int i = index; i < index + length; i++)
- temp.Append(buf[i]);
-
- this.rwlock.ExitReadLock();
-
+ using (this.rwlock.ReaderLock())
+ {
+ for (int i = index; i < index + length; i++)
+ temp.Append(buf[i]);
+ }
return temp.ToString();
}
internal void Replace(GapBuffer<char> buf)
{
- this.rwlock.EnterWriteLock();
-
- this.Clear();
- this.buf = buf;
-
- this.rwlock.ExitWriteLock();
+ using (this.rwlock.WriterLock())
+ {
+ this.Clear();
+ this.buf = buf;
+ }
this.Update(this, new DocumentUpdateEventArgs(UpdateType.Replace, 0, 0, buf.Count));
}
internal void Replace(int index, int length, IEnumerable<char> chars, int count)
{
- this.rwlock.EnterWriteLock();
-
- try
+ using (this.rwlock.WriterLock())
{
if (length > 0)
this.buf.RemoveRange(index, length);
this.buf.InsertRange(index, chars, count);
}
- finally
- {
- this.rwlock.ExitWriteLock();
- }
-
this.Update(this, new DocumentUpdateEventArgs(UpdateType.Replace, index, length, count));
}
//内部形式に変換する
var internal_str = from s in str where s != '\r' && s != '\0' select s;
- this.rwlock.EnterWriteLock();
- //str.lengthは事前に確保しておくために使用するので影響はない
- this.buf.InsertRange(index, internal_str, str.Length);
-
- this.rwlock.ExitWriteLock();
+ using (await this.rwlock.WriterLockAsync())
+ {
+ //str.lengthは事前に確保しておくために使用するので影響はない
+ this.buf.InsertRange(index, internal_str, str.Length);
+ }
if (tokenSource != null)
tokenSource.Token.ThrowIfCancellationRequested();
internal async Task SaveAsync(TextWriter fs, CancellationTokenSource tokenSource = null)
{
- try
+ using(await this.rwlock.ReaderLockAsync())
{
- this.rwlock.EnterReadLock();
StringBuilder line = new StringBuilder();
for (int i = 0; i < this.Length; i++)
{
}
}
}
- finally
- {
- this.rwlock.ExitReadLock();
- }
}
internal void ReplaceRegexAll(LineToIndexTable layoutlines, Regex regex, string pattern, bool groupReplace)
{
int lineHeadIndex = layoutlines.GetIndexFromLineNumber(i), lineLength = layoutlines.GetLengthFromLineNumber(i);
int left = lineHeadIndex, right = lineHeadIndex;
- string output = regex.Replace(layoutlines[i], (m) => {
+ string output;
+
+ output = regex.Replace(layoutlines[i], (m) => {
if (groupReplace)
return m.Result(pattern);
else
return pattern;
});
- this.rwlock.EnterWriteLock();
- try
+ using (this.rwlock.WriterLock())
{
//空行は削除する必要はない
if (lineHeadIndex < this.buf.Count)
this.buf.RemoveRange(lineHeadIndex, lineLength);
this.buf.InsertRange(lineHeadIndex, output, output.Length);
}
- finally
- {
- this.rwlock.ExitWriteLock();
- }
this.Update(this, new DocumentUpdateEventArgs(UpdateType.Replace, lineHeadIndex, lineLength, output.Length, i));
}
int newLineLength = lineLength;
while ((right = ts.IndexOf(this.buf, left, lineHeadIndex + newLineLength)) != -1)
{
- this.rwlock.EnterWriteLock();
- try
+ using (this.rwlock.WriterLock())
{
this.buf.RemoveRange(right, target.Length);
this.buf.InsertRange(right, pattern_chars, pattern.Length);
}
- finally
- {
- this.rwlock.ExitWriteLock();
-
- }
left = right + pattern.Length;
newLineLength += pattern.Length - target.Length;
}
-
this.Update(this, new DocumentUpdateEventArgs(UpdateType.Replace, lineHeadIndex, lineLength, newLineLength, i));
}
}
internal int IndexOf(string target, int start, bool ci = false)
{
- this.rwlock.EnterReadLock();
-
- TextSearch ts = new TextSearch(target, ci);
- int patternIndex = ts.IndexOf(this.buf, start, this.buf.Count);
-
- this.rwlock.ExitReadLock();
-
- return patternIndex;
+ using (this.rwlock.ReaderLock())
+ {
+ TextSearch ts = new TextSearch(target, ci);
+ int patternIndex = ts.IndexOf(this.buf, start, this.buf.Count);
+ return patternIndex;
+ }
}
/// <summary>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>5.4.2</Version>
</PackageReference>
+ <PackageReference Include="Nito.AsyncEx">
+ <Version>5.0.0</Version>
+ </PackageReference>
<PackageReference Include="SharpDX">
<Version>4.0.1</Version>
</PackageReference>
<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FooEditEngine.WPF</RootNamespace>
<AssemblyName>FooEditEngine.WPF</AssemblyName>
- <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</ProjectReference>
</ItemGroup>
<ItemGroup>
+ <PackageReference Include="Nito.AsyncEx">
+ <Version>5.0.0</Version>
+ </PackageReference>
<PackageReference Include="SharpDX.Direct2D1">
<Version>4.0.1</Version>
</PackageReference>
<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Test</RootNamespace>
<AssemblyName>Test</AssemblyName>
- <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="SharpDX" publicKeyToken="b4dcf0f35e5521f1" culture="neutral"/>
+ <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="SharpDX.DXGI" publicKeyToken="b4dcf0f35e5521f1" culture="neutral"/>
+ <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/></startup></configuration>
<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>UnitTest</RootNamespace>
<AssemblyName>UnitTest</AssemblyName>
- <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
+ <TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="SharpDX" publicKeyToken="b4dcf0f35e5521f1" culture="neutral"/>
+ <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
+ </dependentAssembly>
+ <dependentAssembly>
+ <assemblyIdentity name="SharpDX.DXGI" publicKeyToken="b4dcf0f35e5521f1" culture="neutral"/>
+ <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/></startup></configuration>
<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FooEditEngine.Windows</RootNamespace>
<AssemblyName>FooEditEngine.Windows</AssemblyName>
- <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<Compile Include="WinIME.cs" />
</ItemGroup>
<ItemGroup>
+ <PackageReference Include="Nito.AsyncEx">
+ <Version>5.0.0</Version>
+ </PackageReference>
<PackageReference Include="SharpDX.Direct2D1">
<Version>4.0.1</Version>
</PackageReference>
//------------------------------------------------------------------------------
// <auto-generated>
// このコードはツールによって生成されました。
-// ランタイム バージョン:4.0.30319.17929
+// ランタイム バージョン:4.0.30319.42000
//
// このファイルへの変更は、以下の状況下で不正な動作の原因になったり、
// コードが再生成されるときに損失したりします。
// または Visual Studio のようなツールを使用して自動生成されました。
// メンバーを追加または削除するには、.ResX ファイルを編集して、/str オプションと共に
// ResGen を実行し直すか、または VS プロジェクトをビルドし直します。
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
//------------------------------------------------------------------------------
// <auto-generated>
// このコードはツールによって生成されました。
-// ランタイム バージョン:4.0.30319.17929
+// ランタイム バージョン:4.0.30319.42000
//
// このファイルへの変更は、以下の状況下で不正な動作の原因になったり、
// コードが再生成されるときに損失したりします。
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.7.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Test.Windows</RootNamespace>
<AssemblyName>Test.Windows</AssemblyName>
- <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <runtime>
+ <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+ <dependentAssembly>
+ <assemblyIdentity name="SharpDX" publicKeyToken="b4dcf0f35e5521f1" culture="neutral"/>
+ <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
+ </dependentAssembly>
+ </assemblyBinding>
+ </runtime>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/></startup></configuration>