// determins the request type passed in the given XML document
        public string DetermineRequestType(string path, out int UploadDownloadPrint, out string[] chatInfo)
        {
            int    b        = 0;
            string scopeVal = "";
            bool   flag     = false;

            string[] st = new string[3];

            try
            {
                // load the XML document
                MSXML2.IXMLDOMDocument document = new MSXML2.DOMDocument();
                if (!document.load(path))
                {
                    throw new Exception("XML request found corrupted.");
                }

                // retrieve the request element
                MSXML2.IXMLDOMElement      element = document.documentElement;
                MSXML2.IXMLDOMNode         node    = element.firstChild;
                MSXML2.IXMLDOMNamedNodeMap nodemap = node.attributes;
                // retrieve it's attributes
                MSXML2.IXMLDOMNode childNode = nodemap.nextNode();

                if (0 == node.nodeName.CompareTo("request"))
                {
                    // see what value does the element tequest holds
                    // and react apprpriately
                    switch (childNode.nodeValue.ToString())
                    {
                    case "CHAT":
                    {
                        b = 4;
                        MSXML2.IXMLDOMNode         scope      = node.firstChild;
                        MSXML2.IXMLDOMNamedNodeMap nodemap2   = scope.attributes;
                        MSXML2.IXMLDOMNode         childNode2 = nodemap2.nextNode();
                        MSXML2.IXMLDOMNode         childNode3 = nodemap2.nextNode();
                        MSXML2.IXMLDOMNode         childNode4 = nodemap2.nextNode();
                        // set file name to upload to "path" parameter
                        st.Initialize();
                        st.SetValue(childNode2.nodeValue.ToString(), 0);
                        st.SetValue(childNode3.nodeValue.ToString(), 1);
                        st.SetValue(childNode4.nodeValue.ToString(), 2);
                        break;
                    }

                    case "SEARCH":
                    {
                        WriteSearchResponse(node);
                        break;
                    }

                    case "SHOWFILES":
                    {
                        WriteShowfileResponse("SHOWFILES");
                        break;
                    }

                    case "DOWNLOAD":
                    {
                        // set flag that its download request
                        b    = 2;
                        flag = true;
                        break;
                    }

                    case "UPLOAD":
                    {
                        // set flag that its upload request
                        b    = 1;
                        flag = true;
                        break;
                    }

                    case "PRINT":
                    {
                        // set flag that its print request
                        b    = 3;
                        flag = true;
                        break;
                    }

                    case "STREAMING":
                    {
                        // set flag that its Streaming request
                        b    = 5;
                        flag = true;
                        break;
                    }

                    default:
                        throw new Exception("Request type could not be resolved.");
                    }

                    if (flag)
                    {
                        MSXML2.IXMLDOMNode         scope      = node.firstChild;
                        MSXML2.IXMLDOMNamedNodeMap nodemap2   = scope.attributes;
                        MSXML2.IXMLDOMNode         childNode2 = nodemap2.nextNode();
                        // set file name to upload to "path" parameter
                        scopeVal = childNode2.nodeValue.ToString();
                    }
                }
            }
            catch (Exception e)
            {
                WriteErrorResponse(e.Message);
            }

            chatInfo            = st;
            UploadDownloadPrint = b;
            return(scopeVal);
        }
Пример #2
0
        /// <summary>
        /// Actual Parsing of ERROR XML
        /// </summary>
        /// <param name="Filename"> </param>
        /// <param name="outStruct"> </param>
        protected int ParseERRORXML(string Filename, out XMLSTRUCT outStruct)
        {
            // initializes all the required variables
            InitVariables();

            // Initialize outStruct variable of this function
            outStruct = new XMLSTRUCT();

            // Process the XML document syncronously
            document.async = false;

            // load the xml document in memory for parsing
            if (document.load(Filename))
            {
                // get the first element of the XML
                element = document.documentElement;

                // get the first child of the element
                node = element.firstChild;

                // extracts the node list present under the node
                nodeList = node.childNodes;

                // iTags will assigns to the number of nodes present
                // in node list
                iTags = nodeList.length;

                // Initialize the ERROR sructure of the outStruct
                // variable
                outStruct.ERROR = new XMLSTRUCT.__ERROR();

                // move the node to the next node of the nodelist
                node = nodeList.nextNode();

                // Extract each value from its specific node
                for (iCounter = 0; iCounter < iTags; iCounter++)
                {
                    // gets the attribute map that is how many attributes
                    // are present in the node
                    nodeMap = node.attributes;

                    // extract the next node from the node map
                    ChildNode = nodeMap.nextNode();

                    // The following 9 lines of code will extract the
                    // various attribute values from the XML node
                    // and fills it to the outStruct's corresponding
                    // structure
                    do
                    {
                        if (0 == ChildNode.nodeName.CompareTo("errorcode"))
                        {
                            outStruct.ERROR.iErrCode = Convert.ToInt32(ChildNode.nodeValue);
                        }
                        else if (0 == ChildNode.nodeName.CompareTo("severity"))
                        {
                            outStruct.ERROR.sSeverity = ChildNode.nodeValue.ToString();
                        }
                        else if (0 == ChildNode.nodeName.CompareTo("description"))
                        {
                            outStruct.ERROR.sDescription = ChildNode.nodeValue.ToString();
                        }
                    } while(null != (ChildNode = nodeMap.nextNode()));

                    // now move to next node
                    node = nodeList.nextNode();
                }
            }

            // Return the number of nodes parsed for the values
            return(iCounter == iTags?iCounter:0);
        }
        // responds for search requests
        private void WriteSearchResponse(MSXML2.IXMLDOMNode node)
        {
            try
            {
                MSXML2.IXMLDOMNode         scope      = node.firstChild;
                MSXML2.IXMLDOMNamedNodeMap nodemap    = scope.attributes;
                MSXML2.IXMLDOMNode         childNode  = nodemap.nextNode();
                MSXML2.IXMLDOMNode         childNode2 = nodemap.nextNode();
                string scopeVal = childNode.nodeValue.ToString();
                string maskVal  = childNode2.nodeValue.ToString();

                // make sure that search request has criteria specified in it
                if (0 != scope.nodeName.CompareTo("scope"))
                {
                    return;
                }

                // validated that directory's existing
                if (!Directory.Exists(scopeVal.Substring(0, scopeVal.LastIndexOf("\\") + 1)))
                {
                    throw new Exception("Directory does not exists any more");
                }

                MSXML2.IXMLDOMDocument document     = CreateDocument();
                MSXML2.IXMLDOMElement  responseElem = document.createElement("response");
                responseElem.setAttribute("type", "SHOWFILES");

                int i = 0;
                // get files in the specified directory satisfying the
                // given criteria
                string[] files = Directory.GetFiles(scopeVal.Substring(0, scopeVal.LastIndexOf("\\") + 1), scopeVal.Substring(scopeVal.LastIndexOf("\\") + 1));
                files.Initialize();

                while (i < files.Length)
                {
                    // make fileinfo elements and fill then up with
                    // required
                    MSXML2.IXMLDOMElement file_infoElem = document.createElement("fileinfo");
                    file_infoElem.setAttribute("filename", files[i]);
                    file_infoElem.setAttribute("mask", maskVal);
                    file_infoElem.setAttribute("filesize", Convert.ToString(new FileInfo(files[i]).Length));
                    ++i;
                    // add them to response element as children;
                    responseElem.appendChild(file_infoElem);
                }

                // get files in the specified directory satisfying the
                // given criteria
                string[] dirs = Directory.GetDirectories(scopeVal.Substring(0, scopeVal.LastIndexOf("\\") + 1), scopeVal.Substring(scopeVal.LastIndexOf("\\") + 1));
                dirs.Initialize();

                i = 0;
                while (i < dirs.Length)
                {
                    // make fileinfo elements and fill then up with
                    // required
                    MSXML2.IXMLDOMElement file_infoElem = document.createElement("fileinfo");
                    file_infoElem.setAttribute("filename", dirs[i] + "\\");
                    file_infoElem.setAttribute("mask", maskVal);
                    ++i;

                    // add them to response element as children;
                    responseElem.appendChild(file_infoElem);
                }
                // close and save the document
                SaveAndCloseDocument(responseElem, document);
            }
            catch (Exception e) { WriteErrorResponse(e.Message); }
        }