ページ

2014年10月29日水曜日

SOAPをJavaで

SOAPをJavaで体験してみる。

そもそもSOAPとは・・・
XML-RPCから発展した、Webサービスの為のXMLベースのRPCプロトコルである。
ウィキペディアより
http://ja.wikipedia.org/wiki/SOAP_(%E3%83%97%E3%83%AD%E3%83%88%E3%82%B3%E3%83%AB)

様々な通信プロトコルで利用可能だが、実際は、TCP/IP, HTTP(S)で利用されている。
メッセージはheaderとbody、headerはオプショナルであり、ルーティングやセキュリティ、
トランザクション等のメタ情報を格納。bodyは主要な情報、ペイロードである。




















JavaでSOAPとなると、Apache-SOAPなるものがあるらしい。
http://www.atmarkit.co.jp/ait/articles/0103/02/news004_3.html
が、これを使かうにはアプリケーションサーバとXMLパーサがセットアップ済み
じゃないといけないらしい。。

今回は、アプリケーションサーバをTomcat、XMLパーサをXML4Jで構築。
http://homepage2.nifty.com/ann/Windows/xml/apache-soap.html

1. Tomcat管理ユーザの作成
  # useradd -s /sbin/nologin tomcat

2. Tomcatのダウンロード
  公式ページからダウンロード http://tomcat.apache.org/
  展開 & 設定
  # tar xvzf apache-tomcat-7.0.56.tar.gz
  # mv apache-tomcat-7.0.56 /usr/local
  # cd /usr/local/
  # chown -R tomcat:tomcat apache-tomcat-7.0.56/
  # ln -s apache-tomcat-7.0.56 tomcat

3. 環境変数の設定
  /etc/profileにJAVA_HOMEとCATALINA_HOMEを設定

  JAVA_HOME=/usr/java/jdk1.8.0_25
  PATH=$PATH:$JAVA_HOME/bin
  CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
  CLASSPATH=$CLASSPATH:/usr/share/java/mysql-connector-java-5.1.33-bin.jar
  CATALINA_HOME=/usr/local/tomcat
  export JAVA_HOME
  export PATH
  export CLASSPATH
  export CATALINA_HOME
 
4. 起動スクリプトの作成
  ↓参照
  http://homepage1.nifty.com/y-osumi/works/code/tomcat7/

  実際に起動してみる
  # /etc/init.d/tomcat start
  内部からはhttp://192.168.XX.XXX:8080にアクセスできたが
 
 
  外からはiptablesを設定していないので無理な模様・・・

5. iptablesの設定
  現在の状況を確認
  # iptables -L --line-number
 
  tomcatで使用するポート(8080)を許可するように設定
  # vi /etc/sysconfig/iptables
  以下の行を追加
  -A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT

 iptable再起動
 # /etc/rc.d/init.d/iptables restart

次にSOAP必要なライブラリを入手 & 配置

必要なjarファイル
・mail.jar -> http://www.oracle.com/technetwork/java/index-138643.html
・activation.jar -> http://www.oracle.com/technetwork/java/jaf11-139815.html
・soap.jar ->

soap.warを$CATALINA_HOME/webapps配下へ配置

それぞれを$CATALINA_HOME/libへ配置
所有者をtomcatに設定
# chown -R tomcat:tomcat mail.jar
# chown -R tomcat:tomcat activation.jar
Tomcat再起動!!

確認の為、http://192.168.XX.XXX:8080/soap/ に接続













無事、起動している事を確認!!

サーバー側にクラスを作る

簡単なクラスを作成
// SOAP
public class HelloSoap {
  public String say() {
    return "Hello World";
  }
}
~
コンパイルし、できたclassファイルをsoap/WEB-INF/classes配下にコピー
 # javac HelloSoap.java
 # cp -p /usr/local/tomcat/work/SOAP/HelloSoap.class .
Tomcatを再起動!!

サービスの登録

SOAPサーバにサービスを登録する。
登録内容は以下の通り。

ID : urn:HelloSoap
Methods : say
ProviderClass : HelloSoap














deploy後














クライアント側の準備

※事前に、soap.jarをCLASSPATHへ追加しておく。

// SOAPクライアント
import java.net.URL;
import org.apache.soap.rpc.*;
import org.apache.soap.Constants;
public class HelloSoapClient {
    final static String USAGE = "http://localhost:49152/soap/servlet/rpcrouter";
    public static void main(String[] args) {
        if(args.length < 1) {
            System.err.println("Usage: HelloWorldSOAPCliet " + USAGE);
            System.exit(1);
        }
        try {
            URL url = new URL(args[0]);
            // Callオブジェクトを生成
            Call call = new Call();
            // ターゲットとなるURIを指定
            call.setTargetObjectURI("urn:HelloSoap");
            // ターゲットとなるメソッドを指定
            call.setMethodName("say");
            // 直列化のスタイルを指定
            call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
            // 呼び出しを実行
            Response resp = call.invoke(url, "");
            // 戻り値を取得
            if(resp.generatedFault()) {
               System.out.println("Fault: " + resp.getFault());
            } else {
               Parameter result = resp.getReturnValue();
               System.out.println (result.getValue());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

コンパイル
# javac HelloSoapClient.java

実際の実行の前に、やりとりが見えるようにトンネル・モニタを実行します。
# java org.apache.soap.util.net.TcpTunnelGui 49152 localhost 8080

















いざ、実行!!
 # java HelloSoapClient http://localhost:49152/soap/servlet/rpcrouter

















無事、リクエストメッセージのやりとりができている事を確認しました
^^






2014年10月21日火曜日

PhoneGapを使用する 1

クロスプラットフォームで開発可能なPhoneGapを使ってみる。

・インストール
以下公式サイトに載っているようにnpmを使ってインストール。
http://phonegap.com/install/

実際にインストールしてみるも・・失敗orz
https://github.com/npm/npm/issues/2701
どうやらバージョンが古い?かも、ということで最新のNode.js / npmをインストールして
再チャレンジ!!

今度はうまくいきました^^

実際にプロジェクトを作成し、iOSアプリを作ってみる。
$ phonegap create hello-app
[phonegap] create called with the options /Users/{ユーザ名}/Documents/develop/phonegap/hello-app com.phonegap.helloworld HelloWorld
[phonegap] Customizing default config.xml file
[phonegap] created project at /Users/{ユーザ名}/Documents/develop/phonegap/hello-app
$ cd hello-app/
$ phonegap run ios
[phonegap] detecting iOS SDK environment...
[phonegap] using the local environment
[phonegap] adding the iOS platform...
[phonegap] compiling iOS...
Build settings from command line:
    ARCHS = i386
    CONFIGURATION_BUILD_DIR = /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/ios/build/emulator
    SDKROOT = iphonesimulator8.0
    VALID_ARCHS = i386

=== BUILD TARGET CordovaLib OF PROJECT CordovaLib WITH CONFIGURATION Debug ===

Check dependencies
この後もずらっとビルドされ、hello-app/platforms/ios配下にxcodeのプロジェクトが作成される。
















HelloWorld.xcodeprojをxcodeで開いて、シュミレータで確認してみる。
























ちゃんと実行できる事を確認。今度は同じアプリをAndroidで実行してみる。
Androidの場合は色々環境がなってないと怒られました・・・
環境変数にANDROID_HOMEが設定されていない、androidコマンドや、antコマンドが使えない!!など、.bash_profileにもろもろ追加して再実行。
$ phonegap build android
[phonegap] detecting Android SDK environment...
[phonegap] using the local environment
[phonegap] adding the Android platform...
Creating Cordova project for the Android platform:
Path: platforms/android
Package: com.phonegap.helloworld
Name: HelloWorld
Android target: android-19
Copying template files...
Project successfully created.
cp: no such file or directory: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/icon.png

[phonegap] compiling Android...
cp: no such file or directory: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/icon.png

Buildfile: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/build.xml

-set-mode-check:

-set-debug-files:

-check-env:
 [checkenv] Android SDK Tools Revision 23.0.2
 [checkenv] Installed at /Applications/Android Studio.app/sdk

-setup:
     [echo] Project Name: HelloWorld
  [gettype] Project Type: Application

-set-debug-mode:

-debug-obfuscation-check:

-pre-build:

-build-setup:
[getbuildtools] Using latest Build Tools: 20.0.0
     [echo] Resolving Build Target for HelloWorld...
[gettarget] Project Target:   Android 4.4.2
[gettarget] API level:        19
     [echo] ----------
     [echo] Creating output directories if needed...
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/rsObj
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/rsLibs
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-gen
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/classes
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/dexedLibs
     [echo] ----------
     [echo] Resolving Dependencies for HelloWorld...
[dependency] Library dependencies:
[dependency] 
[dependency] ------------------
[dependency] Ordered libraries:
[dependency] 
[dependency] ------------------
     [echo] ----------
     [echo] Building Libraries with 'debug'...

nodeps:

-set-mode-check:

-set-debug-files:

-check-env:
 [checkenv] Android SDK Tools Revision 23.0.2
 [checkenv] Installed at /Applications/Android Studio.app/sdk

-setup:
     [echo] Project Name: HelloWorld
  [gettype] Project Type: Android Library

-set-debug-mode:

-debug-obfuscation-check:

-pre-build:

-build-setup:
[getbuildtools] Using latest Build Tools: 20.0.0
     [echo] Resolving Build Target for HelloWorld...
[gettarget] Project Target:   Android 4.4.2
[gettarget] API level:        19
     [echo] ----------
     [echo] Creating output directories if needed...
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/res
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/libs
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/res
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/rsObj
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/rsLibs
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-gen
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/classes
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/dexedLibs
     [echo] ----------
     [echo] Resolving Dependencies for HelloWorld...
[dependency] Library dependencies:
[dependency] No Libraries
[dependency] 
[dependency] ------------------

-code-gen:
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
     [echo] Handling aidl files...
     [aidl] No AIDL files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
     [echo] ----------
     [echo] Handling Resources...
     [aapt] Generating resource IDs...
     [echo] ----------
     [echo] Handling BuildConfig class...
[buildconfig] Generating BuildConfig class.

-pre-compile:

-compile:
    [javac] Compiling 93 source files to /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/classes
    [javac] 注意:一部の入力ファイルは非推奨のAPIを使用またはオーバーライドしています。
    [javac] 注意:詳細は、-Xlint:deprecationオプションを指定して再コンパイルしてください。
     [echo] Creating library output jar file...
      [jar] Building jar: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/classes.jar

-post-compile:

-obfuscate:

-dex:
     [echo] Library project: do not convert bytecode...

-crunch:
   [crunch] Crunching PNG Files in source dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/res
   [crunch] To destination dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/res
   [crunch] Crunched 0 PNG files to update cache

-package-resources:
     [echo] Library project: do not package resources...

-package:
     [echo] Library project: do not package apk...

-post-package:

-do-debug:
     [echo] Library project: do not create apk...
[propertyfile] Creating new property file: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/build.prop
[propertyfile] Updating property file: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/build.prop
[propertyfile] Updating property file: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/build.prop
[propertyfile] Updating property file: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/build.prop

-post-build:

debug:

-code-gen:
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
     [echo] Handling aidl files...
     [aidl] No AIDL files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
     [echo] ----------
     [echo] Handling Resources...
     [aapt] Generating resource IDs...
     [echo] ----------
     [echo] Handling BuildConfig class...
[buildconfig] Generating BuildConfig class.

-pre-compile:
     [echo] Set jars path to: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/classes.jar

-compile:
    [javac] Compiling 3 source files to /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/classes

-post-compile:

-obfuscate:

-dex:
      [dex] input: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/classes
      [dex] input: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/classes.jar
      [dex] Pre-Dexing /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/classes.jar -> classes-0892cf444a5a04f0045d76451949d362.jar
      [dex] Converting compiled files and external libraries into /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/classes.dex...
       [dx] Merged dex A (7 defs/2.2KiB) with dex B (209 defs/317.1KiB). Result is 216 defs/389.0KiB. Took 0.4s

-crunch:
   [crunch] Crunching PNG Files in source dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res
   [crunch] To destination dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res
   [crunch] Processing image to cache: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res/drawable-hdpi/icon.png => /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-hdpi/icon.png
   [crunch]   (processed image to cache entry /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-hdpi/icon.png: 52% size of source)
   [crunch] Processing image to cache: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res/drawable-land-hdpi/screen.png => /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-land-hdpi/screen.png
   [crunch]   (processed image to cache entry /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-land-hdpi/screen.png: 97% size of source)
   [crunch] Processing image to cache: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res/drawable-land-ldpi/screen.png => /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-land-ldpi/screen.png
   [crunch]   (processed image to cache entry /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-land-ldpi/screen.png: 96% size of source)
   [crunch] Processing image to cache: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res/drawable-land-mdpi/screen.png => /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-land-mdpi/screen.png
   [crunch]   (processed image to cache entry /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-land-mdpi/screen.png: 97% size of source)
   [crunch] Processing image to cache: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res/drawable-land-xhdpi/screen.png => /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-land-xhdpi/screen.png
   [crunch]   (processed image to cache entry /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-land-xhdpi/screen.png: 99% size of source)
   [crunch] Processing image to cache: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res/drawable-port-hdpi/screen.png => /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-port-hdpi/screen.png
   [crunch]   (processed image to cache entry /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-port-hdpi/screen.png: 97% size of source)
   [crunch] Processing image to cache: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res/drawable-port-ldpi/screen.png => /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-port-ldpi/screen.png
   [crunch]   (processed image to cache entry /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-port-ldpi/screen.png: 97% size of source)
   [crunch] Processing image to cache: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res/drawable-port-mdpi/screen.png => /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-port-mdpi/screen.png
   [crunch]   (processed image to cache entry /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-port-mdpi/screen.png: 99% size of source)
   [crunch] Processing image to cache: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res/drawable-port-xhdpi/screen.png => /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-port-xhdpi/screen.png
   [crunch]   (processed image to cache entry /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-port-xhdpi/screen.png: 99% size of source)
   [crunch] Processing image to cache: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res/drawable/icon.png => /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable/icon.png
   [crunch]   (processed image to cache entry /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable/icon.png: 53% size of source)
   [crunch] Crunched 10 PNG files to update cache

-package-resources:
     [aapt] Creating full resource package...
     [aapt]     (skipping file '.pgbomit' due to ANDROID_AAPT_IGNORE pattern '.*')

-package:
[apkbuilder] Current build type is different than previous build: forced apkbuilder run.
[apkbuilder] Creating HelloWorld-debug-unaligned.apk and signing it with a debug key...

-post-package:

-do-debug:
 [zipalign] Running zip align on final apk...
     [echo] Debug Package: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/HelloWorld-debug.apk
[propertyfile] Creating new property file: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/build.prop
[propertyfile] Updating property file: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/build.prop
[propertyfile] Updating property file: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/build.prop
[propertyfile] Updating property file: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/build.prop

-post-build:
     [move] Moving 1 file to /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build
     [move] Moving 1 file to /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build

debug:

BUILD SUCCESSFUL
Total time: 42 seconds
Using apk: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/HelloWorld-debug-unaligned.apk
[phonegap] successfully compiled Android app
今度は無事に実行できました。

apkファイルはというと、hello-app/platforms/android/ant-build配下にあります。
















実際にAndroid端末にインストールして確認。
























ちゃんと両方で確認できました^^
Bluetoothも触れるっぽい!!
https://github.com/don/BluetoothSerial

2014年10月19日日曜日

ハッピーターンアイス

どんな味か気になってしまったので、購入。



















一口目があまじょっぱい味だったので「ん?」っとなりましたが、続けて食べると
美味しく感じるようになりました。

久しぶりに・・・ミニ四駆!!

小学校?以来にミニ四駆を作ってみた

久しぶりにミニ四駆が作りたい衝動にかられて、作ってみました。
購入したのは「ピークスパイダー」
ダッシュ四駆郎(古いorz)かとばっかし思っていたら爆走兄弟レッツ&ゴーらしい・・・





















せっかく完成したのにモーター別売りでしたorz
早く走らせたい・・・

2014年10月18日土曜日

C#お戯れ 1 - LINQ + SQLite -

LINQ + SQLite

まずは、そもそも使用しているWindows環境にどのバージョンの.NET frameworkが
インストールされているのか確認。

以下サイトを参考に確認してみる。













どうやら、

Windows 8.1 と共にインストールされる .NET Framework 4.5.1

がインストールされている模様。
次にフレームワークに合ったSQLiteをダウンロード。

今回は、「sqlite-netFx451-static-binary-x64-2013-1.zip」をダウンロードしました。

C#でサンプルアプリケーション作成

VisualStudio > 新しいプロジェクト > C# > Windowsフォームアプリケーション
で新規プロジェクト作成。

次にSQLiteを使用する為に参照の追加を行う。
プロジェクト右クリック > 参照の追加














参照タブ > ダウンロードした「System.Data.SQLite.dll」と「System.Data.SQLite.Linq.dll」を追加



















この方法でLINQ使って〜と思っていたら、O/Rマッピングができなかったので断念orz
次回以降また挑戦してみるorz。


2014年10月17日金曜日

iOSアプリ開発してみる 4 - Segumented Control -

iOS7以降でのSegumented Controlに画像表示

例えば以下の画像をそれぞれ、Segmented Controlに表示してみる。
 

Xcode上で新規グループ(Image)を作成し、それぞれの画像を登録。
Segment Controlのアトリビュートインスペクタで以下に設定
  • セグメント4つに設定
  • セグメント1 : bloackIcon.png
  • セグメント2 : redIcon.png
  • セグメント3 : yellowIcon.png
  • セグメント4 : greedIcon.png
実際に表示させてみると・・・












表示が全て青色になっているorz 色々調べてみると以下サイトを発見!!
UIKitを使いこなそう
どうやらデフォルト色で塗られている模様。 そこでSegment Controlをアウトレットとして登録し、 ソース上でイメージを設定する。
/* 画像読み込み                       */
UIImage *blackImage = [[UIImage imageNamed:@"blackIcon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *redImage = [[UIImage imageNamed:@"redIcon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *yellowImage = [[UIImage imageNamed:@"yellowIcon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *greenImage = [[UIImage imageNamed:@"greenIcon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
/* セグメントコントロールへ画像設定       */
[_colorSegment setImage:blackImage forSegmentAtIndex:0];
[_colorSegment setImage:redImage forSegmentAtIndex:1];
[_colorSegment setImage:yellowImage forSegmentAtIndex:2];
[_colorSegment setImage:greenImage forSegmentAtIndex:3];
いざ実行!!












無事表示されました^^

2014年10月13日月曜日

Atomまとめ 2 - Markdown -

パッケージ追加とMarkdownを使ってみる。

・パッケージ追加
    Hex・・・ファイルをヘキサ形式で見れる
 


















やり方としては、Packages > Hex Viewでみれる。

・Markdown記法
    今までこのブログを書く際は、直接書いていたがAtomでMarkdownで書いたものを
    使用してもいいかも。
    参考サイト http://kojika17.com/2013/01/starting-markdown.html


 

















コード等を書く際に便利なpreタグを挿入してくれるのが良い^^

↓Markdownで書かれたものをコピーしてみた

Markdown

> code

a

  • a
  • b
  • c
    1. d
    2. e
a
b

b


次からこれを使って書くばい^^

2014年10月12日日曜日

Dockerをさわってみる 2 - Docker1.0 -

2014.06.09にDocker1.0がリリースされて色々変わっている件

いままでDockerと読んでいた本体のソフトウェアは「Docker Engine」に名称が変更になったらしい。新しいサービスとしてDocker Hubを発表。Docker indexは「Docker Hub Registory」 へ。。。

↓イメージ














詳しくはWEB で・・・
http://www.atmarkit.co.jp/ait/articles/1406/10/news031.html

今回は、コンテナ作成し色々カスタマイズしてみる。

・コンテナ作成
[root@localhost ~]# docker run -it --name ubuntu02 ubuntu /bin/bash
root@a3cccf6e59be:/# apt-get install -y nginx
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package nginx
root@a3cccf6e59be:/# exit

コンテナ作成は上手くいったが、パッケージインストールができない!!
よく分からないのでとりあえずapt-get update !!
すると、、、上手く行きましたorz

control + d でコンテナ終了させる。
docker ps -a で実行させた全てのコンテナ一覧を表示。
[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                       PORTS               NAMES
367e49fa4dc0        ubuntu:14.04        /bin/bash           3 minutes ago       Exited (0) 13 seconds ago                        ubuntu03             
a3cccf6e59be        ubuntu:14.04        /bin/bash           8 minutes ago       Exited (100) 7 minutes ago                       ubuntu02             
2510a5487997        ubuntu:14.04        /bin/bash           14 minutes ago      Exited (0) 9 minutes ago                         ubuntu01             
879b7468bb85        ubuntu:14.04        echo Hello          28 hours ago        Exited (0) 28 hours ago                          condescending_pike   
[root@localhost ~]# 

nginxをインストールしたubuntu03を元に新規イメージを作成してみる。
[root@localhost ~]# docker commit ubuntu03 fuji/nginx
fd64b49b28caf96275bbaccbd6e9bed47d76331d7ab64a851474bf3f44e246e5
[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
fuji/nginx          latest              fd64b49b28ca        8 seconds ago       231.2 MB
ubuntu              14.10               b8d67033ed07        32 hours ago        242.4 MB
ubuntu              utopic              b8d67033ed07        32 hours ago        242.4 MB
ubuntu              14.04.1             1357f421be38        32 hours ago        192.7 MB
ubuntu              latest              1357f421be38        32 hours ago        192.7 MB
ubuntu              trusty              1357f421be38        32 hours ago        192.7 MB
ubuntu              14.04               1357f421be38        32 hours ago        192.7 MB
ubuntu              12.04               2bed76595591        32 hours ago        114.6 MB
ubuntu              12.04.5             2bed76595591        32 hours ago        114.6 MB
ubuntu              precise             2bed76595591        32 hours ago        114.6 MB
[root@localhost ~]# 

ちゃんと「fuji/nginx」のイメージが作成されている^^

・バックグラウンドで実行
先ほどのfuji/nginxイメージを元にバックグラウンドで実行するコンテナを作成してみる。
[root@localhost ~]# docker run -d -p 80:80 --name nginx1 fuji/nginx /usr/sbin/nginx -g 'daemon off;' -c /etc/nginx/nginx.conf
d500411c0af2d2c6a07cc7882e043fb641a2035f24090033e588d9c17a09c24a
2014/10/12 00:11:36 Error response from daemon: Cannot start container d500411c0af2d2c6a07cc7882e043fb641a2035f24090033e588d9c17a09c24a: listen tcp 0.0.0.0:80: bind: address already in use

ん!?何かエラーが・・・
80ポートがかぶっているorzホストのCentOSで既に80ポートをapacheさんが使用しているからか・・・
とりあえずポート指定無しで実行!!
[root@localhost ~]# docker run -d --name nginx2 fuji/nginx /usr/sbin/nginx -g 'daemon off;' -c /etc/nginx/nginx.conf
960de36b0911a2ccad45773aae6938bf542a3aa657cd922177c783e217bb56c0
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS               NAMES
960de36b0911        fuji/nginx:latest   /usr/sbin/nginx -g '   4 seconds ago       Up 3 seconds                            nginx2              
[root@localhost ~]# 
起動はでけた^^;

こんどはホスト側のapacheを停止させて実行してみる。
[root@localhost ~]# service httpd stop
httpd を停止中:                                            [  OK  ]

バックグラウンドで実行中のコンテナを停止
[root@localhost ~]# docker stop nginx2
nginx2
[root@localhost ~]# 

ポートを指定して実行
[root@localhost ~]# docker run -d -p 80:80 --name nginx3 fuji/nginx /usr/sbin/nginx -g 'daemon off;' -c /etc/nginx/nginx.conf
8f6f070d392d53ca71b4ac0ba53d6032cd2dd96a685beb621231952bf257f553
[root@localhost ~]# curl localhost:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@localhost ~]# 

できてる^^
ブラウザでも確認














コンテナを停止させ、再度起動してみる。
バックグラウンドでのコンテナを停止。
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                NAMES
8f6f070d392d        fuji/nginx:latest   /usr/sbin/nginx -g '   2 minutes ago       Up 2 minutes        0.0.0.0:80->80/tcp   nginx3              
[root@localhost ~]# docker stop nginx3
nginx3
[root@localhost ~]# !curl
curl localhost:80
curl: (7) couldn't connect to host
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

再度実行
[root@localhost ~]# docker start nginx3
nginx3

確認
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                NAMES
8f6f070d392d        fuji/nginx:latest   /usr/sbin/nginx -g '   5 minutes ago       Up 19 seconds       0.0.0.0:80->80/tcp   nginx3              
[root@localhost ~]# 

ちゃんと実行されている^^
[root@localhost ~]# !curl
curl localhost:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

次回はDockerfileをお勉強^^