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"?> | |
|
2 | <Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
|
3 | <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | |
|
4 | <PropertyGroup> | |
|
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 /> | |
|
1 | <Project Sdk="Microsoft.NET.Sdk"> | |
|
2 | <PropertyGroup Condition="'$(OSTYPE)'=='linux'"> | |
|
3 | <TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks> | |
|
4 | <FrameworkPathOverride Condition="'$(TargetFramework)'=='net46'">/usr/lib/mono/4.6-api/</FrameworkPathOverride> | |
|
16 | 5 | </PropertyGroup> |
|
17 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |
|
18 | <PlatformTarget>AnyCPU</PlatformTarget> | |
|
19 | <DebugSymbols>true</DebugSymbols> | |
|
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> | |
|
6 | ||
|
7 | <PropertyGroup Condition="'$(OSTYPE)'=='windows'"> | |
|
8 | <TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks> | |
|
26 | 9 | </PropertyGroup> |
|
27 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |
|
28 | <PlatformTarget>AnyCPU</PlatformTarget> | |
|
29 | <DebugType>pdbonly</DebugType> | |
|
30 | <Optimize>true</Optimize> | |
|
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> | |
|
10 | ||
|
11 | <PropertyGroup> | |
|
12 | <OutputType>Exe</OutputType> | |
|
13 | <IsPackable>false</IsPackable> | |
|
37 | 14 | </PropertyGroup> |
|
38 | <ItemGroup> | |
|
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> | |
|
15 | ||
|
48 | 16 | <ItemGroup> |
|
49 | <Compile Include="Program.cs" /> | |
|
50 | <Compile Include="Properties\AssemblyInfo.cs" /> | |
|
51 | </ItemGroup> | |
|
52 | <ItemGroup> | |
|
53 | <None Include="App.config" /> | |
|
17 | <ProjectReference Include="../Implab/Implab.csproj"/> | |
|
54 | 18 | </ItemGroup> |
|
55 | <ItemGroup> | |
|
56 | <ProjectReference Include="..\Implab\Implab.csproj"> | |
|
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 | |
|
19 | ||
|
20 | </Project> |
@@ -15,7 +15,6 using System.Xml.Serialization; | |||
|
15 | 15 | |
|
16 | 16 | namespace Implab.Playground { |
|
17 | 17 | using System.Diagnostics; |
|
18 | using System.Runtime.Remoting.Messaging; | |
|
19 | 18 | using static Trace<Program>; |
|
20 | 19 | |
|
21 | 20 | public class Program { |
@@ -1,8 +1,14 | |||
|
1 | 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 | 11 | <PropertyGroup> |
|
4 | <TargetFramework>netcoreapp2.1</TargetFramework> | |
|
5 | ||
|
6 | 12 | <IsPackable>false</IsPackable> |
|
7 | 13 | </PropertyGroup> |
|
8 | 14 |
@@ -4,38 +4,26 using System.Threading.Tasks; | |||
|
4 | 4 | using Implab.Components; |
|
5 | 5 | using Xunit; |
|
6 | 6 | |
|
7 | namespace Implab.Test | |
|
8 | { | |
|
9 | class TimeLog : PollingComponent { | |
|
10 | public TimeLog() : base(true) { | |
|
11 | } | |
|
7 | namespace Implab.Test { | |
|
12 | 8 | |
|
13 | protected override Task Poll(CancellationToken ct) { | |
|
14 | Console.WriteLine("Poll"); | |
|
15 | return Task.CompletedTask; | |
|
16 | } | |
|
17 | } | |
|
18 | ||
|
19 | public class UnitTest1 | |
|
20 | { | |
|
9 | public class RunnableComponentTests { | |
|
21 | 10 | [Fact] |
|
22 | public async Task Test1() | |
|
23 | { | |
|
11 | public async Task Test1() { | |
|
24 | 12 | |
|
25 |
using(var |
|
|
26 | tl.StateChanged += (self, args) => Console.WriteLine("{0}", args.State); | |
|
27 | tl.Delay = 1000; | |
|
28 | tl.Interval = 500; | |
|
29 | ||
|
13 | using (var m = new MockPollComponent(true)) { | |
|
14 | m.StartWorker = async (ct) => await Task.Yield(); | |
|
15 | m.StopWorker = async (ct) => await Task.Yield(); | |
|
30 | 16 | |
|
31 | tl.Start(CancellationToken.None); | |
|
32 |
|
|
|
17 | Assert.Equal(ExecutionState.Ready, m.State); | |
|
18 | Assert.NotNull(m.Completion); | |
|
33 | 19 | |
|
34 | await Task.Delay(2000); | |
|
20 | m.Start(CancellationToken.None); | |
|
21 | await m.Completion; | |
|
22 | Assert.Equal(ExecutionState.Running, m.State); | |
|
35 | 23 | |
|
36 |
|
|
|
37 |
await |
|
|
38 | await Task.Delay(3000); | |
|
24 | m.Stop(CancellationToken.None); | |
|
25 | await m.Completion; | |
|
26 | Assert.Equal(ExecutionState.Stopped, m.State); | |
|
39 | 27 | } |
|
40 | 28 | } |
|
41 | 29 | } |
@@ -50,7 +50,7 namespace Implab.Components { | |||
|
50 | 50 | try { |
|
51 | 51 | // await for pending poll |
|
52 | 52 | await m_poll; |
|
53 |
} catch (OperationCanceledException |
|
|
53 | } catch (OperationCanceledException) { | |
|
54 | 54 | // OK |
|
55 | 55 | } |
|
56 | 56 | } |
@@ -71,12 +71,16 namespace Implab.Components { | |||
|
71 | 71 | try { |
|
72 | 72 | m_pending.Start(); |
|
73 | 73 | await m_poll; |
|
74 | ScheduleNextPoll(Interval); | |
|
74 | 75 | } catch (Exception e) { |
|
75 | 76 | UnhandledException.DispatchEvent(this, new UnhandledExceptionEventArgs(e, false)); |
|
77 | ||
|
76 | 78 | if (FailOnError) |
|
77 | 79 | Fail(e); |
|
80 | else | |
|
81 | ScheduleNextPoll(Interval); | |
|
78 | 82 | } |
|
79 | ScheduleNextPoll(Interval); | |
|
83 | ||
|
80 | 84 | } |
|
81 | 85 | |
|
82 | 86 | protected override void Dispose(bool disposing) { |
@@ -319,6 +319,7 namespace Implab.Components { | |||
|
319 | 319 | MoveSuccess(cookie); |
|
320 | 320 | } catch (Exception e) { |
|
321 | 321 | MoveFailed(e, cookie); |
|
322 | throw; | |
|
322 | 323 | } |
|
323 | 324 | }, ct); |
|
324 | 325 |
@@ -13,7 +13,7 namespace Implab { | |||
|
13 | 13 | m_promise = new Promise(); |
|
14 | 14 | } |
|
15 | 15 | |
|
16 |
internal Deferred(Promise promise |
|
|
16 | internal Deferred(Promise promise) { | |
|
17 | 17 | Debug.Assert(promise != null); |
|
18 | 18 | m_promise = promise; |
|
19 | 19 | } |
@@ -8,9 +8,12 | |||
|
8 | 8 | and SharedLock, Trace helpers on top of System.Diagnostics, ObjectPool etc. |
|
9 | 9 | </Description> |
|
10 | 10 | <Copyright>2012-2018 Sergey Smirnov</Copyright> |
|
11 | <LicenseUrl>https://opensource.org/licenses/BSD-2-Clause</LicenseUrl> | |
|
12 | <ProjectUrl>https://implab.org</ProjectUrl> | |
|
11 | <Version>3.0.6</Version> | |
|
12 | <PackageLicenseUrl>https://opensource.org/licenses/BSD-2-Clause</PackageLicenseUrl> | |
|
13 | <PackageProjectUrl>https://implab.org</PackageProjectUrl> | |
|
13 | 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 | 17 | <TargetFrameworks>netstandard2.0;net46</TargetFrameworks> |
|
15 | 18 | <FrameworkPathOverride Condition="'$(TargetFramework)'=='net46' and '$(OSTYPE)'=='linux'">/usr/lib/mono/4.5/</FrameworkPathOverride> |
|
16 | 19 | <DefineConstants Condition="'$(TargetFramework)'=='net46'">NETFX_TRACE_BUG;$(DefineConstants)</DefineConstants> |
@@ -2,6 +2,7 | |||
|
2 | 2 | using System.Collections.Generic; |
|
3 | 3 | using System.Diagnostics; |
|
4 | 4 | using System.Reflection; |
|
5 | using System.Threading; | |
|
5 | 6 | using System.Threading.Tasks; |
|
6 | 7 | using Implab.Parallels; |
|
7 | 8 | |
@@ -152,31 +153,44 namespace Implab { | |||
|
152 | 153 | } |
|
153 | 154 | |
|
154 | 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(); | |
|
158 | var d = new Deferred(p, DefaultDispatcher); | |
|
159 | public static IPromise Create(PromiseExecutor executor, CancellationToken ct) { | |
|
160 | Safe.ArgumentNotNull(executor, nameof(executor)); | |
|
161 | if (!ct.CanBeCanceled) | |
|
162 | return Create(executor); | |
|
163 | ||
|
164 | var d = new Deferred(); | |
|
165 | ||
|
166 | ct.Register(d.Cancel); | |
|
159 | 167 | |
|
160 | 168 | try { |
|
169 | if (!ct.IsCancellationRequested) | |
|
161 | 170 | executor(d); |
|
162 | 171 |
} catch |
|
163 | 172 | d.Reject(e); |
|
164 | 173 | } |
|
165 | ||
|
166 | 174 | return d.Promise; |
|
167 | 175 | } |
|
168 | 176 | |
|
169 | 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 | 182 | Safe.ArgumentNotNull(executor, nameof(executor)); |
|
171 | 183 | |
|
172 | 184 | var d = new Deferred<T>(); |
|
173 | 185 | |
|
186 | ct.Register(d.Cancel); | |
|
187 | ||
|
174 | 188 | try { |
|
189 | if (!ct.IsCancellationRequested) | |
|
175 | 190 | executor(d); |
|
176 | 191 |
} catch |
|
177 | 192 | d.Reject(e); |
|
178 | 193 | } |
|
179 | ||
|
180 | 194 | return d.Promise; |
|
181 | 195 | } |
|
182 | 196 |
|
1 | 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