Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HistoricalScheduling", "HistoricalScheduling\HistoricalScheduling.csproj", "{C5D62A31-BE20-4FD1-84A1-45984F22A427}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C5D62A31-BE20-4FD1-84A1-45984F22A427}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C5D62A31-BE20-4FD1-84A1-45984F22A427}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C5D62A31-BE20-4FD1-84A1-45984F22A427}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C5D62A31-BE20-4FD1-84A1-45984F22A427}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

View File

@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.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>{C5D62A31-BE20-4FD1-84A1-45984F22A427}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HistoricalScheduling</RootNamespace>
<AssemblyName>HistoricalScheduling</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</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>
<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>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Reactive.Core, Version=2.0.20905.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\System.Reactive.Core.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Interfaces, Version=2.0.20905.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\System.Reactive.Interfaces.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Linq, Version=2.0.20905.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\System.Reactive.Linq.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.PlatformServices, Version=2.0.20905.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\System.Reactive.PlatformServices.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</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>

View File

@@ -0,0 +1,151 @@
using System;
using System.Collections.Generic;
using System.Reactive;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Reactive.Subjects;
namespace HistoricalScheduling
{
class Program
{
static void Main(string[] args)
{
var log = new LogScheduler<int>(GetLog());
log.Process((xs, s) =>
{
var res0 = xs.Timestamp(s);
res0.Subscribe(t => Console.WriteLine("0> " + t));
var res1 = xs.Where(x => x % 2 != 0).Timestamp(s);
res1.Subscribe(t => Console.WriteLine("1> " + t));
var res2 = xs.Buffer(TimeSpan.FromDays(63), s).Select(b => b.Count).Timestamp(s);
res2.Subscribe(t => Console.WriteLine("2> " + t));
var res3 = Observable.Interval(TimeSpan.FromDays(1), s).TakeUntil(new DateTimeOffset(2013, 1, 1, 12, 0, 0, TimeSpan.Zero), s).Select(_ => s.Clock);
res3.Subscribe(t =>
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("It's now " + t);
Console.ResetColor();
});
//
// If the end of the log should cause the scheduler to stop, add the following line:
//
// xs.Subscribe(_ => { }, s.Stop);
});
}
static IEnumerable<Timestamped<int>> GetLog()
{
for (int i = 1; i <= 12; i++)
{
var date = new DateTimeOffset(2012, i, 1, 12, 0, 0, TimeSpan.Zero);
var value = i * i;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Log read for {0} - Value = {1}", date, value);
Console.ResetColor();
yield return new Timestamped<int>(i * i, date);
}
}
}
class LogScheduler<T>
{
private readonly IEnumerable<Timestamped<T>> _source;
public LogScheduler(IEnumerable<Timestamped<T>> source)
{
_source = source;
}
public void Process(Action<IObservable<T>, HistoricalScheduler> query)
{
var enumerator = _source.GetEnumerator();
var scheduler = new Scheduler(enumerator);
query(scheduler.Source, scheduler);
scheduler.Start();
}
class Scheduler : HistoricalScheduler
{
private readonly Subject<T> _subject = new Subject<T>();
private readonly IEnumerator<Timestamped<T>> _enumerator;
public Scheduler(IEnumerator<Timestamped<T>> enumerator)
{
_enumerator = enumerator;
MoveNext(true);
}
public Scheduler(IEnumerator<Timestamped<T>> enumerator, DateTimeOffset startTime)
{
_enumerator = enumerator;
this.AdvanceTo(startTime);
MoveNext();
}
public void MoveNext(bool initializeInitialTimeFromLog = false)
{
var nextLog = default(Timestamped<T>);
if (TryMoveNext(out nextLog))
{
if (initializeInitialTimeFromLog)
this.AdvanceTo(nextLog.Timestamp);
ScheduleOnNext(nextLog);
}
else
{
this.Schedule(_subject.OnCompleted);
}
}
public IObservable<T> Source
{
get { return _subject.AsObservable(); }
}
private bool TryMoveNext(out Timestamped<T> value)
{
try
{
if (_enumerator.MoveNext())
{
value = _enumerator.Current;
return true;
}
}
catch
{
_enumerator.Dispose();
throw;
}
_enumerator.Dispose();
value = default(Timestamped<T>);
return false;
}
private void ScheduleOnNext(Timestamped<T> value)
{
this.Schedule(value.Timestamp, () =>
{
_subject.OnNext(value.Value);
MoveNext();
});
}
}
}
}

View File

@@ -0,0 +1,36 @@
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("HistoricalScheduling")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HistoricalScheduling")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[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("a83a7d41-910c-4168-b811-ba6f5fd06767")]
// 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")]

View File

@@ -0,0 +1 @@
f767bb9aa09536eee642a3380bffe7c535560a55

View File

@@ -0,0 +1 @@
cd601f8c50db07a389b4babbbdd49bced6f2f417