Esempio n. 1
0
        /// <summary>
        /// Publish a Report to a Windows Live Space.
        /// A 'Report' in this context is a complete post including
        /// a screenshot of a KnowledgeMap.
        /// </summary>
        /// <param name="reportBody">Textual body of the Report.</param>
        /// <param name="knowledgeMap">Byte array rep. of a KnowledgeMap screenshot.</param>
        /// <returns></returns>
        public static WlsBridgeStatusCode PublishReport(string reportBody, string postTitle, string knowledgeMap, byte[] kmByteArray, string spaceName)
        {
            //If user is not authenticated, run the authentication proc.
            if (!WindowsLiveBridge.IsUserAthenticated)
            {
                //Authenticate User
                WindowsLiveBridge.AuthenticateUser();
                if (WindowsLiveBridge.LastStatusCode != WlsBridgeStatusCode.UserAuthenticated)
                {
                    return(WindowsLiveBridge.LastStatusCode);
                }
            }

            //We made it through the login, now lets try pushing som data to the Space.
            if (WindowsLiveBridge.PublishBlogPostData_RPCXML(reportBody, postTitle, knowledgeMap, kmByteArray, spaceName) != WlsBridgeStatusCode.Idle)
            {
                return(WindowsLiveBridge.LastStatusCode);
            }

            //Last, lets open a browser and show the result:
            if (WindowsLiveBridge.OpenSpaceInBrowser(spaceName) != WlsBridgeStatusCode.Idle)
            {
                return(WindowsLiveBridge.LastStatusCode);
            }

            return(WlsBridgeStatusCode.Idle);
        }
Esempio n. 2
0
        /// <summary>
        /// Pushes a blog post into a spaces blog.
        /// </summary>
        /// <param name="postBody">Body of the Post</param>
        /// <param name="subject">Subject (Title) of the Post</param>
        /// <param name="knowledgeMapBits"></param>
        /// <param name="kmByteArray"></param>
        /// <param name="spaceUrl">Url to the space that this post will be published to</param>
        private static WlsBridgeStatusCode PublishBlogPostData(string postBody, string subject,
                                                               string knowledgeMapBits, byte[] kmByteArray, string spaceUrl)
        {
            spaceUrl = WindowsLiveBridge.ReplaceInvalidXMLChars(spaceUrl);
            subject  = WindowsLiveBridge.ReplaceInvalidXMLChars(subject);
            postBody = WindowsLiveBridge.ReplaceInvalidXMLChars(postBody);
            byte[] postData =
                new UTF8Encoding(false).GetBytes(String.Format(requestXml, "MyBlog", spaceUrl, "", subject, postBody));
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(WindowsLiveBridge.SPACES_API_URL);
            string         ticket  = "";

            try
            {
                ticket = WindowsLiveBridge._oID.GetTicket("storage.msn.com", "MBI", true);
            }
            catch (XmlRpcFaultException xrfe)
            {
                WindowsLiveBridge.LastStatusCode = WlsBridgeStatusCode.XmlRpcError;

                if (xrfe.HelpLink != null)
                {
                    WindowsLiveBridge.LastStatusMessage = xrfe.FaultString +
                                                          "More info at: " + xrfe.HelpLink;
                }
                else
                {
                    WindowsLiveBridge.LastStatusMessage = xrfe.FaultString;
                }

                return(WlsBridgeStatusCode.AuthenticationError);
            }

            request.Headers.Add("Authorization", "WLID1.0 " + ticket);
            request.AllowAutoRedirect = false;
            request.UserAgent         = "EJournal Plus Client v1";
            request.ContentType       = "text/xml";
            request.Pipelined         = false;
            request.ProtocolVersion   = HttpVersion.Version10;
            request.Method            = "POST";
            using (Stream requestStream = request.GetRequestStream())
            {
                requestStream.Write(postData, 0, postData.Length);
            }
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                return(WlsBridgeStatusCode.Idle);
            }
            else
            {
                return(WlsBridgeStatusCode.ConnectivityError);
            }
        }