/// <summary>WPFのUIInvoke</summary> private void button3_Click(object sender, RoutedEventArgs e) { byte[] bytes = BinarySerialize.ObjectToBytes(this.txtMSG.Text); AsyncEventFx.SendAsyncEvent( AsyncEventEnum.EventClass.WPF, "WPF", AsyncEventEnum.EventClass.WPF, "WPF", this.NPCS[0], this.NPS, (uint)bytes.Length, bytes); }
/// <summary>へんなところ</summary> private void button5_Click(object sender, EventArgs e) { byte[] bytes = BinarySerialize.ObjectToBytes(this.txtMSG.Text); AsyncEventFx.SendAsyncEvent( AsyncEventEnum.EventClass.WPF, "いいい", AsyncEventEnum.EventClass.WPF, "いいい", this.NPCS[1], "あああ", (uint)bytes.Length, bytes); //this.NPCS[1], this.NPS, (uint)bytes.Length, bytes); }
public override void Initialize() { _type = typeof(T); _keyElementType = _type.GetGenericArguments()[0]; _keyElementSerialize = BinarySerialize.From(_keyElementType); _valueElementType = _type.GetGenericArguments()[1]; _valueElementSerialize = BinarySerialize.From(_valueElementType); }
protected override void OnReceived(byte[] bytes) { if (bytes.Length > 0) { var serializeType = BinarySerialize.From <MessageRequest>(); var request = serializeType.Deserialize(bytes); Server.BeginMessageProcess?.Invoke(this, request, MessageProcessCallback); } }
/// <summary>Main</summary> /// <param name="args">string[]</param> static void Main(string[] args) { string ver = ""; #if NET45 ver = "NET45"; #elif NET46 ver = "NET46"; #elif NET47 ver = "NET47"; #elif NET48 ver = "NET48"; #elif NETCORE20 ver = "NETCORE20"; #elif NETCORE30 ver = "NETCORE30"; #else #endif string filePath = ""; string fileName = "TestBinarySerializeXplat.txt"; if (System.Environment.OSVersion.Platform == PlatformID.Win32NT) { filePath = @"C:\Users\nishi\"; } else { filePath = "/mnt/c/Users/nishi/"; } filePath += fileName; Dictionary <string, string> dic = null; if (File.Exists(filePath)) { dic = (Dictionary <string, string>) BinarySerialize.BytesToObject( CustomEncode.FromBase64String( ResourceLoader.LoadAsString(filePath, Encoding.UTF8))); Console.WriteLine("loaded string : " + dic["ver"]); Console.ReadKey(); } dic = new Dictionary <string, string>(); dic["ver"] = ver; using (StreamWriter sr = new System.IO.StreamWriter(filePath, false, Encoding.UTF8)) { sr.WriteLine( CustomEncode.ToBase64String( BinarySerialize.ObjectToBytes(dic))); } }
public bool LoadBinary(string path) { bool sucess = false; if (!string.IsNullOrEmpty(path)) { genericList = BinarySerialize.BinaryLoad <List <T> >(path); } return(sucess); }
public void SingleSerialize() { var serialize = BinarySerialize.From <EnumToTest>(); var value = EnumToTest.Value2; var bytes = serialize.Serialize(value); var returnedValue = serialize.Deserialize(bytes); Assert.AreEqual(value, returnedValue); }
protected override void OnReceived(byte[] bytes) { var serializeType = BinarySerialize.From <MessageReponse>(); var response = serializeType.Deserialize(bytes); var handle = _handles[response.Id]; _handles.Remove(response.Id); handle.Response = response; handle.SentCallback(response); }
public void DeepCloneTest(object sourceObject) { try { object resultsObject = BinarySerialize.DeepClone(sourceObject); Assert.AreEqual(resultsObject, sourceObject); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); throw; } }
public void LoadExcludedShips() { LOG.Debug("Load exclusion list"); ExcludedShips.Clear(); if (File.Exists(Commons.GetExclusionListFileName())) { ExcludedShips = BinarySerialize.ReadFromBinaryFile <HashSet <long> >(Commons.GetExclusionListFileName()); } else { LOG.Warning("Exclusion list missing"); } }
static void _SaveObj(string path, object obj) { string dir = Path.GetDirectoryName(path); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } byte[] bytes = BinarySerialize.Serialize(obj); bytes = EncryptDecrypt.Encrypt(bytes); File.WriteAllBytes(path, bytes); Debug.Log(path + " saved."); }
internal static void SaveToRegistry() { if (fonts == null) { return; } foreach (KeyValuePair <string, Font> font in fonts) { byte[] binObj = BinarySerialize.Serialize <Font>(font.Value); new Data <byte[]>(new RegistryProvider("Fonts"), font.Key, binObj); } }
public void TestObject() { var test = new TestObjectClass { Value = "test 123" }; var serialize = BinarySerialize.From <TestObjectClass>(); var bytes = serialize.Serialize(test); var backFrom = serialize.Deserialize(bytes); }
static object _LoadObj(string path) { if (!File.Exists(path)) { return(null); } try { byte[] bytes = File.ReadAllBytes(path); bytes = EncryptDecrypt.Decrypt(bytes); return(BinarySerialize.Deserialize(bytes)); } catch (Exception e) { return(null); } }
public void CustomPropertySerialize() { var values = new AttributeProviderPropertyEntity { TestSomeString = "uma string qualquer!!!" }; var serialize = BinarySerialize.From <AttributeProviderPropertyEntity>(); var bytes = serialize.Serialize(values); var returnedValues = serialize.Deserialize(bytes); Assert.AreEqual(values.TestSomeString, returnedValues.TestSomeString.TrimEnd('\0')); }
public void CustomSerialize() { var values = new AttributeProviderEntity { SomeAnyValue = 666 }; var serialize = BinarySerialize.From <AttributeProviderEntity>(); var bytes = serialize.Serialize(values); var returnedValues = serialize.Deserialize(bytes); Assert.AreEqual(values.SomeAnyValue, returnedValues.SomeAnyValue); }
internal static void ReadFromRegistry() { Data <byte[]> sets = new Data <byte[]>(new RegistryProvider("Fonts")); Dictionary <string, byte[]> values = sets.ReadAllValues(); if (values == null) { return; } foreach (KeyValuePair <string, byte[]> value in values) { Set(value.Key, BinarySerialize.Deserialize <Font>(value.Value)); } }
public void ObjectToBytesTest(object objExpected) { try { byte[] bytFromObject = BinarySerialize.ObjectToBytes(objExpected); // parameter object objActual = BinarySerialize.BytesToObject(bytFromObject); Assert.AreEqual(objExpected, objActual); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); throw; } }
public void BytesToObjectTest(byte[] bytActual) { try { object objFromBytes = BinarySerialize.BytesToObject(bytActual); byte[] byteFromObject = BinarySerialize.ObjectToBytes(objFromBytes); Assert.AreEqual(byteFromObject, bytActual); Assert.AreNotEqual(objFromBytes, bytActual); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); throw; } }
public bool SaveBinary(string path) { bool sucess = false; if (!string.IsNullOrEmpty(path)) { sucess = true; } if (sucess) { BinarySerialize.BinarySave(genericList, path); } return(sucess); }
/// <summary>Sessionサイズ測定</summary> /// <returns>Sessionサイズ(バイト)</returns> /// <remarks>シリアル化できないオブジェクトを含む場合は落ちる。</remarks> public static long CalculateSessionSize() { // ワーク変数 long size = 0; // SessionのオブジェクトをBinarySerializeしてサイズを取得。 foreach (string key in HttpContext.Current.Session.Keys) { // 当該キーのオブジェクト・サイズを足しこむ。 size += BinarySerialize.ObjectToBytes(HttpContext.Current.Session[key]).Length; } // Sessionサイズ(バイト) return(size); }
/// <summary>デリゲード</summary> private void SetResultDgt(object result) { object[] param = (object[])result; AsyncEventHeader aeh = (AsyncEventHeader)param[0]; string msg = (string)BinarySerialize.BytesToObject((byte[])param[1]); MessageBox.Show(this.NPS + " - " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "WindowsFormsApplication.Form1.SetResultDgtメソッドが呼ばれた。" + "\r\nDstEventClass:" + aeh.DstEventClass.ToString() + "\r\nDstFuncID:" + (new string(aeh.DstFuncID)).Trim() + "\r\nSrcEventClass:" + aeh.SrcEventClass.ToString() + "\r\nSrcFuncID:" + (new string(aeh.SrcFuncID)).Trim() + "\r\nSrcPipeName:" + (new string(aeh.SrcPipeName)).Trim() + "\r\nメッセージ:" + msg, this.NPS); }
private Tuple <ISerializeType, PropertyInfo> ReadSerializeFromProperty(PropertyInfo property) { if (property.GetCustomAttributes(typeof(SerializeTypeAttribute), true) .FirstOrDefault() is SerializeTypeAttribute attribute) { var serialize = attribute.GetSerializeType(property.PropertyType); serialize.Initialize(); return(new Tuple <ISerializeType, PropertyInfo>(serialize, property)); } else { return(new Tuple <ISerializeType, PropertyInfo>(BinarySerialize.From(property.PropertyType), property)); } }
public void CustomSerialize() { var sw = Stopwatch.StartNew(); var serialize = BinarySerialize.From <NumbersEntity>(); var bytes = serialize.Serialize(_values); var returnedValues = serialize.Deserialize(bytes); sw.Stop(); Compare(_values, returnedValues); Debug.WriteLine($"NumbersTest.CustomSerialize - Bytes: {bytes.Length.ToString()} - Elapsed: {sw.Elapsed.ToString()}"); }
public string[] ValidateAuthTicket(string authTicket) { try { // 認証チケットの復号化 return((string[])BinarySerialize.BytesToObject( CustomEncode.FromBase64String( SymmetricCryptography.DecryptString( authTicket, GetConfigParameter.GetConfigValue("private-key"), EnumSymmetricAlgorithm.TripleDESCryptoServiceProvider)))); } catch { // 認証失敗 return(null); } }
public void Dispose() { if (_dispose) { _dispose = false; BinarySerialize <Dictionary <string, ReportEventArgs> > bs = new BinarySerialize <Dictionary <string, ReportEventArgs> >(); try { bs.Serialize(sends, "ReportCache"); } catch (Exception ex) { MessageHelper.Instance.WirteError(ex.ToString()); LogClient.LogHelper.LogInfo(Gateway.Config.GatewayName, "Save ReportCache Error ->", ex.Message); } } }
static void LoadShips() { string ShipFile = Commons.GetShipListFileName(); if (File.Exists(ShipFile)) { LOG.Debug("Shipfile exists: " + ShipFile); try { AllShips = BinarySerialize.ReadFromBinaryFile <List <Ship> >(ShipFile); } catch (Exception e) { AllShips = new List <Ship>(); LOG.Error("Exception during load", e); } } else { LOG.Debug("No shipfile exists"); AllShips = new List <Ship>(); } }
public void SendMessage(MessageRequest request, Action <MessageReponse> sentCallback) { request.Id = ++_messageIdIndex; var serializeType = BinarySerialize.From <MessageRequest>(); var bytes = serializeType.Serialize(request); var handle = new MessageHandle { Id = request.Id, Request = request, SentCallback = sentCallback }; _handles.Add(request.Id, handle); Send(bytes); }
public void KnowTypeTestUnknow() { var values = new KnowTypeEntity { ObjectProp = System.DateTime.Now }; try { var serialize = BinarySerialize.From <KnowTypeEntity>(); var bytes = serialize.Serialize(values); } catch (Exception err) { Assert.AreEqual(err.Message.StartsWith("Unknow"), true); } }
public void CustomSerialize() { var values = new InterfaceEntity(); values.Populate(); var sw = Stopwatch.StartNew(); var serialize = BinarySerialize.From<InterfaceEntity>(); var bytes = serialize.Serialize(values); var returnedValues = serialize.Deserialize(bytes); sw.Stop(); Compare(values, returnedValues); Debug.WriteLine($"InterfaceTest.CustomSerialize - Bytes: {bytes.Length.ToString()} - Elapsed: {sw.Elapsed.ToString()}"); }