/// <summary>
        /// PutReference()
        /// Static method which is responsible
        /// for manually updating the patient list in Canvas Oncology App
        /// </summary>
        public static void doReferenceUpdate()
        {
            API settings = new API();

            // make new canvas object
            Canvas c = new Canvas();

            // set the rows for the object based on the data set
            CanvasUtility.SetCanvasRows(c);

            // set canvas url
            CanvasUtility.SetCanvasURL(c,
                                       Canvas.RequestType.ReferencePut);

            // don't process request if there are no rows avaliable
            if (c.Rows.Count == 0)
            {
                return;
            }

            // get the last identity
            Identity lastIdentity = IdentityController.GetLastIdentity();

            // update the text file
            FileStoreUtility.UpdateIndex(lastIdentity.lastId.ToString());

            // make xml
            XMLController.BuildXML(c);

            // get payload
            string XMLPayload = File.ReadAllText(settings.XML_FILE_NAME);

            // make request to update fields
            XMLController.doRequest(c, XMLPayload);
        }
Ejemplo n.º 2
0
        public static void doRequest(Canvas canvas, string Payload)
        {
            string webException     = BLANK;
            string programException = BLANK;
            string responseString   = BLANK;
            // get all xml text
            string XMLDocument   = BLANK;
            string requestString = BLANK;
            // set settings up
            API settings = new API();

            if (!String.IsNullOrEmpty(Payload))
            {
                // XML Doc
                XMLDocument = Payload;
                //XMLDoc is the XML data string being submitted.
                requestString = XMLDocument;
            }
            // set request parameters
            string URL   = canvas.URL;
            string uName = canvas.Username;
            string pWord = canvas.Password;

            try
            {
                HttpWebRequest request  = null;
                WebResponse    response = null;
                // Create a request using a URL that can receive a post.
                request = (HttpWebRequest)WebRequest.Create(URL);
                // Our credentials for the website.
                request.Credentials = new NetworkCredential(uName, pWord);
                // Set the Method property of the request to POST.
                request.Method = METHOD;
                // Set content type
                request.ContentType = CONTENT_TYPE;
                // Wrap the request stream with a text-based writer
                StreamWriter sw = new StreamWriter(request.GetRequestStream());
                // Write the xml as text into the stream
                sw.WriteLine(requestString);
                sw.Close();
                // Send the data to the webserver and get the response.
                response = request.GetResponse();
                if (request != null)
                {
                    // Close the request object
                    request.GetRequestStream().Close();
                }
                string responseFromServer = string.Empty;
                if (response != null)
                {
                    // start stream leader
                    StreamReader incomingStreamReader =
                        new StreamReader(response.GetResponseStream());
                    // Put the response in a string
                    responseFromServer = incomingStreamReader.ReadToEnd();
                    // close out the stream & response reader
                    incomingStreamReader.Close();
                    response.GetResponseStream().Close();
                    // get the web exception
                    webException = ((HttpWebResponse)response).StatusDescription.ToString();
                    // write xml output
                    File.WriteAllText(settings.XML_RESPONSE, responseFromServer);
                    // write the web exception
                    FileStoreUtility.AppendLocalWebLog(webException);
                }
                // look up response string
                responseString = responseFromServer.ToString();
            }
            catch (WebException webEx)
            {
                webException = webEx.Message.ToString();
            }
            catch (Exception ex)
            {
                programException = ex.Message.ToString();
            }
        }