[クラス ライブラリ開発のデザイン ガイドライン]
http://msdn.microsoft.com/library/ms229042
Translate
2014年9月1日月曜日
2014年8月31日日曜日
プリプロセッサディレクティブ
#ifディレクティブに DEBUG をつけると、DEBUG用にビルドされた物を実行する時のみ実行される
同様のことは、System.Diagnostics.Conditional("DEBUG")でも実現でき
メソッド単位に使用する。この場合Release用にコンパイルされる側では
条件付きメソッドの呼び出しは削除されるそうな。
using System.Windows.Forms;
namespace SampleCode {
class Program {
static void Main(string[] args) {
#if DEBUG
MessageBox.Show("DEBUG");
#else
MessageBox.Show("RELEASE");
#endif
}
}
}
DEBUGがあるならRELEASEもあるのかと思ったらそれはないのでelseで分岐する同様のことは、System.Diagnostics.Conditional("DEBUG")でも実現でき
メソッド単位に使用する。この場合Release用にコンパイルされる側では
条件付きメソッドの呼び出しは削除されるそうな。
using System.Windows.Forms;
namespace ConsoleApp {
class Program {
static void Main(string[] args) {
ShowMessage("DEBUGの時のみ実行");
}
[System.Diagnostics.Conditional("DEBUG")]
static void ShowMessage(string str) {
MessageBox.Show(str);
}
}
}
github
□Windows
MinGWを使っているので GitBushを起動
$ssh-keygen -t rsa -C "github_from_win"
保存するディレクトリを聞かれます。
デフォルトのまんまならEnter
Enter file in which to save the key(/c/Users/UserName/.ssh/id_rsa):
パスフレーズを聞かれます。
ssh接続する時に聞かれるものです。
Enter passphrase (empty for no passphrase):
Enter save passphrase again:
これで、.sshにid_rsaとid_rsa.pub(公開鍵)が作成されるので
githubにアクセスして
Settings⇒SSH keys⇒Add SSH key
titleを入力し、先ほど生成されたid_rsa.pub(公開鍵)を貼付けます
で登録。
git clone git@github.com:[UserName]/[RepositoryName]
でクローンできます。
2014年6月14日土曜日
redmineをお試しでさわりたくてmac os xにテスト的にいれてみたというお話
サービスに登録して恒久的に動かすというわけじゃなくてちょっといろいろ試してみたくて入れてみた的なスタンスです。
前提、いろいろ入ってるよ。
なので足りないものだけしかいれてないよ。
■nginx
% brew install nginx
でするする入ったよ。
% nginx
で実行
http://localhost:8080
で確認。
うん動いたね。
他のコマンド
% nginx -s stop
% nginx -s reload
参考
% nginx -v
nginx version: nginx/1.4.2
以上
■mysql
入れてあるよ。
redmaine用のDB作っておくよ。
mysql -u username -p
mysql> create database redmine default character set utf8;
mysql> quit
はい。DBの準備完了
■redmine
サイトにいってダウンロード
http://www.redmine.org/projects/redmine/wiki/Download
今は2.5.1
好きなとこに解凍
□DB接続情報を設定
redmine/config/database.yml.exampleを複製して
redmine/config/database.ymlを作成
production:
adapter: mysql2
database: redmine
host: localhost
username: username
password: ********
encoding: utf8
databaseはさっきcreateしたdb名
dbに入るためのusernameとパスを指定
□config/configuration.yml の作成
ひとまず、redmineを動かすだけなので、exampleを複製するのみとしておく
redmine/config/configuration.yml.exampleを複製して
redmine/config/configuration.yml
何もノータッチ。
□unicornを使いたい
gem install unicorn
□Gemfileに追加
gem "unicorn"
□uniconrn.rbの作成
redmine/config/unicorn.rb
下記を参照させていただきました。
さくらVPSで nginx + MySQL + Unicorn + Redmine の運用
□Gemパッケージのインストール
bundle install --without development test
□Redmineの初期設定とデータベースのテーブル作成
bundle exec rake generate_secret_token
RAILS_ENV=production bundle exec rake db:migrate
□まずは動くか確認
% bundle exec unicorn_rails -c config/unicorn.rb -E production -D -p 5001
問題なく動いた。
お試しと言ってもオプションに-Dつけてデーモンとして起動
とめたければ
ps -ef | grep unicorn | grep -v grep で親プロセスを調べて
kill -Quit プロセス番号
□nginxから呼ぶ
/usr/local/etc/nginx/ ここにいるそうな。
/usr/local/etc/nginx/nginx.conf を書き換えた
location / {
root html;
index index.html index.htm;
proxy_pass http://localhost:5001/; #追加
}
本当は、直接書き換えたりはせずに、変更して
チェックにかけてエラーを吐かないか確認して
それから上書きして
% nginx -s reload
という事情はすっとばして・・・
http://localhost:8080
でredmineが表示されることを確認。
なるほど。
前提、いろいろ入ってるよ。
なので足りないものだけしかいれてないよ。
■nginx
% brew install nginx
でするする入ったよ。
% nginx
で実行
http://localhost:8080
で確認。
うん動いたね。
他のコマンド
% nginx -s stop
% nginx -s reload
参考
% nginx -v
nginx version: nginx/1.4.2
以上
■mysql
入れてあるよ。
redmaine用のDB作っておくよ。
mysql -u username -p
mysql> create database redmine default character set utf8;
mysql> quit
はい。DBの準備完了
■redmine
サイトにいってダウンロード
http://www.redmine.org/projects/redmine/wiki/Download
今は2.5.1
好きなとこに解凍
□DB接続情報を設定
redmine/config/database.yml.exampleを複製して
redmine/config/database.ymlを作成
production:
adapter: mysql2
database: redmine
host: localhost
username: username
password: ********
encoding: utf8
databaseはさっきcreateしたdb名
dbに入るためのusernameとパスを指定
□config/configuration.yml の作成
ひとまず、redmineを動かすだけなので、exampleを複製するのみとしておく
redmine/config/configuration.yml.exampleを複製して
redmine/config/configuration.yml
何もノータッチ。
□unicornを使いたい
gem install unicorn
□Gemfileに追加
gem "unicorn"
□uniconrn.rbの作成
redmine/config/unicorn.rb
下記を参照させていただきました。
さくらVPSで nginx + MySQL + Unicorn + Redmine の運用
worker_processes 2
#working_directory /home/www/rails/charag
listen File.expand_path("tmp/unicorn.sock", ENV['RAILS_ROOT'])
pid File.expand_path("tmp/unicorn.pid", ENV['RAILS_ROOT'])
timeout 60
preload_app true # ダウンタイムをなくす
stdout_path File.expand_path("log/unicorn.stdout.log", ENV['RAILS_ROOT'])
stderr_path File.expand_path("log/unicorn.stderr.log", ENV['RAILS_ROOT'])
GC.respond_to?(:copy_on_write_friendly=) and GC.copy_on_write_friendly = true
before_fork do |server, worker|
defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
old_pid = "#{server.config[:pid]}.oldbin"
if old_pid != server.pid
begin
sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
Process.kill(sig, File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
end
end
sleep 1
end
after_fork do |server, worker|
defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
end
□Gemパッケージのインストール
bundle install --without development test
□Redmineの初期設定とデータベースのテーブル作成
bundle exec rake generate_secret_token
RAILS_ENV=production bundle exec rake db:migrate
□まずは動くか確認
% bundle exec unicorn_rails -c config/unicorn.rb -E production -D -p 5001
問題なく動いた。
お試しと言ってもオプションに-Dつけてデーモンとして起動
とめたければ
ps -ef | grep unicorn | grep -v grep で親プロセスを調べて
kill -Quit プロセス番号
□nginxから呼ぶ
/usr/local/etc/nginx/ ここにいるそうな。
/usr/local/etc/nginx/nginx.conf を書き換えた
location / {
root html;
index index.html index.htm;
proxy_pass http://localhost:5001/; #追加
}
本当は、直接書き換えたりはせずに、変更して
チェックにかけてエラーを吐かないか確認して
それから上書きして
% nginx -s reload
という事情はすっとばして・・・
http://localhost:8080
でredmineが表示されることを確認。
なるほど。
2013年11月30日土曜日
Nunitで書くまでの流れ
1.Nunitを入手する
https://launchpad.net/nunitv2
現在は、2.6.3
Nunit-2.6.3.msi をダウンロード。
インストール実行
2.Nunitの設定を変更
Nunitを起動する。
メニューバー⇒Tools⇒Settings...
IDE SupportのVisual Studioをクリック
Enable Visual Studio Supportにチェックをつける(Expressでも)
3.クラスとテストを結びつける
テスト対象のクラスを作成
テストクラスを作成
[テストクラス側]
nunitを認知させる
⇒参照設定の .NET タブを選択 nunit.framework を追加
テスト対象を認知させる
⇒参照設定のプロジェクトからテスト対象のクラスを選択
[テスト対象クラス側]
テストクラスを認知させる
Properties⇒AssemblyInfo.cs
[assembly: InternalsVisibleTo("テストクラス名")]
4.テストを書く
テストクラスの前に[TestFixture]を書く。
using NUnit.Framework;
していないと破線でそんなの知らんとおこるので、[TestFixture]上でCtrl+. でuse NUnit.Frameworkを表示
[Test]
テストメソッドの前につける
[TestCase]
テストメソッドの前に引数の値をリスト化して並べる
メソッド
Assert.True(期待値 == 実際の値, [メッセージ]);
Assert.AreEqual(期待値, 実際の値);
Assert.IsNull(実際の値);
Assert.IsEmpty(実際の値)
Assert.IsInstanceOfType(期待値, 実際の値);
Assert.IsAssignableFrom(期待値, 実際の値);
http://www.nunit.org/index.php?p=classicModel&r=2.6.3
5.テストしてみる
・ソースをビルドする
・Nunitを立ち上げ、dllを読み込む
・Unitで保存をしておく(設定の保存)
・Runで実行
サイクルを回す
以上、度忘れした時ようのためのエッセンシャル版まとめ。
参考
http://qiita.com/rohinomiya/items/47f09523f1b9dfa015b1
http://codezine.jp/article/detail/6518
https://launchpad.net/nunitv2
現在は、2.6.3
Nunit-2.6.3.msi をダウンロード。
インストール実行
2.Nunitの設定を変更
Nunitを起動する。
メニューバー⇒Tools⇒Settings...
IDE SupportのVisual Studioをクリック
Enable Visual Studio Supportにチェックをつける(Expressでも)
3.クラスとテストを結びつける
テスト対象のクラスを作成
テストクラスを作成
[テストクラス側]
nunitを認知させる
⇒参照設定の .NET タブを選択 nunit.framework を追加
テスト対象を認知させる
⇒参照設定のプロジェクトからテスト対象のクラスを選択
[テスト対象クラス側]
テストクラスを認知させる
Properties⇒AssemblyInfo.cs
[assembly: InternalsVisibleTo("テストクラス名")]
4.テストを書く
テストクラスの前に[TestFixture]を書く。
using NUnit.Framework;
していないと破線でそんなの知らんとおこるので、[TestFixture]上でCtrl+. でuse NUnit.Frameworkを表示
[Test]
テストメソッドの前につける
[TestCase]
テストメソッドの前に引数の値をリスト化して並べる
メソッド
Assert.True(期待値 == 実際の値, [メッセージ]);
Assert.AreEqual(期待値, 実際の値);
Assert.IsNull(実際の値);
Assert.IsEmpty(実際の値)
Assert.IsInstanceOfType(期待値, 実際の値);
Assert.IsAssignableFrom(期待値, 実際の値);
http://www.nunit.org/index.php?p=classicModel&r=2.6.3
5.テストしてみる
・ソースをビルドする
・Nunitを立ち上げ、dllを読み込む
・Unitで保存をしておく(設定の保存)
・Runで実行
サイクルを回す
以上、度忘れした時ようのためのエッセンシャル版まとめ。
参考
http://qiita.com/rohinomiya/items/47f09523f1b9dfa015b1
http://codezine.jp/article/detail/6518
登録:
投稿 (Atom)