protected string Serialize <TOptionsBase, TSerializer>() where TOptionsBase : ApplicationOptions, new() where TSerializer : OptionsSerializer <TOptionsBase>, new() { var serializer = new TSerializer(); string jsonText = JsonConvert.SerializeObject(this, Formatting.Indented, serializer); return(jsonText); }
public CacheDataAdapter(IObjectPool <FixedSizeBuffer> bufferPool, TSerializer serializer) { if (bufferPool == null) { throw new ArgumentNullException(nameof(bufferPool)); } this.bufferPool = bufferPool; this.serializer = serializer; }
private static void DoCallBackWithResponse <TCallback, TSerializer, TResponse>() where TCallback : ICrossAppDomainCallback <TResponse> where TSerializer : ITextSerialization, new() { TSerializer serializer = new TSerializer(); TCallback callback = CreateCallback <TCallback>(serializer); callback.Callback(); AppDomain.CurrentDomain.SetData(CrossDomainActionId.Id, serializer.ToText(callback)); }
public static T Get <T>(string configname, string table, string rowid, Func <Type, string, System.Reflection.PropertyInfo> funGetProperty) where T : new() { //实例化Socket连接 //transport = new TSocket("2.5.172.38", 30001); var transport = new TSocket(configname); //实例化一个协议对象 TProtocol tProtocol = new TBinaryProtocol(transport); byte[] tablenamebytes = Encoding.UTF8.GetBytes(table); byte[] rownamebytes = Encoding.UTF8.GetBytes(rowid); using (var client = new HBase.Thrift2.THBaseService.Client(tProtocol)) { transport.Open(); try { var rows = client.get(tablenamebytes, new HBase.Thrift2.TGet(rownamebytes)); if (rows.ColumnValues != null && rows.ColumnValues.Count > 0) { T instance = (T)System.Activator.CreateInstance(typeof(T)); var typet = typeof(T); foreach (var cv in rows.ColumnValues) { var columname = Encoding.UTF8.GetString(cv.Qualifier); var pop = funGetProperty(typet, columname); pop.SetValue(instance, TSerializer.GetObject(pop.PropertyType, cv.Value)); } return(instance); } else { return(default(T)); } } finally { transport.Close(); } } }
public static void RegisterSerializer <TType, TSerializer>() where TSerializer : ISerializerBase, new() { TSerializer t = new TSerializer(); Serializers[typeof(TType)] = t; }
static void Main(string[] args) { TSerializer.RegisterSerializer(new SelfTSerializer()); Man man = new Man(); man.Name = "李金川"; man.Sex = 1; man.Age = 30; man.Fei = new int[] { 1, 2, 3 }; man.Addr = new List <string> { "老师", "学生", "朋友" }; Thrift2ClientWarpper.Put <Man>("hbaseclient1", "test", "man", man.Name, man, (m) => { var tps = LJC.FrameWork.EntityBuf.EntityBufCore.GetTypeEntityBufType(typeof(Man)); var list = new List <KeyValuePair <string, object> >(); foreach (Tuple <LJC.FrameWork.EntityBuf.EntityBufType, bool> it in tps) { list.Add(new KeyValuePair <string, object>(it.Item1.Property.PropertyInfo.Name, it.Item1.Property.PropertyInfo.GetValue(m))); } return(list); }); Thrift2ClientWarpper.CheckAndDelete("hbaseclient1", "test", man.Name, "man", "Name", "李金川", new[] { "Sex" }); var resultljc = Thrift2ClientWarpper.Get <Man>("hbaseclient1", "test", man.Name, (t, s) => { var tps = LJC.FrameWork.EntityBuf.EntityBufCore.GetTypeEntityBufType(t); var pop = tps.First(p => p.Item1.Property.PropertyInfo.Name.Equals(s)); return(pop.Item1.Property.PropertyInfo); }); man.Name = "张三丰"; man.Age = 100; Thrift2ClientWarpper.Append <Man>("hbaseclient1", "test", man.Name, "man", man, (m) => { var tps = LJC.FrameWork.EntityBuf.EntityBufCore.GetTypeEntityBufType(typeof(Man)); var list = new List <KeyValuePair <string, object> >(); foreach (Tuple <LJC.FrameWork.EntityBuf.EntityBufType, bool> it in tps) { list.Add(new KeyValuePair <string, object>(it.Item1.Property.PropertyInfo.Name, it.Item1.Property.PropertyInfo.GetValue(m))); } return(list); }); Thrift2ClientWarpper.Delete("hbaseclient1", "test", man.Name); var result = Thrift2ClientWarpper.Get <Man>("hbaseclient1", "test", man.Name, (t, s) => { var tps = LJC.FrameWork.EntityBuf.EntityBufCore.GetTypeEntityBufType(t); var pop = tps.First(p => p.Item1.Property.PropertyInfo.Name.Equals(s)); return(pop.Item1.Property.PropertyInfo); }); return; TTransport transport = null; try { //实例化Socket连接 //transport = new TSocket("2.5.172.38", 30001); transport = new TSocket("hbaseclient1"); //实例化一个协议对象 TProtocol tProtocol = new TBinaryProtocol(transport); //实例化一个Hbase的Client对象 var client = new Hbase.Client(tProtocol); //打开连接 transport.Open(); Console.Write("已连接上"); //client.disableTable(Encoding.UTF8.GetBytes("dz_CDN_Ip_Stat")); //client.deleteTable(Encoding.UTF8.GetBytes("dz_CDN_Ip_Stat")); //client.createTable(Encoding.UTF8.GetBytes("dz_CDN_Ip_Stat"), new List<ColumnDescriptor> { new ColumnDescriptor { Name = Encoding.UTF8.GetBytes("col1") } }); //Console.Write("创建表"); //var boo=client.checkAndPut(Encoding.UTF8.GetBytes("dz_CDN_Ip_Stat"), Encoding.UTF8.GetBytes("201310_001_0_1100"), Encoding.UTF8.GetBytes("col1"), Encoding.UTF8.GetBytes("val"), null, null); //Console.WriteLine("写数据:" + boo); //根据表名,RowKey名来获取结果集 //List<TRowResult> reslut = client.getRow(Encoding.UTF8.GetBytes("dz_CDN_Ip_Stat"), Encoding.UTF8.GetBytes("row1"), null); //Console.WriteLine("读数据:" + reslut.Count); ////遍历结果集 //foreach (var key in reslut) //{ // Console.WriteLine("RowKey:\n{0}", Encoding.UTF8.GetString(key.Row)); // //打印Qualifier和对应的Value // foreach (var k in key.Columns) // { // Console.WriteLine("Family:Qualifier:" + "\n" + Encoding.UTF8.GetString(k.Key)); // Console.WriteLine("Value:" + Encoding.UTF8.GetString(k.Value.Value)); // } //} var tables = client.getTableNames(); foreach (var bi in tables) { transport.Close(); transport.Open(); client.disableTable(bi); client.deleteTable(bi); //var tb = Encoding.UTF8.GetString(bi); //Console.WriteLine(tb); //transport.Close(); //transport.Open(); //var dic = client.getColumnDescriptors(bi); //foreach (var kv in dic) //{ // Console.WriteLine(string.Format("{0}:{1}", Encoding.UTF8.GetString(kv.Key), Encoding.UTF8.GetString(kv.Value.Name))); //} } } catch (Exception e) { System.Console.WriteLine(e); } finally { if (null != transport) { transport.Close(); } } Console.ReadLine(); }
/// <summary> /// Add Serializer into Factory /// </summary> /// <typeparam name="TSerializer"></typeparam> public void AddSerializer <TSerializer>() where TSerializer : ISerializer, new() { var serializer = new TSerializer(); Serializers[serializer.Name] = serializer; }