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);
        }
 /// <summary>
 /// Gets the entity identifier of the entity.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <returns>The entity identifier of the entity.</returns>
 public static StringUdi GetUdi(this IXsltFile entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     return(new StringUdi(Constants.UdiEntityType.Xslt, entity.Path.TrimStart('/')).EnsureClosed());
 }
            private XslCompiledTransform GetXslCompiledTransform()
            {
                CultureInfo          currentCultureInfo = LocalizationScopeManager.CurrentLocalizationScope;
                XslCompiledTransform xslCompiledTransform;

                if (_xslTransformations.TryGetValue(currentCultureInfo, out xslCompiledTransform))
                {
                    return(xslCompiledTransform);
                }

                lock (_lock)
                {
                    if (!_xslTransformations.TryGetValue(currentCultureInfo, out xslCompiledTransform))
                    {
                        using (
                            DebugLoggingScope.CompletionTime(this.GetType(), "Loading and compiling {0}".FormatWith(_xsltFunction.XslFilePath)))
                        {
                            string folderPath = Path.GetDirectoryName(_xsltFunction.XslFilePath);
                            string fileName   = Path.GetFileName(_xsltFunction.XslFilePath);

                            IXsltFile xsltFileHandle = null;

                            try
                            {
                                var xsltFileHandles =
                                    (from file in DataFacade.GetData <IXsltFile>()
                                     where String.Equals(file.FolderPath, folderPath, StringComparison.OrdinalIgnoreCase) &&
                                     String.Equals(file.FileName, fileName, StringComparison.OrdinalIgnoreCase)
                                     select file).ToList();

                                Verify.That(xsltFileHandles.Count == 1, "XSLT file path {0} found {1} times. Only one instance was expected.".FormatWith(_xsltFunction.XslFilePath, xsltFileHandles.Count));
                                xsltFileHandle = xsltFileHandles[0];
                            }
                            catch (Exception ex)
                            {
                                Log.LogError("XsltBasedFunctionProvider", ex);
                                throw;
                            }

                            if (!_subscribedToFileChanges)
                            {
                                xsltFileHandle.SubscribeOnChanged(ClearCachedData);
                                _subscribedToFileChanges = true;
                            }

                            xslCompiledTransform = new XslCompiledTransform();


                            XDocument doc;
                            using (Stream xsltSourceStream = xsltFileHandle.GetReadStream())
                            {
                                using (XmlReader xmlReader = XmlReader.Create(xsltSourceStream))
                                {
                                    doc = XDocument.Load(xmlReader);
                                }
                            }

                            ResolveImportIncludePaths(doc);

                            LocalizationParser.Parse(doc);

                            xslCompiledTransform.Load(doc.CreateReader(), XsltSettings.TrustedXslt, new XmlUrlResolver());

                            _xslTransformations.Add(currentCultureInfo, xslCompiledTransform);
                        }
                    }
                }
                return(xslCompiledTransform);
            }
        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;
        }
Esempio n. 5
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;
        }