Beispiel #1
0
        /// <summary>
        /// Open document will call this method to unsearilize xml data to node
        /// </summary>
        /// <param name="nodeElement"></param>
        protected override void LoadNode(XmlNode nodeElement)
        {
            base.LoadNode(nodeElement);
            // In copy/paste, no need to recreate function defintion
            if (Definition != null)
            {
                return;
            }

            string assembly = null;
            string function;

            if (nodeElement.Attributes["assembly"] == null &&
                nodeElement.Attributes["function"] == null)
            {
                var helper =
                    nodeElement.ChildNodes.Cast <XmlElement>()
                    .Where(
                        subNode =>
                        subNode.Name.Equals(typeof(FunctionDescriptor).FullName))
                    .Select(subNode => new XmlElementHelper(subNode))
                    .FirstOrDefault();

                // To open old file
                if (helper != null)
                {
                    assembly = helper.ReadString("Assembly", "");
                }

                function = nodeElement.Attributes["nickname"].Value.Replace(".get", ".");
            }
            else
            {
                assembly = nodeElement.Attributes["assembly"].Value;
                function = nodeElement.Attributes["function"].Value;
            }

            var engine = dynSettings.Controller.EngineController;

            if (!string.IsNullOrEmpty(assembly))
            {
                var document = nodeElement.OwnerDocument;
                var docPath  = Utilities.GetDocumentXmlPath(document);
                assembly = Utilities.MakeAbsolutePath(docPath, assembly);

                engine.ImportLibrary(assembly);
                Definition = engine.GetFunctionDescriptor(assembly, function);
            }
            else
            {
                Definition = engine.GetFunctionDescriptor(function);
            }

            if (null == Definition)
            {
                throw new Exception("Cannot find function: " + function);
            }

            Initialize();
        }
Beispiel #2
0
        public override void SaveNode(XmlDocument xmlDoc, XmlElement nodeElement, SaveContext context)
        {
            var asmPath = Definition.Assembly ?? "";

            if (context == SaveContext.File)
            {
                // We only make relative paths in a file saving operation.
                var docPath = Utilities.GetDocumentXmlPath(xmlDoc);
                asmPath = Utilities.MakeRelativePath(docPath, asmPath);
            }

            nodeElement.SetAttribute("assembly", asmPath);
            nodeElement.SetAttribute("function", Definition.MangledName ?? "");
        }
Beispiel #3
0
        public override void SerializeCore(XmlElement element, SaveContext context)
        {
            base.SerializeCore(element, context);
            var asmPath = Definition.Assembly ?? "";

            if (context == SaveContext.File)
            {
                // We only make relative paths in a file saving operation.
                var docPath = Utilities.GetDocumentXmlPath(element.OwnerDocument);
                asmPath = Utilities.MakeRelativePath(docPath, asmPath);
            }

            element.SetAttribute("assembly", asmPath);
            element.SetAttribute("function", Definition.MangledName ?? "");
        }
Beispiel #4
0
        public override void LoadNode(XmlNode nodeElement)
        {
            // In copy/paste, no need to recreate function defintion
            if (Definition != null)
            {
                return;
            }

            string assembly = null;
            string function;

            Trace.Assert(nodeElement.Attributes != null, "nodeElement.Attributes != null");

            if (nodeElement.Attributes["assembly"] == null && nodeElement.Attributes["function"] == null)
            {
                // To open old file
                var helper =
                    nodeElement.ChildNodes.Cast <XmlElement>()
                    .Where(
                        subNode => subNode.Name.Equals(typeof(FunctionDescriptor).FullName))
                    .Select(subNode => new XmlElementHelper(subNode))
                    .FirstOrDefault();

                if (helper != null)
                {
                    assembly = helper.ReadString("Assembly", "");
                }

                function = nodeElement.Attributes["nickname"].Value.Replace(".get", ".");
            }
            else
            {
                var xmlAttribute = nodeElement.Attributes["assembly"];
                if (xmlAttribute != null)
                {
                    assembly = xmlAttribute.Value;
                }

                string xmlSignature = nodeElement.Attributes["function"].Value;

                string hintedSigniture =
                    this.engineController.LibraryServices.FunctionSignatureFromFunctionSignatureHint(xmlSignature);

                function = hintedSigniture == null ? xmlSignature : hintedSigniture;
            }

            var engine = this.engineController;

            if (!string.IsNullOrEmpty(assembly))
            {
                var document = nodeElement.OwnerDocument;
                var docPath  = Utilities.GetDocumentXmlPath(document);
                assembly = Utilities.MakeAbsolutePath(docPath, assembly);

                engine.ImportLibrary(assembly);
                Definition = engine.GetFunctionDescriptor(assembly, function);
            }
            else
            {
                Definition = engine.GetFunctionDescriptor(function);
            }

            if (null == Definition)
            {
                throw new UnresolvedFunctionException(function);
            }
        }