public static Dictionary<Guid, string> GetIdToUrlLookup(string dataScopeIdentifier, CultureInfo culture) { using (new DataScope(DataScopeIdentifier.Deserialize(dataScopeIdentifier), culture)) { return GetMap().IdToUrlLookup; } }
public XmlDataTypeStore(DataTypeDescriptor dataTypeDescriptor, Type dataProviderHelperType, Type dataIdClassType, IEnumerable <XmlDataTypeStoreDataScope> xmlDateTypeStoreDataScopes, bool isGeneratedDataType) { DataTypeDescriptor = dataTypeDescriptor ?? throw new ArgumentNullException(nameof(dataTypeDescriptor)); DataProviderHelperType = dataProviderHelperType ?? throw new ArgumentNullException(nameof(dataProviderHelperType)); DataIdClassType = dataIdClassType ?? throw new ArgumentNullException(nameof(dataIdClassType)); IsGeneratedDataType = isGeneratedDataType; _xmlDateTypeStoreDataScopes = xmlDateTypeStoreDataScopes.Evaluate(); var ordering = new List <Func <XElement, IComparable> >(); foreach (string key in dataTypeDescriptor.KeyPropertyNames) { XName localKey = key; ordering.Add(f => (string)f.Attribute(localKey) ?? ""); } Func <IEnumerable <XElement>, IOrderedEnumerable <XElement> > orderer = f => ordering.Skip(1).Aggregate(f.OrderBy(ordering.First()), Enumerable.ThenBy); foreach (XmlDataTypeStoreDataScope xmlDataTypeStoreDataScope in _xmlDateTypeStoreDataScopes) { DataScopeIdentifier dataScopeIdentifier = DataScopeIdentifier.Deserialize(xmlDataTypeStoreDataScope.DataScopeName); CultureInfo culture = CultureInfo.CreateSpecificCulture(xmlDataTypeStoreDataScope.CultureName); Type dataType = dataTypeDescriptor.GetInterfaceType(); Action cacheFlush = () => DataEventSystemFacade.FireExternalStoreChangedEvent(dataType, dataScopeIdentifier.ToPublicationScope(), culture); XmlDataProviderDocumentCache.RegisterExternalFileChangeAction(xmlDataTypeStoreDataScope.Filename, cacheFlush); XmlDataProviderDocumentWriter.RegisterFileOrderer(xmlDataTypeStoreDataScope.Filename, orderer); } }
public static PageUrlOptions ParsePublicUrl(string url, out NameValueCollection notUsedQueryParameters) { var urlString = new UrlString(url); notUsedQueryParameters = null; if (!IsPublicUrl(urlString.FilePath)) { return(null); } string requestPath; Uri uri; if (Uri.TryCreate(urlString.FilePath, UriKind.Absolute, out uri)) { requestPath = HttpUtility.UrlDecode(uri.AbsolutePath).ToLower(); } else { requestPath = urlString.FilePath.ToLower(); } string requestPathWithoutUrlMappingName; CultureInfo locale = PageUrl.GetCultureInfo(requestPath, out requestPathWithoutUrlMappingName); if (locale == null) { return(null); } string dataScopeName = urlString["dataScope"]; if (dataScopeName.IsNullOrEmpty()) { dataScopeName = DataScopeIdentifier.GetDefault().Name; } Guid pageId = Guid.Empty; using (new DataScope(DataScopeIdentifier.Deserialize(dataScopeName), locale)) { if (PageStructureInfo.GetLowerCaseUrlToIdLookup().TryGetValue(requestPath.ToLower(), out pageId) == false) { return(null); } } urlString["dataScope"] = null; notUsedQueryParameters = urlString.GetQueryParameters(); return(new PageUrlOptions(dataScopeName, locale, pageId, UrlType.Public)); }
private void editCodeActivity_Preview_ExecuteCode(object sender, EventArgs e) { IInlineFunction functionInfo = this.GetBinding <IInlineFunction>("Function"); string code = this.GetBinding <string>("FunctionCode"); List <string> selectedAssemblies = this.GetBinding <List <string> >("SelectedAssemblies"); StringInlineFunctionCreateMethodErrorHandler handler = new StringInlineFunctionCreateMethodErrorHandler(); MethodInfo methodInfo = InlineFunctionHelper.Create(functionInfo, code, handler, selectedAssemblies); FlowControllerServicesContainer serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId); IFormFlowWebRenderingService formFlowWebRenderingService = serviceContainer.GetService <IFormFlowWebRenderingService>(); if (handler.HasErrors) { StringBuilder sb = new StringBuilder(); if (!string.IsNullOrWhiteSpace(handler.MissingContainerType)) { AddFormattedTextBlock(sb, handler.MissingContainerType); } if (!string.IsNullOrWhiteSpace(handler.NamespaceMismatch)) { AddFormattedTextBlock(sb, handler.NamespaceMismatch); } if (!string.IsNullOrWhiteSpace(handler.MissionMethod)) { AddFormattedTextBlock(sb, handler.MissionMethod); } if (handler.LoadingException != null) { AddFormattedTextBlock(sb, handler.LoadingException.ToString()); } foreach (Tuple <int, string, string> compileError in handler.CompileErrors) { AddFormattedTextBlock(sb, "{0} : {1} : {2}".FormatWith(compileError.Item1, compileError.Item2, compileError.Item3)); } formFlowWebRenderingService.SetNewPageOutput(new LiteralControl(sb.ToString())); return; } List <ManagedParameterDefinition> parameters = this.GetBinding <List <ManagedParameterDefinition> >("Parameters"); List <object> parameterValues = new List <object>(); bool parameterErrors = false; StringBuilder parameterErrorMessages = new StringBuilder(); foreach (ParameterInfo parameterInfo in methodInfo.GetParameters()) { ManagedParameterDefinition parameter = parameters.FirstOrDefault(f => f.Name == parameterInfo.Name); if (parameter == null) { string message = string.Format(GetText("CSharpInlineFunction.MissingParameterDefinition"), parameterInfo.Name); parameterErrors = true; AddFormattedTextBlock(parameterErrorMessages, message); } else if (parameter.Type != parameterInfo.ParameterType) { string message = string.Format(GetText("CSharpInlineFunction.WrongParameterTestValueType"), parameterInfo.Name, parameterInfo.ParameterType, parameter.Type); parameterErrors = true; AddFormattedTextBlock(parameterErrorMessages, message); } else { string previewValueFunctionMarkup = (string.IsNullOrEmpty(parameter.TestValueFunctionMarkup) ? parameter.DefaultValueFunctionMarkup : parameter.TestValueFunctionMarkup); if (string.IsNullOrEmpty(previewValueFunctionMarkup)) { string message = string.Format(GetText("CSharpInlineFunction.MissingParameterTestOrDefaultValue"), parameterInfo.Name, parameterInfo.ParameterType, parameter.Type); parameterErrors = true; AddFormattedTextBlock(parameterErrorMessages, message); } else { try { BaseRuntimeTreeNode treeNode = FunctionFacade.BuildTree(XElement.Parse(previewValueFunctionMarkup)); object value = treeNode.GetValue(); object typedValue = ValueTypeConverter.Convert(value, parameter.Type); parameterValues.Add(typedValue); } catch (Exception ex) { string message = string.Format("Error setting '{0}'. {1}", parameterInfo.Name, ex.Message); parameterErrors = true; AddFormattedTextBlock(parameterErrorMessages, message); } } } } if (parameterErrors) { formFlowWebRenderingService.SetNewPageOutput(new LiteralControl(parameterErrorMessages.ToString())); return; } CultureInfo oldCurrentCulture = Thread.CurrentThread.CurrentCulture; CultureInfo oldCurrentUICulture = Thread.CurrentThread.CurrentUICulture; try { Guid pageId; if (this.GetBinding <object>("PageId") == null) { pageId = Guid.Empty; } else { 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); } using (new DataScope(DataScopeIdentifier.Deserialize(dataScopeName), cultureInfo)) { Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = cultureInfo; IPage page = DataFacade.GetData <IPage>(f => f.Id == pageId).FirstOrDefault(); if (page != null) { PageRenderer.CurrentPage = page; } object result = methodInfo.Invoke(null, parameterValues.ToArray()); string resultString; try { resultString = PrettyPrinter.Print(result); } catch (Exception ex) { throw new TargetInvocationException(ex); } SetOutput(formFlowWebRenderingService, resultString); } } catch (TargetInvocationException ex) { SetOutput(formFlowWebRenderingService, ex.InnerException.ToString()); } finally { Thread.CurrentThread.CurrentCulture = oldCurrentCulture; Thread.CurrentThread.CurrentUICulture = oldCurrentUICulture; } }
internal static DataTypeDescriptor FromXml(XElement element, bool inheritedFieldsIncluded) { Verify.ArgumentNotNull(element, "element"); if (element.Name != "DataTypeDescriptor") { throw new ArgumentException("The xml is not correctly formatted."); } Guid dataTypeId = (Guid)element.GetRequiredAttribute("dataTypeId"); string name = element.GetRequiredAttributeValue("name"); string @namespace = element.GetRequiredAttributeValue("namespace"); // TODO: check why "hasCustomPhysicalSortOrder" is not used bool hasCustomPhysicalSortOrder = (bool)element.GetRequiredAttribute("hasCustomPhysicalSortOrder"); bool isCodeGenerated = (bool)element.GetRequiredAttribute("isCodeGenerated"); XAttribute cachableAttribute = element.Attribute("cachable"); XAttribute buildNewHandlerTypeNameAttribute = element.Attribute("buildNewHandlerTypeName"); XElement dataAssociationsElement = element.GetRequiredElement("DataAssociations"); XElement dataScopesElement = element.GetRequiredElement("DataScopes"); XElement keyPropertyNamesElement = element.GetRequiredElement("KeyPropertyNames"); // TODO: check why "superInterfaceKeyPropertyNamesElement" is not used // XElement superInterfaceKeyPropertyNamesElement = element.Element("SuperInterfaceKeyPropertyNames"); XElement superInterfacesElement = element.GetRequiredElement("SuperInterfaces"); XElement fieldsElement = element.GetRequiredElement("Fields"); XElement indexesElement = element.Element("Indexes"); XAttribute titleAttribute = element.Attribute("title"); XAttribute labelFieldNameAttribute = element.Attribute("labelFieldName"); XAttribute internalUrlPrefixAttribute = element.Attribute("internalUrlPrefix"); string typeManagerTypeName = (string)element.Attribute("typeManagerTypeName"); bool cachable = cachableAttribute != null && (bool)cachableAttribute; var dataTypeDescriptor = new DataTypeDescriptor(dataTypeId, @namespace, name, isCodeGenerated) { Cachable = cachable }; if (titleAttribute != null) { dataTypeDescriptor.Title = titleAttribute.Value; } if (labelFieldNameAttribute != null) { dataTypeDescriptor.LabelFieldName = labelFieldNameAttribute.Value; } if (internalUrlPrefixAttribute != null) { dataTypeDescriptor.InternalUrlPrefix = internalUrlPrefixAttribute.Value; } if (typeManagerTypeName != null) { typeManagerTypeName = TypeManager.FixLegasyTypeName(typeManagerTypeName); dataTypeDescriptor.TypeManagerTypeName = typeManagerTypeName; } if (buildNewHandlerTypeNameAttribute != null) { dataTypeDescriptor.BuildNewHandlerTypeName = buildNewHandlerTypeNameAttribute.Value; } foreach (XElement elm in dataAssociationsElement.Elements()) { var dataTypeAssociationDescriptor = DataTypeAssociationDescriptor.FromXml(elm); dataTypeDescriptor.DataAssociations.Add(dataTypeAssociationDescriptor); } foreach (XElement elm in dataScopesElement.Elements("DataScopeIdentifier")) { string dataScopeName = elm.GetRequiredAttributeValue("name"); if (DataScopeIdentifier.IsLegasyDataScope(dataScopeName)) { Log.LogWarning("DataTypeDescriptor", "Ignored legacy data scope '{0}' on type '{1}.{2}' while deserializing DataTypeDescriptor. The '{0}' data scope is no longer supported.".FormatWith(dataScopeName, @namespace, name)); continue; } DataScopeIdentifier dataScopeIdentifier = DataScopeIdentifier.Deserialize(dataScopeName); dataTypeDescriptor.DataScopes.Add(dataScopeIdentifier); } foreach (XElement elm in superInterfacesElement.Elements("SuperInterface")) { string superInterfaceTypeName = elm.GetRequiredAttributeValue("type"); if (superInterfaceTypeName.StartsWith("Composite.Data.ProcessControlled.IDeleteControlled")) { Log.LogWarning("DataTypeDescriptor", string.Format("Ignored legacy super interface '{0}' on type '{1}.{2}' while deserializing DataTypeDescriptor. This super interface is no longer supported.", superInterfaceTypeName, @namespace, name)); continue; } Type superInterface; try { superInterface = TypeManager.GetType(superInterfaceTypeName); } catch (Exception ex) { throw XmlConfigurationExtensionMethods.GetConfigurationException("Failed to load super interface '{0}'".FormatWith(superInterfaceTypeName), ex, elm); } dataTypeDescriptor.AddSuperInterface(superInterface, !inheritedFieldsIncluded); } foreach (XElement elm in fieldsElement.Elements()) { var dataFieldDescriptor = DataFieldDescriptor.FromXml(elm); try { dataTypeDescriptor.Fields.Add(dataFieldDescriptor); } catch (Exception ex) { throw XmlConfigurationExtensionMethods.GetConfigurationException("Failed to add a data field: " + ex.Message, ex, elm); } } foreach (XElement elm in keyPropertyNamesElement.Elements("KeyPropertyName")) { var propertyName = elm.GetRequiredAttributeValue("name"); bool isDefinedOnSuperInterface = dataTypeDescriptor.SuperInterfaces.Any(f => f.GetProperty(propertyName) != null); if (!isDefinedOnSuperInterface) { dataTypeDescriptor.KeyPropertyNames.Add(propertyName); } } if (indexesElement != null) { dataTypeDescriptor.Indexes = indexesElement.Elements("Index").Select(DataTypeIndex.FromXml).ToList(); } // Loading field rendering profiles for static data types if (!isCodeGenerated && typeManagerTypeName != null) { Type type = Type.GetType(typeManagerTypeName); if (type != null) { foreach (var fieldDescriptor in dataTypeDescriptor.Fields) { var property = type.GetProperty(fieldDescriptor.Name); if (property != null) { var formRenderingProfile = DynamicTypeReflectionFacade.GetFormRenderingProfile(property); if (formRenderingProfile != null) { fieldDescriptor.FormRenderingProfile = formRenderingProfile; } } } } } return(dataTypeDescriptor); }
private void ValidateAndLoadConfiguration() { XElement typesElement = this.Configuration.SingleOrDefault(f => f.Name == "Types"); if (typesElement == null) { _validationResult.AddFatal(GetText("DataPackageFragmentInstaller.MissingElement")); } if (typesElement == null) { return; } foreach (XElement typeElement in typesElement.Elements("Type")) { var typeAttribute = typeElement.Attribute("type"); if (typeAttribute == null) { _validationResult.AddFatal(Texts.DataPackageFragmentInstaller_MissingAttribute("type"), typeElement); continue; } XAttribute allowOverwriteAttribute = typeElement.Attribute("allowOverwrite"); XAttribute onlyUpdateAttribute = typeElement.Attribute("onlyUpdate"); bool allowOverwrite = allowOverwriteAttribute != null && (bool)allowOverwriteAttribute; bool onlyUpdate = onlyUpdateAttribute != null && (bool)onlyUpdateAttribute; string interfaceTypeName = typeAttribute.Value; interfaceTypeName = TypeManager.FixLegasyTypeName(interfaceTypeName); foreach (XElement dataElement in typeElement.Elements("Data")) { XAttribute dataScopeIdentifierAttribute = dataElement.Attribute("dataScopeIdentifier"); if (dataScopeIdentifierAttribute == null) { _validationResult.AddFatal(Texts.DataPackageFragmentInstaller_MissingAttribute("dataScopeIdentifier"), typeElement); continue; } DataScopeIdentifier dataScopeIdentifier; try { dataScopeIdentifier = DataScopeIdentifier.Deserialize(dataScopeIdentifierAttribute.Value); } catch (Exception) { _validationResult.AddFatal(GetText("DataPackageFragmentInstaller.WrongDataScopeIdentifier").FormatWith(dataScopeIdentifierAttribute.Value), dataScopeIdentifierAttribute); continue; } CultureInfo locale = null; // null => do not use localization bool allLocales = false; bool currentLocale = false; XAttribute localeAttribute = dataElement.Attribute("locale"); if (localeAttribute != null) { if (localeAttribute.Value == "*") { allLocales = true; } else if (localeAttribute.Value == "?") { currentLocale = true; } else { try { locale = CultureInfo.CreateSpecificCulture(localeAttribute.Value); } catch (Exception) { _validationResult.AddFatal(GetText("DataPackageFragmentInstaller.WrongLocale").FormatWith(localeAttribute.Value), localeAttribute); continue; } } } XAttribute dataFilenameAttribute = dataElement.Attribute("dataFilename"); if (dataFilenameAttribute == null) { _validationResult.AddFatal(Texts.DataPackageFragmentInstaller_MissingAttribute("dataFilename"), typeElement); continue; } if (!this.InstallerContext.ZipFileSystem.ContainsFile(dataFilenameAttribute.Value)) { _validationResult.AddFatal(GetText("DataPackageFragmentInstaller.MissingFile").FormatWith(dataFilenameAttribute.Value), dataFilenameAttribute); continue; } XDocument doc; try { using (var stream = this.InstallerContext.ZipFileSystem.GetFileStream(dataFilenameAttribute.Value)) using (var reader = new C1StreamReader(stream)) { doc = XDocument.Load(reader); } } catch (Exception ex) { _validationResult.Add(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, ex)); continue; } XAttribute isDynamicAddedAttribute = typeElement.Attribute("isDynamicAdded"); bool isDynamicAdded = isDynamicAddedAttribute != null && (bool)isDynamicAddedAttribute; var dataType = new DataType { InterfaceTypeName = interfaceTypeName, DataScopeIdentifier = dataScopeIdentifier, Locale = locale, AddToAllLocales = allLocales, AddToCurrentLocale = currentLocale, IsDynamicAdded = isDynamicAdded, AllowOverwrite = allowOverwrite, OnlyUpdate = onlyUpdate, Dataset = doc.Root.Elements("Add") }; _dataTypes.Add(dataType); } } }
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); } }
/// <exclude /> public override IEnumerable <PackageFragmentValidationResult> Validate() { var validationResult = new List <PackageFragmentValidationResult>(); if (this.Configuration.Count(f => f.Name == "Types") > 1) { validationResult.AddFatal(Texts.DataPackageFragmentUninstaller_OnlyOneElement); return(validationResult); } _dataToDelete = new List <DataType>(); XElement typesElement = this.Configuration.SingleOrDefault(f => f.Name == "Types"); if (typesElement == null) { return(validationResult); } foreach (XElement typeElement in typesElement.Elements("Type").Reverse()) { XAttribute typeAttribute = typeElement.Attribute("type"); XAttribute dataScopeIdentifierAttribute = typeElement.Attribute("dataScopeIdentifier"); if (typeAttribute == null) { validationResult.AddFatal(Texts.DataPackageFragmentUninstaller_MissingAttribute("type"), typeElement); continue; } if (dataScopeIdentifierAttribute == null) { validationResult.AddFatal(Texts.DataPackageFragmentUninstaller_MissingAttribute("dataScopeIdentifier"), typeElement); continue; } Type type = TypeManager.TryGetType(typeAttribute.Value); if (type == null) { continue; } if (!DataFacade.GetAllInterfaces().Contains(type)) { continue; } DataScopeIdentifier dataScopeIdentifier; try { dataScopeIdentifier = DataScopeIdentifier.Deserialize(dataScopeIdentifierAttribute.Value); } catch (Exception) { validationResult.AddFatal("Wrong DataScopeIdentifier ({0}) name in the configuration".FormatWith(dataScopeIdentifierAttribute.Value), dataScopeIdentifierAttribute); continue; } foreach (XElement datasElement in typeElement.Elements("Datas").Reverse()) { CultureInfo locale = null; XAttribute localeAttribute = datasElement.Attribute("locale"); if (localeAttribute != null) { locale = CultureInfo.CreateSpecificCulture(localeAttribute.Value); } foreach (XElement keysElement in datasElement.Elements("Keys").Reverse()) { bool allKeyPropertiesValidated = true; var dataKeyPropertyCollection = new DataKeyPropertyCollection(); foreach (XElement keyElement in keysElement.Elements("Key")) { XAttribute keyNameAttribute = keyElement.Attribute("name"); XAttribute keyValueAttribute = keyElement.Attribute("value"); if (keyNameAttribute == null || keyValueAttribute == null) { if (keyNameAttribute == null) { validationResult.AddFatal(GetText("DataPackageFragmentUninstaller.MissingAttribute").FormatWith("name"), keyElement); } if (keyValueAttribute == null) { validationResult.AddFatal(GetText("DataPackageFragmentUninstaller.MissingAttribute").FormatWith("value"), keyElement); } allKeyPropertiesValidated = false; continue; } string keyName = keyNameAttribute.Value; PropertyInfo keyPropertyInfo = type.GetPropertiesRecursively().SingleOrDefault(f => f.Name == keyName); if (keyPropertyInfo == null) { validationResult.AddFatal(GetText("DataPackageFragmentUninstaller.MissingKeyProperty").FormatWith(type, keyName)); allKeyPropertiesValidated = false; } else { try { object keyValue = ValueTypeConverter.Convert(keyValueAttribute.Value, keyPropertyInfo.PropertyType); dataKeyPropertyCollection.AddKeyProperty(keyName, keyValue); } catch (Exception) { allKeyPropertiesValidated = false; validationResult.AddFatal(GetText("DataPackageFragmentUninstaller.DataPackageFragmentUninstaller").FormatWith(keyValueAttribute.Value, keyPropertyInfo.PropertyType)); } } } if (allKeyPropertiesValidated) { IData data; using (new DataScope(dataScopeIdentifier, locale)) { data = DataFacade.TryGetDataByUniqueKey(type, dataKeyPropertyCollection); } if (data != null) { CheckForPotentialBrokenReferences(data, validationResult, type, dataScopeIdentifier, locale, dataKeyPropertyCollection); } } } } } if (validationResult.Count > 0) { _dataToDelete = null; } return(validationResult); }
internal void AddData(string dataTypeName, string dataScopeIdentifier, Func <IData, bool> where) { AddData(TypeManager.TryGetType(dataTypeName), DataScopeIdentifier.Deserialize(dataScopeIdentifier), where); }
private void editCodeActivity_Preview_ExecuteCode(object sender, EventArgs e) { Guid pageId; if (this.GetBinding <object>("PageId") == null) { pageId = Guid.Empty; } else { pageId = this.GetBinding <Guid>("PageId"); } string dataScopeName = this.GetBinding <string>("PageDataScopeName"); string cultureName = this.GetBinding <string>("ActiveCultureName"); // Setting debug page IPage oldPage = PageRenderer.CurrentPage; IPage page = DataFacade.GetData <IPage>(f => f.Id == pageId).FirstOrDefault(); if (page != null) { PageRenderer.CurrentPage = page; } // Setting debug culture CultureInfo oldCurrentCulture = Thread.CurrentThread.CurrentCulture; CultureInfo oldCurrentUICulture = Thread.CurrentThread.CurrentUICulture; CultureInfo cultureInfo = null; if (cultureName != null) { cultureInfo = CultureInfo.CreateSpecificCulture(cultureName); } if (cultureInfo != null) { Thread.CurrentThread.CurrentCulture = cultureInfo; Thread.CurrentThread.CurrentUICulture = cultureInfo; } List <NamedFunctionCall> namedFunctionCalls = GetBinding <List <NamedFunctionCall> >("FunctionCalls"); StringBuilder output = new StringBuilder(); foreach (NamedFunctionCall namedFunctionCall in namedFunctionCalls) { output.AppendLine(namedFunctionCall.FunctionCall.GetCompositeName() + " result:"); object functionResult; try { // Setting debug data scope using (new DataScope(DataScopeIdentifier.Deserialize(dataScopeName), cultureInfo)) { functionResult = namedFunctionCall.FunctionCall.GetValue(); } } catch (Exception ex) { StringBuilder sb = new StringBuilder(); while (ex != null) { sb.AppendLine(ex.ToString()); ex = ex.InnerException; } functionResult = sb.ToString(); } output.AppendLine(PrettyPrinter.Print(functionResult)); output.AppendLine(); } // Restore culture Thread.CurrentThread.CurrentCulture = oldCurrentCulture; Thread.CurrentThread.CurrentUICulture = oldCurrentUICulture; // Page should not be restored FlowControllerServicesContainer serviceContainer = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId); IFormFlowWebRenderingService formFlowWebRenderingService = serviceContainer.GetService <IFormFlowWebRenderingService>(); Control outputControl = new LiteralControl("<pre>" + HttpUtility.HtmlEncode(output) + "</pre>"); formFlowWebRenderingService.SetNewPageOutput(outputControl); }