public XPathsPartEntry(Model model)
        {
            this.model = model;

            xpaths = new xpaths();
            xpaths.Deserialize(model.xpathsPart.XML, out xpaths);
        }
示例#2
0
        /// <summary>
        /// Stuff required to create XPath element
        /// (except for ID, which this method generates)
        /// </summary>
        /// <param name="xpath"></param>
        /// <param name="storeItemID"></param>
        /// <param name="prefixMappings"></param>
        /// <param name="questionID"></param>
        public static xpathsXpath updateXPathsPart(
            Office.CustomXMLPart xpathsPart,
            string xpath, 
            string xpathId,
            string storeItemID, string prefixMappings,
                                        string questionID)
        {
            //Office.CustomXMLPart xpathsPart = ((WedTaskPane)this.Parent.Parent.Parent).xpathsPart;

            xpaths xpaths = new xpaths();
            xpaths.Deserialize(xpathsPart.XML, out xpaths);

            xpathsXpath item = new xpathsXpath();
            item.id = xpathId; //System.Guid.NewGuid().ToString();

            if (!string.IsNullOrWhiteSpace(questionID))
                item.questionID = questionID;

            xpathsXpathDataBinding db = new xpathsXpathDataBinding();
            db.xpath = xpath;
            db.storeItemID = storeItemID;
            if (!string.IsNullOrWhiteSpace(prefixMappings))
                db.prefixMappings = prefixMappings;
            item.dataBinding = db;

            xpaths.xpath.Add(item);

            // Save it in docx
            string result = xpaths.Serialize();
            log.Info(result);
            CustomXmlUtilities.replaceXmlDoc(xpathsPart, result);

            return item;
        }
示例#3
0
        public XPathsPartEntry(Model model)
        {
            this.model = model;

            xpaths = new xpaths();
            xpaths.Deserialize(model.xpathsPart.XML, out xpaths);
        }
示例#4
0
 /// <summary>
 /// Deserializes workflow markup into an xpaths object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output xpaths object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string xml, out xpaths obj, out System.Exception exception)
 {
     exception = null;
     obj       = default(xpaths);
     try
     {
         obj = Deserialize(xml);
         return(true);
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return(false);
     }
 }
示例#5
0
 /// <summary>
 /// Deserializes xml markup from file into an xpaths object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output xpaths object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, out xpaths obj, out System.Exception exception)
 {
     exception = null;
     obj       = default(xpaths);
     try
     {
         obj = LoadFromFile(fileName);
         return(true);
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return(false);
     }
 }
        /// <summary>
        /// Stuff required to create XPath element
        /// (except for ID, which this method generates)
        /// </summary>
        /// <param name="xpath"></param>
        /// <param name="storeItemID"></param>
        /// <param name="prefixMappings"></param>
        /// <param name="questionID"></param>
        public static xpathsXpath updateXPathsPart(
            Office.CustomXMLPart xpathsPart,
            string xpath,
            string xpathId,
            string storeItemID, string prefixMappings,
            string questionID)
        {
            //Office.CustomXMLPart xpathsPart = ((WedTaskPane)this.Parent.Parent.Parent).xpathsPart;

            xpaths xpaths = new xpaths();

            xpaths.Deserialize(xpathsPart.XML, out xpaths);

            xpathsXpath item = new xpathsXpath();

            item.id = xpathId; //System.Guid.NewGuid().ToString();

            if (!string.IsNullOrWhiteSpace(questionID))
            {
                item.questionID = questionID;
            }

            xpathsXpathDataBinding db = new xpathsXpathDataBinding();

            db.xpath       = xpath;
            db.storeItemID = storeItemID;
            if (!string.IsNullOrWhiteSpace(prefixMappings))
            {
                db.prefixMappings = prefixMappings;
            }
            item.dataBinding = db;

            xpaths.xpath.Add(item);

            // Save it in docx
            string result = xpaths.Serialize();

            log.Info(result);
            CustomXmlUtilities.replaceXmlDoc(xpathsPart, result);

            return(item);
        }
 public abstract void listXPaths(List<xpathsXpath> theList,
         conditions conditions,
         xpaths xPaths);
示例#8
0
 /// <summary>
 /// Deserializes workflow markup into an xpaths object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output xpaths object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string xml, out xpaths obj, out System.Exception exception)
 {
     exception = null;
     obj = default(xpaths);
     try
     {
         obj = Deserialize(xml);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }
示例#9
0
 public static bool LoadFromFile(string fileName, out xpaths obj)
 {
     System.Exception exception = null;
     return LoadFromFile(fileName, out obj, out exception);
 }
示例#10
0
 /// <summary>
 /// Deserializes xml markup from file into an xpaths object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output xpaths object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, out xpaths obj, out System.Exception exception)
 {
     exception = null;
     obj = default(xpaths);
     try
     {
         obj = LoadFromFile(fileName);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }
示例#11
0
 public static bool Deserialize(string xml, out xpaths obj)
 {
     System.Exception exception = null;
     return Deserialize(xml, out obj, out exception);
 }
 public override void listXPaths(List<xpathsXpath> theList,
                 conditions conditions,
                 xpaths xPaths)
 {
     itemField.listXPaths(theList, conditions, xPaths);
 }
示例#13
0
 public static bool Deserialize(string xml, out xpaths obj)
 {
     System.Exception exception = null;
     return(Deserialize(xml, out obj, out exception));
 }
        /// <summary>
        /// Create OpenDoPE parts, including optionally, question part.
        /// </summary>
        /// <param name="needQuestionsPart"></param>
        public void process(Microsoft.Office.Interop.Word.Document document, bool needQuestionsPart)
        {
            Model model = Model.ModelFactory(document);

            // Button shouldn't be available if this exists,
            // but ..
            if (model.conditionsPart == null)
            {
                conditions conditions = new conditions();
                string conditionsXml = conditions.Serialize();
                model.conditionsPart = addCustomXmlPart(document, conditionsXml);
            }

            if (model.componentsPart == null)
            {
                components components = new components();
                string componentsXml = components.Serialize();
                model.componentsPart = addCustomXmlPart(document, componentsXml);
            }

            // TODO 2013 12 if there is an existing questions part or answers part
            // I suspect we just want to keep it, rather than overwriting its contents!
            // Unless it is to do with supporting multiple Q, A parts?

            questionnaire q = null;
            if (model.questionsPart == null)
            {
                if (needQuestionsPart)
                {
                    q = new questionnaire();
                }
            }
            else
            {
                //needQuestionsPart = false;

                // Button shouldn't be available if this exists,
                // but ..
                q = new questionnaire();
                questionnaire.Deserialize(model.questionsPart.XML, out q);
            }

            // Add XPath
            xpaths xpaths = new xpaths();
            // Button shouldn't be available if this exists,
            // but ..
            if (model.xpathsPart != null)
            {
                xpaths.Deserialize(model.xpathsPart.XML, out xpaths);
            }

            if (needQuestionsPart)
            {
                // Are there content controls which need questions
                bool missingQuestions = false;
                foreach (Word.ContentControl cc in Globals.ThisAddIn.Application.ActiveDocument.ContentControls)
                {
                    if (cc.XMLMapping.IsMapped)
                    {
                        missingQuestions = true;
                        break;
                    }
                }
                if (missingQuestions)
                {
                    log.Warn("Document contains pre-existing bound content controls; without Questions.");
                    System.Windows.Forms.MessageBox.Show("This docx already contains bound content controls!");
                }
            }

            string xpathsXml = xpaths.Serialize();
            if (model.xpathsPart == null)
            {
                model.xpathsPart = addCustomXmlPart(document, xpathsXml);
            }
            else
            {
                CustomXmlUtilities.replaceXmlDoc(model.xpathsPart, xpathsXml);
            }

            if (model.questionsPart == null && needQuestionsPart)
            {
                string qxml = q.Serialize();
                model.questionsPart = addCustomXmlPart(document, qxml);
            }
        }
 public override void listXPaths(List<xpathsXpath> theList,
                 conditions conditions,
                 xpaths xPaths)
 {
     xpathsXpath xpath = xPaths.getXPathByID(idField);
     theList.Add(xpath);
 }
 public override void listXPaths(List<xpathsXpath> theList,
                 conditions conditions,
                 xpaths xPaths)
 {
     foreach (evaluable particle in itemsField)
     {
         particle.listXPaths(theList, conditions, xPaths);
     }
 }
示例#17
0
 public static bool LoadFromFile(string fileName, out xpaths obj)
 {
     System.Exception exception = null;
     return(LoadFromFile(fileName, out obj, out exception));
 }
 public override void listXPaths(List<xpathsXpath> theList,
                 conditions conditions,
                 xpaths xPaths)
 {
     condition particle = conditions.getConditionByID(idField);
     particle.listXPaths(theList, conditions, xPaths);
 }
        /// <summary>
        /// Create OpenDoPE parts, including optionally, question part.
        /// </summary>
        public void process()
        {
            Microsoft.Office.Interop.Word.Document document = null;
            try
            {
                document = Globals.ThisAddIn.Application.ActiveDocument;
            }
            catch (Exception ex)
            {
                Mbox.ShowSimpleMsgBoxError("No document is open/active. Create or open a docx first.");
                return;
            }

            Model model = Model.ModelFactory(document);

            // Button shouldn't be available if this exists,
            // but ..
            if (model.conditionsPart == null)
            {
                conditions conditions = new conditions();
                string conditionsXml = conditions.Serialize();
                model.conditionsPart = addCustomXmlPart(document, conditionsXml);
            }

            if (model.componentsPart == null)
            {
                components components = new components();
                string componentsXml = components.Serialize();
                model.componentsPart = addCustomXmlPart(document, componentsXml);
            }

            // Add XPath
            xpaths xpaths = new xpaths();
            // Button shouldn't be available if this exists,
            // but ..
            if (model.xpathsPart != null)
            {
                xpaths.Deserialize(model.xpathsPart.XML, out xpaths);
            }
            int idInt = 1;
            foreach (Word.ContentControl cc in Globals.ThisAddIn.Application.ActiveDocument.ContentControls)
            {
                if (cc.XMLMapping.IsMapped)
                {
                    log.Debug("Adding xpath for " + cc.ID);
                    // then we need to add an XPath
                    string xmXpath = cc.XMLMapping.XPath;

                    xpathsXpath item = new xpathsXpath();
                    // I make no effort here to check whether the xpath
                    // already exists, since the part shouldn't already exist!

                    item.id = "x" + idInt;

                    xpathsXpathDataBinding db = new xpathsXpathDataBinding();
                    db.xpath = xmXpath;
                    db.storeItemID = cc.XMLMapping.CustomXMLPart.Id;
                    if (!string.IsNullOrWhiteSpace(cc.XMLMapping.PrefixMappings))
                        db.prefixMappings = cc.XMLMapping.PrefixMappings;
                    item.dataBinding = db;

                    xpaths.xpath.Add(item);

                    // Write tag
                    TagData td = new TagData(cc.Tag);
                    td.set("od:xpath", item.id);
                    cc.Tag = td.asQueryString();

                    log.Debug(".. added for " + cc.ID);
                    idInt++;
                }
            }
            string xpathsXml = xpaths.Serialize();
            if (model.xpathsPart == null)
            {
                model.xpathsPart = addCustomXmlPart(document, xpathsXml);
            }
            else
            {
                CustomXmlUtilities.replaceXmlDoc(model.xpathsPart, xpathsXml);
            }

            Microsoft.Office.Tools.Word.Document extendedDocument
                = Globals.ThisAddIn.Application.ActiveDocument.GetVstoObject(Globals.Factory);

            //Microsoft.Office.Tools.CustomTaskPane ctp
            //    = Globals.ThisAddIn.createCTP(document, cxp, xpathsPart, conditionsPart, questionsPart, componentsPart);
            //extendedDocument.Tag = ctp;
            //// Want a 2 way association
            //WedTaskPane wedTaskPane = (WedTaskPane)ctp.Control;
            //wedTaskPane.associatedDocument = document;

            //extendedDocument.Shutdown += new EventHandler(
            //    Globals.ThisAddIn.extendedDocument_Shutdown);

            //taskPane.setupCcEvents(document);

            log.Debug("Done. Task pane now also open.");
        }