// end constructors /// <summary> /// Executes the Delete request. /// </summary> /// <returns>an error code string</returns> public String Execute() { theRequest += script; theRequest += delCommand; String URLstring = fms.Protocol + "://" + fms.ServerAddress + ":" + fms.Port + "/fmi/xml/fmresultset.xml"; String theData = "-db=" + fms.CurrentDatabase + "&-lay=" + fms.CurrentLayout + theRequest; String errorCode = "0"; try { XmlNode root = FMSAxml.RootOfDoc(URLstring, theData, fms.FMAccount, fms.FMPassword, fms.ResponseTimeout, fms.DTDValidation); /* loop through the XML document returned by FMSA */ foreach (XmlNode rootNode in root.ChildNodes) { switch (rootNode.Name.ToLower()) { case "error": errorCode = rootNode.Attributes.GetNamedItem("code").Value; if (errorCode != "0") { FMSAxml.HandleFMSerrors(errorCode); } break; } /* switch rootnode name */ } // foreach root node // return the result return(errorCode); } // try catch (Exception ex) { Tools.LogUtility.WriteEntry(ex, System.Diagnostics.EventLogEntryType.Error); throw; } // catch }
// end constructors /// <summary> /// Executes the duplicate request. /// </summary> /// <returns>RecordID of new record</returns> public String Execute() { theRequest += script; theRequest += dupCommand; // setup the URL and the DATA as seperate strings String URLstring = fms.Protocol + "://" + fms.ServerAddress + ":" + fms.Port + "/fmi/xml/fmresultset.xml"; String theData = "-db=" + fms.CurrentDatabase + "&-lay=" + fms.CurrentLayout + theRequest; String errorCode = ""; String theRecordID = ""; try { XmlNode root = FMSAxml.RootOfDoc(URLstring, theData, fms.FMAccount, fms.FMPassword, fms.ResponseTimeout, fms.DTDValidation); /* loop through the XML document returned by FMSA */ foreach (XmlNode rootNode in root.ChildNodes) { switch (rootNode.Name.ToLower()) { case "error": errorCode = rootNode.Attributes.GetNamedItem("code").Value; if (errorCode != "0") { FMSAxml.HandleFMSerrors(errorCode); } break; case "datasource": case "resultset": /* this is where the data is */ /* now add a row to the table for each found record */ foreach (XmlNode rec in rootNode.ChildNodes) { /* recordid, mod id is in the attributes */ foreach (XmlAttribute attrib in rec.Attributes) { switch (attrib.Name) { case "record-id": theRecordID = attrib.Value; break; } } /* for each attrib */ } /* for each rec */ break; } /* switch rootnode name */ } // foreach root node /* return the result */ return(theRecordID); } // try catch { throw; } // catch }
/// <summary> /// Executes the find and returns a DataSet. /// </summary> /// <returns>DataSet, with all data from the chosen layout and subtables for portals. Related records use the parent's record ID as their foreign key.</returns> public DataSet Execute() { theRequest += script; theRequest += BuildFindString(); theRequest += theRequest.EndsWith("&") ? findCommand : "&" + findCommand; DataSet ds = new DataSet(); // need an overload for &-max, probably one for fmLayout too /* if there is related data on the layout in portals then * we're returning multiple tables in the dataset * * example: * http://testserver/fmi/xml/fmresultset.xml?-db=wim_MLB&-lay=list_franchises&-findall */ String URLstring = fms.Protocol + "://" + fms.ServerAddress + ":" + fms.Port + "/fmi/xml/fmresultset.xml"; String theData = "-db=" + fms.CurrentDatabase + "&-lay=" + fms.CurrentLayout + theRequest; Int32 foundFields; Int32 foundRecords; String errorCode = ""; FMField[] fmf = null; try { XmlNode root = FMSAxml.RootOfDoc(URLstring, theData, fms.FMAccount, fms.FMPassword, fms.ResponseTimeout, fms.DTDValidation); /* create a main table for the data on the layout */ DataTable table = ds.Tables.Add("main"); /* loop through the XML document returned by FMSA */ foreach (XmlNode rootNode in root.ChildNodes) { switch (rootNode.Name.ToLower()) { case "error": errorCode = rootNode.Attributes.GetNamedItem("code").Value; if (errorCode != "0") { if (errorCode == "401") // if there are no records, don't toss exception for that { return(ds); } else { FMSAxml.HandleFMSerrors(errorCode); } } break; case "datasource": foundRecords = Convert.ToInt32(rootNode.Attributes.GetNamedItem("total-count").Value); /*Add Koen Van Hulle - SHpartners (06 jun 2006)*/ TimeStampFormat = rootNode.Attributes.GetNamedItem("timestamp-format").Value; DateFormat = rootNode.Attributes.GetNamedItem("date-format").Value; break; case "metadata": /* grab the number of fields */ foundFields = FMSAxml.CountFields(rootNode); fmf = new FMField[foundFields]; int x = 0; /* add columns for the record id & mod ID */ table.Columns.Add("recordID", Type.GetType("System.String")); table.Columns.Add("modID", Type.GetType("System.String")); // add a column for each field found // regular and related fields on the layout!! foreach (XmlNode field in rootNode.ChildNodes) { switch (field.Name) { case "field-definition": /* normal field */ fmf[x] = fms.PopulateFieldInfo(field); Type fieldType = FMSAxml.GetSystemType(field); // add a column for it // except if it already contains a column with that name if (!table.Columns.Contains(fmf[x].Name)) { table.Columns.Add(fmf[x].Name, fieldType); } else { // if the column does already exist, add a dup otherwise // we risk getting in trouble with assigning data to columns table.Columns.Add(fmf[x].Name + "_dup", fieldType); } x++; break; case "relatedset-definition": // fields in portals // has one attribute: the name of the relationship used in the portal (name of the TO, really) string thePortal = field.Attributes.GetNamedItem("table").Value; /* now add a table */ DataTable subTable = ds.Tables.Add(thePortal); /* add columns for the foreign key, mod id, record id */ subTable.Columns.Add("parentRecordID", Type.GetType("System.String")); subTable.Columns.Add("recordID", Type.GetType("System.String")); subTable.Columns.Add("modID", Type.GetType("System.String")); /* add a relationship to the main table */ DataRelation rel; DataColumn left = ds.Tables["main"].Columns["recordID"]; DataColumn right = ds.Tables[thePortal].Columns["parentRecordID"]; rel = new DataRelation(thePortal, left, right); ds.Relations.Add(rel); /* now add columns to the related table */ foreach (XmlNode portalField in field.ChildNodes) { fmf[x] = fms.PopulateFieldInfo(portalField); fmf[x].Portal = thePortal; fieldType = FMSAxml.GetSystemType(portalField); subTable.Columns.Add(fmf[x].Name, fieldType); x++; } break; } // string fieldName = ""; } // foreach field break; case "resultset": /* this is where the data is */ /* now add a row to the table for each found record */ foreach (XmlNode rec in rootNode.ChildNodes) { DataRow newRow = null; string primaryKey = ""; string theRecordID = ""; string theModID = ""; /* recordid, mod id is in the attributes */ foreach (XmlAttribute attrib in rec.Attributes) { switch (attrib.Name) { case "record-id": theRecordID = attrib.Value; primaryKey = theRecordID; break; case "mod-id": theModID = attrib.Value; break; } } /* for each attrib */ /* see if this is a record for the main table * or for a related table * can have "field" or "relatedset" children */ if (rec.HasChildNodes) { /* add a new record to the main table */ newRow = table.NewRow(); newRow["recordID"] = theRecordID; newRow["modID"] = theModID; /* need to do 2 foreaches, one for Field nodes * and one for resultset nodes (related records in * a portal */ foreach (XmlNode recChild in rec.ChildNodes) { switch (recChild.Name) { case "field": /* now get the rest of the fields data into * the row * Changed by Koen Van Hulle - SHpartners */ newRow = FMSAxml.PopulateRow(newRow, recChild, fmf, TimeStampFormat, DateFormat); break; } } // time to add the row table.Rows.Add(newRow); /* 2nd foreach to look for the portal records */ foreach (XmlNode recChild in rec.ChildNodes) { switch (recChild.Name) { case "relatedset": string relTable = recChild.Attributes.GetNamedItem("table").Value; /* has multiple records */ foreach (XmlNode portalRec in recChild.ChildNodes) { /* recordid, mod id is in the attributes */ foreach (XmlAttribute attrib in portalRec.Attributes) { switch (attrib.Name) { case "record-id": theRecordID = attrib.Value; break; case "mod-id": theModID = attrib.Value; break; } } /* for each attrib */ /* ad a new row to the related table */ newRow = ds.Tables[relTable].NewRow(); newRow["recordID"] = theRecordID; newRow["modID"] = theModID; newRow["parentRecordID"] = primaryKey; /* now go get the rest of the fields */ foreach (XmlNode c in portalRec.ChildNodes) { switch (c.Name) { case "field": /* now get the rest of the fields data into * the row * Changed by Koen Van Hulle - SHpartners */ newRow = FMSAxml.PopulateRow(newRow, c, fmf, TimeStampFormat, DateFormat); break; } } /* add the row to the table */ ds.Tables[relTable].Rows.Add(newRow); } break; } // switch name } // 2nd foreach } // if rec has child nodes } /* for each rec */ break; } /* switch rootnode name */ } // foreach root node /* return the result * and also reset the fields collection with the fields we've found here */ fms.Fields = fmf; return(ds); } // try catch (Exception ex) { Tools.LogUtility.WriteEntry(ex, System.Diagnostics.EventLogEntryType.Error); throw; } // catch // return ds; }
/// <summary> /// Executes the "new" command. Throws an error if the command fails. /// </summary> public string Execute() { // if (fms.fmResponseLayout.Length > 0) // theRequest += "&-lay.response=" + fms.fmResponseLayout; theRequest += script; theRequest += fieldString; theRequest += newCommand; String URLstring = fms.Protocol + "://" + fms.ServerAddress + ":" + fms.Port + "/fmi/xml/fmresultset.xml"; String theData = "-db=" + fms.CurrentDatabase + "&-lay=" + fms.CurrentLayout + theRequest; String errorCode = ""; String theRecordID = ""; try { XmlNode root = FMSAxml.RootOfDoc(URLstring, theData, fms.FMAccount, fms.FMPassword, fms.ResponseTimeout, fms.DTDValidation); /* loop through the XML document returned by FMSA */ foreach (XmlNode rootNode in root.ChildNodes) { switch (rootNode.Name.ToLower()) { case "error": errorCode = rootNode.Attributes.GetNamedItem("code").Value; if (errorCode != "0") { FMSAxml.HandleFMSerrors(errorCode); } break; case "resultset": /* this is where the data is */ /* now add a row to the table for each found record */ foreach (XmlNode rec in rootNode.ChildNodes) { /* recordid, mod id is in the attributes */ foreach (XmlAttribute attrib in rec.Attributes) { switch (attrib.Name) { case "record-id": theRecordID = attrib.Value; break; } } /* for each attrib */ } /* for each rec */ break; } /* switch rootnode name */ } // foreach root node /* return the result */ return(theRecordID); } // try catch (Exception ex) { Tools.LogUtility.WriteEntry(ex, System.Diagnostics.EventLogEntryType.Error); throw; } // catch }