Esempio n. 1
0
        static void DoTheRestore(string path)
        {
            LbxApplication libronixApp = null;

            try
            {
                // If Libronix isn't running, we'll get an exception here
                object libApp = Marshal.GetActiveObject("LibronixDLS.LbxApplication");
                return;                 // It IS running; don't disturb it.
            }
            catch (COMException e)
            {
                if ((uint)e.ErrorCode == 0x800401E3)                 // MK_E_UNAVAILABLE
                {
                    // try to start
                    libronixApp = new LbxApplicationClass();
                }
            }
            if (libronixApp == null)             // can't start, or not installed.
            {
                return;
            }
            try
            {
                // Try to load workspace.
                if (!File.Exists(path))
                {
                    libronixApp.Visible = true;                     //let them see it, anyway.
                    return;
                }
                object             document = libronixApp.MSXML.CreateDocument(0);
                MSXML2.DOMDocument doc      = document as MSXML2.DOMDocument;
                doc.load(path);

                //Type docType = document.GetType();
                //MethodInfo info = docType.GetMethod("Save");
                //if (info == null)
                //{
                //    ReportLoadProblem();
                //    return;
                //}
                //info.Invoke(document, new object[] { path });
                libronixApp.LoadWorkspace(document, "", DlsSaveChanges.dlsPromptToSaveChanges);
                libronixApp.Visible = true;                 //only after we reload the workspace, to save flashing.
            }
            catch (Exception)
            {
                libronixApp.Visible = true;                 //let them see it, anyway.
                ReportLoadProblem();
            }
        }
        /// <summary>
        /// Determine the type of request/response recived in XML
        /// This is done by extracting the attribute value from the
        /// first node value of first child element of the document
        /// </summary>
        /// <param name="XMLFilename"> </param>
        public string TypeOfXMLRecieved(string XMLFilename)
        {
            // Declares and initializes a local variable document
            // of type IXMLDOMDocument present in MSXML2 class. This
            // variable is used to point to the XML filename or document
            MSXML2.IXMLDOMDocument document = new MSXML2.DOMDocument();

            // Declares a local variable element of type IXMLDOMElement
            // This is used to point to the elements present in the XML
            // document
            MSXML2.IXMLDOMElement element;

            // Declares a local variable node of type IXMLDOMElement
            // This is used to point to the nodes present in the XML
            // Document
            MSXML2.IXMLDOMNode node;

            // A local variable NodeValue is declared of type string
            // it is used to store the retrieved value from the XML and
            // returns it from the function
            string NodeValue;

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

            // Initializes NodeValue to null
            NodeValue = null;

            // Loads the XML document for reading
            if (document.load(XMLFilename))
            {
                // Extract the first element of the XML
                element = document.documentElement;

                // Extract the first child node from the element
                // and stores it to the node
                node = element.firstChild;

                // now extract the first node value from the attributes
                // present in the XML and saves it to NodeValue
                NodeValue = node.attributes.nextNode().nodeValue.ToString();
            }

            // Simply returns the NodeValue variable
            return(NodeValue);
        }
        // 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);
        }