private void initializeCodeActivity_ExecuteCode(object sender, EventArgs e) { IXsltFunction xsltFunction = DataFacade.BuildNew <IXsltFunction>(); xsltFunction.Id = Guid.NewGuid(); xsltFunction.Name = ""; xsltFunction.OutputXmlSubType = "XHTML"; xsltFunction.Description = ""; BaseFunctionFolderElementEntityToken folderToken = (BaseFunctionFolderElementEntityToken)this.EntityToken; xsltFunction.Namespace = folderToken.FunctionNamespace ?? UserSettings.LastSpecifiedNamespace; this.Bindings.Add("NewXslt", xsltFunction); var copyOfOptions = new List <KeyValuePair <Guid, string> >(); foreach (IXsltFunction function in DataFacade.GetData <IXsltFunction>()) { string fullName = function.Namespace + "." + function.Name; copyOfOptions.Add(new KeyValuePair <Guid, string>(function.Id, fullName)); } // Sorting alphabetically by function's full name copyOfOptions.Sort((a, b) => a.Value.CompareTo(b.Value)); copyOfOptions.Insert(0, new KeyValuePair <Guid, string>(Guid.Empty, GetText("AddNewXsltFunctionStep1.LabelCopyFromEmptyOption"))); this.Bindings.Add(Binding_CopyFromFunctionId, Guid.Empty); this.Bindings.Add(Binding_CopyFromOptions, copyOfOptions); }
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); }
internal static bool ValidateXslFilePath(this IXsltFunction xsltFunction) { if (xsltFunction.XslFilePath == null) { return(false); } if (xsltFunction.XslFilePath.Length > 240) { return(false); } return(true); }
private void CloneFunctionCalls(IXsltFunction sourceFunction, IXsltFunction copyTo) { var namedFunctionCalls = DataFacade.GetData <INamedFunctionCall>(nfc => nfc.XsltFunctionId == sourceFunction.Id).ToList(); foreach (INamedFunctionCall namedFunctionCall in namedFunctionCalls) { var clonedFunctionCall = DataFacade.BuildNew <INamedFunctionCall>(); clonedFunctionCall.XsltFunctionId = copyTo.Id; clonedFunctionCall.Name = namedFunctionCall.Name; clonedFunctionCall.SerializedFunction = namedFunctionCall.SerializedFunction; DataFacade.AddNew(clonedFunctionCall); } }
public static IEnumerable <IPackItem> CreateXslt(EntityToken entityToken) { if (entityToken is DataEntityToken) { DataEntityToken dataEntityToken = (DataEntityToken)entityToken; if (dataEntityToken.Data is IXsltFunction) { IXsltFunction data = (IXsltFunction)dataEntityToken.Data; yield return(new PCFunctions(data.Namespace + "." + data.Name)); yield break; } } }
private void codeActivity1_ExecuteCode(object sender, EventArgs e) { DataEntityToken dataEntityToken = (DataEntityToken)this.EntityToken; IXsltFunction xsltFunction = (IXsltFunction)dataEntityToken.Data; if (DataFacade.WillDeleteSucceed <IXsltFunction>(xsltFunction)) { DeleteTreeRefresher deleteTreeRefresher = this.CreateDeleteTreeRefresher(this.EntityToken); IFile file = IFileServices.TryGetFile <IXsltFile>(xsltFunction.XslFilePath); DataFacade.Delete <IParameter>(f => f.OwnerId == xsltFunction.Id); DataFacade.Delete <INamedFunctionCall>(f => f.XsltFunctionId == xsltFunction.Id); DataFacade.Delete(xsltFunction); DeleteFile(file); int count = (from info in DataFacade.GetData <IXsltFunction>() where info.Namespace == xsltFunction.Namespace select info).Count(); if (count == 0) { RefreshFunctionTree(); } else { deleteTreeRefresher.PostRefreshMesseges(); } } else { this.ShowMessage( DialogType.Error, StringResourceSystemFacade.GetString("Composite.Plugins.XsltBasedFunction", "DeleteXsltFunctionWorkflow.CascadeDeleteErrorTitle"), StringResourceSystemFacade.GetString("Composite.Plugins.XsltBasedFunction", "DeleteXsltFunctionWorkflow.CascadeDeleteErrorMessage") ); } }
private void CloneFunctionParameters(IXsltFunction sourceFunction, IXsltFunction copyTo) { var parameters = DataFacade.GetData <IParameter>(p => p.OwnerId == sourceFunction.Id).ToList(); foreach (IParameter parameter in parameters) { var clonedFunctionParameter = DataFacade.BuildNew <IParameter>(); clonedFunctionParameter.OwnerId = copyTo.Id; clonedFunctionParameter.ParameterId = Guid.NewGuid(); clonedFunctionParameter.Name = parameter.Name; clonedFunctionParameter.TypeManagerName = parameter.TypeManagerName; clonedFunctionParameter.HelpText = parameter.HelpText; clonedFunctionParameter.Label = parameter.Label; clonedFunctionParameter.DefaultValueFunctionMarkup = parameter.DefaultValueFunctionMarkup; clonedFunctionParameter.Position = parameter.Position; clonedFunctionParameter.TestValueFunctionMarkup = parameter.TestValueFunctionMarkup; clonedFunctionParameter.WidgetFunctionMarkup = parameter.WidgetFunctionMarkup; DataFacade.AddNew(clonedFunctionParameter); } }
private void editPreviewActivity_ExecuteCode(object sender, EventArgs e) { Stopwatch functionCallingStopwatch = null; long millisecondsToken = 0; CultureInfo oldCurrentCulture = Thread.CurrentThread.CurrentCulture; CultureInfo oldCurrentUICulture = Thread.CurrentThread.CurrentUICulture; try { IXsltFunction xslt = this.GetBinding <IXsltFunction>("CurrentXslt"); string xslTemplate = this.GetBinding <string>("XslTemplate"); IFile persistemTemplateFile = IFileServices.TryGetFile <IXsltFile>(xslt.XslFilePath); if (persistemTemplateFile != null) { string persistemTemplate = persistemTemplateFile.ReadAllText(); if (this.GetBinding <int>("XslTemplateLastSaveHash") != persistemTemplate.GetHashCode()) { xslTemplate = persistemTemplate; ConsoleMessageQueueFacade.Enqueue(new LogEntryMessageQueueItem { Level = LogLevel.Fine, Message = "XSLT file on file system was used. It has been changed by another process.", Sender = this.GetType() }, this.GetCurrentConsoleId()); } } List <NamedFunctionCall> namedFunctions = this.GetBinding <IEnumerable <NamedFunctionCall> >("FunctionCalls").ToList(); // If preview is done multiple times in a row, with no postbacks an object reference to BaseFunctionRuntimeTreeNode may be held // If the function in the BaseFunctionRuntimeTreeNode have ben unloaded / reloaded, this preview will still run on the old instance // We force refresh by serializing / deserializing foreach (NamedFunctionCall namedFunction in namedFunctions) { namedFunction.FunctionCall = (BaseFunctionRuntimeTreeNode)FunctionFacade.BuildTree(namedFunction.FunctionCall.Serialize()); } List <ManagedParameterDefinition> parameterDefinitions = this.GetBinding <IEnumerable <ManagedParameterDefinition> >("Parameters").ToList(); Guid pageId = this.GetBinding <Guid>("PageId"); string dataScopeName = this.GetBinding <string>("PageDataScopeName"); string cultureName = this.GetBinding <string>("ActiveCultureName"); CultureInfo cultureInfo = null; if (cultureName != null) { cultureInfo = CultureInfo.CreateSpecificCulture(cultureName); } IPage page; TransformationInputs transformationInput; using (new DataScope(DataScopeIdentifier.Deserialize(dataScopeName), cultureInfo)) { Thread.CurrentThread.CurrentCulture = cultureInfo; Thread.CurrentThread.CurrentUICulture = cultureInfo; page = DataFacade.GetData <IPage>(f => f.Id == pageId).FirstOrDefault(); if (page != null) { PageRenderer.CurrentPage = page; } functionCallingStopwatch = Stopwatch.StartNew(); transformationInput = RenderHelper.BuildInputDocument(namedFunctions, parameterDefinitions, true); functionCallingStopwatch.Stop(); Thread.CurrentThread.CurrentCulture = oldCurrentCulture; Thread.CurrentThread.CurrentUICulture = oldCurrentUICulture; } string output = ""; string error = ""; try { Thread.CurrentThread.CurrentCulture = cultureInfo; Thread.CurrentThread.CurrentUICulture = cultureInfo; var styleSheet = XElement.Parse(xslTemplate); XsltBasedFunctionProvider.ResolveImportIncludePaths(styleSheet); LocalizationParser.Parse(styleSheet); XDocument transformationResult = new XDocument(); using (XmlWriter writer = new LimitedDepthXmlWriter(transformationResult.CreateWriter())) { XslCompiledTransform xslTransformer = new XslCompiledTransform(); xslTransformer.Load(styleSheet.CreateReader(), XsltSettings.TrustedXslt, new XmlUrlResolver()); XsltArgumentList transformArgs = new XsltArgumentList(); XslExtensionsManager.Register(transformArgs); if (transformationInput.ExtensionDefinitions != null) { foreach (IXsltExtensionDefinition extensionDef in transformationInput.ExtensionDefinitions) { transformArgs.AddExtensionObject(extensionDef.ExtensionNamespace.ToString(), extensionDef.EntensionObjectAsObject); } } Exception exception = null; HttpContext httpContext = HttpContext.Current; Thread thread = new Thread(delegate() { Thread.CurrentThread.CurrentCulture = cultureInfo; Thread.CurrentThread.CurrentUICulture = cultureInfo; Stopwatch transformationStopwatch = Stopwatch.StartNew(); try { using (ThreadDataManager.Initialize()) using (new DataScope(DataScopeIdentifier.Deserialize(dataScopeName), cultureInfo)) { HttpContext.Current = httpContext; var reader = transformationInput.InputDocument.CreateReader(); xslTransformer.Transform(reader, transformArgs, writer); } } catch (ThreadAbortException ex) { exception = ex; Thread.ResetAbort(); } catch (Exception ex) { exception = ex; } transformationStopwatch.Stop(); millisecondsToken = transformationStopwatch.ElapsedMilliseconds; }); thread.Start(); bool res = thread.Join(1000); // sadly, this needs to be low enough to prevent StackOverflowException from fireing. if (res == false) { if (thread.ThreadState == System.Threading.ThreadState.Running) { thread.Abort(); } throw new XslLoadException("Transformation took more than 1000 milliseconds to complete. This could be due to a never ending recursive call. Execution aborted to prevent fatal StackOverflowException."); } if (exception != null) { throw exception; } } if (xslt.OutputXmlSubType == "XHTML") { XhtmlDocument xhtmlDocument = new XhtmlDocument(transformationResult); output = xhtmlDocument.Root.ToString(); } else { output = transformationResult.Root.ToString(); } } catch (Exception ex) { output = "<error/>"; error = string.Format("{0}\n{1}", ex.GetType().Name, ex.Message); Exception inner = ex.InnerException; string indent = ""; while (inner != null) { indent = indent + " - "; error = error + "\n" + indent + inner.Message; inner = inner.InnerException; } } finally { Thread.CurrentThread.CurrentCulture = oldCurrentCulture; Thread.CurrentThread.CurrentUICulture = oldCurrentUICulture; } Page currentPage = HttpContext.Current.Handler as Page; if (currentPage == null) { throw new InvalidOperationException("The Current HttpContext Handler must be a System.Web.Ui.Page"); } UserControl inOutControl = (UserControl)currentPage.LoadControl(UrlUtils.ResolveAdminUrl("controls/Misc/MarkupInOutView.ascx")); inOutControl.Attributes.Add("in", transformationInput.InputDocument.ToString()); inOutControl.Attributes.Add("out", output); inOutControl.Attributes.Add("error", error); inOutControl.Attributes.Add("statusmessage", string.Format("Execution times: Total {0} ms. Functions: {1} ms. XSLT: {2} ms.", millisecondsToken + functionCallingStopwatch.ElapsedMilliseconds, functionCallingStopwatch.ElapsedMilliseconds, millisecondsToken)); FlowControllerServicesContainer serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId); var webRenderService = serviceContainer.GetService <IFormFlowWebRenderingService>(); webRenderService.SetNewPageOutput(inOutControl); } catch (Exception ex) { FlowControllerServicesContainer serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId); Control errOutput = new LiteralControl("<pre>" + ex.ToString() + "</pre>"); var webRenderService = serviceContainer.GetService <IFormFlowWebRenderingService>(); webRenderService.SetNewPageOutput(errOutput); } }
private void CloneFunctionParameters(IXsltFunction sourceFunction, IXsltFunction copyTo) { var parameters = DataFacade.GetData<IParameter>(p => p.OwnerId == sourceFunction.Id).ToList(); foreach (IParameter parameter in parameters) { var clonedFunctionParameter = DataFacade.BuildNew<IParameter>(); clonedFunctionParameter.OwnerId = copyTo.Id; clonedFunctionParameter.ParameterId = Guid.NewGuid(); clonedFunctionParameter.Name = parameter.Name; clonedFunctionParameter.TypeManagerName = parameter.TypeManagerName; clonedFunctionParameter.HelpText = parameter.HelpText; clonedFunctionParameter.Label = parameter.Label; clonedFunctionParameter.DefaultValueFunctionMarkup = parameter.DefaultValueFunctionMarkup; clonedFunctionParameter.Position = parameter.Position; clonedFunctionParameter.TestValueFunctionMarkup = parameter.TestValueFunctionMarkup; clonedFunctionParameter.WidgetFunctionMarkup = parameter.WidgetFunctionMarkup; DataFacade.AddNew(clonedFunctionParameter); } }
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; }
private void CloneFunctionCalls(IXsltFunction sourceFunction, IXsltFunction copyTo) { var namedFunctionCalls = DataFacade.GetData<INamedFunctionCall>(nfc => nfc.XsltFunctionId == sourceFunction.Id).ToList(); foreach (INamedFunctionCall namedFunctionCall in namedFunctionCalls) { var clonedFunctionCall = DataFacade.BuildNew<INamedFunctionCall>(); clonedFunctionCall.XsltFunctionId = copyTo.Id; clonedFunctionCall.Name = namedFunctionCall.Name; clonedFunctionCall.SerializedFunction = namedFunctionCall.SerializedFunction; DataFacade.AddNew(clonedFunctionCall); } }
private void initializeCodeActivity_ExecuteCode(object sender, EventArgs e) { DataEntityToken dataEntityToken = (DataEntityToken)this.EntityToken; IXsltFunction xsltFunction = (IXsltFunction)dataEntityToken.Data; IFile file = IFileServices.GetFile <IXsltFile>(xsltFunction.XslFilePath); IEnumerable <ManagedParameterDefinition> parameters = ManagedParameterManager.Load(xsltFunction.Id); this.Bindings.Add("CurrentXslt", dataEntityToken.Data); this.Bindings.Add("Parameters", parameters); // popular type widgets List <Type> popularTypes = DataFacade.GetAllInterfaces(UserType.Developer); var popularWidgetTypes = FunctionFacade.WidgetFunctionSupportedTypes.Where(f => f.GetGenericArguments().Any(g => popularTypes.Any(h => h.IsAssignableFrom(g)))); IEnumerable <Type> parameterTypeOptions = FunctionFacade.FunctionSupportedTypes.Union(popularWidgetTypes).Union(FunctionFacade.WidgetFunctionSupportedTypes); // At the moment we don't have functions that return IEnumerable<XNode>, so we're hardcoding this type for now parameterTypeOptions = parameterTypeOptions.Union(new [] { typeof(IEnumerable <XNode>) }); this.Bindings.Add("ParameterTypeOptions", parameterTypeOptions.ToList()); string xsltDocumentString = file.ReadAllText(); this.Bindings.Add("XslTemplate", xsltDocumentString); this.Bindings.Add("XslTemplateLastSaveHash", xsltDocumentString.GetHashCode()); List <string> functionErrors; List <NamedFunctionCall> FunctionCalls = RenderHelper.GetValidFunctionCalls(xsltFunction.Id, out functionErrors).ToList(); if ((functionErrors != null) && (functionErrors.Any())) { foreach (string error in functionErrors) { this.ShowMessage(DialogType.Error, "A function call has been dropped", error); } } this.Bindings.Add("FunctionCalls", FunctionCalls); this.Bindings.Add("PageId", PageManager.GetChildrenIDs(Guid.Empty).FirstOrDefault()); if (UserSettings.ActiveLocaleCultureInfo != null) { List <KeyValuePair <string, string> > activeCulturesDictionary = UserSettings.ActiveLocaleCultureInfos.Select(f => new KeyValuePair <string, string>(f.Name, DataLocalizationFacade.GetCultureTitle(f))).ToList(); this.Bindings.Add("ActiveCultureName", UserSettings.ActiveLocaleCultureInfo.Name); this.Bindings.Add("ActiveCulturesList", activeCulturesDictionary); } this.Bindings.Add("PageDataScopeName", DataScopeIdentifier.AdministratedName); this.Bindings.Add("PageDataScopeList", new Dictionary <string, string> { { DataScopeIdentifier.AdministratedName, GetString("EditXsltFunction.LabelAdminitrativeScope") }, { DataScopeIdentifier.PublicName, GetString("EditXsltFunction.LabelPublicScope") } }); // Creating a session state object Guid stateId = Guid.NewGuid(); var state = new FunctionCallDesignerState { WorkflowId = WorkflowInstanceId, ConsoleIdInternal = GetCurrentConsoleId() }; SessionStateManager.DefaultProvider.AddState <IFunctionCallEditorState>(stateId, state, DateTime.Now.AddDays(7.0)); this.Bindings.Add("SessionStateProvider", SessionStateManager.DefaultProviderName); this.Bindings.Add("SessionStateId", stateId); }
public XsltXmlFunction(IXsltFunction xsltFunction) { _xsltFunction = xsltFunction; }
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); } }
public XsltFunctionTreeBuilderLeafInfo(IXsltFunction function) { _function = function; }
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; }
internal static string CreateXslFilePath(this IXsltFunction xsltFunction) { return(string.Format("/{0}/{1}.xsl", xsltFunction.Namespace.Replace(".", "/"), xsltFunction.Name).Replace("//", "/").Replace('\\', '/')); }