このブログの中を検索する

ラベル HowTo の投稿を表示しています。 すべての投稿を表示
ラベル HowTo の投稿を表示しています。 すべての投稿を表示

2013/04/07

Scilab 5.4に対応したNotepad++のスタイル(キーワードの色付け、関数名の補間、引数の解説表示)拡張

title: Scilab 5.4に対応したNotepad++のスタイル(キーワードの色付け、関数名の補間、引数の解説表示)拡張
url: http://fileexchange.scilab.org/toolboxes/140000/

snippet:
-----引用-----

Notepad++ styles for Scilab 5.4 syntax colorization + functions completion & args reminder

-----引用-----


■導入の手順

scilab.xmlをダウンロード
 ↓
C:\Program files\Notepad++\plugins\APIs\scilab.xml
などに配置
 ↓
UserDefineLang.xmlをダウンロード
 ↓
C:\Users\%user_name%\AppData\Roaming\Notepad++\UserDefineLang.xml
などに配置
 ↓
Notepad++のメニューから以下を選択、配置したUserDefineLang.xmlを指定してインポート。
Settings => Import => Import Styles...
 ↓
Notepad++を起動、.sceファイルなどを開くと、Scilabとして認識される。

2013/03/10

JavaScriptがページの読み込み時間を遅くする10の理由

title: JavaScriptがページの読み込み時間を遅くする10の理由
url: http://tokkono.cute.coocan.jp/blog/slow/index.php/web-technology/top-10-reasons-javascript-blocking-page-load/
http://www.slideshare.net/doris1/ps-ts-5400-305400-230-1-v4
http://blog.dynatrace.com/tag/ajax/
http://code.google.com/intl/ja/speed/page-speed/docs/rules_intro.html
http://developer.yahoo.com/performance/rules.html

snippet:
-----引用-----

1. IEの遅いCSSセレクタ
2. 同一オブジェクトに対する多重のCSS検索
3. 多過ぎるXmlHttpRequests
    Ajax Performance Tuning and Best Practices
4. 負荷の高いDOM操作
    新規DOMはCSS設定後に追加し、リフローを最小限にする
    フラグメントへの追加・修正は、リフローが発生しない
    クローンで同一要素の作成を効率化する
5. 多過ぎるJavaScriptファイル
6. 巨大なDOM
7. イベントハンドラの過度なバインディング
8. 外部サービスの実行による速度低下(広告バナーや Facebook への接続)
9. 過度なビジュアル効果
10. 行き過ぎたロギングとモニタリング

 JavaScript と AJAX について書いている我々のブログ や、Google の Web Performance Best Practices、Yahoo の Best Practices for Speeding Up Your Web Site でより多くの情報をチェックして下さい。 Steve Souders や John Resig らが、Webパフォーマンスについて語っていることも読むべきです。また Planet Performance のWebパフォーマンスに関するブログの優れた記事もチェックすると良いでしょう。

-----引用-----

\\tsclient\c : リモートデスクトップでリモートコンピュータ側からローカルコンピュータ側のドライブにアクセスするためのファイルパス名

title: \\tsclient\c : リモートデスクトップでリモートコンピュータ側からローカルコンピュータ側のドライブにアクセスするためのファイルパス名
url: http://www.atmarkit.co.jp/fwin2k/win2ktips/979rdc5drvrdt/rdc5drvrdt.html

snippet:
-----引用-----

1. ローカル・コンピュータ上でリモート・デスクトップ接続(RDC)のオプションを変更する。

2. ローカル・ドライブをコマンドラインからアクセスするには、「\\tsclient\<ドライブ名>」というUNC形式のパスを指定する。ローカル・コンピュータの実際のコンピュータ名に関係なく、UNCのサーバ名は必ず「tsclient」である点に注意すること。例えばローカル・コンピュータのC:\Documents and Settingsフォルダをアクセスするには、以下のパスを指定すればよい。

\\tsclient\C\Documents and Settings

-----引用-----

Office 2003で数式エディタで作成した数式が文字化けした場合、MathTypeフォントをインストールすればよい

title: Office 2003で数式エディタで作成した数式が文字化けした場合、MathTypeフォントをインストールすればよい
url: http://www.dessci.com/en/dl/fonts/getfont.asp

snippet:
-----引用-----

上記URLにあるMathType 6.9 TrueType font installerをインストールするだけで、数式エディタで作成した数式の文字化けが直る

If you want to properly view and print documents containing MathType equations, you will need MathType's fonts installed on your computer. Please read the following instructions to obtain these fonts.

-----引用-----

2012/09/23

Word2007の数式ツールはTeX形式の入力ができる (例: 積分は¥int^[上]_[下][スペース]で簡単に作れる)

title: Word2007の数式ツールはTeX形式の入力ができる (例: 積分は¥int^[上]_[下][スペース]で簡単に作れる)
url: http://www.sunmattu.net/?p=84

snippet:
-----引用-----

Microsoft Office Wordには、Word2003までは数式を書くための数式エディタというツールが、不便ながらもついていました。2003までの標準添付ツールはMathtypeの機能限定版でした。しかし、Word 2007からは、数式を扱う新しい機能が標準装備されました。

Word2007の数式ツールは、記号などはTeX形式の入力ができたりもするので(たとえば、¥times[スペース]と打つと(¥は半角)、×(かけ算)に自動的に変換してくれたり、 ¥alpha[スペース]でαが出てきたり…Σ記号や積分記号も¥int^[上]_[下][スペース]で簡単に作れたりします)、TeXにちょこっと慣れてる人はすぐ使いこなせます。

-----引用-----

2012/06/20

NUnitで複数ケースを実装する方法

title: NUnit複数ケースを実装する方法
url: http://codezine.jp/article/detail/6590?p=2

snippet:
-----引用-----

using NUnit.Framework;
using CsTdd04.FizzBuzz;

namespace CsTdd04.FizzBuzzTest {
  [TestFixture]
  public class FizzBuzzerTest {
    [TestCase(1, "1")]
    [TestCase(3, "Fizz")]
    [TestCase(5, "Buzz")]
    [TestCase(6, "Fizz")]
    [TestCase(9, "Fizz")]
    [TestCase(10, "Buzz")]
    [TestCase(12, "Buzz")]
    [TestCase(15, "FizzBuzz")]
    public void SayTest(int n, string expected) {
      Assert.That((new FizzBuzzer()).Say(n), Is.EqualTo(expected));
    }
  }
}

-----引用-----

Google Data APIを.NETで使用するための開発者ガイド、コードサンプル

title: Google Data APIを.NETで使用するための開発者ガイド、コードサンプル
url: https://sites.google.com/site/copypesouko/--manyuaru/netclientlibra2

snippet:
-----引用-----

.NETクライアントライブラリ開発者ガイド

このドキュメントはGoogle Data API("GData")質問を送って、返された応答を解釈するのに.NETクライアントライブラリを使用する方法を説明します。

チュートリアルと例

以下の例は、C#クライアントライブラリを使用することでどのように様々なGData要求を送るかを示しています。
それらをより具体的にするように、これらの例は、どのように特定のサービス:Googleカレンダー と対話するかを示しています。 私たちはCalendarがあなたが他のサービスで使用のためのこれらの例を適合させるのを助けるために他のGoogleサービスと異なっている場所を指摘するつもりです。Calendarに関する詳しい情報に関しては、Google Calendar Data APIドキュメントを見てください。
あなたのクライアントを構築して、走らせます。
このドキュメントの例をコンパイルするには、次のusingステートメントを使用する必要があります:

using Google.GData.Client;

フィードを要求

Google Calendar Data APIドキュメントで説明されるように、あなたは以下のHTTP要求をCalendarに送ることによって、Calendarフィードを要求できます:
GET http://www.google.com/calendar/feeds/userID/private/full
もちろん、あなたは userID をユーザのEメールアドレスに取り替えなければなりません。 詳細のためのCalendarドキュメントを見てください。あなたは、Calendarと対話するのに代わりに特別なデフォルトURLを使用できますが(Calendarドキュメントで説明されるように)、本書では私たちは private full feed URL を使用するつもりです。(それは、ユーザIDを含みます)。
また、あなたは適切な認証を提供しなければなりません。ウェブアプリケーションにおける、使用ではなく、デスクトップクライアントなどのインストールされたクライアントアプリケーションにおける使用だけに、私たちがここ(「インストールされたアプリケーションのためのGoogle認証」として、知られている)で使用している認証システムが適切であることに注意してください。認証に関する詳しい情報に関しては、 Google Account Authentication ドキュメンテーションを見てください。

ユーザにEメールアドレス" jo@gmail.com "とパスワード"mypassword"でC#クライアントライブラリを使用することでCalendarフィードを要求するには、以下のコードを使用してください:

// クエリーとサービスオブジェクトを作成してください:

FeedQuery query = new FeedQuery();
Service service = new Service("cl", "exampleCo-exampleApp-1"));
// あなたの証明書を設定します:
service.setUserCredentials("jo@gmail.com", "mypassword");

// クエリーオブジェクトを作成してください:
query.Uri = new Uri("http://www.google.com/calendar/feeds/jo@gmail.com/private/full");

// 以下についてクエリーするようにサービスに命令します。
AtomFeed calFeed = service.Query(query);

 Service のクラスはクライアント接続(認証がある)のGDataサービスに代理をします。クライアントライブラリを使用することで質問をサービスに送るための基本手順は以下のステップから成ります:
適切なURLを得るか、または構成してください。
データをサービスに送るなら(あなたが例えば新しいエントリーを挿入しているなら)、クライアントライブラリのクラスを使用することで生データをオブジェクトに変えてください。(あなたがただフィードを要求しているなら、私たちがこの例でしているように、このステップは適用されません。)
サービス名(Calendarのための「Cl」などの)とあなたのアプリケーションの名前を設定して、新しいServiceインスタンスを作成してください。(このフォームで。companyName-applicationName-versionID).
適切な証明書を設定してください。
リクエストを送信し、任意の結果を受け取るメソッドを呼び出します。
 service.setUserCredentials メソッドは標準の.NET Network資格証明書オブジェクトで service.Credentials の特性の用意をします。 資格証明書はあなたのクライアントがだれの代理にクエリーを送るかときのユーザのIDとパスワードへのセットです。 例は本書では「Authentication for Installed Applications」認証システムを使用します。 他の認証システムに関する詳しい情報に関しては、Google Account Authentication ドキュメンテーションを見てください。
全体のフィードを要求するために、あなたは service.Query メソッドを呼びます。(それは、 FeedQuery オブジェクトを取って、そのURLで見つけられた全体の給送を返します)。私たちは、後でどのように本書ではより特定のクエリーを送るかを示すつもりです。
 Service のクラスの他のメソッドのように、 Query は認証を扱って、必要に応じて向け直します。

新しい項目を挿入する

カレンダーフィードにアイテムを挿入するには、次のコードを使用する場合があります:

AtomEntry entry = new AtomEntry();
AtomPerson author = new AtomPerson(AtomPersonType.Author);
author.Name = "Jo March";
author.Email = "jo@gmail.com";
entry.Authors.Add(author);
entry.Title.Text = "Tennis with Beth";
entry.Content.Content = "Meet for a quick lesson.";

Uri postUri = new Uri("http://www.google.com/calendar/feeds/jo@gmail.com/private/full");

// 要求を送ってください、そして、応答を受けてください:
AtomEntry insertedEntry = service.Insert(postUri, entry);

URLを設定した後に、私たちは、 AtomEntry オブジェクトを組み立てます。
エントリータイトルは、 AtomTextConstruct、様々なフォーム(プレーンテキスト、HTML、またはXHTML)でテキストをつかむクラスです。エントリー内容は AtomContentオブジェクトによって表されます、プレーンテキストかフォームのどちらかの、他の中身を保持できるクラス、XMLとバイナリ・データを含んでいます。
各作者は名前、URI、およびEメールアドレスとして代理をされます。 (この例では、私たちはURIを省いています。)  あなたは、エントリーの Authors 収集に AtomAuthor オブジェクトを追加することによって、エントリーに作者を加えます。
私たちは私たちが前の例で作成したのと同じ Service オブジェクトを使用しています。この場合、呼ぶためのメソッドは Insertです。(そのInsertは指定された挿入URLにアイテム を送ります)。
サービスは新たに作成されたエントリーを返します、エントリーへの編集URLのように。(エントリーは追加サーバで発生している要素を含むかもしれません)。
上のコードは POST http://www.google.com/calendar/feeds/jo@gmail.com/private/full (適切な認証がある)を送って、エントリーを提供するのに同等です。

特定のエントリーを要求します。

以下のコードで、あなたは前の例に挿入した特定のエントリーを要求できます。
このシリーズの例の文脈では、そのエントリーを検索するのは本当に必要ではありません、Calendarが既に挿入されたエントリーを返したので。 しかし、あなたがURLをエントリーに知っているときはいつも、同じテクニックを適用できます。

FeedQuery singleQuery = new FeedQuery();
singleQuery.Uri = new Uri(newEntry.SelfUri.ToString());
AtomFeed newFeed = service.Query(singleQuery);
AtomEntry retrievedEntry = newFeed.Entries[0];

挿入されたエントリーには、特性、 ToString() メソッドを使用して、新しいURIオブジェクトを作成するのに使用できる AtomUri オブジェクトを返す SelfUri があります。
次に、私たちはただ新しいAtomFeedオブジェクトを手に入れるためのサービスの Query メソッドを呼ばなければなりません、Entries収集におけるちょうど1つのエントリーで。
上のコードは適切な認証と共に GET http://www.google.com/calendar/feeds/jo@gmail.com/private/full/entryID  をCalendarに送るのに同等です。

エントリの検索

フルテキスト検索で最初に一致したものを取得するには、次のコードを使用します:

FeedQuery myQuery = new Query(feedUrl);
myQuery.Query = "Tennis";
AtomFeed myResultsFeed = myService.Query(myQuery);
if (myResultsFeed.Entries.Count > 0) {
  AtomEntry firstMatchEntry = myResultsFeed.Entries[0];
  String myEntryTitle = firstMatchEntry.Title.Text;
}

この例は、 FeedQuery オブジェクトを組み立てることによって、始まります。(オブジェクトはほとんどURLと関連質問パラメータから成ります)。それぞれの標準のGData クエリーパラメータに、特性があります。
 FeedQuery を組み立てた後に、私たちは、サービスの Query 方法にそれを通過します。(それは、クエリー結果を含むフィードを返します)。 代替的アプローチが自分でURLを構成して(フィードURLにクエリーパラメータを追加することによって)、次に、 Query 方法を呼ぶだろうことですが、 FeedQuery 方法が役に立つ層の抽象化を提供するので、あなたは自分でURLを構成する必要はありません。
フィードの Entries 収集は給送におけるエントリーのリストを返します。 Entries.Count はフィードにおける、エントリーの数を返します。
この場合、クエリーが何か結果を返したなら、私たちは、最初の合う結果を AtomEntry オブジェクトに割り当てます。そして、私たちは、エントリーのタイトルを検索するのに AtomEntry のクラスの Title プロパティを使用します。
上のコードは GET http://www.google.com/calendar/feeds/jo@gmail.com/private/full?q=Tennis をCalendarに送るのに同等です。

カテゴリ別の照会

Note: Google Calendarがラベルをイベントに関連づけないので、この例はCalendarで動作しません。
以前の全文検索に合って、特定のカテゴリにあるすべてのエントリーから成るフィードを検索するか、または特定のラベルを持つには、以下のコードを使用してください:

AtomCategory myCategory = new AtomCategory("by_jo");
QueryCategory myCategoryFilter = new QueryCategory(myCategory);
myQuery.Categories.Add(myCategoryFilter);
AtomFeed myCategoryResultsFeed = myService.Query(myQuery);

 AtomCategory のクラスは、カテゴリフィルタで使用されるためにもちろんカテゴリを表します。 QueryCategory のクラスは複数のカテゴリを含むことができますが、この場合、私たちは、1つのカテゴリだけがあるフィルタを組み立てています。
そして、私たちは既存のクエリーにそのフィルタを加えます。(まだ、それは、前の例からの全文クエリーストリングを含んでいます)。
私たちは再び質問をサービスに送るためのQueryメソッドを使用します。
Calendarがカテゴリ検索を許すなら、上のコードは GET http://www.google.com/calendar/feeds/jo@gmail.com/private/full/-/by_jo?q=Tennis をCalendarに送るのに同等でしょう。

アイテムを更新

既存の項目をアップデートするには、以下のコードを使用してください。 以下の例では、私たちは以前に検索されたエントリーのタイトルを古いテキスト(「ベスがいるテニス」)から「重要なミーティング」に変えています。

retrievedEntry.Title.Text = "Important meeting";
retrievedEntry.Update();

まず最初に、私たちは、私たちが、より早くとって来たエントリーのための新しいタイトルを設定します。 そして、私たちは、 Upate をただアップデートされたエントリーをサービスに送るためのメソッドと呼びます。
サービスはアップデートされたエントリーを返します、このエントリーの新しいバージョンのための新しいURLを含んでいます。(エントリーバージョンの詳しい情報に関して、protocol reference document の Optimistic concurrency 部を見てください)
上のコードはおよそ元のエントリーを取り替えるために新しいエントリー(Atomフォーマットにおける)と共に  PUT http://www.google.com/calendar/feeds/jo@gmail.com/private/full/entryID  をサービスに送るのに同等です。

アイテムを削除する

既存の項目を削除するには、以下のコードを使用してください:

updateEntry.Delete();

削除に使用するURLは編集URLと同じです、したがって、この例が前のものと非常に同様です、もちろんそれを除いて、私たちが Update の代わりに Delete メソッドを呼んでいます。
上のコードはおよそ DELETE http://www.google.com/calendar/feeds/jo@gmail.com/private/full/entryID をサービスに送るのに同等です。

-----引用-----

2012/06/19

MathJax : LaTeX方式で数式を書いてホームページに数式を表示するライブラリ

title: MathJax : LaTeX方式で数式を書いてホームページに数式を表示するライブラリ
url: http://genkuroki.web.fc2.com/

snippet:
-----引用-----

簡単な使い方:次を HTML ファイルの <head> と </head> のあいだに挿入する。それだけで LaTeX 方式で数式を書けるようになる。

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({ tex2jax: { inlineMath: [['$','$'], ["\\(","\\)"]] } });
</script>
<script type="text/javascript"
  src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>
<meta http-equiv="X-UA-Compatible" CONTENT="IE=EmulateIE7" />

最も簡単な使い方:次を HTML ファイル中の <head> と </head> のあいだに挿入する。それだけで LaTeX 方式で数式を書けるようになる。ただし $ $ は使えない。

<script type="text/javascript"
  src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML">
</script>

使用例:

HTMLの中に、LaTeX方式で数式を書くだけで、自動的に数式表示に変換される。

<p>\(\sum_{n=1}^\infty \frac{1}{n^2} = \frac{\pi^2}{6}\)</p>
<p>\[
  \sum_{n=1}^\infty \frac{1}{n^2} = \frac{\pi^2}{6}
  \tag{3}
\]</p>

-----引用-----

2012/05/26

10分で分かるRパッケージの作り方

title: 10分で分かるRパッケージの作り方
url: http://www.slideshare.net/yokkuns/10r

snippet:
-----引用-----

10分で分かるRパッケージの作り方

パッケージのスケルトン作成の例 :
> package.skeleton(list=c("yahooWebSearch", "yahooBlogSearch"), name="RSearchYJ")

-----引用-----

2012/05/22

google-gdataを使ってBloggerブログを操作するサンプルコード

title: google-gdataを使ってBloggerブログを操作するサンプルコード
url: http://code.google.com/p/google-gdata/source/browse/trunk/clients/cs/samples/blogger/ConsoleSample.cs
http://code.google.com/p/google-gdata/

snippet:
-----引用-----

using System;
using System.Text;
using Google.GData.Client;
using System.Net;
using System.Xml;
using System.Text.RegularExpressions;

namespace BloggerDevSample
{
    class ConsoleSample
    {
        /** Lists the user's blogs. */
        static void ListUserBlogs(Service service)
        {
            Console.WriteLine("\nRetrieving a list of blogs");
            FeedQuery query = new FeedQuery();
            // Retrieving a list of blogs
            query.Uri = new Uri("http://www.blogger.com/feeds/default/blogs");
            AtomFeed feed = null;
            feed = service.Query(query);
            foreach (AtomEntry entry in feed.Entries)
            {
                Console.WriteLine("  Blog title: " + entry.Title.Text);
            }
        }

        /** Lists the user's blogs and returns the URI for posting new entries
         * to the blog which the user selected.
         */
        static Uri SelectUserBlog(Service service)
        {
            Console.WriteLine("\nPlease select a blog on which to post.");
            FeedQuery query = new FeedQuery();
            // Retrieving a list of blogs
            query.Uri = new Uri("http://www.blogger.com/feeds/default/blogs");
            AtomFeed feed = service.Query(query);

            // Publishing a blog post
            Uri blogPostUri = null;
            if (feed != null)
            {
                foreach (AtomEntry entry in feed.Entries)
                {
                    // Print out the title of the Blog
                    Console.WriteLine("  Blog name: " + entry.Title.Text);
                    Console.Write("  Post to this blog? (y/n): ");
                    if (Console.ReadLine().Equals("y"))
                    {
                        // find the href in the link with a rel pointing to the blog's feed
                        for (int i = 0; i < entry.Links.Count; i++)
                        {
                            if (entry.Links[i].Rel.Equals("http://schemas.google.com/g/2005#post"))
                            {
                                blogPostUri = new Uri(entry.Links[i].HRef.ToString());
                                Console.WriteLine("  Your new posts will be sent to " + blogPostUri.AbsoluteUri.ToString());
                            }
                        }
                        return blogPostUri;
                    }
                }
            }
            return blogPostUri;
        }

        /** Creates a new blog entry and sends it to the specified Uri */
        static AtomEntry PostNewEntry(Service service, Uri blogPostUri)
        {
            Console.WriteLine("\nPublishing a blog post");
            AtomEntry createdEntry = null;
            if (blogPostUri != null)
            {
                // construct the new entry
                AtomEntry newPost = new AtomEntry();
                newPost.Title.Text = "Marriage!";
                newPost.Content = new AtomContent();
                newPost.Content.Content = "<div xmlns='http://www.w3.org/1999/xhtml'>" +
                    "<p>Mr. Darcy has <em>proposed marriage</em> to me!</p>" +
                    "<p>He is the last man on earth I would ever desire to marry.</p>" +
                    "<p>Whatever shall I do?</p>" +
                    "</div>";
                newPost.Content.Type = "xhtml";
                newPost.Authors.Add(new AtomPerson());
                newPost.Authors[0].Name = "Elizabeth Bennet";
                newPost.Authors[0].Email = "liz@gmail.com";

                createdEntry = service.Insert(blogPostUri, newPost);
                if (createdEntry != null)
                {
                    Console.WriteLine("  New blog post created with title: " + createdEntry.Title.Text);
                }
            }
            return createdEntry;
        }

        /** Creates a new blog entry and sends it to the specified Uri */
        static void PostAndDeleteNewDraftEntry(Service service, Uri blogPostUri)
        {
            Console.WriteLine("\nCreating a draft blog post");
            AtomEntry draftEntry = null;
            if (blogPostUri != null)
            {
                // construct the new entry
                AtomEntry newPost = new AtomEntry();
                newPost.Title.Text = "Marriage! (Draft)";
                newPost.Content = new AtomContent();
                newPost.Content.Content = "<div xmlns='http://www.w3.org/1999/xhtml'>" +
                    "<p>Mr. Darcy has <em>proposed marriage</em> to me!</p>" +
                    "<p>He is the last man on earth I would ever desire to marry.</p>" +
                    "<p>Whatever shall I do?</p>" +
                    "</div>";
                newPost.Content.Type = "xhtml";
                newPost.Authors.Add(new AtomPerson());
                newPost.Authors[0].Name = "Elizabeth Bennet";
                newPost.Authors[0].Email = "liz@gmail.com";
                newPost.IsDraft = true;

                draftEntry = service.Insert(blogPostUri, newPost);
                if (draftEntry != null)
                {
                    Console.WriteLine("  New draft post created with title: " + draftEntry.Title.Text);
                    // Delete the newly created draft entry
                    Console.WriteLine("  Press enter to delete the draft blog post");
                    Console.ReadLine();
                    draftEntry.Delete();
                }
            }
        }

        /** Display the titles for all entries in the previously selected blog. */
        static void ListBlogEntries(Service service, Uri blogUri)
        {
            if (blogUri != null)
            {
                Console.WriteLine("\nRetrieving all blog posts");
                // Retrieve all posts in a blog
                FeedQuery query = new FeedQuery();
                Console.WriteLine("  Query URI: " + blogUri.ToString());
                query.Uri = blogUri;
                AtomFeed feed = service.Query(query);
                foreach (AtomEntry entry in feed.Entries)
                {
                    Console.WriteLine("  Entry Title: " + entry.Title.Text);
                }
            }
        }

        /** Display title for entries in the blog in the hard coded date range. */
        static void ListBlogEntriesInDateRange(Service service, Uri blogUri)
        {
            Console.WriteLine("\nRetrieving posts using query parameters");
            // Retrieve all posts in a blog between Jan 1, 2006 and Apr 12, 2007
            FeedQuery query = new FeedQuery();
            query.Uri = blogUri;
            query.MinPublication = new DateTime(2006, 1, 1);
            query.MaxPublication = new DateTime(2007, 4, 12);
            AtomFeed feed = service.Query(query);
            foreach (AtomEntry entry in feed.Entries)
            {
                Console.WriteLine("  Entry Title: " + entry.Title.Text);
            }
        }

        /** Change the contents of the newly created blog entry. */
        static AtomEntry EditEntry(AtomEntry toEdit)
        {
            Console.WriteLine("\nUpdating post");
            // Edit the new entry
            if (toEdit != null)
            {
                toEdit.Title.Text = "Marriage Woes!";
                Console.WriteLine("  Press enter to update");
                Console.ReadLine();
                toEdit = toEdit.Update();
            }
            return toEdit;
        }

        /** Delete the specified blog entry. */
        static void DeleteEntry(AtomEntry toDelete)
        {
            Console.WriteLine("\nDeleting post");
            // Delete the edited entry
            if (toDelete != null)
            {
                Console.WriteLine("  Press enter to delete the new blog post");
                Console.ReadLine();
                toDelete.Delete();
            }
        }

        /** Get the comments feed URI for the desired blog entry. */
        static Uri SelectBlogEntry(Service service, Uri blogPostUri)
        {
            Console.WriteLine("\nPlease select a blog entry on which to comment.");
            FeedQuery query = new FeedQuery();
            query.Uri = blogPostUri;
            AtomFeed feed = service.Query(query);
            Uri commentPostUri = null;

            if (feed != null)
            {
                foreach (AtomEntry entry in feed.Entries)
                {
                    // Print out the title of the Blog
                    Console.WriteLine("  Blog entry title: " + entry.Title.Text);
                    Console.Write("  Post a comment on this entry? (y/n): ");

                    if (Console.ReadLine().Equals("y"))
                    {
                        // Create the Post URL for adding a comment by finding this entry's id number.

                        // Find the href in the link with a rel pointing to the blog's feed.
                        for (int i = 0; i < entry.Links.Count; i++)
                        {
                           
                            if (entry.Links[i].Rel == "edit")
                            {
                                string commentUriStart = Regex.Replace(blogPostUri.ToString(), "/posts/default", "");
                                string selfLink = entry.Links[i].HRef.ToString();
                                string entryId = Regex.Replace(selfLink, blogPostUri.ToString() + "/", "");
                                // Build the comment URI from the blog id in and the entry id.
                                commentPostUri = new Uri(commentUriStart + "/" + entryId + "/comments/default");
                                Console.WriteLine("  Your new comments will be sent to " + commentPostUri.ToString());
                                return commentPostUri;
                            }
                        }
                    }
                }
            }

            return commentPostUri;
        }

        static AtomEntry PostNewComment(Service service, Uri commentPostUri)
        {
            Console.WriteLine("\nCommenting on a blog post");
            AtomEntry postedComment = null;
            if (commentPostUri != null)
            {
                // Add a comment.
                AtomEntry comment;
                comment = new AtomEntry();
                comment.Title.Text = "This is my first comment";
                comment.Content.Content = "This is my first comment";
                comment.Authors.Add(new AtomPerson());
                comment.Authors[0].Name = "Blog Author Name";
                postedComment = service.Insert(commentPostUri, comment);
                Console.WriteLine("  Result's title: " + postedComment.Title.Text);
            }
            return postedComment;
        }

        static void ListEntryComments(Service service, Uri commentUri)
        {
            if (commentUri != null)
            {
                Console.WriteLine("\nRetrieving all blog post comments");
                // Retrieve all comments on a blog entry
                FeedQuery query = new FeedQuery();
                Console.WriteLine("  Query URI: " + commentUri.ToString());
                query.Uri = commentUri;
                AtomFeed feed = service.Query(query);
                foreach (AtomEntry entry in feed.Entries)
                {
                    Console.WriteLine("  Comment Title: " + entry.Title.Text);
                }
            }
        }

        static void DeleteComment(AtomEntry commentEntry)
        {
            Console.WriteLine("\nDeleting the comment");
            if (commentEntry != null)
            {
                // Delete the comment.
                Console.WriteLine("  Press enter to delete the new comment post");
                Console.ReadLine();
                commentEntry.Delete();
            }
        }

        static void Main(string[] args)
        {
            Service service = new Service("blogger", "blogger-example");

            // ClientLogin using username/password authentication
            string username;
            string password;
            if (args.Length != 2)
            {
                Console.WriteLine("Usage: BloggerDevSample.exe <username> <password>");
                return;
            }
            else
            {
                username = args[0];
                password = args[1];
            }

            service.Credentials = new GDataCredentials(username, password);

            ListUserBlogs(service);
            Uri blogPostUri = SelectUserBlog(service);
            AtomEntry createdEntry = PostNewEntry(service, blogPostUri);
            PostAndDeleteNewDraftEntry(service, blogPostUri);
            ListBlogEntries(service, blogPostUri);
            ListBlogEntriesInDateRange(service, blogPostUri);
            AtomEntry editedEntry = EditEntry(createdEntry);
            DeleteEntry(editedEntry);
            Uri commentPostUri = SelectBlogEntry(service, blogPostUri);
            AtomEntry commentEntry = PostNewComment(service, commentPostUri);
            ListEntryComments(service, commentPostUri);
            DeleteComment(commentEntry);

            Console.WriteLine("Press enter to quit");
            Console.ReadLine();
        }
    }
}

-----引用-----