public void Validate(uint Price, string SKU, string Token, Action <bool, string> Callback) { try { Requests.HeaderMap headers = new Requests.HeaderMap(); headers["Content-Type"] = "application/json"; ISerializeObject dataObj = Creator.Create <ISerializeObject>(); dataObj["MerchantID"] = merchantID; dataObj["Authority"] = Token; dataObj["Amount"] = Price; string data = Requests.PostString(VALIDATE_URL, dataObj.Content, headers); ISerializeObject obj = Creator.Create <ISerializeObject>(data); bool isOK = (Convert.ToInt32(obj["Status"]) == 100); Callback(isOK, ""); } catch (Exception ex) { Callback(false, ex.ToString()); } }
public static object ActionStringPars(string command, string[] pars, ISerializeObject serializeObject, ref bool needBack) { if (!ActionDictionary.ContainsKey(command)) { needBack = false; return(null); } ActionInfo actionInfo = ActionDictionary[command]; if (actionInfo.ControllerObject == null) { needBack = false; return(null); } object[] convertByTypePars = GetActionCallParameters(actionInfo, pars, serializeObject); if (actionInfo.MethodInfo.ReturnType == typeof(void)) { needBack = false; } else { needBack = true; } return(actionInfo.MethodInfo.Invoke(actionInfo.ControllerObject, convertByTypePars)); }
public InstanceData AddInstance(string ID, ISerializeObject SerializeObject) { InstanceData instance = new InstanceData(ID, SerializeObject); instances.Add(instance); return(instance); }
public static object UnpackOneParameter(string msg, Type type, ISerializeObject serializeObject) { if (type == typeof(string) || type == typeof(DateTime) || type.GetTypeInfo().BaseType == typeof(System.Type) || type == typeof(int) || type == typeof(float) ) { return(Convert.ChangeType(msg, type)); } else if (type.GetTypeInfo().IsEnum) { return(Enum.Parse(type, msg)); } else { if (msg == null) { return(null); } else { if (serializeObject == null) { return(null); } object data = serializeObject.DeserializeFromString(msg, type); return(data); } } }
public static string PackOneParameter(object obj, ISerializeObject serializeObject) { if (obj == null) { return("null"); } string backStr = ""; Type type = obj.GetType(); if (!type.GetTypeInfo().IsClass || type == typeof(string) || type == typeof(DateTime) || type.GetTypeInfo().BaseType == typeof(System.Type) || type.GetTypeInfo().IsEnum || type == typeof(int) || type == typeof(float) ) { backStr = obj.ToString(); } else { if (serializeObject == null) { backStr = obj.ToString(); } else { backStr = serializeObject.SerializeToString(obj); } } return(backStr); }
protected ISerializeArray BuildISerializeData(DataTable Table) { if (Table == null || Table.Rows.Count == 0) { return(null); } ISerializeArray arr = Creator.Create <ISerializeArray>(); for (int i = 0; i < Table.Rows.Count; ++i) { DataRow row = Table.Rows[i]; ISerializeObject obj = arr.AddObject(); for (int j = 0; j < Table.Columns.Count; ++j) { string colName = Table.Columns[j].ColumnName; object value = row[colName]; if (value == DBNull.Value) { value = null; } obj.Set(colName, value); } } return(arr); }
public static object Bind(ISerializeData Data, Type Type) { if (Data == null) { throw new NullReferenceException("Data cannot be null"); } if (Type.IsArray != (Data is ISerializeArray)) { throw new ArgumentException("Type [" + Type + "] and [" + Data.GetType() + "] are not same"); } Type elementType = (Type.IsArray ? Type.GetElementType() : Type); if (Data is ISerializeObject) { ISerializeObject obj = (ISerializeObject)Data; if (obj.Contains(TYPE_FIELD_NAME)) { string typeName = obj.Get <string>(TYPE_FIELD_NAME); elementType = Type.GetType(typeName); if (elementType == null) { throw new ArgumentException(string.Format("Couldn't find Specified type {0}", typeName), TYPE_FIELD_NAME); } } return(Bind(obj, elementType)); } return(Bind((ISerializeArray)Data, Type)); }
/// <inheritdoc cref="ISerializeAsync.SerializeAsync{T}(Stream, T, CancellationToken)" /> public static ValueTask SerializeAsync <T>(this ISerializeObject serializer, Stream target, T item, CancellationToken cancellationToken = default) { if (serializer is null) { throw new ArgumentNullException(nameof(serializer)); } return(serializer is ISerializeAsync s ? s.SerializeAsync(target, item, cancellationToken) : SerializeAsync(serializer, target, item, typeof(T), cancellationToken)); }
public static T DeserializeObject <T>(this ISerializeObject serializeObject, string text, Encoding encoding) { if (string.IsNullOrEmpty(text)) { throw new ArgumentNullException("text"); } var ms = new MemoryStream(encoding.GetBytes(text)); return(serializeObject.DeserializeObject <T>(ms)); }
/// <inheritdoc cref="ISerialize.Serialize{T}(T)" /> public static string?Serialize <T>(this ISerializeObject serializer, T item) { if (serializer is null) { throw new ArgumentNullException(nameof(serializer)); } return(serializer is ISerialize s ? s.Serialize(item) : serializer.Serialize(item, typeof(T))); }
/// <inheritdoc cref="ISerializeObjectAsync.SerializeAsync(Stream, object, Type, CancellationToken)"/> public static ValueTask SerializeAsync(this ISerializeObject serializer, Stream target, object?item, Type type, CancellationToken cancellationToken = default) { if (serializer is null) { throw new ArgumentNullException(nameof(serializer)); } return(serializer is ISerializeObjectAsync s ? s.SerializeAsync(target, item, type, cancellationToken) : DefaultMethods.SerializeAsync(serializer, target, item, type)); }
private string SendMessage(ISerializeObject Message) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; Requests.HeaderMap headers = new Requests.HeaderMap(); headers["Authorization"] = "Token " + restAPIKey; headers["Content-Type"] = "application/json"; headers["Accept"] = "application/json"; return(Requests.PostBytes(URL, Encoding.UTF8.GetBytes(Message.Content), headers)); }
public static string PackParameter(string command, ISerializeObject serializeObject, params object[] pars) { StringBuilder sendParameter = new StringBuilder(); sendParameter.Append(command).Append(SplitString); for (int i = 0; i < pars.Length; i++) { sendParameter.Append(PackOneParameter(pars[i], serializeObject)).Append(SplitString); } return(sendParameter.ToString().TrimEnd(SplitString.ToCharArray())); }
public static string SerializeObject <T>(this ISerializeObject serializeObject, T instance, Encoding encoding) { if (instance == null) { throw new ArgumentNullException("instance"); } var ms = new MemoryStream(); serializeObject.SerializeObject(instance, ms); return(StreamConvert.ConvertStreamToString(ms, encoding)); }
public static void Override(ISerializeObject Data, ISerializeObject On) { var it = Data.GetEnumerator(); while (it.MoveNext()) { string key = it.Current.Key; object value = it.Current.Value; object onValue = On.Get <object>(key); if (value is ISerializeObject) { ISerializeObject onObj = null; if (onValue != null) { if (onValue is ISerializeObject) { onObj = (ISerializeObject)onValue; } else { Data.Remove(key); it = Data.GetEnumerator(); } } if (onObj == null) { onObj = On.AddObject(key); } Override((ISerializeData)value, onObj); } else if (value is ISerializeArray) { if (onValue != null) { Data.Remove(key); } it = Data.GetEnumerator(); Override((ISerializeData)value, On.AddArray(key)); } else { On.Set(key, value); } } }
private static object Bind(ISerializeObject Object, Type Type) { object obj = Activator.CreateInstance(Type); MemberInfo[] members = Type.GetMemberVariables(ReflectionExtensions.AllNonStaticFlags); for (int i = 0; i < members.Length; ++i) { MemberInfo member = members[i]; if (!Object.Contains(member.Name)) { continue; } Type memberType = null; if (member is FieldInfo) { memberType = ((FieldInfo)member).FieldType; } else if (member is PropertyInfo) { PropertyInfo propertyInfo = (PropertyInfo)member; if (!propertyInfo.CanWrite) { continue; } memberType = propertyInfo.PropertyType; } object value = Cast(Object.Get <object>(member.Name), memberType); if (member is FieldInfo) { ((FieldInfo)member).SetValue(obj, value); } else if (member is PropertyInfo) { ((PropertyInfo)member).SetValue(obj, value, null); } } return(obj); }
public void Validate(uint Price, string SKU, string Token, Action <bool, string> Callback) { try { string data = Requests.Get(string.Format(VALIDATE_URL, packageName, SKU, Token, accessToken)); ISerializeObject obj = Creator.Create <ISerializeObject>(data); bool isOK = (Convert.ToInt32(obj["purchaseState"]) == 0); Callback(isOK, ""); } catch (Exception ex) { Callback(false, ex.ToString()); } }
public void Send(string Title, string Message, params string[] PlayerID) { if (PlayerID == null || PlayerID.Length == 0) { Send(Title, Message, new Segments[] { Segments.All }); return; } ISerializeObject messageObj = BuildMessage(Title, Message); ISerializeObject filter = messageObj.AddObject("filter"); ISerializeArray pushe_id = filter.AddArray("pushe_id"); pushe_id.AddRange(PlayerID); SendMessage(messageObj); }
private ISerializeObject BuildMessage(string Title, string Message) { ISerializeObject messageObj = Creator.Create <ISerializeObject>(); ISerializeArray applications = messageObj.AddArray("applications"); applications.Add(packageName); ISerializeObject notification = messageObj.AddObject("notification"); notification["content"] = Message; if (!string.IsNullOrEmpty(Title)) { notification["title"] = Title; } return(messageObj); }
/// <summary> /// Serializes the provided item to a stream. /// </summary> public static async ValueTask SerializeAsync(ISerializeObject serializer, Stream target, object?item, Type type) { if (serializer is null) { throw new ArgumentNullException(nameof(serializer)); } if (target is null) { throw new ArgumentNullException(nameof(target)); } if (type is null) { throw new ArgumentNullException(nameof(type)); } var text = serializer.Serialize(item, type); using var writer = new StreamWriter(target); await writer.WriteAsync(text).ConfigureAwait(false); }
public static string GetRefreshToken(string Code, string ClientID, string ClientSecret, string RedirectURI) { Requests.ParameterMap parameters = new Requests.ParameterMap(); parameters["grant_type"] = "authorization_code"; parameters["code"] = Code; parameters["client_id"] = ClientID; parameters["client_secret"] = ClientSecret; parameters["redirect_uri"] = RedirectURI; string data = Requests.Post(TOKEN_URL, null, parameters); ISerializeObject obj = Creator.Create <ISerializeObject>(data); if (obj.Contains("refresh_token")) { return(obj.Get <string>("refresh_token")); } return(""); }
private static List <KeyValueItem> GetXml(out string strErro) { strErro = string.Empty; if (null == keyvalues) { try { var configurationOperate = ConfigurationOperate.CreateInstance(); byte[] bytes = configurationOperate.GetConfigurationContent(fileName); ISerializeObject iSerializeObject = SerializerCreator.CreateSerializer(SerializeType.XML, new Type[] { typeof(KeyValueItem) }); keyvalues = iSerializeObject.DeserializeObject <List <KeyValueItem> >(new MemoryStream(bytes)); } catch (Exception e) { strErro = "取配置文件出错:" + e.Message; keyvalues = null; } } return(keyvalues); }
private void GetAccessToken() { try { Requests.ParameterMap parameters = new Requests.ParameterMap(); parameters["grant_type"] = "refresh_token"; parameters["client_id"] = clientID; parameters["client_secret"] = clientSecret; parameters["refresh_token"] = refreshToken; string data = Requests.Post(TOKEN_URL, null, parameters); ISerializeObject obj = Creator.Create <ISerializeObject>(data); accessToken = obj["access_token"].ToString(); } catch { } }
static void Main(string[] args) { Database db = new MySQLDatabase("localhost", "root", "!QAZ2wsx", "bourse_analyzer"); MigrationManager.Migrate(db, null, null); long num = 1000; object obj = Activator.CreateInstance(typeof(Number), num); test t = new test(); ISerializeObject d = Creator.Serialize <ISerializeObject>(t); test f = Creator.Bind <test>(Creator.Create <ISerializeObject>(d.Content)); BufferStream buff = new BufferStream(new byte[10000]); Serializer.Serialize(f, buff); buff.ResetRead(); f = Serializer.Deserialize <test>(buff); }
public void Start(int port, ISerializeObject serializeObject, Assembly assembly = null) { if (assembly != null) { RouteManager.RegistAssembly(assembly); } SerializeObject = serializeObject; SocketServer = new SocketServer(); SocketServer.Start <LemonMessage>(port); SocketServer.SetOnReceiveEvent((s, m) => { LemonMessage oldmsg = (LemonMessage)m; List <string> pars = oldmsg.Body.Split(new string[] { ParameterConverter.SplitString }, StringSplitOptions.None).ToList(); string command = pars[0]; pars.RemoveAt(0); try { bool needBack = false; object ret = RouteManager.ActionStringPars(command, pars.ToArray(), SerializeObject, ref needBack); if (needBack) { LemonMessage msg = new LemonMessage(); msg.Body = ParameterConverter.PackOneParameter(ret, serializeObject); msg.StateCode = 0; s.SendMessage(msg); } } catch (Exception ex) { LemonMessage msg = new LemonMessage(); msg.Body = ex.Message; msg.StateCode = -1; s.SendMessage(msg); } }); }
private bool MustCompile() { if (!File.Exists(EnvironmentHelper.FinalOutputDirectory + SelectedRule.TargetName + GetExtension(this))) { return(true); } string hashesFilePath = intermediateModulePath + HashesFileName; ISerializeObject hashesData = null; if (File.Exists(hashesFilePath)) { hashesData = Creator.Create <ISerializeObject>(File.ReadAllText(hashesFilePath)); } if (hashesData == null) { hashesData = Creator.Create <ISerializeObject>(); } bool result = false; string configurationTypeName = typeof(ProjectBase.ProfileBase.BuildConfigurations).Name; if (!hashesData.Contains(configurationTypeName) || hashesData.Get <int>(configurationTypeName) != (int)BuildSystem.BuildConfiguration) { result = true; } hashesData.Set(configurationTypeName, (int)BuildSystem.BuildConfiguration); string platformTypeName = typeof(ProjectBase.ProfileBase.PlatformTypes).Name; if (!hashesData.Contains(platformTypeName) || hashesData.Get <int>(platformTypeName) != (int)BuildSystem.PlatformType) { result = true; } hashesData.Set(platformTypeName, (int)BuildSystem.PlatformType); if (!result) { List <string> extensions = new List <string>(); extensions.AddRange(EnvironmentHelper.HeaderFileExtensions); extensions.AddRange(EnvironmentHelper.CompileFileExtensions); extensions.AddRange(EnvironmentHelper.CSharpFileExtensions); string[] files = FileSystemUtilites.GetAllFiles(sourcePathRoot, extensions.ToArray()); foreach (string file in files) { string filePathHash = GetHash(file).ToString(); int contentHash = GetHash(File.ReadAllText(file)); if (hashesData.Contains(filePathHash) && hashesData.Get <int>(filePathHash) == contentHash) { continue; } hashesData.Set(filePathHash, contentHash); result = true; } } File.WriteAllText(hashesFilePath, hashesData.Content); return(result); }
public InstanceData(string ID, ISerializeObject SerializeObject) { this.ID = ID; this.SerializeObject = SerializeObject; }
public LemonClient(string ip, int port, ISerializeObject serializeObject) { IP = ip; Port = port; SerializeObject = serializeObject; }
public static string SerializeObject <T>(this ISerializeObject serializeObject, T instance) { return(SerializeObject <T>(serializeObject, instance, Encoding.Default)); }
public void Send(string Title, string Message, Segments[] Segments) { ISerializeObject messageObj = BuildMessage(Title, Message); SendMessage(messageObj); }