2014年6月12日 星期四

[Synology] Crontab settings

於Synology DS211j 中增加例行工作

vi /etc/crontab

#minute hour    mday    month   wday    who     command
17      8       *       *       2,5     root    /usr/bin/php -n -d safe_mode_exec_dir='' /usr/syno/bin/autoupdate.php
14      5       *       *       2,5     root    /usr/syno/bin/synopkg chkupgradepkg
0       0       *       *       3       root    /var/packages/AntiVirus/target/bin/synoavscan --all
0       3       *       *       *       root    /usr/syno/bin/syno_poweroff_feasible_check

修改後,儲存離開,並執行下列指令

synoservice -restart crond

2014年6月10日 星期二

[C#] Windows Service Code Debug method

C# service Debug 方法 原始出處

個人採用方法三

只需加一些程式碼判斷與獨立使用即可!


在主要Service程式中獨立的 Start 與 Stop
public void Start(string[] args)
{
    this.OnStart(args);
}

public void Stop()
{
    this.OnStop();
}  

Program.cs中需新增的判斷
 if (Environment.UserInteractive)
 {
     Service1 s = new Service1();
     s.Start(null);
     Console.WriteLine("服務已啟動,請按下 Enter 鍵關閉服務...");
    // 必須要透過 Console.ReadLine(); 先停止程式執行
    // 因為 Windows Service 大多是利用多 Thread 或 Timer 執行長時間的工作
    // 所以雖然主執行緒停止執行了,但服務中的執行緒已經在運行了!
    Console.ReadLine();
    s.Stop();

    Console.WriteLine("服務已關閉");
 }
 else
{
   //原有程式碼
}

最後在專案的property裡設置輸出類型(Output Type),選擇 
Console Application

Google Finance API (目前已停止更新,終止服務時間未定)

Google Finance API
兩種方式,第一種較詳細
http://www.google.com/finance/info?infotype=infoquoteall&q=2311
http://finance.google.com/finance/info?client=ig&q=TPE:2311

q=後面接股票代碼,格式可以為
q=TPE:2311
q=2311

{
"id": "674465"
,"t" : "2330"                               股票代號
,"e" : "TPE"
,"l" : "122.50"
,"l_fix" : "122.50"
,"l_cur" : "NT$122.50"             成交價格
,"s": "0"
,"ltt":"1:30PM GMT+8"            時間
,"lt" : "Jun 6, 1:30PM GMT+8"
,"lt_dts" : "2014-06-06T13:30:08Z"
,"c" : "-0.50"                             漲跌
,"c_fix" : "-0.50"
,"cp" : "-0.41"                           漲幅
,"cp_fix" : "-0.41"
,"ccol" : "chr"
,"pcls_fix" : "123"                     昨收
,"eo" : ""
,"delay": ""
,"op" : "123.50"                       開盤價
,"hi" : "123.50"                        最高
,"lo" : "122.00"                        最低
,"vo" : "19.28M"
,"avvo" : ""
,"hi52" : "124.00"
,"lo52" : "92.90"
,"mc" : "3.18T"
,"pe" : "16.17"
,"fwpe" : ""
,"beta" : ""
,"eps" : "7.58"
,"shares" : "25.93B"
,"inst_own" : ""
,"name" : "Taiwan Semiconductor Mfg. Co. Ltd."  公司名稱
,"type" : "Company"
}


原始出處

[PHP] Multi-Dimension array sorting Method

Multi-Dimension array sorting Method,多微陣列排序方法 (網路上找到的)

function aasort (&$array, $key) {
    $sorter=array();
    $ret=array();
    reset($array);
    foreach ($array as $ii => $va) {
        $sorter[$ii]=$va[$key];
    }
    asort($sorter);
    foreach ($sorter as $ii => $va) {
        $ret[$ii]=$array[$ii];
    }
    $array=$ret;
}

aasort($your_array,"order");

[PHP] Array to File (File back to Array)

PHP中將Array寫入檔案,以便日後讀出的方法

寫入檔案前,需先做serialize的處理
$string = serialize($arr);
file_put_contents('File.txt', $string);

讀出檔案後,需做unserialize的處理
$str = file_get_contents('serialtest.txt');
$arr = unserialize($str);

[Synology] PHP exec disable

於Synology裡,在PHP中使用exec時,碰到 exec()無法使用的情況,需依照下列步驟處理。

修改下列檔案
/usr/syno/etc/php.ini
/usr/syno/etc/php/user-setting.ini

將下面這行設定
safe_mode_exec_dir = /usr/syno/bin
修改為
safe_mode_exec_dir =  

Apache重啟
/usr/syno/etc/rc.d/S97apache-user.sh restart 


p.s. 我使用的是Synology DS211j 機器 - DSM 4.3的版本

搜尋此網誌