Beispiel #1
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);
        }
Beispiel #2
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);
        }