/// <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 xpathsXpath createXpath( string xpath, string xpathId, string storeItemID, string prefixMappings, string questionID) { 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); return(item); }
public override bool Equals(object obj) { xpathsXpath other = obj as xpathsXpath; return((other.id.Equals(this.id)) && (other.dataBinding.Equals(this.dataBinding))); }
/// <summary> /// Add the condition to the conditions part. /// </summary> /// <param name="model"></param> /// <param name="cxpId"></param> /// <param name="strXPath"></param> /// <param name="prefixMappings"></param> public condition setup(xpathsXpath xpath) { condition result = null; ////////////////////////// // Second, create and add the condition // If the Condition is already defined in our Condition part, don't do it again. // Also need this for ID generation. Dictionary <string, string> conditionsById = new Dictionary <string, string>(); foreach (condition xx in conditions.condition) { conditionsById.Add(xx.id, ""); if (xx.Item is xpathref) { xpathref ex = (xpathref)xx.Item; if (ex.id.Equals(xpath.id)) { result = xx; log.Info("This Condition is already setup, with ID: " + xx.id); break; } } } if (result == null) // not already defined { // Add the new condition result = new condition(); //result.id = IdGenerator.generateIdForXPath(conditionsById, null, null, xpath.dataBinding.xpath); result.id = IdHelper.GenerateShortID(5); xpathref xpathref = new xpathref(); xpathref.id = xpath.id; result.Item = xpathref; conditions.condition.Add(result); // Save the conditions in docx string ser = conditions.Serialize(); log.Info(ser); CustomXmlUtilities.replaceXmlDoc(model.conditionsPart, ser); } // Set this conditionId = result.id; log.Debug("Condition written!"); return(result); }
/// <summary> /// Deserializes xml markup from file into an xpathsXpath object /// </summary> /// <param name="fileName">string xml file to load and deserialize</param> /// <param name="obj">Output xpathsXpath 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 xpathsXpath obj, out System.Exception exception) { exception = null; obj = default(xpathsXpath); try { obj = LoadFromFile(fileName); return(true); } catch (System.Exception ex) { exception = ex; return(false); } }
/// <summary> /// Deserializes workflow markup into an xpathsXpath object /// </summary> /// <param name="xml">string workflow markup to deserialize</param> /// <param name="obj">Output xpathsXpath 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 xpathsXpath obj, out System.Exception exception) { exception = null; obj = default(xpathsXpath); try { obj = Deserialize(xml); 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); }
/// <summary> /// Add xpath to xpaths part, and a condition to the conditions part. /// </summary> /// <param name="model"></param> /// <param name="cxpId"></param> /// <param name="strXPath"></param> /// <param name="prefixMappings"></param> public condition setup(string cxpId, string strXPath, string prefixMappings, bool setupQuestionNow) { ////////////////////////// // First, add the new XPath // Drop any trailing "/" from a Condition XPath if (strXPath.EndsWith("/")) { strXPath = strXPath.Substring(0, strXPath.Length - 1); log.Debug("truncated to " + strXPath); } XPathsPartEntry xppe = new XPathsPartEntry(model); xpathsXpath xpath = xppe.setup("cond", cxpId, strXPath, prefixMappings, setupQuestionNow); xppe.save(); return(setup(xpath)); }
public void populateControl(xpathsXpath xpathObj, string sampleAnswer, bool isInteger, string hint) { this.textBoxSampleAnswer.Text = sampleAnswer; //<xs:attribute name="required" type="xs:boolean" /> if (xpathObj.requiredSpecified && xpathObj.required) { this.checkBoxRequired.Checked = true; } else { this.checkBoxRequired.Checked = false; } //<xs:attribute name="prepopulate" type="xs:boolean" /> if (xpathObj.prepopulateSpecified && xpathObj.prepopulate) { this.checkBoxPopulateForm.Checked = true; } else { this.checkBoxPopulateForm.Checked = false; } //<xs:attribute name="fieldWidth" type="xs:positiveInteger" /> this.textBoxFieldWidth.Text = xpathObj.fieldWidth; // Min length for string //<xs:attribute name="lower" type="xs:string" /> this.textBoxLengthMin.Text = xpathObj.lower; //<xs:attribute name="lowerOperator" type="xs:string" /> // Not relevant // Max length for string //<xs:attribute name="upper" type="xs:string" /> this.textBoxLengthMax.Text = xpathObj.upper; //<xs:attribute name="upperOperator" type="xs:string" /> // Not relevant this.textBoxHint.Text = hint; }
public xpathsXpath createXpath( string xpath, string xpathId, string storeItemID, string prefixMappings, string questionID) { 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); return item; }
public static bool LoadFromFile(string fileName, out xpathsXpath obj) { System.Exception exception = null; return LoadFromFile(fileName, out obj, out exception); }
private void identifyLogicInXPath(xpathsXpath xp, Word.Range range, Word.ContentControl cc) { BBxpaths.Add(xp.Clone() ); // From Java QuestionsInUse String xpathVal = xp.dataBinding.xpath; string questionID=null; if (xpathVal.StartsWith("/")) { // simple questionID = xp.questionID; question q = srcQuestionnaire.getQuestion(questionID); BBquestions.Add(q); } else if (xpathVal.Contains("position()")) { return; } else { log.Debug(xpathVal); questionID = xpathVal.Substring(xpathVal.LastIndexOf("@id") + 5); // System.out.println("Got qid: " + qid); questionID = questionID.Substring(0, questionID.IndexOf("'")); // System.out.println("Got qid: " + qid); log.Debug("question " + questionID + " is in use via condition " ); question q = srcQuestionnaire.getQuestion(questionID); BBquestions.Add(q); } // Answer // If its not top level, we'll have it already when we add repeat // Therefore here, we only look at the top level ones. //Office.CustomXMLNode destination = answersPart.SelectSingleNode(xp.dataBinding.xpath); answer a = null; foreach (object o in srcAnswers.Items) { if (o is answer) { a = (answer)o; if (a.id.Equals(questionID)) // question ID == answer ID { BBanswers.Add(a); break; } } } if (a == null) { // Not found at top level, so must be repeated testOldestRepeatIncluded(range, cc); } }
private void populateQuestionTab() { xpathObj = xppe.getXPathByQuestionID(q.id); this.controlQuestionCommon1.populateControl(q); this.controlQuestionVaryWhichRepeat1.init(answersPart, questionnaire, q, xppe, new ConditionsPartEntry(model) ); //this.controlQuestionVaryWhichRepeat1.treeViewRepeat.Visible = true; //this.controlQuestionVaryWhichRepeat1.treeViewRepeat.Update(); }
private void injectLogicXPath(XPathsPartEntry targetXppe, xpathsXpath xp, string sourceAttr, string answersPartStoreID) { if (sourceAttr != null) xp.source = sourceAttr; if (answersPartStoreID != null) { xp.dataBinding.storeItemID = answersPartStoreID; } targetXppe.getXPaths().xpath.Add(xp); // this is a HashSet, so we're overrwriting, not adding :-) }
public void populateXPath(xpathsXpath xpathObj) { xpathObj.type = "card-number"; //<xs:attribute name="required" type="xs:boolean" /> xpathObj.requiredSpecified = true; xpathObj.required = this.checkBoxRequired.Checked; //<xs:attribute name="prepopulate" type="xs:boolean" /> xpathObj.prepopulateSpecified = true; xpathObj.prepopulate = this.checkBoxPopulateForm.Checked; //<xs:attribute name="fieldWidth" type="xs:positiveInteger" /> //<xs:attribute name="lower" type="xs:string" /> //<xs:attribute name="lowerOperator" type="xs:string" /> //<xs:attribute name="upper" type="xs:string" /> //<xs:attribute name="upperOperator" type="xs:string" /> }
public void populateXPath(xpathsXpath xpathObj) { xpathObj.type = "email"; //<xs:attribute name="required" type="xs:boolean" /> xpathObj.requiredSpecified = true; xpathObj.required = this.checkBoxRequired.Checked; //<xs:attribute name="prepopulate" type="xs:boolean" /> xpathObj.prepopulateSpecified = true; xpathObj.prepopulate = this.checkBoxPopulateForm.Checked; //<xs:attribute name="fieldWidth" type="xs:positiveInteger" /> int result; if (!string.IsNullOrWhiteSpace(this.textBoxFieldWidth.Text) && int.TryParse(this.textBoxFieldWidth.Text, out result)) { xpathObj.fieldWidth = this.textBoxFieldWidth.Text; } //<xs:attribute name="lower" type="xs:string" /> //<xs:attribute name="lowerOperator" type="xs:string" /> //<xs:attribute name="upper" type="xs:string" /> //<xs:attribute name="upperOperator" type="xs:string" /> }
public void populateXPath(xpathsXpath xpathObj) { xpathObj.type = "date"; //<xs:attribute name="required" type="xs:boolean" /> xpathObj.requiredSpecified = true; xpathObj.required = this.checkBoxRequired.Checked; //<xs:attribute name="prepopulate" type="xs:boolean" /> xpathObj.prepopulateSpecified = true; xpathObj.prepopulate = this.checkBoxPopulateForm.Checked; //<xs:attribute name="fieldWidth" type="xs:positiveInteger" /> //<xs:attribute name="lower" type="xs:string" /> if (!this.listBoxLowerOperator.SelectedItem.Equals("n/a")) { if (this.datePickerLower.Value!=null) { xpathObj.lower = formatDate(this.datePickerLower.Value); } //<xs:attribute name="lowerOperator" type="xs:string" /> xpathObj.lowerOperator = (string)this.listBoxLowerOperator.SelectedItem; } //<xs:attribute name="upper" type="xs:string" /> if (!this.listBoxUpperOperator.SelectedItem.Equals("n/a")) { if (this.datePickerUpper.Value != null) { xpathObj.upper = formatDate(this.datePickerUpper.Value); } //<xs:attribute name="upperOperator" type="xs:string" /> xpathObj.upperOperator = (string)this.listBoxUpperOperator.SelectedItem; } }
public void populateControl(xpathsXpath xpathObj, string sampleAnswer, bool isInteger, string hint) { this.datePickerSample.Text = sampleAnswer; //<xs:attribute name="required" type="xs:boolean" /> if (xpathObj.requiredSpecified && xpathObj.required) { this.checkBoxRequired.Checked = true; } else { this.checkBoxRequired.Checked = false; } //<xs:attribute name="prepopulate" type="xs:boolean" /> if (xpathObj.prepopulateSpecified && xpathObj.prepopulate) { this.checkBoxPopulateForm.Checked = true; } else { this.checkBoxPopulateForm.Checked = false; } //<xs:attribute name="fieldWidth" type="xs:positiveInteger" /> // Not relevant //<xs:attribute name="lower" type="xs:string" /> if (string.IsNullOrEmpty(xpathObj.lower)) { this.datePickerLower.Value = DateTime.Now; } else { this.datePickerLower.Value = formatDate(xpathObj.lower); } //<xs:attribute name="lowerOperator" type="xs:string" /> if (string.IsNullOrEmpty(xpathObj.lowerOperator)) { this.listBoxLowerOperator.SelectedItem = "n/a"; } else { this.listBoxLowerOperator.SelectedItem = xpathObj.lowerOperator; } //<xs:attribute name="upper" type="xs:string" /> if (string.IsNullOrEmpty(xpathObj.upper)) { this.datePickerUpper.Value = DateTime.Now; } else { this.datePickerUpper.Value = formatDate(xpathObj.upper); } //<xs:attribute name="upperOperator" type="xs:string" /> if (string.IsNullOrEmpty(xpathObj.upperOperator)) { this.listBoxUpperOperator.SelectedItem = "n/a"; } else { this.listBoxUpperOperator.SelectedItem = xpathObj.upperOperator; } this.textBoxHint.Text = hint; }
public static bool Deserialize(string xml, out xpathsXpath obj) { System.Exception exception = null; return Deserialize(xml, out obj, out exception); }
public static bool Deserialize(string xml, out xpathsXpath obj) { System.Exception exception = null; return(Deserialize(xml, out obj, out exception)); }
public static bool LoadFromFile(string fileName, out xpathsXpath obj) { System.Exception exception = null; return(LoadFromFile(fileName, out obj, out exception)); }
/// <summary> /// When an answer's vary in repeat changes: /// - move the node /// - change its xpath /// - change the databinding in all relevant controls /// </summary> /// <param name="questionID"></param> /// <param name="xp"></param> /// <param name="answersPart"></param> public void moveIfNecessary(string questionID, xpathsXpath xp, Office.CustomXMLPart answersPart) { string varyInRepeat = getVaryingRepeat( ); if (varyInRepeat == null) { // make the answer top level and we're done. NodeMover nm = new NodeMover(); nm.Move(xp.dataBinding.xpath, "/oda:answers"); nm.adjustBinding(thisQuestionControls, "/oda:answers", questionID); } else { // Move it to the selected repeat // get the node corresponding to the repeat's row Office.CustomXMLNode node = answersPart.SelectSingleNode("//oda:repeat[@qref='" + varyInRepeat + "']/oda:row[1]"); if (node == null) { log.Error("no node for nested repeat " + varyInRepeat); } string toRepeat = NodeToXPath.getXPath(node); NodeMover nm = new NodeMover(); nm.Move(xp.dataBinding.xpath, toRepeat); nm.adjustBinding(thisQuestionControls, toRepeat, questionID); } }
public void updateQuestionFromForm(xpathsXpath xpathObj, question q, Office.CustomXMLNode node) { // Currently used only by QuestionEdit. Why not also initial populate? // sampleAnswer node.Text = getSampleAnswerProcessed(); //if (!string.IsNullOrWhiteSpace(getHint())) //{ q.hint = getHint(); //} populateXPath(xpathObj); }
public void populateXPath(xpathsXpath xpathObj) { log.Info("in pX " + listBoxDataTypes.SelectedItem); if (listBoxDataTypes.SelectedItem.ToString().Equals("date")) { this.ControlDataTypeMAIN.controlDataTypeDate.populateXPath(xpathObj); } else if (listBoxDataTypes.SelectedItem.ToString().Equals("text")) { this.ControlDataTypeMAIN.controlDataTypeString.populateXPath(xpathObj); } else if (listBoxDataTypes.SelectedItem.ToString().Equals("number")) { this.ControlDataTypeMAIN.controlDataTypeNumber.populateXPath(xpathObj); } else if (listBoxDataTypes.SelectedItem.ToString().Equals("email")) { this.ControlDataTypeMAIN.controlDataTypeEmail.populateXPath(xpathObj); } else if (listBoxDataTypes.SelectedItem.ToString().Equals("card number")) { this.ControlDataTypeMAIN.controlDataTypeCreditCard.populateXPath(xpathObj); } else { // Shouldn't happen!! log.Error("Unrecognised selection: " + listBoxDataTypes.SelectedItem); } }
public void populateControl(xpathsXpath xpathObj, responseFree rF, string sampleAnswer, string hint) { // responseFree object currently has empty content model, but pass it anyway sampleAnswer = this.trimSampleAnswerDelims(sampleAnswer); if (xpathObj.type.Equals("string")) { listBoxDataTypes.SelectedItem = "text"; // TODO: visible stuff? this.ControlDataTypeMAIN.controlDataTypeString.populateControl(xpathObj, sampleAnswer, false, hint); } else if (xpathObj.type.Equals("date")) { listBoxDataTypes.SelectedItem = "date"; this.ControlDataTypeMAIN.controlDataTypeDate.populateControl(xpathObj, sampleAnswer, false, hint); } else if (xpathObj.type.Equals("email")) { listBoxDataTypes.SelectedItem = "email"; this.ControlDataTypeMAIN.controlDataTypeEmail.populateControl(xpathObj, sampleAnswer, false, hint); } else if (xpathObj.type.Equals("decimal")) { listBoxDataTypes.SelectedItem = "number"; this.ControlDataTypeMAIN.controlDataTypeNumber.populateControl(xpathObj, sampleAnswer, false, hint); } else if (xpathObj.type.Equals("integer")) { listBoxDataTypes.SelectedItem = "number"; this.ControlDataTypeMAIN.controlDataTypeNumber.populateControl(xpathObj, sampleAnswer, true, hint); } else if (xpathObj.type.Equals("positiveInteger")) { listBoxDataTypes.SelectedItem = "number"; this.ControlDataTypeMAIN.controlDataTypeNumber.populateControl(xpathObj, sampleAnswer, true, hint); } else if (xpathObj.type.Equals("nonNegativeInteger")) { listBoxDataTypes.SelectedItem = "number"; this.ControlDataTypeMAIN.controlDataTypeNumber.populateControl(xpathObj, sampleAnswer, true, hint); } else if (xpathObj.type.Equals("negativeInteger")) { listBoxDataTypes.SelectedItem = "number"; this.ControlDataTypeMAIN.controlDataTypeNumber.populateControl(xpathObj, sampleAnswer, true, hint); } else if (xpathObj.type.Equals("nonPositiveInteger")) { listBoxDataTypes.SelectedItem = "number"; this.ControlDataTypeMAIN.controlDataTypeNumber.populateControl(xpathObj, sampleAnswer, true, hint); } else if (xpathObj.type.Equals("card-number")) { listBoxDataTypes.SelectedItem = "card number"; this.ControlDataTypeMAIN.controlDataTypeCreditCard.populateControl(xpathObj, sampleAnswer, false, hint); } else { // TODO add their custom type log.Error("XPath " + xpathObj.id + " has unknown value for datatype: '" + xpathObj.type); } //this.textBoxSampleAnswer.Text = trimSampleAnswerDelims(sampleAnswer); //this.checkBoxRequired.Checked = xpathObj.required; }
public void populateControl(xpathsXpath xpathObj, question q, string defaultAnswer) { responseFixed = q.response.Item as responseFixed; if (xpathObj.type.Equals("string")) { this.radioTypeText.Checked = true; } else if (xpathObj.type.Equals("decimal")) { this.radioTypeNumber.Checked = true; } else if (xpathObj.type.Equals("date")) { this.radioTypeDate.Checked = true; } else if (xpathObj.type.Equals("boolean")) { this.radioTypeBoolean.Checked = true; } //else if (xpathObj.type.Equals("duration")) //{ // this.radioTypeText.Checked = true; //} //else if (xpathObj.type.Equals("email")) //{ // this.radioTypeText.Checked = true; //} //else if (xpathObj.type.Equals("cardnumber")) //{ // this.radioTypeText.Checked = true; //} else { log.Error("XPath " + xpathObj.id + " has unknown value for datatype: '" + xpathObj.type); } // The possible responses int i = 0; this.dataGridView1.Rows.Add(responseFixed.item.Count); foreach (responseFixedItem rFI in responseFixed.item) { this.dataGridView1.Rows[i].Cells[0].Value = rFI.value; this.dataGridView1.Rows[i].Cells[1].Value = rFI.label; i++; } // How many responses can be checked? if (responseFixed.canSelectMany) { this.radioButtonYes.Checked = true; } else { this.radioButtonNo.Checked = true; } // Interview appearance if (q.appearance.Equals(appearanceType.compact)) { this.radioButtonAppearanceCompact.Checked = true; } else if (q.appearance.Equals(appearanceType.full)) { this.radioButtonAppearanceFull.Checked = true; } else if (q.appearance.Equals(appearanceType.minimal) ){ this.radioButtonAppearanceMinimal.Checked = true; } // Default this.textBoxDefault.Text = defaultAnswer; }
/// <summary> /// Add the XPath to the XPaths part. As a side effect, set fields tag /// and xpathid /// </summary> /// <param name="model"></param> /// <param name="cxpId">storeItemID for data binding</param> /// <param name="strXPath"></param> /// <param name="prefixMappings"></param> public xpathsXpath setup(string idTypeSuffix, string cxpId, string strXPath, string prefixMappings, bool setupQuestionNow) { xpathsXpath result = null; // If the XPath is already defined in our XPaths part, don't do it again. // Also need this for ID generation. Dictionary <string, string> xpathsById = new Dictionary <string, string>(); foreach (xpathsXpath xx in xpaths.xpath) { try { xpathsById.Add(xx.id, ""); } catch (Exception e) { log.Error(xx.id + " exists already!"); // How did this happen?? throw e; } if (xx.dataBinding.xpath.Equals(strXPath) && xx.dataBinding.storeItemID.Equals(cxpId)) { result = xx; xpathId = xx.id; log.Info("This XPath is already setup, with ID: " + xpathId); break; } } if (result == null) // not already defined { //xpathId = IdGenerator.generateIdForXPath(xpathsById, "", idTypeSuffix, strXPath); xpathId = IdHelper.GenerateShortID(5); // Question string questionID = null; if (setupQuestionNow && model.questionsPart != null) { throw new NotImplementedException(); //FormQuestion formQuestion = new FormQuestion(model.questionsPart, // strXPath, xpathId); //formQuestion.ShowDialog(); //// TODO - handle cancel //formQuestion.updateQuestionsPart(formQuestion.getQuestion()); //questionID = formQuestion.textBoxQID.Text; //formQuestion.Dispose(); } // Also add to XPaths result = createXpath( strXPath, xpathId, cxpId, prefixMappings, questionID); } return(result); }
/// <summary> /// Deserializes workflow markup into an xpathsXpath object /// </summary> /// <param name="xml">string workflow markup to deserialize</param> /// <param name="obj">Output xpathsXpath 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 xpathsXpath obj, out System.Exception exception) { exception = null; obj = default(xpathsXpath); try { obj = Deserialize(xml); return true; } catch (System.Exception ex) { exception = ex; return false; } }
public void updateQuestionFromForm(xpathsXpath xpathObj, question q, Office.CustomXMLNode node) { // data type xpathObj.type = getDataType(); // The items, and canSelectMany responseFixed.item.Clear(); injectItems(); // interview appearance q.appearance = getAppearanceType(); q.appearanceSpecified = true; if (string.IsNullOrWhiteSpace(getDefault())) { node.Text = "«multiple choice»"; } else { node.Text = getDefault(); } }
/// <summary> /// Deserializes xml markup from file into an xpathsXpath object /// </summary> /// <param name="fileName">string xml file to load and deserialize</param> /// <param name="obj">Output xpathsXpath 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 xpathsXpath obj, out System.Exception exception) { exception = null; obj = default(xpathsXpath); try { obj = LoadFromFile(fileName); return true; } catch (System.Exception ex) { exception = ex; return false; } }
/// <summary> /// Add the condition to the conditions part. /// </summary> /// <param name="model"></param> /// <param name="cxpId"></param> /// <param name="strXPath"></param> /// <param name="prefixMappings"></param> public condition setup(xpathsXpath xpath) { condition result = null; ////////////////////////// // Second, create and add the condition // If the Condition is already defined in our Condition part, don't do it again. // Also need this for ID generation. Dictionary<string, string> conditionsById = new Dictionary<string, string>(); foreach (condition xx in conditions.condition) { conditionsById.Add(xx.id, ""); if (xx.Item is xpathref) { xpathref ex = (xpathref)xx.Item; if (ex.id.Equals(xpath.id)) { result = xx; log.Info("This Condition is already setup, with ID: " + xx.id); break; } } } if (result == null) // not already defined { // Add the new condition result = new condition(); //result.id = IdGenerator.generateIdForXPath(conditionsById, null, null, xpath.dataBinding.xpath); result.id = IdHelper.GenerateShortID(5); xpathref xpathref = new xpathref(); xpathref.id = xpath.id; result.Item = xpathref; conditions.condition.Add(result); // Save the conditions in docx string ser = conditions.Serialize(); log.Info(ser); CustomXmlUtilities.replaceXmlDoc(model.conditionsPart, ser); } // Set this conditionId = result.id; log.Debug("Condition written!"); return result; }
public void moveIfNecessary(string questionID, xpathsXpath xp, Office.CustomXMLPart answersPart) { controlQuestionVaryWhichRepeat1.moveIfNecessary(questionID, xp, answersPart); }
/// <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."); }