public Manager() { FromConfig.LoadConfigData(); _storage = Storage.GetInstanse; TimerCallback trash = new TimerCallback(RunTrash); queueChecker = new Timer(trash, null, new TimeSpan(0), FromConfig.CheckingUnusedBox); }
/// <summary> /// Serialize configuration objects according to <see cref="XmlNode"/> and <see cref="FromConfig"/> /// </summary> /// <typeparam name="T">Target type</typeparam> /// <param name="Target">Serialized assignment target</param> /// <param name="section">Configuration node</param> internal static void FormatFromConfig <T>(T Target, XmlNode section) { var props = GetConfigProperties <T>(); foreach (var info in props) { FromConfig config = info.GetCustomAttribute <FromConfig>(); if (!string.IsNullOrEmpty(config.FormatHandler)) { var method = typeof(T).GetMethod(config.FormatHandler, BindingFlags.Public | BindingFlags.Instance); if (method != null) { method.Invoke(Target, new object[] { section }); continue; } } string name = config.Name ?? info.Name; var attribute = section.Attributes[name]; if (attribute != null) { if (info.PropertyType.BaseType == typeof(Enum)) { info.SetValue(Target, Enum.Parse(info.PropertyType, attribute.Value)); } if (info.PropertyType == typeof(Uri)) { info.SetValue(Target, new Uri(attribute.Value)); } else { info.SetValue(Target, Convert.ChangeType(attribute.Value, info.PropertyType)); } } else if (config.Required) { throw new ArgumentNullException($"Missing required attributes: {name}"); } } }
// // FromConfig // private byte[] FromConfigToProto(FromConfig fromConfig) { if (fromConfig == FromConfig.Instance) { return(EmptyBytes); } var message = new Proto.Msg.FromConfig(); if (fromConfig.Resizer != null) { message.Resizer = _payloadSupport.PayloadToProto(fromConfig.Resizer); } if (!string.IsNullOrEmpty(fromConfig.RouterDispatcher)) { message.RouterDispatcher = fromConfig.RouterDispatcher; } return(message.ToByteArray()); }
// private constructor private Storage() { FromConfig.LoadConfigData(); _storage = new MainTree(); _queueToTrash = new Queue(); }