private void finalizecodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken);

            IXsltFunction xslt = this.GetBinding <IXsltFunction>("NewXslt");
            Guid          copyFromFunctionId = this.GetBinding <Guid>(Binding_CopyFromFunctionId);

            IXsltFunction copyFromFunction = null;

            if (copyFromFunctionId != Guid.Empty)
            {
                copyFromFunction = DataFacade.GetData <IXsltFunction>().First(f => f.Id == copyFromFunctionId);
            }

            xslt.XslFilePath = xslt.CreateXslFilePath();

            IFile file = IFileServices.TryGetFile <IXsltFile>(xslt.XslFilePath);

            using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
            {
                if (file == null)
                {
                    IXsltFile xsltfile = DataFacade.BuildNew <IXsltFile>();

                    xsltfile.FolderPath = System.IO.Path.GetDirectoryName(xslt.XslFilePath);
                    xsltfile.FileName   = System.IO.Path.GetFileName(xslt.XslFilePath);

                    string xslTemplate = _newXsltMarkup;
                    if (copyFromFunction != null)
                    {
                        IFile copyFromFile = IFileServices.GetFile <IXsltFile>(copyFromFunction.XslFilePath);
                        xslTemplate = copyFromFile.ReadAllText();
                    }

                    xsltfile.SetNewContent(xslTemplate);

                    DataFacade.AddNew <IXsltFile>(xsltfile, "XslFileProvider");
                }

                xslt = DataFacade.AddNew <IXsltFunction>(xslt);

                UserSettings.LastSpecifiedNamespace = xslt.Namespace;


                if (copyFromFunction != null)
                {
                    CloneFunctionParameters(copyFromFunction, xslt);
                    CloneFunctionCalls(copyFromFunction, xslt);
                }

                transactionScope.Complete();
            }
            addNewTreeRefresher.PostRefreshMesseges(xslt.GetDataEntityToken());

            FlowControllerServicesContainer container = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);
            var executionService = container.GetService <IActionExecutionService>();

            executionService.Execute(xslt.GetDataEntityToken(), new WorkflowActionToken(typeof(EditXsltFunctionWorkflow)), null);
        }
예제 #2
0
        private void saveCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            try
            {
                IXsltFunction xslt         = this.GetBinding <IXsltFunction>("CurrentXslt");
                IXsltFunction previousXslt = DataFacade.GetData <IXsltFunction>(f => f.Id == xslt.Id).SingleOrDefault();

                IFile persistemTemplateFile = IFileServices.TryGetFile <IXsltFile>(xslt.XslFilePath);
                if (persistemTemplateFile != null)
                {
                    string persistemTemplate = (persistemTemplateFile != null ? persistemTemplateFile.ReadAllText() : "");

                    if (this.GetBinding <int>("XslTemplateLastSaveHash") != persistemTemplate.GetHashCode())
                    {
                        this.Bindings["XslTemplate"] = persistemTemplate;
                        this.RerenderView();
                        ConsoleMessageQueueFacade.Enqueue(new LogEntryMessageQueueItem {
                            Level = LogLevel.Fine, Message = "XSLT file on file system has been changed by another process. In-browser editor updated to reflect file on file system.", Sender = this.GetType()
                        }, this.GetCurrentConsoleId());
                    }
                }

                string xslTemplate = this.GetBinding <string>("XslTemplate");

                var parameters = this.GetBinding <IEnumerable <ManagedParameterDefinition> >("Parameters");

                IEnumerable <NamedFunctionCall> FunctionCalls = this.GetBinding <IEnumerable <NamedFunctionCall> >("FunctionCalls");

                if (FunctionCalls.Select(f => f.Name).Distinct().Count() != FunctionCalls.Count())
                {
                    ShowMessage(DialogType.Error,
                                GetString("EditXsltFunctionWorkflow.SameLocalFunctionNameClashTitle"),
                                GetString("EditXsltFunctionWorkflow.SameLocalFunctionNameClashMessage"));
                    return;
                }


                using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
                {
                    // Renaming related file if necessary
                    string oldRelativePath = previousXslt.XslFilePath.Replace('\\', '/'); // This replace takes care of old paths having \ in them
                    string newRelativePath = xslt.CreateXslFilePath();

                    if (string.Compare(oldRelativePath, newRelativePath, true) != 0)
                    {
                        var    xlsFile    = IFileServices.GetFile <IXsltFile>(previousXslt.XslFilePath);
                        string systemPath = (xlsFile as FileSystemFileBase).SystemPath;
                        // Implement it in another way?
                        string xsltFilesRoot = systemPath.Substring(0, systemPath.Length - previousXslt.XslFilePath.Length);

                        string newSystemPath = (xsltFilesRoot + newRelativePath).Replace('\\', '/');

                        if ((string.Compare(systemPath, newSystemPath, true) != 0) && C1File.Exists(newSystemPath))
                        {
                            FlowControllerServicesContainer serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);
                            var consoleMessageService = serviceContainer.GetService <IManagementConsoleMessageService>();
                            consoleMessageService.ShowMessage(
                                DialogType.Error,
                                GetString("EditXsltFunctionWorkflow.InvalidName"),
                                GetString("EditXsltFunctionWorkflow.CannotRenameFileExists").FormatWith(newSystemPath));
                            return;
                        }

                        string directoryPath = Path.GetDirectoryName(newSystemPath);
                        if (!C1Directory.Exists(directoryPath))
                        {
                            C1Directory.CreateDirectory(directoryPath);
                        }

                        C1File.Move(systemPath, newSystemPath);

                        xslt.XslFilePath = newRelativePath;

                        // TODO: Implement removing empty Xslt directories
                    }


                    IFile file = IFileServices.GetFile <IXsltFile>(xslt.XslFilePath);
                    file.SetNewContent(xslTemplate);

                    ManagedParameterManager.Save(xslt.Id, parameters);

                    DataFacade.Update(xslt);
                    DataFacade.Update(file);

                    this.Bindings["XslTemplateLastSaveHash"] = xslTemplate.GetHashCode();


                    DataFacade.Delete <INamedFunctionCall>(f => f.XsltFunctionId == xslt.Id);
                    DataFacade.AddNew <INamedFunctionCall>(ConvertFunctionCalls(FunctionCalls, xslt.Id));

                    transactionScope.Complete();
                }

                if (previousXslt.Namespace != xslt.Namespace || previousXslt.Name != xslt.Name || previousXslt.Description != xslt.Description)
                {
                    // This is a some what nasty hack. Due to the nature of the BaseFunctionProviderElementProvider, this hack is needed
                    BaseFunctionFolderElementEntityToken entityToken = new BaseFunctionFolderElementEntityToken("ROOT:XsltBasedFunctionProviderElementProvider");
                    RefreshEntityToken(entityToken);
                }

                SetSaveStatus(true);
            }
            catch (Exception ex)
            {
                LoggingService.LogCritical("XSLT Save", ex);

                FlowControllerServicesContainer serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId);
                var consoleMsgService = serviceContainer.GetService <IManagementConsoleMessageService>();
                consoleMsgService.ShowMessage(DialogType.Error, "Error", ex.Message);

                SetSaveStatus(false);
            }
        }
        private void IsValidData(object sender, ConditionalEventArgs e)
        {
            IXsltFunction function = this.GetBinding <IXsltFunction>("NewXslt");

            e.Result = false;

            if (function.Name == string.Empty)
            {
                this.ShowFieldMessage("NewXslt.Name", GetText("AddNewXsltFunctionWorkflow.MethodEmpty"));
                return;
            }

            if (string.IsNullOrWhiteSpace(function.Namespace))
            {
                this.ShowFieldMessage("NewXslt.Namespace", GetText("AddNewXsltFunctionWorkflow.NamespaceEmpty"));
                return;
            }

            if (!function.Namespace.IsCorrectNamespace('.'))
            {
                this.ShowFieldMessage("NewXslt.Namespace", GetText("AddNewXsltFunctionWorkflow.InvalidNamespace"));
                return;
            }

            string functionName      = function.Name;
            string functionNamespace = function.Namespace;
            bool   nameIsReserved    = DataFacade.GetData <IXsltFunction>()
                                       .Where(func => string.Compare(func.Name, functionName, true) == 0 &&
                                              string.Compare(func.Namespace, functionNamespace, true) == 0)
                                       .Any();

            if (nameIsReserved)
            {
                this.ShowFieldMessage("NewXslt.Name", GetText("AddNewXsltFunctionWorkflow.DuplicateName"));
                return;
            }

            function.XslFilePath = function.CreateXslFilePath();

            ValidationResults validationResults = ValidationFacade.Validate <IXsltFunction>(function);

            if (!validationResults.IsValid)
            {
                foreach (ValidationResult result in validationResults)
                {
                    this.ShowFieldMessage(string.Format("{0}.{1}", "NewXslt", result.Key), result.Message);
                }

                return;
            }


            if (!function.ValidateXslFilePath())
            {
                this.ShowFieldMessage("NewXslt.Name", GetText("AddNewXsltFunctionWorkflow.TotalNameTooLang"));
                return;
            }


            IXsltFile xsltfile = DataFacade.BuildNew <IXsltFile>();

            xsltfile.FolderPath = System.IO.Path.GetDirectoryName(function.XslFilePath);
            xsltfile.FileName   = System.IO.Path.GetFileName(function.XslFilePath);

            if (!DataFacade.ValidatePath(xsltfile, "XslFileProvider"))
            {
                this.ShowFieldMessage("NewXslt.Name", GetText("AddNewXsltFunctionWorkflow.TotalNameTooLang"));
                return;
            }

            e.Result = true;
        }
예제 #4
0
        private void IsValidData(object sender, ConditionalEventArgs e)
        {
            IXsltFunction function = this.GetBinding <IXsltFunction>("CurrentXslt");

            if (function.Name == string.Empty)
            {
                this.ShowFieldMessage("CurrentXslt.Name", GetString("EditXsltFunctionWorkflow.EmptyMethodName"));
                e.Result = false;
                return;
            }


            if (string.IsNullOrWhiteSpace(function.Namespace))
            {
                this.ShowFieldMessage("CurrentXslt.Namespace", GetString("EditXsltFunctionWorkflow.NamespaceEmpty"));
                return;
            }


            if (!function.Namespace.IsCorrectNamespace('.'))
            {
                this.ShowFieldMessage("CurrentXslt.Namespace", GetString("EditXsltFunctionWorkflow.InvalidNamespace"));
                e.Result = false;
                return;
            }


            if (!(function.XslFilePath.StartsWith("\\") || function.XslFilePath.StartsWith("/")))
            {
                this.ShowFieldMessage("CurrentXslt.Name", GetString("EditXsltFunctionWorkflow.InvalidFileName"));
                e.Result = false;
                return;
            }


            function.XslFilePath = function.CreateXslFilePath();

            ValidationResults validationResults = ValidationFacade.Validate <IXsltFunction>(function);

            if (!validationResults.IsValid)
            {
                foreach (ValidationResult result in validationResults)
                {
                    this.ShowFieldMessage(string.Format("{0}.{1}", "CurrentXslt", result.Key), result.Message);
                }

                return;
            }


            if (!function.ValidateXslFilePath())
            {
                this.ShowFieldMessage("NewXslt.Name", GetString("AddNewXsltFunctionWorkflow.TotalNameTooLang"));
                return;
            }


            IXsltFile xsltfile = DataFacade.BuildNew <IXsltFile>();

            xsltfile.FolderPath = System.IO.Path.GetDirectoryName(function.XslFilePath);
            xsltfile.FileName   = System.IO.Path.GetFileName(function.XslFilePath);

            if (!DataFacade.ValidatePath(xsltfile, "XslFileProvider"))
            {
                this.ShowFieldMessage("CurrentXslt.Name", GetString("EditXsltFunctionWorkflow.TotalNameTooLang"));
                return;
            }

            e.Result = true;
        }