.Net分類文章 顯示方式:簡文 | 列表

September 17,2009

Upgrade Mono to 2.4.2.3 in Ubuntu Jaunty

網路上能看到的,多半都是自己編譯 tarball...

  1. 下載 mono in karmic 頁面 File 指示的三個檔案,先解開 mono_2.4.2.3+dfsg.orig.tar.gz,然後切到解開後的目錄下,打上 patch: cat mono_2.4.2.3+dfsg-1.diff.gz | gunzip | patch -p1,再用 chmod +x 幫 debian/rules 加上可執行的屬性。
  2. 安裝必要的套件: sudo apt-get install debhelper dpkg-dev libglib2.0-dev bison libtool dpatch libxml-dom-perl libxslt1-dev dc, lsb-release, libx11-dev libxt-dev zlib1g-dev autoconf automake
  3. 打開 debian/shlibs.local,把 libsqlite3 後面的 3.6.13 改為 3.6.10,因為 9.04 的 sqlite 是 3.6.10 版。
  4. 切到 mono 下,開始 build: cd mono;dpkg-buildpackage
  5. 把打包好的 deb 作成 local repository: 假設你把這些 deb 都放到 /opt/mono_debs 下,然後建立 Packages.gz: cd /opt/mono_debs && dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz。
  6. 新增 apt repository:在 /etc/apt/sources.list.d/ 下新增一個 mono.list,裡面放:
    deb file:///opt/mono_debs ./
    接下來就可以用 apt-get update、apt-get upgrade 來更新了。


理論上,這樣就可以更新了,但是事實上,因為 dependency 的關係,apt 會試圖安裝舊的 2.0.1 的 deb 來滿足相依性而導致應用程式有問題。
最好,也循上述的方法,把相關的基底 gtk-sharp2、xsp、gecko-sharp、mono-addins...等套件也重新 build 一次,這樣出現問題的情況應該會減少許多。

我個人建議,要用最新的 mono 還是衝 Karmic (9.10) 吧,這樣會省事很多。

Posted by elleryq at 樂多Roodo!14:54回應(0)引用(0)
標籤:Ubuntu,mono

July 27,2009

WebDev.WebServer.exe

朋友傳給我幾個 ASP.Net 網頁,是用 3.0/3.5 寫的,懶得用 VWD 2008 開起來看,所以就偷懶用 WebDev.WebServer.exe 來跑,可是卻無法跑起來,會有找不到 System.Linq 的錯誤。原本以為 3.0/3.5 有另一個 WebDev.WebServer.exe,但卻遍尋不著,最後還是用 VWD 2008 開了,當然也能正常執行了。不過我就好奇了,所以用 ProcessExplorer 查了一下,發現我沒錯,的確是用 WebDev.WebServer.exe 執行。再仔細想了一下,才想到,可能是 web.config 裡有鬼,朋友傳給我的檔案裡沒有 web.config,直接執行 WebDev.WebServer.exe ,會使用 .Net 2.0 預設的 web.config。但用 VWD 2008 開過以後,補上了 web.config,裡面有這麼幾行:
<system.web>
<assemblies>
	<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
	<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
	<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
	<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</system.web>
一切真相大白,原來是補上了 3.0/3.5 所需的 Assembly,讓 WebDev.WebServer.exe 在跑 3.0/3.5 的 ASP.Net 網頁時沒有問題。

Posted by elleryq at 樂多Roodo!17:13回應(0)引用(0)
標籤:.net,asp.net

May 27,2009

Mono rpms for CentOS/RHEL 4.x

雖然Mono官方不再提供 CentOS/RHEL 4.x 的 rpm 了,你還是可以自己重新 build。
在我看過 spec 檔案以後,我發現 Mono 開發團隊已經有加上對 Linux 發行套件的判斷,也就是說其實你可以直接下載 source rpm,安裝必要的函式庫之後,執行 rpmbuild --rebuild xxx.src.rpm 來 build 出 rpm。

source rpms 放在 這裡

Posted by elleryq at 樂多Roodo!23:50回應(0)引用(0)
標籤:linux,mono

May 13,2009

如何在 .Net 調用Yahoo!搜索 斷章取義 API

無心工作,剛好又看到有人問怎麼用,所以就牛刀小試一下。基本上用 WebClient 就可以搞定:
//
// Yahoo!搜尋『斷章取義』API http://tw.developer.yahoo.com/cas/
// Yahoo!搜尋『斷章取義』API 技術文件 http://tw.developer.yahoo.com/cas/api.php
//
using System;
using System.IO;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.Text;
using System.Net;

namespace Yahoo
{
    public class CAS
    {
        private string _GetString( byte[] bytes )
        {
            return Encoding.UTF8.GetString(bytes);
        }

        private WebClient GetWebClient()
        {
            WebClient client = new WebClient();
            // client.Proxy = new WebProxy("localhost", 8000);
            client.Encoding = Encoding.UTF8;
            return client;
        }

        private NameValueCollection GetParameters()
        {
            NameValueCollection data = new NameValueCollection();

            // TODO: Place your appid here.
            data.Add("appid", "APgdNPnV34E7WQlhpBYaQvaRWPjwvd8exe094Q_r_7GWEOBFh9UDQY6vqNgZVwhc");
            return data;
        }

        public string WordSegmentation(string content)
        {
            NameValueCollection data = GetParameters();
            data.Add("content", content);

            WebClient client = GetWebClient();
            byte[] responseArray = client.UploadValues("http://asia.search.yahooapis.com/cas/v1/ws", "POST", data);
            return _GetString(responseArray);
        }

        public string Authenticate()
        {
            NameValueCollection data = GetParameters();

            WebClient client = GetWebClient();
            byte[] responseArray = client.UploadValues("http://asia.search.yahooapis.com/cas/v1/AuthBootUp.php", "POST", data);
            return _GetString(responseArray);
        }

        public string KeywordExtraction( string content, int threshold, int maxnum )
        {
            NameValueCollection data = GetParameters();
            data.Add("content", content);
            data.Add("threshold", threshold.ToString());
            data.Add("maxnum", maxnum.ToString());

            WebClient client = GetWebClient();
            byte[] responseArray = client.UploadValues("http://asia.search.yahooapis.com/cas/v1/ke", "POST", data);
            return _GetString(responseArray);
        }

        public static void Main() 
        {
            Yahoo.CAS cas = new Yahoo.CAS();

            // 如果你重新申請 appid 的話,要先作 Authenticate
            // Console.WriteLine( cas.Authenticate() );
            Console.WriteLine( cas.WordSegmentation( "your_text" ));
            Console.WriteLine( cas.KeywordExtraction( "your_text", 30, 10));

            // 得到的字串是 XML,要轉為 DataSet 的話,可以這樣作
            /*
            string text = cas.WordSegmentation( "your_text" );
            TextReader stringReader = new StringReader(text);
            DataSet dataSet1 = new DataSet();
            dataSet1.ReadXml(stringReader);
            // 轉好以後應會有兩個 DataTable,資料都在第二個 Table 裡,也就是 dataSet1.Tables[1]
            */
        }
    }
}

Posted by elleryq at 樂多Roodo!13:37回應(0)引用(0)
標籤:.net,c#

September 5,2008

列出 log4net 設定裡所有的 repository 跟 appender

Debug 用的,主要是看自己的 log4net 設定對不對。
StringBuilder sb = new StringBuilder();
ILoggerRepository[] repos = LogManager.GetAllRepositories();
foreach( ILoggerRepository repo in repos )
{
	sb.AppendLine( "=====" );
	sb.AppendLine( string.Format( "{0} - configured={1}", repo.Name, repo.Configured.ToString() );
	sb.AppendLine( "Appenders:" );
	foreach( IAppender appender in repo.GetAppenders() )
	{
		sb.AppendLine( string.Format( "\t{0}", appender.Name ) );
	}
}
sb.AppendLine( "=====" );
Console.WriteLine( sb.ToString() );

Posted by elleryq at 樂多Roodo!16:27回應(0)引用(0)

August 25,2008

debuan/ubuntu nant-0.85 的 SMP bug

最近在 Ubuntu 下用 NAnt 時,有 50% 的機率會遇到類似這樣的錯誤:
The current runtime framework 'mono-2.0' is not correctly configured in the NAnt configuration file.
    Function call failed.
Expression: ${path::combine(prefix, 'lib/mono/1.0')}
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        Illegal characters in path
Parameter name: path1
找了好久,都不知道原因所在,因為有時候是正常執行的。去Google試了好幾個關鍵字,都找不到解。今天用 nant "Illegal characters in path" 去找,終於找到了:#483073 - nant: race condition on SMP systems - Debian Bug report logs
裡面提供的暫時解法是利用環境變數 MONO_NO_SMP,把 SMP 關掉,再執行即可。所以只要編輯 /usr/bin/nant,在 exec 之前加上 export MONO_NO_SMP=1 即可。

Posted by elleryq at 樂多Roodo!14:53回應(0)引用(0)

August 22,2008

最近用 MySql Connector/Net 的幾個心得

  1. 連線字串加上 charset=utf8,如此一來,完全不用更改 MySQL 伺服器設定,只要確定建 database/table 時有指定 utf-8 編碼即可。
  2. SQL 參數在使用 @ 時,若碰到問題,不妨改用 ? 試試。我的確碰到這問題,它卡了我兩、三天,而且改用 ? 也解決了。忘了在哪兒看到,剛好有提到這點,真的是幸好我有看到...
  3. MySQL 有提供 MySqlHelper 類別,省掉寫 Helper 的麻煩...
  4. MySQLConnector/Net下載網站上沒有給 Linux 的版本,事實上,是通用的,你可以直接拿給Mono用,不需要作任何改動。


Posted by elleryq at 樂多Roodo!9:51回應(0)引用(0)

August 8,2008

.NET framework essential Chapter 7/8-ASP.Net/Windows form

各自只有一個章節,不過作者很簡明扼要地把該介紹的東西都介紹了。

ASP.Net 除了講 HtmlControl、WebControl 以外,還介紹了 Directive、Session 設定等等。
Windows form 則是簡單的介紹如何開始、Layout 的配置,以及比較容易讓人混淆的 MDI Form。

這本書真的很不錯,講的都很基本,看完對 .NET 會有一定程度的了解,不至於在茫茫大海似的類別庫裡淹死。

Posted by elleryq at 樂多Roodo!9:51回應(0)引用(0)

August 7,2008

App_Offline.htm

今天 Trace Mono System.Web.HttpRuntime 時看到的,如果在你 ASP.Net 2.0 網站目錄下放置一個 app_offline.htm 時,不管你瀏覽什麼網頁,都只會看到 app_offline.htm 的內容。

詳情可以參考 ScottGu 大 的文章:App_Offline.htm

很鳥的是,.NET Documentation 裡完全沒提到這個。

Posted by elleryq at 樂多Roodo!14:57回應(2)引用(0)

August 5,2008

Mono 與音訊、視訊

mplayer 的 -input 可以指定 file,man 裡面說明了你可以給一個 FIFO 的檔案。
藉著這個,於是就可以寫程式來控制 mplayer 來播放影片或是音樂。
你可以參考致遠管理學院資工系專題研究計畫研究成果報告計畫: Linux C# 設計 ...

你還可以使用 GStreamer#Mono team 的人已經幫你將 gstreamer 函式庫包裝為 GStreamer#,因此使用 GStreamer# 也可以進行播放影片和音樂,最好的例子是 Banshee
不過這只適用於 Linux。

Posted by elleryq at 樂多Roodo!17:49回應(0)引用(0)
 [1]  [2]  [3]  [4]  [5]  [6]  [7]  [8]  [9]  [10]  [下10頁]  [最終頁]