Ejemplo n.º 1
0
        public static HttpStatusCode EditEntry(
            HatenaBlogAtomPubClient hatenaBlog,
            PostedEntry entry,
            PostMode postMode,
            IHatenaBlogEntryEditor editor,
            IDiffGenerator diff,
            Func <bool> confirmBeforePosting,
            out bool isModified
            )
        {
            Console.Write("{0} \"{1}\" ", entry.EntryUri, entry.Title);

            isModified = false;

            if (editor.Edit(entry, out var originalText, out var modifiedText))
            {
                isModified = true;

                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("(変更あり)");
                Console.ResetColor();

                diff.DisplayDifference(originalText, modifiedText);

                Console.WriteLine();
            }
Ejemplo n.º 2
0
        public override HttpStatusCode UpdateEntry(PostedEntry updatingEntry, out XDocument responseDocument)
        {
            if (atom == null)
            {
                throw new InvalidOperationException("not logged in");
            }

            responseDocument = null;

            try {
                var putDocument = CreatePostDocument(updatingEntry);

                putDocument.Root.Add(
                    updatingEntry.Authors.Select(author =>
                                                 string.IsNullOrEmpty(author)
              ? null
              : new XElement(
                                                     AtomPub.Namespaces.Atom + "author",
                                                     new XElement(
                                                         AtomPub.Namespaces.Atom + "name",
                                                         author
                                                         )
                                                     )
                                                 )
                    );

                return(atom.Put(updatingEntry.MemberUri, putDocument, out responseDocument));
            }
            catch (Exception ex) {
                throw new PostEntryFailedException(updatingEntry, ex);
            }
        }
Ejemplo n.º 3
0
        public override HttpStatusCode UpdateEntry(PostedEntry updatingEntry, out XDocument responseDocument)
        {
            responseDocument = new XDocument();

            return(HttpStatusCode.OK);
        }
Ejemplo n.º 4
0
        internal static IEnumerable <Tuple <PostedEntry, XElement> > ReadEntries(XDocument doc)
        {
            return(doc.Element(AtomPub.Namespaces.Atom + "feed")
                   ?.Elements(AtomPub.Namespaces.Atom + "entry")
                   ?.Select(entry => Tuple.Create(ConvertEntry(entry), entry)) ?? Enumerable.Empty <Tuple <PostedEntry, XElement> >());

            PostedEntry ConvertEntry(XElement entry)
            {
                /*
                 * posted-entry only propeties
                 */
                var memberUri = entry
                                .Elements(AtomPub.Namespaces.Atom + "link")
                                .FirstOrDefault(link => link.HasAttributeWithValue("rel", "edit"))
                                ?.GetAttributeValue("href", StringConversion.ToUriNullable);
                var entryUri = entry
                               .Elements(AtomPub.Namespaces.Atom + "link")
                               .FirstOrDefault(link => link.HasAttributeWithValue("rel", "alternate") && link.HasAttributeWithValue("type", "text/html"))
                               ?.GetAttributeValue("href", StringConversion.ToUriNullable);
                var id = StringConversion.ToUriNullable(entry.Element(AtomPub.Namespaces.Atom + "id")?.Value);
                var formattedContent = entry.Element(AtomPub.Namespaces.Hatena + "formatted-content")?.Value;
                var authors          = entry
                                       .Elements(AtomPub.Namespaces.Atom + "author")
                                       .Select(elementAuthor => elementAuthor.Element(AtomPub.Namespaces.Atom + "name")?.Value);
                var datePublished = DateTimeOffset.MinValue;

                try {
                    datePublished = DateTimeOffset.Parse(entry.Element(AtomPub.Namespaces.Atom + "published")?.Value);
                }
                catch (ArgumentNullException) {
                    // ignore exception
                }
                catch (FormatException) {
                    // ignore exception
                }

                var e = new PostedEntry(
                    id: id,
                    memberUri: memberUri,
                    entryUri: entryUri,
                    datePublished: datePublished,
                    authors: authors,
                    formattedContent: formattedContent
                    );

                /*
                 * basic propeties
                 */
                e.Title       = entry.Element(AtomPub.Namespaces.Atom + "title")?.Value;
                e.Summary     = entry.Element(AtomPub.Namespaces.Atom + "summary")?.Value;
                e.Content     = entry.Element(AtomPub.Namespaces.Atom + "content")?.Value;
                e.ContentType = entry.Element(AtomPub.Namespaces.Atom + "content")?.GetAttributeValue("type");

                try {
                    e.DateUpdated = DateTimeOffset.Parse(entry.Element(AtomPub.Namespaces.Atom + "updated")?.Value);
                }
                catch (ArgumentNullException) {
                    // ignore exception
                }
                catch (FormatException) {
                    // ignore exception
                }

                foreach (var category in entry.Elements(AtomPub.Namespaces.Atom + "category").Select(c => c.GetAttributeValue("term")))
                {
                    e.Categories.Add(category);
                }

                e.IsDraft = IsYes(entry.Element(AtomPub.Namespaces.App + "control")?.Element(AtomPub.Namespaces.App + "draft")?.Value);

                return(e);
            }

            bool IsYes(string str)
            {
                return(string.Equals(str, "yes", StringComparison.OrdinalIgnoreCase));
            }
        }
Ejemplo n.º 5
0
 public abstract HttpStatusCode UpdateEntry(PostedEntry updatingEntry, out XDocument responseDocument);