Ejemplo n.º 1
0
        FMSAxml SetupFMSAxml()
        {
            var asr = new System.Configuration.AppSettingsReader();

            var fms = new FMSAxml(
                theServer: (string)asr.GetValue("TestServerName", typeof(string)),
                theAccount: (string)asr.GetValue("TestServerUser", typeof(string)),
                thePort: (int)asr.GetValue("TestServerPort", typeof(int)),
                thePW: (string)asr.GetValue("TestServerPass", typeof(string))
                );
            return fms;
        }
Ejemplo n.º 2
0
        public static FMSAxml SetupFMSAxml()
        {
            var config = InitConfiguration();

            var fms = new FMSAxml(
                theServer: config["TestServerName"],
                theAccount: config["TestServerUser"],
                thePort: Convert.ToInt32(config["TestServerPort"]),
                thePW: config["TestServerPass"]
                );

            return(fms);
        }
Ejemplo n.º 3
0
        FMSAxml SetupFMSAxml()
        {
            var asr = new System.Configuration.AppSettingsReader();

            var fms = new FMSAxml(
                theServer: (string)asr.GetValue("TestServerName", typeof(string)),
                theAccount: (string)asr.GetValue("TestServerUser", typeof(string)),
                thePort: (int)asr.GetValue("TestServerPort", typeof(int)),
                thePW: (string)asr.GetValue("TestServerPass", typeof(string))
                );

            return(fms);
        }
Ejemplo n.º 4
0
        // 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
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NewRequest"/> class.
 /// </summary>
 /// <param name="f">The instance of the outer class.</param>
 /// <remarks>While this class is publicly available, use the "CreateNewRecordRequest" method to create a new request.</remarks>
 internal NewRecord(FMSAxml f)
 {
     fms = f;
     newCommand = "&-new";
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates an instance of the Edit request class.
 /// </summary>
 /// <param name="f">The instance of the outer FMSAxml class</param>
 /// <param name="recID">The FileMaker RecordID of the row to edit.</param>
 /// <remarks>While this class is publicly available, use the "CreateEditRequest" method to create a new request.</remarks>
 internal Edit(FMSAxml f, string recID)
 {
     fms         = f;
     editCommand = "&-edit";
     theRequest += "&-recid=" + recID;
 }
Ejemplo n.º 7
0
        /// <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;
        }
Ejemplo n.º 8
0
        // constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="T:DeleteRequest"/> class.
        /// </summary>
        /// <param name="f">The outer class instance</param>
        /// <param name="recID">The rec ID.</param>
        /// <remarks>While this class is publicly available, use the "CreateDeleteRequest" method to create a new request.</remarks>
        internal Delete(FMSAxml f, String recID)
        {
            fms        = f;
            delCommand = "&-delete";
            theRequest = "&-recid=" + recID;
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FindRequest"/> class.
 /// </summary>
 /// <param name="s">The SearchType enumerator</param>
 /// <param name="f">The instance of the outer FMSAxml class</param>
 /// <remarks>While this class is publicly available, use the "CreateFindRequest" method to create a new request.</remarks>
 internal Find(SearchType s, FMSAxml f)
 {
     fms         = f;
     findCommand = RealSearchType(s);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CompoundFindRequest"/> class.
 /// </summary>
 /// <param name="f">The instance of the outer FMSAxml class</param>
 internal CompoundFind(FMSAxml f)
 {
     fms = f;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CompoundFindRequest"/> class.
 /// </summary>
 /// <param name="f">The instance of the outer FMSAxml class</param>
 internal CompoundFind(FMSAxml f)
 {
     fms = f;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FindRequest"/> class.
 /// </summary>
 /// <param name="s">The SearchType enumerator</param>
 /// <param name="f">The instance of the outer FMSAxml class</param>
 /// <remarks>While this class is publicly available, use the "CreateFindRequest" method to create a new request.</remarks>
 internal Find(SearchType s, FMSAxml f)
 {
     fms = f;
     findCommand = RealSearchType(s);
 }
Ejemplo n.º 13
0
 // constructors
 /// <summary>
 /// Initializes a new instance of the <see cref="T:DeleteRequest"/> class.
 /// </summary>
 /// <param name="f">The outer class instance</param>
 /// <param name="recID">The rec ID.</param>
 /// <remarks>While this class is publicly available, use the "CreateDeleteRequest" method to create a new request.</remarks>
 internal Delete(FMSAxml f, String recID)
 {
     fms = f;
     delCommand = "&-delete";
     theRequest = "&-recid=" + recID;
 }
Ejemplo n.º 14
0
 // constructors
 /// <summary>
 /// Initializes a new instance of the <see cref="T:DupRequest"/> class.  Use the createDupRequest method instead!
 /// </summary>
 /// <param name="f">The instance of the outer class.</param>
 /// <param name="recID">The rec ID.</param>
 /// <remarks>While this class is publicly available, use the "CreateDuplicateRequest" method to create a new request.</remarks>
 internal Duplicate(FMSAxml f, string recID)
 {
     fms = f;
     dupCommand = "&-dup";
     theRequest = "&-recid=" + recID;
 }
Ejemplo n.º 15
0
        // 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
        }
Ejemplo n.º 16
0
        // constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="T:DupRequest"/> class.  Use the createDupRequest method instead!
        /// </summary>
        /// <param name="f">The instance of the outer class.</param>
        /// <param name="recID">The rec ID.</param>
        /// <remarks>While this class is publicly available, use the "CreateDuplicateRequest" method to create a new request.</remarks>
        internal Duplicate(FMSAxml f, string recID)
        {
            fms        = f;
            dupCommand = "&-dup";
            theRequest = "&-recid=" + recID;
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NewRequest"/> class.
 /// </summary>
 /// <param name="f">The instance of the outer class.</param>
 /// <remarks>While this class is publicly available, use the "CreateNewRecordRequest" method to create a new request.</remarks>
 internal NewRecord(FMSAxml f)
 {
     fms        = f;
     newCommand = "&-new";
 }
Ejemplo n.º 18
0
        /// <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
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Creates an instance of the Edit request class.
 /// </summary>
 /// <param name="f">The instance of the outer FMSAxml class</param>
 /// <param name="recID">The FileMaker RecordID of the row to edit.</param>
 /// <remarks>While this class is publicly available, use the "CreateEditRequest" method to create a new request.</remarks>
 internal Edit(FMSAxml f, string recID)
 {
     fms = f;
     editCommand = "&-edit";
     theRequest += "&-recid=" + recID;
 }