예제 #1
0
        public override async Task <bool> UpdateEntry(EntryFull entry)
        {
            if (!(entry is AtomEntry))
            {
                return(false);
            }

            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Put,
                RequestUri = entry.EditUri,
                Content    = new StringContent((entry as AtomEntry).AsUTF8Xml(), Encoding.UTF8, "application/atom+xml")
            };

            var response = await _HTTPConn.Client.SendAsync(request);

            ToDebugWindow(">> HTTP Request PUT "
                          + Environment.NewLine
                          + entry.EditUri.AbsoluteUri
                          + Environment.NewLine
                          + (entry as AtomEntry).AsUTF16Xml()
                          + Environment.NewLine + Environment.NewLine
                          + "<< HTTP Response " + response.StatusCode.ToString()
                          + Environment.NewLine);

            if (response.IsSuccessStatusCode)
            {
                return(true);
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Put failed. Status code is " + response.StatusCode.ToString());

                var contents = await response.Content.ReadAsStringAsync();

                /*
                 * Hatena AtomPub returns this.
                 * BadRequest 400 Cannot Change into Draft
                 */

                if (contents != null)
                {
                    System.Diagnostics.Debug.WriteLine(contents);

                    ToDebugWindow("<< HTTP Request PUT failed. HTTP Response content is:"
                                  + Environment.NewLine
                                  + contents
                                  + Environment.NewLine);
                }

                return(false);
            }
        }
예제 #2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public EditorViewModel(EntryFull ent)
        {
            _ent = ent;
            _bc  = ent.Client as BlogClient;

            PublishStatus.Add("Publish");
            PublishStatus.Add("Draft");

            switch (_ent.Status)
            {
            case EntryFull.EditStatus.esNew:
                PublishStatusIndex = 0;
                break;

            case EntryFull.EditStatus.esNormal:
                PublishStatusIndex = 0;
                break;

            case EntryFull.EditStatus.esDraft:
                PublishStatusIndex = 1;
                break;

            default:
                PublishStatusIndex = 0;
                break;
            }
            // Or
            if (_ent.IsDraft)
            {
                PublishStatusIndex = 1;
            }
            else
            {
                PublishStatusIndex = 0;
            }

            OpenInBrowserCommand = new RelayCommand(OpenInBrowserCommand_Execute, OpenInBrowserCommand_CanExecute);
            UpdateEntryCommand   = new RelayCommand(UpdateEntryCommand_Execute, UpdateEntryCommand_CanExecute);
            PostNewEntryCommand  = new RelayCommand(PostNewEntryCommand_Execute, PostNewEntryCommand_CanExecute);
        }
예제 #3
0
        public override async Task <bool> UpdateEntry(EntryFull entry)
        {
            // TODO: For now
            if (!(entry is AtomEntry))
            {
                return(false);
            }

            System.Diagnostics.Debug.WriteLine((entry as AtomEntry).AsXml());

            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Put,
                RequestUri = entry.EditUri,
                Content    = new StringContent((entry as AtomEntry).AsXml(), Encoding.UTF8, "application/atom+xml")
            };

            var response = await _HTTPConn.Client.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                System.Diagnostics.Debug.WriteLine("updated. Status code is " + response.StatusCode.ToString());
                return(true);
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Put failed. Status code is " + response.StatusCode.ToString());

                var contents = await response.Content.ReadAsStringAsync();

                System.Diagnostics.Debug.WriteLine(contents);

                /*
                 * BadRequest 400 Cannot Change into Draft
                 */

                return(false);
            }
        }
예제 #4
0
        private async Task <bool> GetEntry(EntryItem selectedEntry)
        {
            if (selectedEntry == null)
            {
                return(false);
            }

            if (!(_selectedNode is NodeEntryCollection))
            {
                return(false);
            }

            BlogClient bc = selectedEntry.Client as BlogClient;

            if (bc == null)
            {
                return(false);
            }

            if (selectedEntry.EditUri == null)
            {
                return(false);
            }

            // TODO:
            // HTTP Head, if_modified_since or etag or something... then  UpdateEntry();

            EntryFull bfe = await bc.GetFullEntry(selectedEntry.EditUri);

            if (selectedEntry == null)
            {
                return(false);
            }

            selectedEntry.EntryBody = bfe;

            return(true);
        }
예제 #5
0
        public override async Task <bool> PostEntry(EntryFull entry)
        {
            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Post,
                RequestUri = entry.PostUri,
                Content    = new StringContent((entry as AtomEntry).AsUTF8Xml(), Encoding.UTF8, "application/atom+xml")
            };

            var response = await _HTTPConn.Client.SendAsync(request);

            ToDebugWindow(">> HTTP Request POST "
                          + Environment.NewLine
                          + entry.EditUri.AbsoluteUri
                          + Environment.NewLine
                          + (entry as AtomEntry).AsUTF16Xml()
                          + Environment.NewLine + Environment.NewLine
                          + "<< HTTP Response " + response.StatusCode.ToString()
                          + Environment.NewLine);

            /*
             * XNamespace atom = "http://www.w3.org/2005/Atom";
             * XNamespace app = "http://www.w3.org/2007/app";
             *
             * XDocument doc = new XDocument(new XElement(atom + "entry",
             *                                      new XAttribute(XNamespace.Xmlns + "app", app.NamespaceName),
             *                                      new XElement(atom + "title", "test title"),
             *                                      new XElement(atom + "author",
             *                                          new XElement(atom + "name", "me")),
             *                                      new XElement(atom + "content",
             *                                          new XAttribute("type", "text/plain"),
             *                                          new XText("asdf")),
             *                                      new XElement(atom + "category",
             *                                          new XAttribute("term", "test categ")
             *                                          ),
             *                                      new XElement(app + "control",
             *                                          new XElement(app + "draft", "yes")
             *                                          )
             *                                      )
             *                           );
             *
             * System.Diagnostics.Debug.WriteLine("content xml: " + doc.ToString());
             */

            if (response.IsSuccessStatusCode)
            {
                Uri entryUrl = response.Headers.Location;

                if (entryUrl != null)
                {
                    entry.EditUri = entryUrl;

                    string contenTypeString = response.Content.Headers.GetValues("Content-Type").FirstOrDefault();

                    if (!contenTypeString.StartsWith("application/atom+xml"))
                    {
                        System.Diagnostics.Debug.WriteLine("Content-Type is invalid: " + contenTypeString);

                        ToDebugWindow("<< Content-Type is invalid: " + contenTypeString
                                      + Environment.NewLine
                                      + "expecting " + "application/atom+xml"
                                      + Environment.NewLine);
                    }
                    else
                    {
                        // TODO: load content body xml entry and get id and rel alt and such.
                    }

                    //System.Diagnostics.Debug.WriteLine("created: " + entryUrl);

                    ToDebugWindow("<< HTTP Response Header - Location: "
                                  + Environment.NewLine
                                  + entryUrl
                                  + Environment.NewLine);

                    return(true);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Post IsSuccess, but Location header is null. ");

                    ToDebugWindow("POST is successfull, but Location header is missing. "
                                  + Environment.NewLine
                                  + Environment.NewLine);

                    return(false);
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Post failed. Status code is " + response.StatusCode.ToString());

                var contents = await response.Content.ReadAsStringAsync();

                if (contents != null)
                {
                    System.Diagnostics.Debug.WriteLine(contents);

                    ToDebugWindow("POST failed. HTTP Response content is:"
                                  + Environment.NewLine
                                  + contents
                                  + Environment.NewLine);
                }

                return(false);
            }
        }
예제 #6
0
 public abstract Task <bool> PostEntry(EntryFull entry);
예제 #7
0
 public abstract Task <bool> UpdateEntry(EntryFull entry);
예제 #8
0
        public override async Task <bool> PostEntry(EntryFull entry)
        {
            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Post,
                RequestUri = entry.PostUri,
                Content    = new StringContent((entry as AtomEntry).AsXml(), Encoding.UTF8, "application/atom+xml")
            };

            var response = await _HTTPConn.Client.SendAsync(request);

            /*
             * XNamespace atom = "http://www.w3.org/2005/Atom";
             * XNamespace app = "http://www.w3.org/2007/app";
             *
             * XDocument doc = new XDocument(new XElement(atom + "entry",
             *                                      new XAttribute(XNamespace.Xmlns + "app", app.NamespaceName),
             *                                      new XElement(atom + "title", "test title"),
             *                                      new XElement(atom + "author",
             *                                          new XElement(atom + "name", "me")),
             *                                      new XElement(atom + "content",
             *                                          new XAttribute("type", "text/plain"),
             *                                          new XText("asdf")),
             *                                      new XElement(atom + "category",
             *                                          new XAttribute("term", "test categ")
             *                                          ),
             *                                      new XElement(app + "control",
             *                                          new XElement(app + "draft", "yes")
             *                                          )
             *                                      )
             *                           );
             *
             * System.Diagnostics.Debug.WriteLine("content xml: " + doc.ToString());
             */


            if (response.IsSuccessStatusCode)
            {
                Uri entryUrl = response.Headers.Location;

                if (entryUrl != null)
                {
                    entry.EditUri = entryUrl;

                    // TODO: load content body xml entry and get id and rel alt and such.


                    System.Diagnostics.Debug.WriteLine("created: " + entryUrl);
                    return(true);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Post IsSuccess, but Location header is null. ");
                    return(false);
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Post failed. Status code is " + response.StatusCode.ToString());

                var contents = await response.Content.ReadAsStringAsync();

                System.Diagnostics.Debug.WriteLine(contents);
                return(false);
            }
        }
예제 #9
0
 public override async Task <bool> PostEntry(EntryFull entry)
 {
     return(true);
 }