Mercurial > pub > ImplabNet
changeset 260:547a2fc0d93e v3 v3.0.6
minor fixes
author | cin |
---|---|
date | Fri, 13 Apr 2018 19:14:59 +0300 |
parents | 7d52dc684bbd |
children | 05a87f575512 |
files | Implab.Playground/Implab.Playground.csproj Implab.Playground/Program.cs Implab.Playground/Properties/AssemblyInfo.cs Implab.Test/Implab.Test.csproj Implab.Test/MockPollComponent.cs Implab.Test/RunnableComponentTests.cs Implab/Components/PollingComponent.cs Implab/Components/RunnableComponent.cs Implab/Deferred.cs Implab/Implab.csproj Implab/Promise.cs |
diffstat | 11 files changed, 111 insertions(+), 146 deletions(-) [+] |
line wrap: on
line diff
--- a/Implab.Playground/Implab.Playground.csproj Fri Apr 13 03:57:39 2018 +0300 +++ b/Implab.Playground/Implab.Playground.csproj Fri Apr 13 19:14:59 2018 +0300 @@ -1,69 +1,20 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> - <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProjectGuid>{100DFEB0-75BE-436F-ADDF-1F46EF433F46}</ProjectGuid> - <OutputType>Exe</OutputType> - <AppDesignerFolder>Properties</AppDesignerFolder> - <RootNamespace>Implab.Playground</RootNamespace> - <AssemblyName>Implab.Playground</AssemblyName> - <TargetFrameworkVersion>v4.6</TargetFrameworkVersion> - <FileAlignment>512</FileAlignment> - <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> - <TargetFrameworkProfile /> +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup Condition="'$(OSTYPE)'=='linux'"> + <TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks> + <FrameworkPathOverride Condition="'$(TargetFramework)'=='net46'">/usr/lib/mono/4.6-api/</FrameworkPathOverride> </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - <PlatformTarget>AnyCPU</PlatformTarget> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>bin\Debug\</OutputPath> - <DefineConstants>DEBUG;TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> + + <PropertyGroup Condition="'$(OSTYPE)'=='windows'"> + <TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks> </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <PlatformTarget>AnyCPU</PlatformTarget> - <DebugType>pdbonly</DebugType> - <Optimize>true</Optimize> - <OutputPath>bin\Release\</OutputPath> - <DefineConstants>TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - <Prefer32Bit>true</Prefer32Bit> - <DebugSymbols>true</DebugSymbols> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <IsPackable>false</IsPackable> </PropertyGroup> - <ItemGroup> - <Reference Include="System" /> - <Reference Include="System.Core" /> - <Reference Include="System.Xml.Linq" /> - <Reference Include="System.Data.DataSetExtensions" /> - <Reference Include="Microsoft.CSharp" /> - <Reference Include="System.Data" /> - <Reference Include="System.Net.Http" /> - <Reference Include="System.Xml" /> - </ItemGroup> + <ItemGroup> - <Compile Include="Program.cs" /> - <Compile Include="Properties\AssemblyInfo.cs" /> - </ItemGroup> - <ItemGroup> - <None Include="App.config" /> + <ProjectReference Include="../Implab/Implab.csproj"/> </ItemGroup> - <ItemGroup> - <ProjectReference Include="..\Implab\Implab.csproj"> - <Project>{f550f1f8-8746-4ad0-9614-855f4c4b7f05}</Project> - <Name>Implab</Name> - </ProjectReference> - </ItemGroup> - <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> - <!-- To modify your build process, add your task inside one of the targets below and uncomment it. - Other similar extension points exist, see Microsoft.Common.targets. - <Target Name="BeforeBuild"> - </Target> - <Target Name="AfterBuild"> - </Target> - --> -</Project> \ No newline at end of file + +</Project>
--- a/Implab.Playground/Program.cs Fri Apr 13 03:57:39 2018 +0300 +++ b/Implab.Playground/Program.cs Fri Apr 13 19:14:59 2018 +0300 @@ -15,7 +15,6 @@ namespace Implab.Playground { using System.Diagnostics; - using System.Runtime.Remoting.Messaging; using static Trace<Program>; public class Program {
--- a/Implab.Playground/Properties/AssemblyInfo.cs Fri Apr 13 03:57:39 2018 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Implab.Playground")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Implab.Playground")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("100dfeb0-75be-436f-addf-1f46ef433f46")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")]
--- a/Implab.Test/Implab.Test.csproj Fri Apr 13 03:57:39 2018 +0300 +++ b/Implab.Test/Implab.Test.csproj Fri Apr 13 19:14:59 2018 +0300 @@ -1,8 +1,14 @@ <Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup Condition="'$(OSTYPE)'=='linux'"> + <TargetFrameworks>netcoreapp2.0</TargetFrameworks> + <FrameworkPathOverride Condition="'$(TargetFramework)'=='net46'">/usr/lib/mono/4.5/</FrameworkPathOverride> + </PropertyGroup> + + <PropertyGroup Condition="'$(OSTYPE)'=='windows'"> + <TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks> + </PropertyGroup> <PropertyGroup> - <TargetFramework>netcoreapp2.1</TargetFramework> - <IsPackable>false</IsPackable> </PropertyGroup> @@ -13,5 +19,5 @@ <ProjectReference Include="../Implab/Implab.csproj"/> <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /> </ItemGroup> - + </Project>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Implab.Test/MockPollComponent.cs Fri Apr 13 19:14:59 2018 +0300 @@ -0,0 +1,35 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using Implab.Components; + +namespace Implab.Test { + public class MockPollComponent : PollingComponent { + + public Func<CancellationToken,Task> PollWorker { get; set;} + + public Func<CancellationToken, Task> StartWorker { get; set; } + + public Func<CancellationToken, Task> StopWorker { get; set; } + + public MockPollComponent(bool initialized) : base(initialized) { + } + + protected async override Task Poll(CancellationToken ct) { + if(PollWorker!= null) + await PollWorker.Invoke(ct); + } + + protected async override Task StopInternalAsync(CancellationToken ct) { + if (StopWorker != null) + await StopWorker.Invoke(ct); + } + + protected async override Task StartInternalAsync(CancellationToken ct) { + if (StartWorker != null) + await StartWorker.Invoke(ct); + } + + + } +} \ No newline at end of file
--- a/Implab.Test/RunnableComponentTests.cs Fri Apr 13 03:57:39 2018 +0300 +++ b/Implab.Test/RunnableComponentTests.cs Fri Apr 13 19:14:59 2018 +0300 @@ -4,38 +4,26 @@ using Implab.Components; using Xunit; -namespace Implab.Test -{ - class TimeLog : PollingComponent { - public TimeLog() : base(true) { - } +namespace Implab.Test { - protected override Task Poll(CancellationToken ct) { - Console.WriteLine("Poll"); - return Task.CompletedTask; - } - } - - public class UnitTest1 - { + public class RunnableComponentTests { [Fact] - public async Task Test1() - { + public async Task Test1() { - using(var tl = new TimeLog()) { - tl.StateChanged += (self, args) => Console.WriteLine("{0}", args.State); - tl.Delay = 1000; - tl.Interval = 500; + using (var m = new MockPollComponent(true)) { + m.StartWorker = async (ct) => await Task.Yield(); + m.StopWorker = async (ct) => await Task.Yield(); + Assert.Equal(ExecutionState.Ready, m.State); + Assert.NotNull(m.Completion); - tl.Start(CancellationToken.None); - await tl.Completion; + m.Start(CancellationToken.None); + await m.Completion; + Assert.Equal(ExecutionState.Running, m.State); - await Task.Delay(2000); - - tl.Stop(CancellationToken.None); - await tl.Completion; - await Task.Delay(3000); + m.Stop(CancellationToken.None); + await m.Completion; + Assert.Equal(ExecutionState.Stopped, m.State); } } }
--- a/Implab/Components/PollingComponent.cs Fri Apr 13 03:57:39 2018 +0300 +++ b/Implab/Components/PollingComponent.cs Fri Apr 13 19:14:59 2018 +0300 @@ -50,7 +50,7 @@ try { // await for pending poll await m_poll; - } catch (OperationCanceledException e) { + } catch (OperationCanceledException) { // OK } } @@ -71,12 +71,16 @@ try { m_pending.Start(); await m_poll; + ScheduleNextPoll(Interval); } catch (Exception e) { UnhandledException.DispatchEvent(this, new UnhandledExceptionEventArgs(e, false)); + if (FailOnError) Fail(e); + else + ScheduleNextPoll(Interval); } - ScheduleNextPoll(Interval); + } protected override void Dispose(bool disposing) {
--- a/Implab/Components/RunnableComponent.cs Fri Apr 13 03:57:39 2018 +0300 +++ b/Implab/Components/RunnableComponent.cs Fri Apr 13 19:14:59 2018 +0300 @@ -319,6 +319,7 @@ MoveSuccess(cookie); } catch (Exception e) { MoveFailed(e, cookie); + throw; } }, ct);
--- a/Implab/Deferred.cs Fri Apr 13 03:57:39 2018 +0300 +++ b/Implab/Deferred.cs Fri Apr 13 19:14:59 2018 +0300 @@ -13,7 +13,7 @@ m_promise = new Promise(); } - internal Deferred(Promise promise, IDispatcher dispatcher) { + internal Deferred(Promise promise) { Debug.Assert(promise != null); m_promise = promise; }
--- a/Implab/Implab.csproj Fri Apr 13 03:57:39 2018 +0300 +++ b/Implab/Implab.csproj Fri Apr 13 19:14:59 2018 +0300 @@ -8,9 +8,12 @@ and SharedLock, Trace helpers on top of System.Diagnostics, ObjectPool etc. </Description> <Copyright>2012-2018 Sergey Smirnov</Copyright> - <LicenseUrl>https://opensource.org/licenses/BSD-2-Clause</LicenseUrl> - <ProjectUrl>https://implab.org</ProjectUrl> + <Version>3.0.6</Version> + <PackageLicenseUrl>https://opensource.org/licenses/BSD-2-Clause</PackageLicenseUrl> + <PackageProjectUrl>https://implab.org</PackageProjectUrl> <RepositoryUrl>https://hg.implab.org/pub/ImplabNet/</RepositoryUrl> + <RepositoryType>mercurial</RepositoryType> + <PackageTags>IMPLAB;Json pull-parser;Json Xml;async;diagnostics;serialization;</PackageTags> <TargetFrameworks>netstandard2.0;net46</TargetFrameworks> <FrameworkPathOverride Condition="'$(TargetFramework)'=='net46' and '$(OSTYPE)'=='linux'">/usr/lib/mono/4.5/</FrameworkPathOverride> <DefineConstants Condition="'$(TargetFramework)'=='net46'">NETFX_TRACE_BUG;$(DefineConstants)</DefineConstants>
--- a/Implab/Promise.cs Fri Apr 13 03:57:39 2018 +0300 +++ b/Implab/Promise.cs Fri Apr 13 19:14:59 2018 +0300 @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Reflection; +using System.Threading; using System.Threading.Tasks; using Implab.Parallels; @@ -152,31 +153,44 @@ } public static IPromise Create(PromiseExecutor executor) { - Safe.ArgumentNotNull(executor, nameof(executor)); + return Create(executor, CancellationToken.None); + } - var p = new Promise(); - var d = new Deferred(p, DefaultDispatcher); - + public static IPromise Create(PromiseExecutor executor, CancellationToken ct) { + Safe.ArgumentNotNull(executor, nameof(executor)); + if (!ct.CanBeCanceled) + return Create(executor); + + var d = new Deferred(); + + ct.Register(d.Cancel); + try { - executor(d); - } catch (Exception e) { + if (!ct.IsCancellationRequested) + executor(d); + } catch(Exception e) { d.Reject(e); } - return d.Promise; } public static IPromise<T> Create<T>(PromiseExecutor<T> executor) { + return Create(executor, CancellationToken.None); + } + + public static IPromise<T> Create<T>(PromiseExecutor<T> executor, CancellationToken ct) { Safe.ArgumentNotNull(executor, nameof(executor)); var d = new Deferred<T>(); - + + ct.Register(d.Cancel); + try { - executor(d); - } catch (Exception e) { + if (!ct.IsCancellationRequested) + executor(d); + } catch(Exception e) { d.Reject(e); } - return d.Promise; }