Пример #1
0
        /// <summary>
        /// Adds a new child.
        /// </summary>
        /// <param name="persistenceInformation">The persistence information that describes the dataset that should be copied.</param>
        /// <returns>
        /// The newly created dataset.
        /// </returns>
        public DatasetFacade AddChild(IPersistenceInformation persistenceInformation)
        {
            {
                Enforce.Argument(() => persistenceInformation);
            }

            // For user created datasets we have some default settings:
            // - We don't ever allow nodes to be adopted, it just creates too much of a hassle with
            //   updating the node links etc.
            // - We always allow user created datasets to become parents, they may need to split
            //   of their calculations
            // - We allow all user created datasets to be copied
            // - User created datasets can always be deleted
            var creationInformation = new DatasetCreationInformation
            {
                CanBeAdopted       = false,
                CanBecomeParent    = true,
                CanBeCopied        = true,
                CanBeDeleted       = true,
                CreatedOnRequestOf = DatasetCreator.User,
                LoadFrom           = persistenceInformation,
            };

            var child = m_Dataset.CreateNewChild(creationInformation);

            return(new DatasetFacade(child));
        }
Пример #2
0
        /// <summary>
        /// Loads a new project from the given resource stream.
        /// </summary>
        /// <param name="persistenceInformation">The object that describes how the project was persisted.</param>
        public void LoadProject(IPersistenceInformation persistenceInformation)
        {
            if (!CanLoadProject())
            {
                throw new CannotLoadProjectException();
            }

            var context = new LoadProjectContext
            {
                LoadFrom = persistenceInformation
            };

            Debug.Assert(m_Service.Contains(LoadProjectCommand.CommandId), "A command has gone missing.");
            m_Service.Invoke(LoadProjectCommand.CommandId, context);

            var project = context.Result;

            if (project == null)
            {
                throw new FailedToLoadProjectException();
            }

            m_Facade = new ProjectFacade(project.Result);

            RaiseOnNewProjectLoaded();
        }
Пример #3
0
        /// <summary>
        /// Saves the existing project.
        /// </summary>
        /// <param name="projectFacade">The object that contains the methods that allow interaction with the project system.</param>
        /// <param name="persistenceInformation">The object that describes how the project should be persisted.</param>
        /// <param name="timer">The function that creates and stores timing intervals.</param>
        private static void OnSaveProject(
            ILinkToProjects projectFacade,
            IPersistenceInformation persistenceInformation,
            Func <string, IDisposable> timer)
        {
            // If there is no facade then we're in design mode or something
            // else weird.
            if (projectFacade == null)
            {
                return;
            }

            if (!projectFacade.HasActiveProject())
            {
                return;
            }

            using (timer("Saving project"))
            {
                var project = projectFacade.ActiveProject();
                project.SaveProject(persistenceInformation);

                projectFacade.ActiveProject().History.Mark(Resources.SaveProjectCommand_HistoryMark);
            }
        }
Пример #4
0
        /// <summary>
        /// Creates a new project definition object.
        /// </summary>
        /// <returns>
        /// The current builder instance with all the storage cleared.
        /// </returns>
        public IBuildProjects Define()
        {
            m_Distributor    = null;
            m_ProjectStorage = null;

            return(this);
        }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Project"/> class.
        /// </summary>
        /// <param name="timeline">The timeline for the current project.</param>
        /// <param name="distributor">
        /// The function which returns a <see cref="DistributionPlan"/> for a given
        /// <see cref="DatasetActivationRequest"/>.
        /// </param>
        /// <param name="dataStorageProxyBuilder">The function which returns a storage proxy for a newly loaded dataset.</param>
        /// <param name="notifications">The object that stores the notifications for the user interface.</param>
        /// <param name="diagnostics">The object that provides the diagnostics methods for the application.</param>
        /// <param name="persistenceInfo">
        /// The object that describes how the project was persisted.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="timeline"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when <paramref name="distributor"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when <paramref name="dataStorageProxyBuilder"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when <paramref name="notifications"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when <paramref name="diagnostics"/> is <see langword="null" />.
        /// </exception>
        public Project(
            ITimeline timeline,
            Func <DatasetActivationRequest, CancellationToken, IEnumerable <DistributionPlan> > distributor,
            Func <DatasetOnlineInformation, DatasetStorageProxy> dataStorageProxyBuilder,
            ICollectNotifications notifications,
            SystemDiagnostics diagnostics,
            IPersistenceInformation persistenceInfo)
        {
            {
                Lokad.Enforce.Argument(() => timeline);
                Lokad.Enforce.Argument(() => distributor);
                Lokad.Enforce.Argument(() => dataStorageProxyBuilder);
                Lokad.Enforce.Argument(() => notifications);
                Lokad.Enforce.Argument(() => diagnostics);
            }

            m_Timeline = timeline;
            m_Timeline.ForgetAllHistory();

            m_Timeline.OnRolledBack    += OnTimelineRolledBack;
            m_Timeline.OnRolledForward += OnTimelineRolledForward;

            m_ProjectInformation = m_Timeline.AddToTimeline(ProjectHistoryStorage.CreateInstance);
            m_Datasets           = m_Timeline.AddToTimeline(DatasetHistoryStorage.CreateInstance);

            m_DatasetDistributor      = distributor;
            m_DataStorageProxyBuilder = dataStorageProxyBuilder;

            m_Notifications = notifications;
            m_Diagnostics   = diagnostics;

            if (persistenceInfo != null)
            {
                RestoreFromStore(persistenceInfo);
            }

            // Create a root dataset if there isn't one
            if (m_RootDataset == null)
            {
                var dataset = CreateDataset(
                    null,
                    new DatasetCreationInformation
                {
                    CreatedOnRequestOf = DatasetCreator.System,
                    LoadFrom           = new NullPersistenceInformation(),
                    CanBeDeleted       = false,
                    CanBeCopied        = false,
                    CanBecomeParent    = true,
                    CanBeAdopted       = false,
                    IsRoot             = true,
                });

                m_RootDataset   = dataset.Id;
                dataset.Name    = Resources.Projects_Dataset_RootDatasetName;
                dataset.Summary = Resources.Projects_Dataset_RootDatasetSummary;
            }

            m_Timeline.SetCurrentAsDefault();
        }
Пример #6
0
 /// <summary>
 /// Saves the current project.
 /// </summary>
 /// <param name="persistenceInformation">The object that describes how the project should be persisted.</param>
 public void SaveProject(IPersistenceInformation persistenceInformation)
 {
     if (m_Current != null)
     {
         m_Current.Save(persistenceInformation);
         HasProjectChanged = false;
     }
 }
Пример #7
0
        /// <summary>
        /// Provides the <see cref="Stream"/> from which the project must be loaded.
        /// </summary>
        /// <param name="persistenceInfo">
        /// The object that describes how the project was persisted.
        /// </param>
        /// <returns>
        /// The current builder instance with the stream containing the project stored.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="persistenceInfo"/> is <see langword="null" />.
        /// </exception>
        public IBuildProjects FromStorage(IPersistenceInformation persistenceInfo)
        {
            {
                Lokad.Enforce.Argument(() => persistenceInfo);
            }

            m_ProjectStorage = persistenceInfo;
            return(this);
        }
Пример #8
0
        /// <summary>
        /// Saves the project and all the datasets to the given stream.
        /// </summary>
        /// <param name="persistenceInfo">
        /// The object that describes how the project should be persisted.
        /// </param>
        /// <remarks>
        /// Note that saving project and dataset information to a stream on the local machine may take
        /// some time because the datasets may be large, reside on a remote machine or both.
        /// </remarks>
        public void Save(IPersistenceInformation persistenceInfo)
        {
            {
                Lokad.Enforce.With <CannotUseProjectAfterClosingItException>(
                    !IsClosed,
                    Resources.Exceptions_Messages_CannotUseProjectAfterClosingIt);
                Lokad.Enforce.Argument(() => persistenceInfo);
            }

            // Do we need to have a save flag that we can set to prevent closing from happening
            // while saving?
            throw new NotImplementedException();
        }
Пример #9
0
        /// <summary>
        /// Loads a new project.
        /// </summary>
        /// <param name="projectFacade">The object that contains the methods that allow interaction with the project system.</param>
        /// <param name="persistenceInformation">The object that describes how the project was persisted.</param>
        /// <param name="timer">The function that creates and stores timing intervals.</param>
        private static void OnLoadProject(
            ILinkToProjects projectFacade,
            IPersistenceInformation persistenceInformation,
            Func <string, IDisposable> timer)
        {
            // If there is no facade then we're in design mode or something
            // else weird.
            if (projectFacade == null)
            {
                return;
            }

            using (timer("Loading project"))
            {
                projectFacade.LoadProject(persistenceInformation);
            }
        }
Пример #10
0
        /// <summary>
        /// Exports the given dataset as the base of a new project.
        /// </summary>
        /// <param name="datasetToExport">
        /// The ID number of the dataset that should be exported.
        /// </param>
        /// <param name="shouldIncludeChildren">
        /// Indicates if all the child datasets of <paramref name="datasetToExport"/> should be included in the
        /// export or not.
        /// </param>
        /// <param name="persistenceInfo">
        /// The object that describes how the dataset should be exported.
        /// </param>
        /// <remarks>
        /// Note that saving project and dataset information to a stream on the local machine may take
        /// some time because the datasets may be large, reside on a remote machine or both.
        /// </remarks>
        public void Export(DatasetId datasetToExport, bool shouldIncludeChildren, IPersistenceInformation persistenceInfo)
        {
            {
                Lokad.Enforce.With <CannotUseProjectAfterClosingItException>(
                    !IsClosed,
                    Resources.Exceptions_Messages_CannotUseProjectAfterClosingIt);
                Lokad.Enforce.Argument(() => datasetToExport);
                Lokad.Enforce.With <UnknownDatasetException>(
                    m_Datasets.Datasets.ContainsKey(datasetToExport),
                    Resources.Exceptions_Messages_UnknownDataset_WithId,
                    datasetToExport);
                Lokad.Enforce.Argument(() => persistenceInfo);
            }

            // Do we need to have a save flag that we can set to prevent closing from happening
            // while saving?
            throw new NotImplementedException();
        }
Пример #11
0
 private static DatasetId RestoreFromStore(IPersistenceInformation persistenceInfo)
 {
     // Restore the dataset here ...
     // Probably needs to be version safe etc.
     // Note that we also need to store the stream somewhere
     // so that we always have access to it (which will probably be on disk)
     // this may cause all kinds of untold chaos, e.g.
     // - disk full / not big enough
     // - The stream is a remote stream and cuts out half way (i.e we don't consume it on time)
     //
     //
     // When creating a dataset check:
     // - The root must not have parents
     // - Adding the dataset should not create any cycles
     // - No parent may become a child of a child node
     //   OR better yet, no node may become a child after it is inserted
     return(new DatasetId());
 }
Пример #12
0
        /// <summary>
        /// Loads the project from the given stream. Note that in first instance
        /// only the project is loaded, the datasets will not be loaded
        /// until requested.
        /// </summary>
        /// <param name="persistenceInfo">
        /// The object that describes how the project was persisted.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="persistenceInfo"/> is <see langword="null" />.
        /// </exception>
        public void LoadProject(IPersistenceInformation persistenceInfo)
        {
            {
                Lokad.Enforce.Argument(() => persistenceInfo);
            }

            UnloadProject();

            lock (m_Lock)
            {
                m_Current = m_Builder.Define()
                            .WithTimeline(m_TimelineBuilder())
                            .WithDatasetDistributor((request, token) => m_DatasetDistributor.ProposeDistributionFor(request, token))
                            .WithDataStorageBuilder(m_DataStorageProxyBuilder)
                            .WithNotifications(m_Notifications)
                            .WithDiagnostics(m_Diagnostics)
                            .FromStorage(persistenceInfo)
                            .Build();
            }
        }
Пример #13
0
        private static IDatasetOfflineInformation CreateOfflineInfo(IPersistenceInformation storage)
        {
            var mock = new Mock <IDatasetOfflineInformation>();

            {
                mock.Setup(d => d.CanBeAdopted)
                .Returns(false);
                mock.Setup(d => d.CanBecomeParent)
                .Returns(true);
                mock.Setup(d => d.CanBeCopied)
                .Returns(false);
                mock.Setup(d => d.CanBeDeleted)
                .Returns(true);
                mock.Setup(d => d.CreatedBy)
                .Returns(DatasetCreator.User);
                mock.Setup(d => d.StoredAt)
                .Returns(storage);
            }

            return(mock.Object);
        }
Пример #14
0
        /// <summary>
        /// Loads a new project from the given resource stream.
        /// </summary>
        /// <param name="persistenceInformation">The object that describes how the project was persisted.</param>
        public void LoadProject(IPersistenceInformation persistenceInformation)
        {
            if (!CanLoadProject())
            {
                throw new CannotLoadProjectException();
            }

            var context = new LoadProjectContext
                {
                    LoadFrom = persistenceInformation
                };

            Debug.Assert(m_Service.Contains(LoadProjectCommand.CommandId), "A command has gone missing.");
            m_Service.Invoke(LoadProjectCommand.CommandId, context);

            var project = context.Result;
            if (project == null)
            {
                throw new FailedToLoadProjectException();
            }

            m_Facade = new ProjectFacade(project.Result);

            RaiseOnNewProjectLoaded();
        }
Пример #15
0
 private static DatasetId RestoreFromStore(IPersistenceInformation persistenceInfo)
 {
     // Restore the dataset here ...
     // Probably needs to be version safe etc.
     // Note that we also need to store the stream somewhere
     // so that we always have access to it (which will probably be on disk)
     // this may cause all kinds of untold chaos, e.g.
     // - disk full / not big enough
     // - The stream is a remote stream and cuts out half way (i.e we don't consume it on time)
     //
     //
     // When creating a dataset check:
     // - The root must not have parents
     // - Adding the dataset should not create any cycles
     // - No parent may become a child of a child node
     //   OR better yet, no node may become a child after it is inserted
     return new DatasetId();
 }
Пример #16
0
        /// <summary>
        /// Saves the project and all the datasets to the given stream.
        /// </summary>
        /// <param name="persistenceInfo">
        /// The object that describes how the project should be persisted.
        /// </param>
        /// <remarks>
        /// Note that saving project and dataset information to a stream on the local machine may take
        /// some time because the datasets may be large, reside on a remote machine or both.
        /// </remarks>
        public void Save(IPersistenceInformation persistenceInfo)
        {
            {
                Lokad.Enforce.With<CannotUseProjectAfterClosingItException>(
                    !IsClosed,
                    Resources.Exceptions_Messages_CannotUseProjectAfterClosingIt);
                Lokad.Enforce.Argument(() => persistenceInfo);
            }

            // Do we need to have a save flag that we can set to prevent closing from happening
            // while saving?
            throw new NotImplementedException();
        }
Пример #17
0
        /// <summary>
        /// Exports the given dataset as the base of a new project.
        /// </summary>
        /// <param name="datasetToExport">
        /// The ID number of the dataset that should be exported.
        /// </param>
        /// <param name="shouldIncludeChildren">
        /// Indicates if all the child datasets of <paramref name="datasetToExport"/> should be included in the
        /// export or not.
        /// </param>
        /// <param name="persistenceInfo">
        /// The object that describes how the dataset should be exported.
        /// </param>
        /// <remarks>
        /// Note that saving project and dataset information to a stream on the local machine may take
        /// some time because the datasets may be large, reside on a remote machine or both.
        /// </remarks>
        public void Export(DatasetId datasetToExport, bool shouldIncludeChildren, IPersistenceInformation persistenceInfo)
        {
            {
                Lokad.Enforce.With<CannotUseProjectAfterClosingItException>(
                    !IsClosed,
                    Resources.Exceptions_Messages_CannotUseProjectAfterClosingIt);
                Lokad.Enforce.Argument(() => datasetToExport);
                Lokad.Enforce.With<UnknownDatasetException>(
                    m_Datasets.Datasets.ContainsKey(datasetToExport),
                    Resources.Exceptions_Messages_UnknownDataset_WithId,
                    datasetToExport);
                Lokad.Enforce.Argument(() => persistenceInfo);
            }

            // Do we need to have a save flag that we can set to prevent closing from happening
            // while saving?
            throw new NotImplementedException();
        }
Пример #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Project"/> class.
        /// </summary>
        /// <param name="timeline">The timeline for the current project.</param>
        /// <param name="distributor">
        /// The function which returns a <see cref="DistributionPlan"/> for a given
        /// <see cref="DatasetActivationRequest"/>.
        /// </param>
        /// <param name="dataStorageProxyBuilder">The function which returns a storage proxy for a newly loaded dataset.</param>
        /// <param name="notifications">The object that stores the notifications for the user interface.</param>
        /// <param name="diagnostics">The object that provides the diagnostics methods for the application.</param>
        /// <param name="persistenceInfo">
        /// The object that describes how the project was persisted.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="timeline"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when <paramref name="distributor"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when <paramref name="dataStorageProxyBuilder"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when <paramref name="notifications"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown when <paramref name="diagnostics"/> is <see langword="null" />.
        /// </exception>
        public Project(
            ITimeline timeline,
            Func<DatasetActivationRequest, CancellationToken, IEnumerable<DistributionPlan>> distributor,
            Func<DatasetOnlineInformation, DatasetStorageProxy> dataStorageProxyBuilder,
            ICollectNotifications notifications,
            SystemDiagnostics diagnostics,
            IPersistenceInformation persistenceInfo)
        {
            {
                Lokad.Enforce.Argument(() => timeline);
                Lokad.Enforce.Argument(() => distributor);
                Lokad.Enforce.Argument(() => dataStorageProxyBuilder);
                Lokad.Enforce.Argument(() => notifications);
                Lokad.Enforce.Argument(() => diagnostics);
            }

            m_Timeline = timeline;
            m_Timeline.ForgetAllHistory();

            m_Timeline.OnRolledBack += OnTimelineRolledBack;
            m_Timeline.OnRolledForward += OnTimelineRolledForward;

            m_ProjectInformation = m_Timeline.AddToTimeline(ProjectHistoryStorage.CreateInstance);
            m_Datasets = m_Timeline.AddToTimeline(DatasetHistoryStorage.CreateInstance);

            m_DatasetDistributor = distributor;
            m_DataStorageProxyBuilder = dataStorageProxyBuilder;

            m_Notifications = notifications;
            m_Diagnostics = diagnostics;

            if (persistenceInfo != null)
            {
                RestoreFromStore(persistenceInfo);
            }

            // Create a root dataset if there isn't one
            if (m_RootDataset == null)
            {
                var dataset = CreateDataset(
                    null,
                    new DatasetCreationInformation
                        {
                            CreatedOnRequestOf = DatasetCreator.System,
                            LoadFrom = new NullPersistenceInformation(),
                            CanBeDeleted = false,
                            CanBeCopied = false,
                            CanBecomeParent = true,
                            CanBeAdopted = false,
                            IsRoot = true,
                        });

                m_RootDataset = dataset.Id;
                dataset.Name = Resources.Projects_Dataset_RootDatasetName;
                dataset.Summary = Resources.Projects_Dataset_RootDatasetSummary;
            }

            m_Timeline.SetCurrentAsDefault();
        }
Пример #19
0
        /// <summary>
        /// Provides the <see cref="Stream"/> from which the project must be loaded.
        /// </summary>
        /// <param name="persistenceInfo">
        /// The object that describes how the project was persisted.
        /// </param>
        /// <returns>
        /// The current builder instance with the stream containing the project stored.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="persistenceInfo"/> is <see langword="null" />.
        /// </exception>
        public IBuildProjects FromStorage(IPersistenceInformation persistenceInfo)
        {
            {
                Lokad.Enforce.Argument(() => persistenceInfo);
            }

            m_ProjectStorage = persistenceInfo;
            return this;
        }
Пример #20
0
        /// <summary>
        /// Creates a new project definition object.
        /// </summary>
        /// <returns>
        /// The current builder instance with all the storage cleared.
        /// </returns>
        public IBuildProjects Define()
        {
            m_Distributor = null;
            m_ProjectStorage = null;

            return this;
        }
Пример #21
0
 /// <summary>
 /// Saves the current project.
 /// </summary>
 /// <param name="persistenceInformation">The object that describes how the project should be persisted.</param>
 public void SaveProject(IPersistenceInformation persistenceInformation)
 {
     if (m_Current != null)
     {
         m_Current.Save(persistenceInformation);
         HasProjectChanged = false;
     }
 }
        private static IDatasetOfflineInformation CreateOfflineInfo(IPersistenceInformation storage)
        {
            var mock = new Mock<IDatasetOfflineInformation>();
            {
                mock.Setup(d => d.Id)
                    .Returns(new DatasetId());
                mock.Setup(d => d.CanBeAdopted)
                    .Returns(false);
                mock.Setup(d => d.CanBecomeParent)
                    .Returns(true);
                mock.Setup(d => d.CanBeCopied)
                    .Returns(false);
                mock.Setup(d => d.CanBeDeleted)
                    .Returns(true);
                mock.Setup(d => d.CreatedBy)
                    .Returns(DatasetCreator.User);
                mock.Setup(d => d.StoredAt)
                    .Returns(storage);
            }

            return mock.Object;
        }
Пример #23
0
        /// <summary>
        /// Loads the project from the given stream. Note that in first instance
        /// only the project is loaded, the datasets will not be loaded
        /// until requested.
        /// </summary>
        /// <param name="persistenceInfo">
        /// The object that describes how the project was persisted.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="persistenceInfo"/> is <see langword="null" />.
        /// </exception>
        public void LoadProject(IPersistenceInformation persistenceInfo)
        {
            {
                Lokad.Enforce.Argument(() => persistenceInfo);
            }

            UnloadProject();

            lock (m_Lock)
            {
                m_Current = m_Builder.Define()
                    .WithTimeline(m_TimelineBuilder())
                    .WithDatasetDistributor((request, token) => m_DatasetDistributor.ProposeDistributionFor(request, token))
                    .WithDataStorageBuilder(m_DataStorageProxyBuilder)
                    .WithNotifications(m_Notifications)
                    .WithDiagnostics(m_Diagnostics)
                    .FromStorage(persistenceInfo)
                    .Build();
            }
        }