public bool TrySerialize(Type objectToSerializeType, object objectToSerialize, IXmlSerializer xmlSerializer, out XElement serializedObject)
        {
            if (objectToSerializeType == null)
            {
                throw new ArgumentNullException("objectToSerializeType");
            }
            if (xmlSerializer == null)
            {
                throw new ArgumentNullException("xmlSerializer");
            }

            serializedObject = null;
            if (objectToSerializeType != typeof(NamedFunctionCall))
            {
                return(false);
            }

            NamedFunctionCall namedFunctionCall = objectToSerialize as NamedFunctionCall;

            serializedObject = new XElement("NamedFunctionCall");

            if (namedFunctionCall != null)
            {
                serializedObject.Add(new XElement("Name", xmlSerializer.Serialize(typeof(string), namedFunctionCall.Name)));

                if (namedFunctionCall.FunctionCall != null)
                {
                    serializedObject.Add(new XElement("Value", namedFunctionCall.FunctionCall.Serialize()));
                }
            }

            return(true);
        }
Пример #2
0
        private void initalizeStateCodeActivity_Initialize_ExecuteCode(object sender, EventArgs e)
        {
            List<NamedFunctionCall> namedFunctionCalls = new List<NamedFunctionCall>();

            if (Payload != "")
            {
                IFunction function = FunctionFacade.GetFunction(Payload);

                BaseRuntimeTreeNode baseRuntimeTreeNode = FunctionFacade.BuildTree(function, new Dictionary<string, object>());

                NamedFunctionCall namedFunctionCall = new NamedFunctionCall("", (BaseFunctionRuntimeTreeNode)baseRuntimeTreeNode);

                namedFunctionCalls.Add(namedFunctionCall);

                string layoutLabel = string.Format(StringResourceSystemFacade.GetString("Composite.Plugins.AllFunctionsElementProvider", "FunctionTesterWorkflow.Layout.Label"), function.Name);
                this.Bindings.Add("LayoutLabel", layoutLabel);
            }

            this.Bindings.Add("FunctionCalls", namedFunctionCalls);
            this.Bindings.Add("Parameters", new List<ManagedParameterDefinition>());
            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, StringResourceSystemFacade.GetString("Composite.Plugins.AllFunctionsElementProvider", "FunctionTesterWorkflow.AdminitrativeScope.Label") }, 
                { DataScopeIdentifier.PublicName, StringResourceSystemFacade.GetString("Composite.Plugins.AllFunctionsElementProvider", "FunctionTesterWorkflow.PublicScope.Label") } 
            });


            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 bool TryDeserialize(XElement serializedObject, IXmlSerializer xmlSerializer, out object deserializedObject)
        {
            if (serializedObject == null) throw new ArgumentNullException("serializedObject");
            if (xmlSerializer == null) throw new ArgumentNullException("xmlSerializer");

            deserializedObject = null;

            if (serializedObject.Name.LocalName != "NamedFunctionCall") return false;

            NamedFunctionCall namedFunctionCall = new NamedFunctionCall(null, null);

            XElement nameElement = serializedObject.Element("Name");
            if (nameElement != null)
            {
                if (nameElement.Elements().Count() != 1) return false;

                namedFunctionCall.Name = (string)xmlSerializer.Deserialize(nameElement.Elements().Single());
            }

            XElement valueElement = serializedObject.Element("Value");
            if (valueElement != null)
            {
                if (valueElement.Elements().Count() != 1) return false;

                object result;
                try
                {
                    result = FunctionFacade.BuildTree(valueElement.Elements().Single());
                }
                catch (Exception)
                {
                    return false;
                }
                if ((result is BaseFunctionRuntimeTreeNode) == false) return false;

                namedFunctionCall.FunctionCall = (BaseFunctionRuntimeTreeNode)result;
            }

            deserializedObject = namedFunctionCall;
            return true;
        }
        public bool TryDeserialize(XElement serializedObject, IXmlSerializer xmlSerializer, out object deserializedObject)
        {
            if (serializedObject == null)
            {
                throw new ArgumentNullException("serializedObject");
            }
            if (xmlSerializer == null)
            {
                throw new ArgumentNullException("xmlSerializer");
            }

            deserializedObject = null;

            if (serializedObject.Name.LocalName != "NamedFunctionCall")
            {
                return(false);
            }

            NamedFunctionCall namedFunctionCall = new NamedFunctionCall(null, null);

            XElement nameElement = serializedObject.Element("Name");

            if (nameElement != null)
            {
                if (nameElement.Elements().Count() != 1)
                {
                    return(false);
                }

                namedFunctionCall.Name = (string)xmlSerializer.Deserialize(nameElement.Elements().Single());
            }

            XElement valueElement = serializedObject.Element("Value");

            if (valueElement != null)
            {
                if (valueElement.Elements().Count() != 1)
                {
                    return(false);
                }

                object result;
                try
                {
                    result = FunctionFacade.BuildTree(valueElement.Elements().Single());
                }
                catch (Exception)
                {
                    return(false);
                }
                if ((result is BaseFunctionRuntimeTreeNode) == false)
                {
                    return(false);
                }

                namedFunctionCall.FunctionCall = (BaseFunctionRuntimeTreeNode)result;
            }

            deserializedObject = namedFunctionCall;
            return(true);
        }
Пример #5
0
        private static object GetFunctionCallResult(FunctionContextContainer functionContextContainer, NamedFunctionCall namedFunctionCall, bool addDetailedComments)
        {
            object result = namedFunctionCall.FunctionCall.GetValue(functionContextContainer);

            if (!(result is IXsltExtensionDefinition))
            {
                if (addDetailedComments)
                {
                    if (result is IEnumerable<XElement>) result = ((IEnumerable<XElement>)result).ToList(); // timers dont like lazy stuff, so evaluate now
                    if (result is IEnumerable<XNode>) result = ((IEnumerable<XNode>)result).ToList(); // timers dont like lazy stuff, so evaluate now
                }

                result = CreateFunctionCallResultNode(namedFunctionCall.Name, result);
            }

            return result;
        }