public void BuildWithoutTimeline() { var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null); var builder = new ProjectBuilder(); var offline = new Mock <IDatasetOfflineInformation>(); var plan = new DistributionPlan( (p, t, r) => new Task <DatasetOnlineInformation>( () => new DatasetOnlineInformation( new DatasetId(), new EndpointId("id"), new NetworkIdentifier("machine"), new Mock <ISendCommandsToRemoteEndpoints>().Object, new Mock <INotifyOfRemoteEndpointEvents>().Object, systemDiagnostics), t), offline.Object, new NetworkIdentifier("mymachine"), new DatasetActivationProposal()); Func <DatasetActivationRequest, CancellationToken, IEnumerable <DistributionPlan> > distributor = (r, c) => new List <DistributionPlan> { plan }; Assert.Throws <CannotCreateProjectWithoutTimelineException>(() => builder.WithDatasetDistributor(distributor).Build()); }
private void HandleOnIsActivatedUpdate(object sender, EventArgs e) { // See if the restored status still matches up with the online status of the dataset // If not make sure that it does if (m_DistributionLocation.Current != null) { if (m_Connection == null) { // For now we go with the naive approach. Distribute onto the same machine as last time // and if we can't find it then grab the first machine in the selection. // At some point we should make this a whole lot smarter but for now it'll do. var original = m_DistributionLocation.Current; m_Diagnostics.Log( LevelToLog.Trace, HostConstants.LogPrefix, string.Format( CultureInfo.InvariantCulture, Resources.DatasetProxy_LogMessage_ReactivatingFromPreviouslyStoredLocation_WithLocation, Id, original)); Func <IEnumerable <DistributionSuggestion>, SelectedProposal> selector = c => { var selected = from suggestion in c where suggestion.Plan.MachineToDistributeTo.Equals(original) select suggestion; DistributionPlan plan = selected.Any() ? selected.First().Plan : c.Any() ? c.First().Plan : null; return(new SelectedProposal(plan)); }; var source = new CancellationTokenSource(); var activationTask = Activate( DistributionLocations.All, selector, m_Notifications, source.Token, false); activationTask.ContinueWith(t => source.Dispose()); } } else { if (m_Connection != null) { Deactivate(false); } } }
public void Summary() { ITimeline timeline = null; timeline = new Timeline(t => BuildStorage(timeline, t)); var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null); var offline = new Mock <IDatasetOfflineInformation>(); var plan = new DistributionPlan( (p, t, r) => Task <DatasetOnlineInformation> .Factory.StartNew( () => new DatasetOnlineInformation( new DatasetId(), new EndpointId("id"), new NetworkIdentifier("machine"), new Mock <ISendCommandsToRemoteEndpoints>().Object, new Mock <INotifyOfRemoteEndpointEvents>().Object, systemDiagnostics), t, TaskCreationOptions.None, new CurrentThreadTaskScheduler()), offline.Object, new NetworkIdentifier("mymachine"), new DatasetActivationProposal()); Func <DatasetActivationRequest, CancellationToken, IEnumerable <DistributionPlan> > distributor = (r, c) => new List <DistributionPlan> { plan }; var proxyLayer = new Mock <IProxyCompositionLayer>(); var project = new Project( timeline, distributor, d => new DatasetStorageProxy( d, new GroupSelector( new Mock <IConnectGroups>().Object, proxyLayer.Object), proxyLayer.Object), new Mock <ICollectNotifications>().Object, systemDiagnostics); var summary = string.Empty; project.OnSummaryChanged += (s, e) => { summary = e.Value; }; project.Summary = "MyNewName"; Assert.AreEqual(project.Summary, summary); // Set the summary again, to the same thing. This // shouldn't notify summary = string.Empty; project.Summary = "MyNewName"; Assert.AreEqual(string.Empty, summary); }
public void ExportAfterClosing() { ITimeline timeline = null; timeline = new Timeline(t => BuildStorage(timeline, t)); var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null); var offline = new Mock <IDatasetOfflineInformation>(); var plan = new DistributionPlan( (p, t, r) => Task <DatasetOnlineInformation> .Factory.StartNew( () => new DatasetOnlineInformation( new DatasetId(), new EndpointId("id"), new NetworkIdentifier("machine"), new Mock <ISendCommandsToRemoteEndpoints>().Object, new Mock <INotifyOfRemoteEndpointEvents>().Object, systemDiagnostics), t, TaskCreationOptions.None, new CurrentThreadTaskScheduler()), offline.Object, new NetworkIdentifier("mymachine"), new DatasetActivationProposal()); Func <DatasetActivationRequest, CancellationToken, IEnumerable <DistributionPlan> > distributor = (r, c) => new List <DistributionPlan> { plan }; var proxyLayer = new Mock <IProxyCompositionLayer>(); var project = new Project( timeline, distributor, d => new DatasetStorageProxy( d, new GroupSelector( new Mock <IConnectGroups>().Object, proxyLayer.Object), proxyLayer.Object), new Mock <ICollectNotifications>().Object, systemDiagnostics); var dataset = project.BaseDataset(); project.Close(); Assert.Throws <CannotUseProjectAfterClosingItException>( () => project.Export(dataset.Id, false, new Mock <IPersistenceInformation>().Object)); }
public void BuildWithDistributorAndStorage() { ITimeline timeline = new Timeline(BuildStorage); var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null); var offline = new Mock <IDatasetOfflineInformation>(); var builder = new ProjectBuilder(); var plan = new DistributionPlan( (p, t, r) => new Task <DatasetOnlineInformation>( () => new DatasetOnlineInformation( new DatasetId(), new EndpointId("id"), new NetworkIdentifier("machine"), new Mock <ISendCommandsToRemoteEndpoints>().Object, new Mock <INotifyOfRemoteEndpointEvents>().Object, systemDiagnostics), t), offline.Object, new NetworkIdentifier("mymachine"), new DatasetActivationProposal()); Func <DatasetActivationRequest, CancellationToken, IEnumerable <DistributionPlan> > distributor = (r, c) => new List <DistributionPlan> { plan }; var proxyLayer = new Mock <IProxyCompositionLayer>(); var project = builder.Define() .WithTimeline(timeline) .WithDatasetDistributor(distributor) .FromStorage(new Mock <IPersistenceInformation>().Object) .WithDataStorageBuilder( d => new DatasetStorageProxy( d, new GroupSelector( new Mock <IConnectGroups>().Object, proxyLayer.Object), proxyLayer.Object)) .WithNotifications(new Mock <ICollectNotifications>().Object) .WithDiagnostics(systemDiagnostics) .Build(); Assert.IsNotNull(project); }
private static DistributionPlan CreateNewDistributionPlan( DatasetActivationProposal proposal, IDatasetOfflineInformation offlineInfo, SystemDiagnostics systemDiagnostics) { var plan = new DistributionPlan( (p, t, r) => Task <DatasetOnlineInformation> .Factory.StartNew( () => new DatasetOnlineInformation( new DatasetId(), new EndpointId("id"), new NetworkIdentifier("machine"), new Mock <ISendCommandsToRemoteEndpoints>().Object, new Mock <INotifyOfRemoteEndpointEvents>().Object, systemDiagnostics), t), offlineInfo, NetworkIdentifier.ForLocalMachine(), proposal); return(plan); }
public void SaveWithNullPersistenceInformation() { ITimeline timeline = null; timeline = new Timeline(t => BuildStorage(timeline, t)); var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null); var offline = new Mock <IDatasetOfflineInformation>(); var plan = new DistributionPlan( (p, t, r) => new Task <DatasetOnlineInformation>( () => new DatasetOnlineInformation( new DatasetId(), new EndpointId("id"), new NetworkIdentifier("machine"), new Mock <ISendCommandsToRemoteEndpoints>().Object, new Mock <INotifyOfRemoteEndpointEvents>().Object, systemDiagnostics), t), offline.Object, new NetworkIdentifier("mymachine"), new DatasetActivationProposal()); Func <DatasetActivationRequest, CancellationToken, IEnumerable <DistributionPlan> > distributor = (r, c) => new List <DistributionPlan> { plan }; var proxyLayer = new Mock <IProxyCompositionLayer>(); var project = new Project( timeline, distributor, d => new DatasetStorageProxy( d, new GroupSelector( new Mock <IConnectGroups>().Object, proxyLayer.Object), proxyLayer.Object), new Mock <ICollectNotifications>().Object, systemDiagnostics); Assert.Throws <ArgumentNullException>(() => project.Save(null)); }
/// <summary> /// Initializes a new instance of the <see cref="SelectedProposal"/> class. /// </summary> /// <param name="plan">The selected plan.</param> public SelectedProposal(DistributionPlan plan) { WasSelectionCanceled = plan == null; Plan = plan; }
public void RollForwardWithDeletesOnly() { ITimeline timeline = null; timeline = new Timeline(t => BuildStorage(timeline, t)); var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null); var offline = new Mock <IDatasetOfflineInformation>(); var plan = new DistributionPlan( (p, t, r) => Task <DatasetOnlineInformation> .Factory.StartNew( () => new DatasetOnlineInformation( new DatasetId(), new EndpointId("id"), new NetworkIdentifier("machine"), new Mock <ISendCommandsToRemoteEndpoints>().Object, new Mock <INotifyOfRemoteEndpointEvents>().Object, systemDiagnostics), t, TaskCreationOptions.None, new CurrentThreadTaskScheduler()), offline.Object, new NetworkIdentifier("mymachine"), new DatasetActivationProposal()); Func <DatasetActivationRequest, CancellationToken, IEnumerable <DistributionPlan> > distributor = (r, c) => new List <DistributionPlan> { plan }; var proxyLayer = new Mock <IProxyCompositionLayer>(); var project = new Project( timeline, distributor, d => new DatasetStorageProxy( d, new GroupSelector( new Mock <IConnectGroups>().Object, proxyLayer.Object), proxyLayer.Object), new Mock <ICollectNotifications>().Object, systemDiagnostics); // Create a 'binary' tree of datasets. This should create the following tree: // X // / \ // / \ // / \ // / \ // / \ // X X // / \ / \ // / \ / \ // / \ / \ // X X X X // / \ / \ // X X X X var children = new List <DatasetId>(); var datasets = new Queue <IProxyDataset>(); var root = project.BaseDataset(); datasets.Enqueue(root); int count = 0; while (count < 10) { var creationInformation = new DatasetCreationInformation() { CreatedOnRequestOf = DatasetCreator.User, CanBecomeParent = true, CanBeAdopted = false, CanBeCopied = false, CanBeDeleted = true, LoadFrom = new Mock <IPersistenceInformation>().Object, }; var parent = datasets.Dequeue(); var newChildren = parent.CreateNewChildren(new DatasetCreationInformation[] { creationInformation, creationInformation }); foreach (var child in newChildren) { datasets.Enqueue(child); children.Add(child.Id); count++; } } var marks = new List <TimeMarker>(); marks.Add(project.History.Mark()); for (int i = children.Count - 1; i > -1; i--) { var child = project.Dataset(children[i]); child.Delete(); marks.Add(project.History.Mark()); } project.History.RollBackTo(marks[0]); for (int i = 1; i < marks.Count; i++) { project.History.RollForwardTo(marks[i]); Assert.AreEqual(children.Count - i + 1, project.NumberOfDatasets); for (int j = 0; j < children.Count; j++) { var child = project.Dataset(children[j]); if (j < children.Count - i) { Assert.IsTrue(child.IsValid); } else { Assert.IsNull(child); } } } }
/// <summary> /// Initializes a new instance of the <see cref="SelectedProposal"/> class. /// </summary> /// <param name="plan">The selected plan.</param> public SelectedProposal(DistributionPlan plan) { WasSelectionCanceled = plan == null; Plan = plan; }