Auto status change to "Under Review"
@@ -0,0 +1,35 | |||||
|
1 | using System; | |||
|
2 | using System.Threading; | |||
|
3 | using System.Threading.Tasks; | |||
|
4 | using Implab.Components; | |||
|
5 | ||||
|
6 | namespace Implab.Test { | |||
|
7 | public class MockPollComponent : PollingComponent { | |||
|
8 | ||||
|
9 | public Func<CancellationToken,Task> PollWorker { get; set;} | |||
|
10 | ||||
|
11 | public Func<CancellationToken, Task> StartWorker { get; set; } | |||
|
12 | ||||
|
13 | public Func<CancellationToken, Task> StopWorker { get; set; } | |||
|
14 | ||||
|
15 | public MockPollComponent(bool initialized) : base(initialized) { | |||
|
16 | } | |||
|
17 | ||||
|
18 | protected async override Task Poll(CancellationToken ct) { | |||
|
19 | if(PollWorker!= null) | |||
|
20 | await PollWorker.Invoke(ct); | |||
|
21 | } | |||
|
22 | ||||
|
23 | protected async override Task StopInternalAsync(CancellationToken ct) { | |||
|
24 | if (StopWorker != null) | |||
|
25 | await StopWorker.Invoke(ct); | |||
|
26 | } | |||
|
27 | ||||
|
28 | protected async override Task StartInternalAsync(CancellationToken ct) { | |||
|
29 | if (StartWorker != null) | |||
|
30 | await StartWorker.Invoke(ct); | |||
|
31 | } | |||
|
32 | ||||
|
33 | ||||
|
34 | } | |||
|
35 | } No newline at end of file |
@@ -1,69 +1,20 | |||||
1 | <?xml version="1.0" encoding="utf-8"?> |
|
1 | <Project Sdk="Microsoft.NET.Sdk"> | |
2 | <Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|
2 | <PropertyGroup Condition="'$(OSTYPE)'=='linux'"> | |
3 | <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
|
3 | <TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks> | |
4 | <PropertyGroup> |
|
4 | <FrameworkPathOverride Condition="'$(TargetFramework)'=='net46'">/usr/lib/mono/4.6-api/</FrameworkPathOverride> | |
5 | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|
|||
6 | <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|
|||
7 | <ProjectGuid>{100DFEB0-75BE-436F-ADDF-1F46EF433F46}</ProjectGuid> |
|
|||
8 | <OutputType>Exe</OutputType> |
|
|||
9 | <AppDesignerFolder>Properties</AppDesignerFolder> |
|
|||
10 | <RootNamespace>Implab.Playground</RootNamespace> |
|
|||
11 | <AssemblyName>Implab.Playground</AssemblyName> |
|
|||
12 | <TargetFrameworkVersion>v4.6</TargetFrameworkVersion> |
|
|||
13 | <FileAlignment>512</FileAlignment> |
|
|||
14 | <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> |
|
|||
15 | <TargetFrameworkProfile /> |
|
|||
16 | </PropertyGroup> |
|
5 | </PropertyGroup> | |
17 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|
6 | ||
18 | <PlatformTarget>AnyCPU</PlatformTarget> |
|
7 | <PropertyGroup Condition="'$(OSTYPE)'=='windows'"> | |
19 | <DebugSymbols>true</DebugSymbols> |
|
8 | <TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks> | |
20 | <DebugType>full</DebugType> |
|
|||
21 | <Optimize>false</Optimize> |
|
|||
22 | <OutputPath>bin\Debug\</OutputPath> |
|
|||
23 | <DefineConstants>DEBUG;TRACE</DefineConstants> |
|
|||
24 | <ErrorReport>prompt</ErrorReport> |
|
|||
25 | <WarningLevel>4</WarningLevel> |
|
|||
26 | </PropertyGroup> |
|
9 | </PropertyGroup> | |
27 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|
10 | ||
28 | <PlatformTarget>AnyCPU</PlatformTarget> |
|
11 | <PropertyGroup> | |
29 | <DebugType>pdbonly</DebugType> |
|
12 | <OutputType>Exe</OutputType> | |
30 | <Optimize>true</Optimize> |
|
13 | <IsPackable>false</IsPackable> | |
31 | <OutputPath>bin\Release\</OutputPath> |
|
|||
32 | <DefineConstants>TRACE</DefineConstants> |
|
|||
33 | <ErrorReport>prompt</ErrorReport> |
|
|||
34 | <WarningLevel>4</WarningLevel> |
|
|||
35 | <Prefer32Bit>true</Prefer32Bit> |
|
|||
36 | <DebugSymbols>true</DebugSymbols> |
|
|||
37 | </PropertyGroup> |
|
14 | </PropertyGroup> | |
38 | <ItemGroup> |
|
15 | ||
39 | <Reference Include="System" /> |
|
|||
40 | <Reference Include="System.Core" /> |
|
|||
41 | <Reference Include="System.Xml.Linq" /> |
|
|||
42 | <Reference Include="System.Data.DataSetExtensions" /> |
|
|||
43 | <Reference Include="Microsoft.CSharp" /> |
|
|||
44 | <Reference Include="System.Data" /> |
|
|||
45 | <Reference Include="System.Net.Http" /> |
|
|||
46 | <Reference Include="System.Xml" /> |
|
|||
47 | </ItemGroup> |
|
|||
48 | <ItemGroup> |
|
16 | <ItemGroup> | |
49 | <Compile Include="Program.cs" /> |
|
17 | <ProjectReference Include="../Implab/Implab.csproj"/> | |
50 | <Compile Include="Properties\AssemblyInfo.cs" /> |
|
|||
51 | </ItemGroup> |
|
|||
52 | <ItemGroup> |
|
|||
53 | <None Include="App.config" /> |
|
|||
54 | </ItemGroup> |
|
18 | </ItemGroup> | |
55 | <ItemGroup> |
|
19 | ||
56 | <ProjectReference Include="..\Implab\Implab.csproj"> |
|
20 | </Project> | |
57 | <Project>{f550f1f8-8746-4ad0-9614-855f4c4b7f05}</Project> |
|
|||
58 | <Name>Implab</Name> |
|
|||
59 | </ProjectReference> |
|
|||
60 | </ItemGroup> |
|
|||
61 | <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
|
|||
62 | <!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
|
|||
63 | Other similar extension points exist, see Microsoft.Common.targets. |
|
|||
64 | <Target Name="BeforeBuild"> |
|
|||
65 | </Target> |
|
|||
66 | <Target Name="AfterBuild"> |
|
|||
67 | </Target> |
|
|||
68 | --> |
|
|||
69 | </Project> No newline at end of file |
|
@@ -15,7 +15,6 using System.Xml.Serialization; | |||||
15 |
|
15 | |||
16 | namespace Implab.Playground { |
|
16 | namespace Implab.Playground { | |
17 | using System.Diagnostics; |
|
17 | using System.Diagnostics; | |
18 | using System.Runtime.Remoting.Messaging; |
|
|||
19 | using static Trace<Program>; |
|
18 | using static Trace<Program>; | |
20 |
|
19 | |||
21 | public class Program { |
|
20 | public class Program { |
@@ -1,8 +1,14 | |||||
1 | <Project Sdk="Microsoft.NET.Sdk"> |
|
1 | <Project Sdk="Microsoft.NET.Sdk"> | |
|
2 | <PropertyGroup Condition="'$(OSTYPE)'=='linux'"> | |||
|
3 | <TargetFrameworks>netcoreapp2.0</TargetFrameworks> | |||
|
4 | <FrameworkPathOverride Condition="'$(TargetFramework)'=='net46'">/usr/lib/mono/4.5/</FrameworkPathOverride> | |||
|
5 | </PropertyGroup> | |||
|
6 | ||||
|
7 | <PropertyGroup Condition="'$(OSTYPE)'=='windows'"> | |||
|
8 | <TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks> | |||
|
9 | </PropertyGroup> | |||
2 |
|
10 | |||
3 | <PropertyGroup> |
|
11 | <PropertyGroup> | |
4 | <TargetFramework>netcoreapp2.1</TargetFramework> |
|
|||
5 |
|
||||
6 | <IsPackable>false</IsPackable> |
|
12 | <IsPackable>false</IsPackable> | |
7 | </PropertyGroup> |
|
13 | </PropertyGroup> | |
8 |
|
14 | |||
@@ -13,5 +19,5 | |||||
13 | <ProjectReference Include="../Implab/Implab.csproj"/> |
|
19 | <ProjectReference Include="../Implab/Implab.csproj"/> | |
14 | <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /> |
|
20 | <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /> | |
15 | </ItemGroup> |
|
21 | </ItemGroup> | |
16 |
|
22 | |||
17 | </Project> |
|
23 | </Project> |
@@ -4,38 +4,26 using System.Threading.Tasks; | |||||
4 | using Implab.Components; |
|
4 | using Implab.Components; | |
5 | using Xunit; |
|
5 | using Xunit; | |
6 |
|
6 | |||
7 | namespace Implab.Test |
|
7 | namespace Implab.Test { | |
8 | { |
|
|||
9 | class TimeLog : PollingComponent { |
|
|||
10 | public TimeLog() : base(true) { |
|
|||
11 | } |
|
|||
12 |
|
8 | |||
13 | protected override Task Poll(CancellationToken ct) { |
|
9 | public class RunnableComponentTests { | |
14 | Console.WriteLine("Poll"); |
|
|||
15 | return Task.CompletedTask; |
|
|||
16 | } |
|
|||
17 | } |
|
|||
18 |
|
||||
19 | public class UnitTest1 |
|
|||
20 | { |
|
|||
21 | [Fact] |
|
10 | [Fact] | |
22 | public async Task Test1() |
|
11 | public async Task Test1() { | |
23 | { |
|
|||
24 |
|
12 | |||
25 |
using(var |
|
13 | using (var m = new MockPollComponent(true)) { | |
26 | tl.StateChanged += (self, args) => Console.WriteLine("{0}", args.State); |
|
14 | m.StartWorker = async (ct) => await Task.Yield(); | |
27 | tl.Delay = 1000; |
|
15 | m.StopWorker = async (ct) => await Task.Yield(); | |
28 | tl.Interval = 500; |
|
|||
29 |
|
16 | |||
|
17 | Assert.Equal(ExecutionState.Ready, m.State); | |||
|
18 | Assert.NotNull(m.Completion); | |||
30 |
|
19 | |||
31 |
|
|
20 | m.Start(CancellationToken.None); | |
32 |
await |
|
21 | await m.Completion; | |
|
22 | Assert.Equal(ExecutionState.Running, m.State); | |||
33 |
|
23 | |||
34 | await Task.Delay(2000); |
|
24 | m.Stop(CancellationToken.None); | |
35 |
|
25 | await m.Completion; | ||
36 | tl.Stop(CancellationToken.None); |
|
26 | Assert.Equal(ExecutionState.Stopped, m.State); | |
37 | await tl.Completion; |
|
|||
38 | await Task.Delay(3000); |
|
|||
39 | } |
|
27 | } | |
40 | } |
|
28 | } | |
41 | } |
|
29 | } |
@@ -50,7 +50,7 namespace Implab.Components { | |||||
50 | try { |
|
50 | try { | |
51 | // await for pending poll |
|
51 | // await for pending poll | |
52 | await m_poll; |
|
52 | await m_poll; | |
53 |
} catch (OperationCanceledException |
|
53 | } catch (OperationCanceledException) { | |
54 | // OK |
|
54 | // OK | |
55 | } |
|
55 | } | |
56 | } |
|
56 | } | |
@@ -71,12 +71,16 namespace Implab.Components { | |||||
71 | try { |
|
71 | try { | |
72 | m_pending.Start(); |
|
72 | m_pending.Start(); | |
73 | await m_poll; |
|
73 | await m_poll; | |
|
74 | ScheduleNextPoll(Interval); | |||
74 | } catch (Exception e) { |
|
75 | } catch (Exception e) { | |
75 | UnhandledException.DispatchEvent(this, new UnhandledExceptionEventArgs(e, false)); |
|
76 | UnhandledException.DispatchEvent(this, new UnhandledExceptionEventArgs(e, false)); | |
|
77 | ||||
76 | if (FailOnError) |
|
78 | if (FailOnError) | |
77 | Fail(e); |
|
79 | Fail(e); | |
|
80 | else | |||
|
81 | ScheduleNextPoll(Interval); | |||
78 | } |
|
82 | } | |
79 | ScheduleNextPoll(Interval); |
|
83 | ||
80 | } |
|
84 | } | |
81 |
|
85 | |||
82 | protected override void Dispose(bool disposing) { |
|
86 | protected override void Dispose(bool disposing) { |
@@ -319,6 +319,7 namespace Implab.Components { | |||||
319 | MoveSuccess(cookie); |
|
319 | MoveSuccess(cookie); | |
320 | } catch (Exception e) { |
|
320 | } catch (Exception e) { | |
321 | MoveFailed(e, cookie); |
|
321 | MoveFailed(e, cookie); | |
|
322 | throw; | |||
322 | } |
|
323 | } | |
323 | }, ct); |
|
324 | }, ct); | |
324 |
|
325 |
@@ -13,7 +13,7 namespace Implab { | |||||
13 | m_promise = new Promise(); |
|
13 | m_promise = new Promise(); | |
14 | } |
|
14 | } | |
15 |
|
15 | |||
16 |
internal Deferred(Promise promise |
|
16 | internal Deferred(Promise promise) { | |
17 | Debug.Assert(promise != null); |
|
17 | Debug.Assert(promise != null); | |
18 | m_promise = promise; |
|
18 | m_promise = promise; | |
19 | } |
|
19 | } |
@@ -8,9 +8,12 | |||||
8 | and SharedLock, Trace helpers on top of System.Diagnostics, ObjectPool etc. |
|
8 | and SharedLock, Trace helpers on top of System.Diagnostics, ObjectPool etc. | |
9 | </Description> |
|
9 | </Description> | |
10 | <Copyright>2012-2018 Sergey Smirnov</Copyright> |
|
10 | <Copyright>2012-2018 Sergey Smirnov</Copyright> | |
11 | <LicenseUrl>https://opensource.org/licenses/BSD-2-Clause</LicenseUrl> |
|
11 | <Version>3.0.6</Version> | |
12 | <ProjectUrl>https://implab.org</ProjectUrl> |
|
12 | <PackageLicenseUrl>https://opensource.org/licenses/BSD-2-Clause</PackageLicenseUrl> | |
|
13 | <PackageProjectUrl>https://implab.org</PackageProjectUrl> | |||
13 | <RepositoryUrl>https://hg.implab.org/pub/ImplabNet/</RepositoryUrl> |
|
14 | <RepositoryUrl>https://hg.implab.org/pub/ImplabNet/</RepositoryUrl> | |
|
15 | <RepositoryType>mercurial</RepositoryType> | |||
|
16 | <PackageTags>IMPLAB;Json pull-parser;Json Xml;async;diagnostics;serialization;</PackageTags> | |||
14 | <TargetFrameworks>netstandard2.0;net46</TargetFrameworks> |
|
17 | <TargetFrameworks>netstandard2.0;net46</TargetFrameworks> | |
15 | <FrameworkPathOverride Condition="'$(TargetFramework)'=='net46' and '$(OSTYPE)'=='linux'">/usr/lib/mono/4.5/</FrameworkPathOverride> |
|
18 | <FrameworkPathOverride Condition="'$(TargetFramework)'=='net46' and '$(OSTYPE)'=='linux'">/usr/lib/mono/4.5/</FrameworkPathOverride> | |
16 | <DefineConstants Condition="'$(TargetFramework)'=='net46'">NETFX_TRACE_BUG;$(DefineConstants)</DefineConstants> |
|
19 | <DefineConstants Condition="'$(TargetFramework)'=='net46'">NETFX_TRACE_BUG;$(DefineConstants)</DefineConstants> |
@@ -2,6 +2,7 | |||||
2 | using System.Collections.Generic; |
|
2 | using System.Collections.Generic; | |
3 | using System.Diagnostics; |
|
3 | using System.Diagnostics; | |
4 | using System.Reflection; |
|
4 | using System.Reflection; | |
|
5 | using System.Threading; | |||
5 | using System.Threading.Tasks; |
|
6 | using System.Threading.Tasks; | |
6 | using Implab.Parallels; |
|
7 | using Implab.Parallels; | |
7 |
|
8 | |||
@@ -152,31 +153,44 namespace Implab { | |||||
152 | } |
|
153 | } | |
153 |
|
154 | |||
154 | public static IPromise Create(PromiseExecutor executor) { |
|
155 | public static IPromise Create(PromiseExecutor executor) { | |
155 | Safe.ArgumentNotNull(executor, nameof(executor)); |
|
156 | return Create(executor, CancellationToken.None); | |
|
157 | } | |||
156 |
|
158 | |||
157 | var p = new Promise(); |
|
159 | public static IPromise Create(PromiseExecutor executor, CancellationToken ct) { | |
158 | var d = new Deferred(p, DefaultDispatcher); |
|
160 | Safe.ArgumentNotNull(executor, nameof(executor)); | |
159 |
|
161 | if (!ct.CanBeCanceled) | ||
|
162 | return Create(executor); | |||
|
163 | ||||
|
164 | var d = new Deferred(); | |||
|
165 | ||||
|
166 | ct.Register(d.Cancel); | |||
|
167 | ||||
160 | try { |
|
168 | try { | |
161 | executor(d); |
|
169 | if (!ct.IsCancellationRequested) | |
162 | } catch (Exception e) { |
|
170 | executor(d); | |
|
171 | } catch(Exception e) { | |||
163 | d.Reject(e); |
|
172 | d.Reject(e); | |
164 | } |
|
173 | } | |
165 |
|
||||
166 | return d.Promise; |
|
174 | return d.Promise; | |
167 | } |
|
175 | } | |
168 |
|
176 | |||
169 | public static IPromise<T> Create<T>(PromiseExecutor<T> executor) { |
|
177 | public static IPromise<T> Create<T>(PromiseExecutor<T> executor) { | |
|
178 | return Create(executor, CancellationToken.None); | |||
|
179 | } | |||
|
180 | ||||
|
181 | public static IPromise<T> Create<T>(PromiseExecutor<T> executor, CancellationToken ct) { | |||
170 | Safe.ArgumentNotNull(executor, nameof(executor)); |
|
182 | Safe.ArgumentNotNull(executor, nameof(executor)); | |
171 |
|
183 | |||
172 | var d = new Deferred<T>(); |
|
184 | var d = new Deferred<T>(); | |
173 |
|
185 | |||
|
186 | ct.Register(d.Cancel); | |||
|
187 | ||||
174 | try { |
|
188 | try { | |
175 | executor(d); |
|
189 | if (!ct.IsCancellationRequested) | |
176 | } catch (Exception e) { |
|
190 | executor(d); | |
|
191 | } catch(Exception e) { | |||
177 | d.Reject(e); |
|
192 | d.Reject(e); | |
178 | } |
|
193 | } | |
179 |
|
||||
180 | return d.Promise; |
|
194 | return d.Promise; | |
181 | } |
|
195 | } | |
182 |
|
196 |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 3
ok, latest stable version should be in default
You need to be logged in to leave comments.
Login now