更改命名空間的做法網路上很多教學
這篇記錄更改命名空間後編譯不過的問題
改變命名空間後
要在solution點右鍵選property
設定debug地方只勾選要編譯成DLL的專案
才會編譯成功
寫程式就像學音樂一樣,只看樂譜不動手永遠無法演奏出美妙旋律。只演奏一遍也不可能立刻成為音樂家。 這部落格紀錄我的學習筆記,各位看倌若找不到需要的資料請見諒~~~ This blog records my study about Computer Science.
總網頁瀏覽量
2013年12月20日 星期五
2013年10月30日 星期三
C# 序列化 反序列化binaryformatter
序列化目前就筆者所知有三種
一種序列化為binary型式
一種序列化為xml型式
另一種序列化為json型式
其中json型式沒有支援輸出檔案,要自己做
本篇用binaryformat序列化法
[Serializable]
class MessageEvent: ISerializable
{
public MessageEvent(SerializationInfo info, StreamingContext context) {
message= (string)info.GetValue("message", typeof(string));
timestamp = (long)info.GetValue("timestamp", typeof(long));//typeof型態要符合變數型態,否則會報TargetInvocationException
property = (string)info.GetValue("property", typeof(string));
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("label",variable);
info.AddValue("label",variable);
info.AddValue("label",variable);
}
}
序列化:
MessageEvent mesEvent= new MessageEvent("hello earth",100L,"new");
string FILE_DIRECTORY = "D:\\SerializeFile\\";
DateTime saveNow = DateTime.Now;
String fileTimestamp = saveNow.ToString(("yyyyMMddHHmmssfff"));
BinaryFormatter serializer = new BinaryFormatter();
FileStream file = new FileStream(FILE_DIRECTORY+fileTimestamp+".txt", FileMode.Create);
serializer.Serialize(file, mesEvent);
file.Close();
public static void DeserializeFile() {
while (true)
{
string[] filesnames = Directory.GetFiles(FILE_DIRECTORY);
foreach (string filename in filesnames)
{
if(File.Exists(filename)){
MessageEvent resultMesEvent = null;
FileStream file = null;
try
{
BinaryFormatter serializer = new BinaryFormatter();
file = new FileStream(filename,FileMode.Open);
resultMesEvent = (MessageEvent)serializer.Deserialize(file);
Console.WriteLine("Serialize Success");
}
catch (TargetInvocationException ex) {
Console.WriteLine("please check serialized obj construct");
}
catch (System.IO.IOException ioe)
{
Console.WriteLine(ioe);
}
finally {
file.Close();
File.Delete(filename);//file.Close之後才delete
}
}
}
}
}
一種序列化為binary型式
一種序列化為xml型式
另一種序列化為json型式
其中json型式沒有支援輸出檔案,要自己做
本篇用binaryformat序列化法
[Serializable]
class MessageEvent: ISerializable
{
public MessageEvent(SerializationInfo info, StreamingContext context) {
message= (string)info.GetValue("message", typeof(string));
timestamp = (long)info.GetValue("timestamp", typeof(long));//typeof型態要符合變數型態,否則會報TargetInvocationException
property = (string)info.GetValue("property", typeof(string));
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("label",variable);
info.AddValue("label",variable);
info.AddValue("label",variable);
}
}
序列化:
MessageEvent mesEvent= new MessageEvent("hello earth",100L,"new");
string FILE_DIRECTORY = "D:\\SerializeFile\\";
DateTime saveNow = DateTime.Now;
String fileTimestamp = saveNow.ToString(("yyyyMMddHHmmssfff"));
BinaryFormatter serializer = new BinaryFormatter();
FileStream file = new FileStream(FILE_DIRECTORY+fileTimestamp+".txt", FileMode.Create);
serializer.Serialize(file, mesEvent);
file.Close();
反序列化:
public static void DeserializeFile() {
while (true)
{
string[] filesnames = Directory.GetFiles(FILE_DIRECTORY);
foreach (string filename in filesnames)
{
if(File.Exists(filename)){
MessageEvent resultMesEvent = null;
FileStream file = null;
try
{
BinaryFormatter serializer = new BinaryFormatter();
file = new FileStream(filename,FileMode.Open);
resultMesEvent = (MessageEvent)serializer.Deserialize(file);
Console.WriteLine("Serialize Success");
}
catch (TargetInvocationException ex) {
Console.WriteLine("please check serialized obj construct");
}
catch (System.IO.IOException ioe)
{
Console.WriteLine(ioe);
}
finally {
file.Close();
File.Delete(filename);//file.Close之後才delete
}
}
}
}
}
C# 列印日期(顯示毫秒)
DateTime saveNow = DateTime.Now;
System.Console.WriteLine("step 1: " + saveNow.ToString("yyyy/MM/dd tt hh:mm:ss.fffff"));
String str = saveNow.ToString(("yyyyMMddHHmmssfff"));
System.Console.WriteLine("step 1: " + saveNow.ToString("yyyy/MM/dd tt hh:mm:ss.fffff"));
String str = saveNow.ToString(("yyyyMMddHHmmssfff"));
2013年10月24日 星期四
C# log4net用法
http://luckystar1216.pixnet.net/blog/post/13159723-%E4%BD%BF%E7%94%A8log4net%E7%B4%80%E9%8C%84%E7%A8%8B%E5%BC%8F%E5%9F%B7%E8%A1%8C%E9%81%8E%E7%A8%8B%E7%9A%84log(for-c%23)
log4net需要靠.xml配置來指定Log格式
log要寫入的路徑
別人已經寫得很詳盡
貼個網址讓自己方便查閱
log4net需要靠.xml配置來指定Log格式
log要寫入的路徑
別人已經寫得很詳盡
貼個網址讓自己方便查閱
2013年10月14日 星期一
Run Flume with Eclipse on Windows
本文是在windows用eclipse啟動flume agent
1.
首先去官方網站下載
flume原始碼,我下載的是flume 1.4版
以existing maven project之姿,匯入eclipse
2.
找到flume-parent
maven編譯之,參數設定如下


6.接著會看到console一直跑下面結果,啟動成功
mvn package -DskipTests -Drat.numUnapprovedLicenses=100
1.
首先去官方網站下載
flume原始碼,我下載的是flume 1.4版
以existing maven project之姿,匯入eclipse
2.
找到flume-parent
maven編譯之,參數設定如下
4.
修改log4j.properties的設定
flume.root.logger=DEBUG,console
#flume.root.logger=INFO,LOGFILE
5.
找到flume-ng-node的Application.java
run as java application
參數設定如下
6.接著會看到console一直跑下面結果,啟動成功
mvn package -DskipTests -Drat.numUnapprovedLicenses=100
2013年10月7日 星期一
Clinet端寫入Buffer
每個put操作都是遠端程序呼叫(Remote procedure call,RPC),將資料從client端傳輸至server並返回。
如果資料傳輸速度1ms那麼表示每秒可以處理1000次往返。
採用buffer方式傳送資料可以減少電腦執行RPC
Hbase Client端預設不使用緩衝區(buffer),
啟用buffer方法如下:
table.setAutoFlush(false);
將autoflush設定為false
如此一來可以將資料寫入client端的buffer
如果要強迫將資料寫入hbase時,呼叫
void flushCommits() throws IOException
刷新buffer兩種方式:
1.Explict flush(明確刷新):
直接在程式中呼叫flushCommets()
2.Implict flush(隱含刷新)
當呼叫put()或者setWriteBufferSize()會觸發flushCommits()
HTable的close() method也會觸發刷新
Configuration conf = HBaseConfiguration.create();
HBaseHelper help = HBaseHelper.getHelper(conf);
help.dropTable("usertable");
help.createTable("usertable", "cf1","cf2","cf3");
HTable table = new HTable(conf,"usertable");
System.out.println("Auto Flush:"+table.isAutoFlush());
table.setAutoFlush(false);
KeyValue kv = new KeyValue(Bytes.toBytes("RK1"),Bytes.toBytes("cf1"),Bytes.toBytes("qual"),Bytes.toBytes("value"));
Put put1 = new Put(Bytes.toBytes("RK1"));
put1.add(kv);
table.put(put1);
Put put2 =new Put(Bytes.toBytes("RK2"));
put2.add(Bytes.toBytes("cf1"),Bytes.toBytes("quali1"),Bytes.toBytes("val2"));
table.put(put2);
Get get =new Get(Bytes.toBytes("RK1"));
Result result = table.get(get);
System.out.println("FirstResult"+result);
table.flushCommits();
Result res2 =table.get(get);
System.out.println(res2);
table.close();
注意客戶端程式不可以中途中斷
否則緩衝區的資料可不會自己跑去Hbase
如果資料傳輸速度1ms那麼表示每秒可以處理1000次往返。
採用buffer方式傳送資料可以減少電腦執行RPC
Hbase Client端預設不使用緩衝區(buffer),
啟用buffer方法如下:
table.setAutoFlush(false);
將autoflush設定為false
如此一來可以將資料寫入client端的buffer
如果要強迫將資料寫入hbase時,呼叫
void flushCommits() throws IOException
刷新buffer兩種方式:
1.Explict flush(明確刷新):
直接在程式中呼叫flushCommets()
2.Implict flush(隱含刷新)
當呼叫put()或者setWriteBufferSize()會觸發flushCommits()
HTable的close() method也會觸發刷新
Configuration conf = HBaseConfiguration.create();
HBaseHelper help = HBaseHelper.getHelper(conf);
help.dropTable("usertable");
help.createTable("usertable", "cf1","cf2","cf3");
HTable table = new HTable(conf,"usertable");
System.out.println("Auto Flush:"+table.isAutoFlush());
table.setAutoFlush(false);
KeyValue kv = new KeyValue(Bytes.toBytes("RK1"),Bytes.toBytes("cf1"),Bytes.toBytes("qual"),Bytes.toBytes("value"));
Put put1 = new Put(Bytes.toBytes("RK1"));
put1.add(kv);
table.put(put1);
Put put2 =new Put(Bytes.toBytes("RK2"));
put2.add(Bytes.toBytes("cf1"),Bytes.toBytes("quali1"),Bytes.toBytes("val2"));
table.put(put2);
Get get =new Get(Bytes.toBytes("RK1"));
Result result = table.get(get);
System.out.println("FirstResult"+result);
table.flushCommits();
Result res2 =table.get(get);
System.out.println(res2);
table.close();
注意客戶端程式不可以中途中斷
否則緩衝區的資料可不會自己跑去Hbase
hbase program雜記&KeyValue類別
Configuration conf =HBaseConfiguration.create();
這行程式碼背後運作是使用當前java類別路徑,加載hbase-default.xml,hbase-site.xml組態檔。
HBase可以對每個columnfamily儲存多個版本,每個版本用timestamp,並用降冪順序來儲存他們。timestamp型態是long,單位是毫秒,紀錄的時間是從1970年1月1日開始到今天的時間。
所以必須確保server擁有正確的時間且彼此是同步的
當有資料匯入Hbase,若不在Client端指定時間,則會以server時間為準。
例子:
先匯入rowkey為rk1, columnfamily1為cf1的一筆資料
put 'usertable','rk1','cf1','vlaue1'
0 row(s) in 0.2300 seconds
再匯入同樣columnfamily與rowkey的資料,value不一樣
put 'usertable','rk1','cf1','ddddd'
0 row(s) in 0.0100 seconds
ROW COLUMN+CELL
rk1 column=cf1:, timestamp=1381154563122, value=ddddd
1 row(s) in 0.0260 seconds
指定列出版本數就會列出過去曾經匯入的紀錄
scan 'usertable',{VERSIONS => 3}
ROW COLUMN+CELL
rk1 column=cf1:, timestamp=1381154563122, value=ddddd
rk1 column=cf1:, timestamp=1381154533794, value=vlaue1
1 row(s) in 0.0220 seconds
scan 'usertable',{VERSIONS => 2}
ROW COLUMN+CELL
rk1 column=cf1:, timestamp=1381154563122, value=ddddd
rk1 column=cf1:, timestamp=1381154533794, value=vlaue1
1 row(s) in 0.0230 seconds
KeyValue類別是很重要的API
Hbase Client很常用
用來包裝"資料"以及"特定儲存單元的位置",位置可以是rowkey,column family名稱,column qualifier以及timestamp,KeyValue提供大量constructor供各位使用。長相大致這樣:KeyValue(byte[] row,int offset,int rowlength);
在Hbase0.97板之後KeyValue改名為Cell
KeyValue提供大量implement Comparator的內部class。
KeyValue裡面的method可以用來比較部分已儲存的資料以及確定其類型....and so on.
這行程式碼背後運作是使用當前java類別路徑,加載hbase-default.xml,hbase-site.xml組態檔。
HBase可以對每個columnfamily儲存多個版本,每個版本用timestamp,並用降冪順序來儲存他們。timestamp型態是long,單位是毫秒,紀錄的時間是從1970年1月1日開始到今天的時間。
所以必須確保server擁有正確的時間且彼此是同步的
當有資料匯入Hbase,若不在Client端指定時間,則會以server時間為準。
例子:
先匯入rowkey為rk1, columnfamily1為cf1的一筆資料
put 'usertable','rk1','cf1','vlaue1'
0 row(s) in 0.2300 seconds
再匯入同樣columnfamily與rowkey的資料,value不一樣
put 'usertable','rk1','cf1','ddddd'
0 row(s) in 0.0100 seconds
打上scan table只會列出最新版本的資料
scan 'usertable'ROW COLUMN+CELL
rk1 column=cf1:, timestamp=1381154563122, value=ddddd
1 row(s) in 0.0260 seconds
指定列出版本數就會列出過去曾經匯入的紀錄
scan 'usertable',{VERSIONS => 3}
ROW COLUMN+CELL
rk1 column=cf1:, timestamp=1381154563122, value=ddddd
rk1 column=cf1:, timestamp=1381154533794, value=vlaue1
1 row(s) in 0.0220 seconds
scan 'usertable',{VERSIONS => 2}
ROW COLUMN+CELL
rk1 column=cf1:, timestamp=1381154563122, value=ddddd
rk1 column=cf1:, timestamp=1381154533794, value=vlaue1
1 row(s) in 0.0230 seconds
KeyValue類別是很重要的API
Hbase Client很常用
用來包裝"資料"以及"特定儲存單元的位置",位置可以是rowkey,column family名稱,column qualifier以及timestamp,KeyValue提供大量constructor供各位使用。長相大致這樣:KeyValue(byte[] row,int offset,int rowlength);
在Hbase0.97板之後KeyValue改名為Cell
KeyValue提供大量implement Comparator的內部class。
KeyValue裡面的method可以用來比較部分已儲存的資料以及確定其類型....and so on.
訂閱:
文章 (Atom)
