Example #1
0
 //------
 // The following are overloads created that allow for the creation of Elements. You can specify a tag name and a value so that we don't
 // have to keep doing AppendStartTag, Append, AppendEndTag for every single element built up in the code!
 //------
 public void AppendTagsWithValue(string sTagName, string sValue)
 {
     // NOTE:    Unlike Attributes (e.g. Attrib="SomeValue"), elements (e.g. <Element>SomeValue</Element>) should not have single or
     //          double quotes encoded.
     AppendStartTag(sTagName);
     Append(CXMLHelper.FixXMLStringForElement(sValue));
     AppendEndTag(sTagName);
 }
Example #2
0
        // Handles the work of making a request and pulling Employee(s) from the result of a request (if there was an error the return value will
        // be null)
        protected static List <CEmployee> ProcessRequest(APIRequestResult aRequestResult)
        {
            // Make sure the Prev/Next Page URI, if there was an error, etc are reset in the event the user is re-using an object that has already
            // been used for a different call (don't want a previous call's results giving the caller false information)
            aRequestResult.ResetResultData();


            // Pass the request on to the REST API. If there was an error then exit now
            CRestApiHelper.MakeAPIRequest(aRequestResult);
            if (aRequestResult.HadRequestError)
            {
                return(null);
            }

            // Load in the XML returned from the API call
            XmlDocument xdDoc = new XmlDocument();

            xdDoc.LoadXml(aRequestResult.RequestResult);


            // Will hold the list of employees that will be returned to the calling function
            List <CEmployee> lstEmployees = new List <CEmployee>();

            // Grab the root element and get the Previous/Next Page URIs from it (when requesting a specific employee there will be no paging
            // information returned since a single record is all that is ever returned. If that's the case we want our Previous/Next Page URIs to
            // hold 'N/A' rather than "" which is why we pass in the URI_NOT_AVAILABLE constant)
            XmlElement xeDocElement = xdDoc.DocumentElement;

            aRequestResult.ResultPrevPageURI = CXMLHelper.GetChildNodeValue(xeDocElement, Constants.PREV_PAGE_URI, Constants.URI_NOT_AVAILABLE);
            aRequestResult.ResultNextPageURI = CXMLHelper.GetChildNodeValue(xeDocElement, Constants.NEXT_PAGE_URI, Constants.URI_NOT_AVAILABLE);

            XmlElement xeEmployee = null;

            // Grab the list of Employee nodes and loop through the elements...
            XmlNodeList xnlEmployees = xeDocElement.GetElementsByTagName("Employee");
            int         iCount       = xnlEmployees.Count;

            for (int iIndex = 0; iIndex < iCount; iIndex++)
            {
                // Grab the current element
                xeEmployee = (XmlElement)xnlEmployees[iIndex];

                // Add the current item to our list
                lstEmployees.Add(new CEmployee(
                                     CDovicoID.Parse(CXMLHelper.GetChildNodeValue(xeEmployee, "ID")),
                                     CXMLHelper.GetChildNodeValue(xeEmployee, "LastName"),
                                     CXMLHelper.GetChildNodeValue(xeEmployee, "FirstName")
                                     // NOTE: If this is an Employee/Me/ request, the rest of the fields may not be available
                                     ));
            } // End of the for(int iIndex = 0; iIndex < iCount; iIndex++) loop.


            // Return the list of Employees to the caller
            return(lstEmployees);
        }
Example #3
0
        public static string GetInfoMeOptions(ref APIRequestResult aRequestResult)
        {
            // Set the URI for the Employee/Me/ request. Process the request and if the returned list is not null (no errors) then return the first item in the list (there
            // should only ever be the one item)
            aRequestResult.SetRequestURI("Employees/Me/Options/", "");
            aRequestResult.ContentType = "text/xml";
            CRestApiHelper.MakeAPIRequest(aRequestResult);

            XmlDocument xdDoc = new XmlDocument();

            xdDoc.LoadXml(aRequestResult.RequestResult);
            string ShowBillable = CXMLHelper.GetChildNodeValue(xdDoc.DocumentElement, "ShowBillable");

            return(ShowBillable);
        }
Example #4
0
 // sValue will be HTML Encoded (e.g. '<B>Bold' will become '&lt;B&gt;Bold')
 public void Append(string sString, string sValue)
 {
     Append(sString);
     Append(CXMLHelper.FixXMLString(sValue));
 }
Example #5
0
        // Helper that fires off the request to the REST API and processes the results
        protected static List <CTimeEntry> ProcessRequest(ref APIRequestResult aRequestResult)
        {
            // Make sure the Prev/Next Page URI, if there was an error, etc are reset in the event the user is re-using an object that has already
            // been used for a different call (don't want a previous call's results giving the caller false information)
            aRequestResult.ResetResultData();


            // Pass the request on to the REST API. If there was an error then exit now
            CRestApiHelper.MakeAPIRequest(aRequestResult);
            if (aRequestResult.HadRequestError)
            {
                return(null);
            }

            // Load in the XML returned from the API call
            XmlDocument xdDoc = new XmlDocument();

            xdDoc.LoadXml(aRequestResult.RequestResult);


            // Will hold the list of Time Entries that will be returned to the calling function
            List <CTimeEntry> lstTimeEntries = new List <CTimeEntry>();

            // Grab the root element and get the Previous/Next Page URIs from it (when requesting a specific time entry there will be no paging
            // information returned since a single record is all that is ever returned. If that's the case we want our Previous/Next Page URIs to
            // hold 'N/A' rather than "" which is why we pass in the URI_NOT_AVAILABLE constant)
            XmlElement xeDocElement = xdDoc.DocumentElement;

            aRequestResult.ResultPrevPageURI = CXMLHelper.GetChildNodeValue(xeDocElement, Constants.PREV_PAGE_URI, Constants.URI_NOT_AVAILABLE);
            aRequestResult.ResultNextPageURI = CXMLHelper.GetChildNodeValue(xeDocElement, Constants.NEXT_PAGE_URI, Constants.URI_NOT_AVAILABLE);


            XmlElement xeTimeEntry = null, xeClient = null, xeProject = null, xeTask = null;
            DateTime   dtDate = DateTime.Now;

            // Grab the list of Time Entry nodes and loop through the elements...
            XmlNodeList xnlTimeEntries = xeDocElement.GetElementsByTagName("TimeEntry");
            int         iCount         = xnlTimeEntries.Count;

            for (int iIndex = 0; iIndex < iCount; iIndex++)
            {
                // Grab the current element and the required sub-elements
                xeTimeEntry = (XmlElement)xnlTimeEntries[iIndex];
                xeClient    = (XmlElement)xeTimeEntry.GetElementsByTagName("Client")[0];
                xeProject   = (XmlElement)xeTimeEntry.GetElementsByTagName("Project")[0];
                xeTask      = (XmlElement)xeTimeEntry.GetElementsByTagName("Task")[0];

                // Parse the date
                CDateHelper.GetDateFromAPIDateString(CXMLHelper.GetChildNodeValue(xeTimeEntry, "Date"), out dtDate);

                // Add the current item to our list
                lstTimeEntries.Add(new CTimeEntry(
                                       CXMLHelper.GetChildNodeValue(xeTimeEntry, "ID"),
                                       CDovicoID.Parse(CXMLHelper.GetChildNodeValue(xeClient, "ID")),
                                       CXMLHelper.GetChildNodeValue(xeClient, "Name"),
                                       CDovicoID.Parse(CXMLHelper.GetChildNodeValue(xeProject, "ID")),
                                       CXMLHelper.GetChildNodeValue(xeProject, "Name"),
                                       CDovicoID.Parse(CXMLHelper.GetChildNodeValue(xeTask, "ID")),
                                       CXMLHelper.GetChildNodeValue(xeTask, "Name"),
                                       dtDate,
                                       CXMLHelper.GetChildNodeValue(xeTimeEntry, "StartTime"),
                                       CXMLHelper.GetChildNodeValue(xeTimeEntry, "StopTime"),
                                       double.Parse(CXMLHelper.GetChildNodeValue(xeTimeEntry, "TotalHours"), Constants.CULTURE_US_ENGLISH),
                                       CXMLHelper.GetChildNodeValue(xeTimeEntry, "Description")
                                       ));
            } // End of the for(int iIndex = 0; iIndex < iCount; iIndex++) loop.


            // Return the list of Employees to the caller
            return(lstTimeEntries);
        }