忍者ブログ

2007/03/04開始。ソフトウェア管理やDelerer SEの作者であるおにぎりくんの試行錯誤の記録です。
2024
前の月へ 04 : 12345678910111213141516171819202122232425262728293031 : 06 次の月へ
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

SurfaceRT上でC#プログラムを動かす

環境

ターゲット:SurfaceRT (Windows RT 8.0、jailbroken)
ホスト:Windows7 + VisualStudio Express 2012 for Windows Desktop

やったこと

自作コンソールアプリを、脱獄済みの初代Surface上で動かす。

手順

  1. VisualStudio Express 2012 for Windows Desktopを起動し、C#のコンソールアプリケーションプロジェクトを作成する
  2. プログラムを書く
  3. 動作確認する
  4. Release / Any CPUでビルドする
  5. binディレクトリにできたexeファイルをSurfaceRTに転送する
  6. exeファイルを実行する

結果

exeファイルを実行できた
作成したプログラム
using System;

namespace ConsoleApplication2
{
    class Program
    {
        public static CommandShell MainCommandShell = new CommandShell();
        static void Main(string[] args)
        {
            Console.WriteLine("=== sample program ===");
            MainCommandShell.loop();
        }
    }

    /// 
    /// ユーザーからコマンド入力を受け、処理を実行するシェル。
    /// loopメソッドで開始し、exitメソッドで終了する。
    /// 
    class CommandShell
    {
        /// 
        /// 実行可能なコマンドの配列
        /// 
        private Command[] Commands = { new HelpCommand(), new ExitCommand() };

        /// 
        /// ループを終了するかどうか
        /// 
        private Boolean running = false;

        /// 
        /// シェルを開始する
        /// 
        public void loop()
        {
            running = true;
            while (running)
            {
                Console.Write("> ");
                string cmd = Console.ReadLine();
                foreach (Command command in Commands)
                {
                    if (command.process(cmd))
                        break;
                }
            }
        }
        /// 
        /// シェルを終了する
        /// 
        public void exit()
        {
            running = false;
        }
    }
    /// 
    /// シェルで実行できるコマンド
    /// 
    interface Command
    {
        Boolean process(string cmd);
    }
    /// 
    /// ヘルプコマンド
    /// 
    class HelpCommand : Command
    {
        public Boolean process(string cmd)
        {
            if (cmd.StartsWith("help"))
            {
                Console.WriteLine("help: exit");
                return true;
            }
            else
            {
                return false;
            }
        }
    }
    /// 
    /// 終了コマンド
    /// 
    class ExitCommand : Command
    {
        public Boolean process(string cmd)
        {
            if (cmd.StartsWith("exit"))
            {
                Console.WriteLine("exit");
                Program.MainCommandShell.exit();
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}

感想

簡単に動いた。
GUIアプリも書いてみたい。
C#らしいプログラムの書き方を忘れてる。命名規則?プロパティ?
PR
スポンサード・リンク
フリーソフト指向::開発日記 by LapisCactus
忍者ブログ | [PR]

今日の聖書
自己紹介
名前:
LapisCactus (おにぎりくん)
Twitter:
Mail:
onigirikun_hsp@hotmail.com
自己紹介:
ふつうのしすてむえんじにあ。
趣味で「ソフトウェア管理」や
「TextView」を作っています。
仕事でもコンピュータを触っているのに
趣味も同じという。
健康に悪いですね。
カレンダー
04 2024/05 06
S M T W T F S
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
ブログ内検索
最新CM
[03/03 kusakari]
[11/12 おにぎりくん]
[11/08 れい]
アクセス解析