/// <summary>
        /// Called when the dataset should be activated.
        /// </summary>
        /// <param name="projectFacade">The object that contains the methods that allow interaction with the project system.</param>
        /// <param name="dataset">The dataset.</param>
        /// <param name="selector">
        ///     The function that is used to select the most suitable machine to distribute the dataset to.
        /// </param>
        /// <param name="timer">The function that creates and stores timing intervals.</param>
        private static void OnActivate(
            ILinkToProjects projectFacade,
            DatasetFacade dataset,
            Func <IEnumerable <DistributionSuggestion>, SelectedProposal> selector,
            Func <string, IDisposable> timer)
        {
            // If there is no application facade, then we're in
            // designer mode, or something else silly.
            if (dataset == null)
            {
                return;
            }

            if (dataset.IsActivated || !dataset.CanActivate)
            {
                return;
            }

            using (timer("Loading dataset onto machine"))
            {
                var source = new CancellationTokenSource();
                dataset.Activate(
                    DistributionLocations.All,
                    selector,
                    source.Token)
                .ContinueWith(t => source.Dispose());
                projectFacade.ActiveProject().History.Mark();
            }
        }
Beispiel #2
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);
            }
        }
Beispiel #3
0
        private ActivateDatasetCommand CreateActivateDatasetCommand(
            ILinkToProjects projectFacade,
            DatasetFacade dataset,
            Func <string, IDisposable> timer)
        {
            var context = m_Container.Resolve <IContextAware>();
            Func <IEnumerable <DistributionSuggestion>, SelectedProposal> selector =
                c =>
            {
                var presenter = (IPresenter)m_Container.Resolve(typeof(MachineSelectorPresenter));
                var view      = m_Container.Resolve(presenter.ViewType) as IMachineSelectorView;
                presenter.Initialize(view, new MachineSelectorParameter(context, c));

                var window = view as Window;
                window.Owner = Application.Current.MainWindow;
                if (window.ShowDialog() ?? false)
                {
                    return(new SelectedProposal(view.Model.SelectedPlan));
                }

                return(new SelectedProposal());
            };

            var command = m_Container.Resolve <ActivateDatasetCommand>(
                new TypedParameter(typeof(ILinkToProjects), projectFacade),
                new TypedParameter(typeof(DatasetFacade), dataset),
                new TypedParameter(typeof(Func <IEnumerable <DistributionSuggestion>, SelectedProposal>), selector),
                new TypedParameter(typeof(SystemDiagnostics), timer));

            return(command);
        }
Beispiel #4
0
        private static bool CanRedo(ILinkToProjects projectFacade)
        {
            // If there is no facade then we're in design mode or something
            // else weird.
            if (projectFacade == null)
            {
                return(false);
            }

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

            var project = projectFacade.ActiveProject();

            if (project.History.CanRollForward)
            {
                var markers = project.History.MarkersInTheFuture();

                var markerToRollBackTo = markers.FirstOrDefault(m => !m.Equals(project.History.Current));
                return(markerToRollBackTo != null);
            }

            return(false);
        }
Beispiel #5
0
        /// <summary>
        /// Called when the last undo action should be redone.
        /// </summary>
        /// <param name="projectFacade">
        /// The object that contains the methods that allow interaction with
        /// the project system.
        /// </param>
        /// <param name="timer">The function that creates and stores timing intervals.</param>
        private static void OnRedo(ILinkToProjects projectFacade, 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("Redoing change"))
            {
                var project = projectFacade.ActiveProject();
                if (project.History.CanRollForward)
                {
                    var markers = project.History.MarkersInTheFuture();

                    var markerToRollBackTo = markers.FirstOrDefault(m => !m.Equals(project.History.Current));
                    if (markerToRollBackTo != null)
                    {
                        project.History.RollForwardTo(markerToRollBackTo);
                    }
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DatasetDetailModel"/> class.
        /// </summary>
        /// <param name="context">The context that is used to execute actions on the UI thread.</param>
        /// <param name="progressTracker">The object that handles the progress notifications for the applications.</param>
        /// <param name="project">The project that holds all the data.</param>
        /// <param name="dataset">The dataset.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="context"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="progressTracker"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="project"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="dataset"/> is <see langword="null" />.
        /// </exception>
        public DatasetDetailModel(IContextAware context, ITrackSteppingProgress progressTracker, ILinkToProjects project, DatasetFacade dataset)
            : base(context)
        {
            {
                Lokad.Enforce.Argument(() => progressTracker);
                Lokad.Enforce.Argument(() => project);
                Lokad.Enforce.Argument(() => dataset);
            }

            m_ProgressTracker        = progressTracker;
            m_Project                = project;
            m_Dataset                = dataset;
            m_Dataset.OnNameChanged += (s, e) =>
            {
                Notify(() => Name);
                Notify(() => DisplayName);
            };
            m_Dataset.OnSummaryChanged          += (s, e) => Notify(() => Summary);
            m_Dataset.OnProgressOfCurrentAction += HandleDatasetProgress;
            m_Dataset.OnDeactivated             += (s, e) =>
            {
                Notify(() => IsActivated);
                Notify(() => Endpoint);
                RaiseOnDeactivated();
            };
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DatasetDetailModel"/> class.
        /// </summary>
        /// <param name="context">The context that is used to execute actions on the UI thread.</param>
        /// <param name="progressTracker">The object that handles the progress notifications for the applications.</param>
        /// <param name="project">The project that holds all the data.</param>
        /// <param name="dataset">The dataset.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="context"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="progressTracker"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="project"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="dataset"/> is <see langword="null" />.
        /// </exception>
        public DatasetDetailModel(IContextAware context, ITrackSteppingProgress progressTracker, ILinkToProjects project, DatasetFacade dataset)
            : base(context)
        {
            {
                Lokad.Enforce.Argument(() => progressTracker);
                Lokad.Enforce.Argument(() => project);
                Lokad.Enforce.Argument(() => dataset);
            }

            m_ProgressTracker = progressTracker;
            m_Project = project;
            m_Dataset = dataset;
            m_Dataset.OnNameChanged += (s, e) =>
                {
                    Notify(() => Name);
                    Notify(() => DisplayName);
                };
            m_Dataset.OnSummaryChanged += (s, e) => Notify(() => Summary);
            m_Dataset.OnProgressOfCurrentAction += HandleDatasetProgress;
            m_Dataset.OnDeactivated += (s, e) =>
                {
                    Notify(() => IsActivated);
                    Notify(() => Endpoint);
                    RaiseOnDeactivated();
                };
        }
 public ActivateDatasetCommand(
     ILinkToProjects projectFacade,
     DatasetFacade dataset,
     Func <IEnumerable <DistributionSuggestion>, SelectedProposal> selector,
     Func <string, IDisposable> timer)
     : base(obj => OnActivate(projectFacade, dataset, selector, timer), obj => CanActivate(dataset))
 {
 }
        private static bool CanShowTab(ILinkToProjects projectFacade)
        {
            // If there is no facade then we're in design mode or something
            // else weird.
            if (projectFacade == null)
            {
                return(false);
            }

            return(projectFacade.HasActiveProject());
        }
Beispiel #10
0
        private static bool CanCreateNewProject(ILinkToProjects projectFacade)
        {
            // If there is no project facade, then we're in
            // designer mode, or something else silly.
            if (projectFacade == null)
            {
                return(false);
            }

            return(projectFacade.CanCreateNewProject());
        }
        private static bool CanLoadProject(ILinkToProjects projectFacade)
        {
            // If there is no facade then we're in design mode or something
            // else weird.
            if (projectFacade == null)
            {
                return(false);
            }

            // return projectFacade.CanLoadProject();
            return(false);
        }
        /// <summary>
        /// Called when the existing project should be closed.
        /// </summary>
        /// <param name="projectFacade">
        /// The object that contains the methods that allow interaction with
        /// the project system.
        /// </param>
        /// <param name="timer">The function that creates and stores timing intervals.</param>
        private static void OnCloseProject(ILinkToProjects projectFacade, Func <string, IDisposable> timer)
        {
            // If there is no project facade, then we're in
            // designer mode, or something else silly.
            if (projectFacade == null)
            {
                return;
            }

            using (timer("Unloading project"))
            {
                projectFacade.UnloadProject();
            }
        }
Beispiel #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ScriptHost"/> class.
        /// </summary>
        /// <param name="projects">The object that handles all the project related actions.</param>
        /// <param name="appdomainBuilder">The function that creates a new <see cref="AppDomain"/> with the given name.</param>
        /// <param name="scheduler">The scheduler that will be used to schedule tasks.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="projects"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="appdomainBuilder"/> is <see langword="null" />.
        /// </exception>
        public ScriptHost(
            ILinkToProjects projects,
            Func <string, AppDomainPaths, AppDomain> appdomainBuilder,
            TaskScheduler scheduler = null)
        {
            {
                Enforce.Argument(() => projects);
                Enforce.Argument(() => appdomainBuilder);
            }

            m_Projects         = new ScriptBackEndProjectHub(projects);
            m_AppDomainBuilder = appdomainBuilder;
            m_Scheduler        = scheduler ?? TaskScheduler.Default;
        }
        /// <summary>
        /// Called when a new child dataset should be added.
        /// </summary>
        /// <param name="projectFacade">The object that contains the methods that allow interaction with the project system.</param>
        /// <param name="datasetFacade">The object that contains the methods that allow interaction with a dataset.</param>
        /// <param name="timer">The function that creates and stores timing intervals.</param>
        private static void OnAddNewChild(ILinkToProjects projectFacade, DatasetFacade datasetFacade, Func <string, IDisposable> timer)
        {
            // If there is no dataset facade, then we're in
            // designer mode, or something else silly.
            if (datasetFacade == null)
            {
                return;
            }

            using (timer("Add dataset to graph"))
            {
                datasetFacade.AddChild();
                projectFacade.ActiveProject().History.Mark();
            }
        }
        /// <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);
            }
        }
Beispiel #16
0
        private static bool ShouldSaveProject(ILinkToProjects projectFacade)
        {
            // If there is no facade then we're in design mode or something
            // else weird.
            if (projectFacade == null)
            {
                return(false);
            }

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

            var project = projectFacade.ActiveProject();

            return(project.ShouldSaveProject());
        }
        /// <summary>
        /// Called when the dataset should be deactivated.
        /// </summary>
        /// <param name="projectFacade">The object that contains the methods that allow interaction with the project system.</param>
        /// <param name="dataset">The dataset.</param>
        /// <param name="timer">The function that creates and stores timing intervals.</param>
        private static void OnDeactivate(ILinkToProjects projectFacade, DatasetFacade dataset, Func<string, IDisposable> timer)
        {
            // If there is no application facade, then we're in 
            // designer mode, or something else silly.
            if (dataset == null)
            {
                return;
            }

            if (!dataset.IsActivated)
            {
                return;
            }

            using (timer("Unloading dataset"))
            {
                dataset.Deactivate();
                projectFacade.ActiveProject().History.Mark();
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ScriptBackEndProjectHub"/> class.
        /// </summary>
        /// <param name="projects">The object that handles all the project activities.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="projects"/> is <see langword="null" />.
        /// </exception>
        public ScriptBackEndProjectHub(ILinkToProjects projects)
        {
            {
                Enforce.Argument(() => projects);
            }

            m_Projects = projects;
            {
                m_Projects.OnNewProjectLoaded +=
                    (s, e) =>
                    {
                        m_Current = null;
                        RaiseOnNewProjectLoaded();
                    };
                m_Projects.OnProjectUnloaded +=
                    (s, e) =>
                    {
                        m_Current = null;
                        RaiseOnProjectUnloaded();
                    };
            }
        }
Beispiel #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ScriptBackEndProjectHub"/> class.
        /// </summary>
        /// <param name="projects">The object that handles all the project activities.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="projects"/> is <see langword="null" />.
        /// </exception>
        public ScriptBackEndProjectHub(ILinkToProjects projects)
        {
            {
                Enforce.Argument(() => projects);
            }

            m_Projects = projects;
            {
                m_Projects.OnNewProjectLoaded +=
                    (s, e) =>
                {
                    m_Current = null;
                    RaiseOnNewProjectLoaded();
                };
                m_Projects.OnProjectUnloaded +=
                    (s, e) =>
                {
                    m_Current = null;
                    RaiseOnProjectUnloaded();
                };
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ShowProjectsTabCommand"/> class.
 /// </summary>
 /// <param name="context">The context that is used to execute actions on the UI thread.</param>
 /// <param name="projectFacade">
 ///     The object that contains the methods that allow interaction
 ///     with the project system.
 /// </param>
 /// <param name="eventAggregator">The event aggregator.</param>
 public ShowProjectsTabCommand(IContextAware context, ILinkToProjects projectFacade, IEventAggregator eventAggregator)
     : base(obj => ShowTab(context, eventAggregator), obj => CanShowTab(projectFacade))
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DeleteDatasetCommand"/> class.
 /// </summary>
 /// <param name="projectFacade">The object that contains the methods that allow interaction with the project system.</param>
 /// <param name="datasetFacade">The object that contains the methods that allow interaction with a dataset.</param>
 /// <param name="timer">The function that creates and stores timing intervals.</param>
 public DeleteDatasetCommand(ILinkToProjects projectFacade, DatasetFacade datasetFacade, Func <string, IDisposable> timer)
     : base(obj => OnDeleteDataset(projectFacade, datasetFacade, timer), obj => CanDeleteDataset(datasetFacade))
 {
 }
Beispiel #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RedoCommand"/> class.
 /// </summary>
 /// <param name="projectFacade">
 /// The object that contains the methods that allow interaction
 /// with the project system.
 /// </param>
 /// <param name="timer">The function that creates and stores timing intervals.</param>
 public RedoCommand(ILinkToProjects projectFacade, Func <string, IDisposable> timer)
     : base(obj => OnRedo(projectFacade, timer), obj => CanRedo(projectFacade))
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="OpenProjectCommand"/> class.
 /// </summary>
 /// <param name="projectFacade">The object that contains the methods that allow interaction with the project system.</param>
 /// <param name="timer">The function that creates and stores timing intervals.</param>
 public OpenProjectCommand(ILinkToProjects projectFacade, Func <string, IDisposable> timer)
     : base(obj => OnLoadProject(projectFacade, obj as IPersistenceInformation, timer), obj => CanLoadProject(projectFacade))
 {
 }
 private static bool CanCloseProject(ILinkToProjects projectFacade)
 {
     // If there is no project facade, then we're in
     // designer mode, or something else silly.
     return(projectFacade != null && projectFacade.CanUnloadProject());
 }
Beispiel #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SaveProjectCommand"/> class.
 /// </summary>
 /// <param name="projectFacade">The object that contains the methods that allow interaction with the project system.</param>
 /// <param name="timer">The function that creates and stores timing intervals.</param>
 public SaveProjectCommand(ILinkToProjects projectFacade, Func <string, IDisposable> timer)
     : base(obj => OnSaveProject(projectFacade, obj as IPersistenceInformation, timer), obj => ShouldSaveProject(projectFacade))
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CloseProjectCommand"/> class.
 /// </summary>
 /// <param name="projectFacade">
 /// The object that contains the methods that allow interaction
 /// with the project system.
 /// </param>
 /// <param name="timer">The function that creates and stores timing intervals.</param>
 public CloseProjectCommand(ILinkToProjects projectFacade, Func <string, IDisposable> timer)
     : base(obj => OnCloseProject(projectFacade, timer), obj => CanCloseProject(projectFacade))
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AddChildDatasetCommand"/> class.
 /// </summary>
 /// <param name="projectFacade">The object that contains the methods that allow interaction with the project system.</param>
 /// <param name="datasetFacade">The object that contains the methods that allow interaction with a dataset.</param>
 /// <param name="timer">The function that creates and stores timing intervals.</param>
 public AddChildDatasetCommand(ILinkToProjects projectFacade, DatasetFacade datasetFacade, Func <string, IDisposable> timer)
     : base(obj => OnAddNewChild(projectFacade, datasetFacade, timer), obj => CanAddNewChild(datasetFacade))
 {
 }
Beispiel #28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ScriptHost"/> class.
        /// </summary>
        /// <param name="projects">The object that handles all the project related actions.</param>
        /// <param name="appdomainBuilder">The function that creates a new <see cref="AppDomain"/> with the given name.</param>
        /// <param name="scheduler">The scheduler that will be used to schedule tasks.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="projects"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="appdomainBuilder"/> is <see langword="null" />.
        /// </exception>
        public ScriptHost(
            ILinkToProjects projects,
            Func<string, AppDomainPaths, AppDomain> appdomainBuilder,
            TaskScheduler scheduler = null)
        {
            {
                Enforce.Argument(() => projects);
                Enforce.Argument(() => appdomainBuilder);
            }

            m_Projects = new ScriptBackEndProjectHub(projects);
            m_AppDomainBuilder = appdomainBuilder;
            m_Scheduler = scheduler ?? TaskScheduler.Default;
        }