Пример #1
0
        private void ExecuteSaveFile(bool background = true)
        {
            if (string.IsNullOrEmpty(xamlFile))
            {
                ExecuteSaveFileAs();
                return;
            }
            StatusBarText.Text = "Saving...";
            wd.Flush();
            lastSavedXaml = wd.Text;
            ToggleDocumentHasChangesVisual(false);
            mustSave = false;
            IXamlFileProvider provider = XamlFileProviderFactory.GetNewXamlFileProvider(!string.IsNullOrEmpty(password));

            if (background)
            {
                this.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(delegate
                {
                    provider.WriteXamlFile(xamlFile, wd.Text, password);
                    StatusBarText.Text = "Done.";
                    this.IsEnabled     = true;
                }));
            }
            else
            {
                provider.WriteXamlFile(xamlFile, wd.Text, password);
                StatusBarText.Text = "Done.";
            }
            RefreshTitle();
        }
Пример #2
0
        private void LoadWorkflow()
        {
            if (workflow == null)
            {
                string password     = null;
                string errorMessage = null;
                if (XamlFileProviderFactory.IsXamlFileEncrypted(App.XamlFile))
                {
                    password = GetPassword();
                    if (string.IsNullOrEmpty(password))
                    {
                        errorMessage = string.Format("The file '{0}' is protected and requires the correct password to open.", App.XamlFile);
                    }
                }

                if (string.IsNullOrEmpty(errorMessage))
                {
                    try
                    {
                        IXamlFileProvider provider = XamlFileProviderFactory.GetXamlFileProvider(App.XamlFile, password);
                        provider.LoadXamlFile(App.XamlFile, password);
                        workflow = provider.XamlDocument;
                    }
                    catch (Exception ex)
                    {
                        errorMessage = ex.Message;
                        if (errorMessage == "The encrypted string was not in a valid format.")
                        {
                            errorMessage = "The password you specified was incorrect.";
                        }
                        errorMessage = string.Format("The following error occurred while trying to open '{0}' : \n\n{1}", App.XamlFile, errorMessage);
                    }
                }
                if (!string.IsNullOrEmpty(errorMessage))
                {
                    ShowErrorMessage(errorMessage, "Failed to load file");
                    password = null;
                    this.Close();
                }
            }
        }
Пример #3
0
        protected override void Execute(CodeActivityContext context)
        {
            console = context.GetExtension <ActivityConsole>();
            if (console == null)
            {
                console = new ActivityConsole();
            }

            string xamlFile = XamlFileName.Get(context);
            Dictionary <string, object> inputs = Inputs.Get(context);

            try
            {
                Activity workflow     = null;
                string   xamlFileName = XamlFileName.Get(context);

                string password     = null;
                string errorMessage = null;
                if (XamlFileProviderFactory.IsXamlFileEncrypted(xamlFileName))
                {
                    password = Password.Get(context);
                    if (string.IsNullOrEmpty(password))
                    {
                        errorMessage = string.Format("The file '{0}' is protected and requires the correct password to open.", xamlFileName);
                    }
                }

                if (string.IsNullOrEmpty(errorMessage))
                {
                    try
                    {
                        IXamlFileProvider provider = XamlFileProviderFactory.GetXamlFileProvider(xamlFileName, password);
                        provider.LoadXamlFile(xamlFileName, password);
                        workflow = provider.XamlDocument;
                    }
                    catch (Exception ex)
                    {
                        errorMessage = ex.Message;
                        if (errorMessage == "The encrypted string was not in a valid format.")
                        {
                            errorMessage = "The password you specified was incorrect.";
                        }
                        errorMessage = string.Format("The following error occurred while trying to open '{0}' : \n\n{1}", xamlFileName, errorMessage);
                    }
                }
                if (!string.IsNullOrEmpty(errorMessage))
                {
                    throw new ArgumentException(errorMessage);
                }

                WorkflowApplication wa;
                if (inputs != null && inputs.Count > 0)
                {
                    wa = new WorkflowApplication(workflow, Inputs.Get(context));
                }
                else
                {
                    wa = new WorkflowApplication(workflow);
                }
                wa.Extensions.Add(console);
                wa.Completed            = WorkflowCompleted;
                wa.OnUnhandledException = WorkflowUnhandledException;
                wa.Aborted = WorkflowAborted;
                isBusy     = true;
                console.WriteLine(Environment.NewLine + xamlFile + " Executing..." + Environment.NewLine);
                wa.Run();
                while (isBusy)
                {
                    System.Threading.Thread.Sleep(200);
                }
                console.WriteLine(Environment.NewLine + xamlFile + " Execution Complete." + Environment.NewLine);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #4
0
        private void LoadDesignerAndWorkflow(string fileName = null)
        {
            isLoadingXaml = true;
            Encrypt       = false;
            mustSave      = false;

            if (wd != null)
            {
                MainLayout.Children.Remove(this.wd.View);
                MainLayout.Children.Remove(this.wd.PropertyInspectorView);
                this.wd.ModelChanged -= wd_ModelChanged;
                this.wd = null;
            }
            //Create an instance of WorkflowDesigner class.
            this.wd = new WorkflowDesigner();

            DesignerConfigurationService configService = this.wd.Context.Services.GetService <DesignerConfigurationService>();

            configService.TargetFrameworkName = new FrameworkName(".NETFramework", new Version(4, 5));
            configService.LoadingFromUntrustedSourceEnabled = true;

            this.wd.ModelChanged += new EventHandler(wd_ModelChanged);

            //Place the designer canvas in the middle column of the grid.
            Grid.SetRow(this.wd.View, 1);
            Grid.SetColumn(this.wd.View, 2);

            AddPropertyInspector();

            if (string.IsNullOrEmpty(fileName))
            {
                this.wd.Load(new Sequence());
                wd.Flush();
                lastSavedXaml = wd.Text;
                mustSave      = true;
            }
            else
            {
                password = null;
                string errorMessage = null;
                if (XamlFileProviderFactory.IsXamlFileEncrypted(fileName))
                {
                    if (!GetPassword())
                    {
                        errorMessage = string.Format("The file '{0}' is protected and requires the correct password to open.", xamlFile);
                    }
                    else
                    {
                        Encrypt = true;
                    }
                }

                if (string.IsNullOrEmpty(errorMessage))
                {
                    try
                    {
                        IXamlFileProvider provider = XamlFileProviderFactory.GetXamlFileProvider(fileName, password);
                        provider.LoadXamlFile(fileName, password);
                        this.wd.Load(provider.XamlDocument);
                        wd.Flush();
                        lastSavedXaml = wd.Text;
                    }
                    catch (Exception ex)
                    {
                        errorMessage = ex.Message;
                        if (errorMessage == "The encrypted string was not in a valid format.")
                        {
                            errorMessage = "The password you specified was incorrect.";
                        }
                        errorMessage = string.Format("The following error occurred while trying to open '{0}' : \n\n{1}", xamlFile, errorMessage);
                    }
                }
                if (!string.IsNullOrEmpty(errorMessage))
                {
                    xamlFile = string.Empty;
                    ShowErrorMessage(errorMessage, "Failed to load file");
                    this.wd.Load(new Sequence());
                    password = null;
                    mustSave = true;
                    Encrypt  = false;
                }
            }

            busyGettingPassword = true;
            Protect.GetBindingExpression(System.Windows.Controls.Primitives.ToggleButton.IsCheckedProperty).UpdateTarget();
            busyGettingPassword = false;

            //Add the designer canvas to the grid.
            MainLayout.Children.Add(this.wd.View);

            StatusBarText.Text = "";
            ToggleDocumentHasChangesVisual(mustSave);

            isLoadingXaml = false;
        }