Esempio n. 1
0
        /// <summary>
        /// Event called once drupal returns a list of paths for
        /// images. We get raw string output from the server here
        /// so its up to us to parse the xml ourselves here on
        /// an application specific basis.
        /// The objective is to extract a list of absolute images paths
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void HandleNewViewData(object sender, DrupalEventArgs args)
        {
            System.Diagnostics.Debug.WriteLine("handleNewViewData: ");
            // Create an XmlReader
            using (XmlReader.Create(new StringReader(args.TheMessage)))
            {
                try
                {
                    txt_Operations.Text = args.TheMessage;

                    switch (args.ResponseType)
                    {
                    case DrupalUtilities.MethodNodeRetrieve:

                        System.Diagnostics.Debug.WriteLine("Node Data: " + args.TheMessage);
                        break;

                    case DrupalUtilities.MethodViewRetrieve:
                        System.Diagnostics.Debug.WriteLine("View Data: " + args.TheMessage);

                        break;
                    }
                }
                catch (XmlException e)
                {
                    System.Diagnostics.Debug.WriteLine("Exception parsing drupal result xml: {0}", e.ToString());
                }
            }
        }
Esempio n. 2
0
        private void ParseDrupalXmlResponse(string response, string responseType)
        {
            if (response == "")
            {
                return;
            }
            // Create an XmlReader
            using (var reader = XmlReader.Create(new StringReader(response)))
            {
                try
                {
                    switch (responseType)
                    {
                    case MethodUserLogout:
                        reader.ReadToFollowing("result");
                        var tempLogoutValue = reader.ReadElementContentAsString();
                        System.Diagnostics.Debug.WriteLine("Logout xml parse result: " + tempLogoutValue);
                        if (tempLogoutValue == "1")
                        {
                            _loggedInUserId = "-1";
                        }

                        // DISPATCH
                        var logoutEventData = new DrupalEventArgs(MethodUserLogout, response);
                        NewDrupalViewData(this, logoutEventData);
                        break;

                    case MethodUserLogin:
                        reader.ReadToFollowing("uid");
                        _loggedInUserId = reader.ReadElementContentAsString();
                        System.Diagnostics.Debug.WriteLine("Login xml parse userID: " + _loggedInUserId);
                        // DISPATCH
                        var loginEventData = new DrupalEventArgs(MethodUserLogin, response);
                        NewDrupalViewData(this, loginEventData);
                        break;

                    case MethodFileCreate:
                        reader.ReadToFollowing("fid");
                        reader.ReadElementContentAsString();
                        // ReadToFollowing auto hops to the next element
                        if (reader.Name != "uri")
                        {
                            reader.ReadToFollowing("uri");
                        }
                        reader.ReadElementContentAsString();
                        var fileEventData = new DrupalEventArgs(MethodFileCreate, response);
                        NewDrupalViewData(this, fileEventData);
                        break;

                    case MethodNodeCreate:
                        reader.ReadToFollowing("nid");
                        reader.ReadElementContentAsString();
                        // ReadToFollowing auto hops to the next element
                        if (reader.Name != "uri")
                        {
                            reader.ReadToFollowing("uri");
                        }
                        reader.ReadElementContentAsString();
                        break;

                    case MethodNodeRetrieve:
                        // Data here will be really unique to the content type of the node may want to consider
                        // passing this off to a specific class.

                        // DISPATCH
                        var thisEventData = new DrupalEventArgs(MethodNodeRetrieve, response);
                        NewDrupalViewData(this, thisEventData);

                        break;

                    case MethodViewRetrieve:
                        // Data here will be really unique to the content types contained in the view may want to consider
                        // passing this off to a specific class.

                        // DISPATCH
                        var nextEventData = new DrupalEventArgs(MethodViewRetrieve, response);
                        NewDrupalViewData(this, nextEventData);

                        break;
                    }
                }
                catch (XmlException e)
                {
                    System.Diagnostics.Debug.WriteLine("Exception parsing drupal result xml: {0}", e.ToString());
                }
            }
        }