public void Load() { Precondition.PropertyNotNull(Settings, nameof(Settings)); if (!Directory.Exists(Settings.ConfigDir)) { return; } var entryFiles = Settings .StoreService .GetEntriesAsync(Settings.ConfigDir, Settings.ConfigFileExtension) .Result; lock (_configMap) { _configMap.Clear(); foreach (var file in entryFiles) { try { LoadConfigDataFrom(file); } catch (Exception ex) { OnLoadConfigDataFail(ex); } } } }
/// <summary> /// Builds a UI from config data and binds its properties to this the UI. /// </summary> /// <param name="config"> /// The config data that will be used to determine the UI structure and binds /// its properties to the UI. /// </param> /// <typeparam name="T"> /// Type of the UI which is an <see cref="IContainer"/>. /// </typeparam> /// <returns>The UI instance that is created from the config data.</returns> public T Build <T>(object config) where T : IContainer { Precondition.ArgumentNotNull(config, nameof(config)); Precondition.PropertyNotNull(SettingBinder, nameof(SettingBinder)); CheckFactories(); var container = _componentManager.CreateComponentFromComponentType <IContainer>(typeof(T)); var configType = config.GetType(); var settings = CreateSettingBuilder(configType).Build(); SettingBinder.BindContainer(container, configType, settings); foreach (var propertyInfo in configType.GetProperties()) { var component = BuildRecursive(config, propertyInfo); if (component == null) { continue; } container.AddChild(component); } return((T)container); }
private void CheckFactories() { Precondition.PropertyNotNull(LayoutManagerFactory, nameof(LayoutManagerFactory)); Precondition.PropertyNotNull(SizeOptionsFactory, nameof(SizeOptionsFactory)); Precondition.PropertyNotNull(DateTimeOptionsFactory, nameof(DateTimeOptionsFactory)); Precondition.PropertyNotNull(ContainerAppearanceFactory, nameof(ContainerAppearanceFactory)); Precondition.PropertyNotNull(EditorAppearanceFactory, nameof(EditorAppearanceFactory)); }
private ISession CreateSession(NamedPipeServerStream client) { var sessionFactory = SessionFactory; Precondition.PropertyNotNull(sessionFactory, nameof(SessionFactory)); var protocolFactory = ProtocolFactory; Precondition.PropertyNotNull(protocolFactory, nameof(ProtocolFactory)); var protocol = protocolFactory(client); return(sessionFactory(protocol)); }
private ISession CreateSession(TcpClient client) { var sessionFactory = SessionFactory; Precondition.PropertyNotNull(sessionFactory, nameof(SessionFactory)); var protocolFactory = ProtocolFactory; Precondition.PropertyNotNull(protocolFactory, nameof(ProtocolFactory)); var protocol = protocolFactory(client.GetStream()); return(sessionFactory(protocol)); }
private void WaitForIncommingData() { var receiver = Receiver; Precondition.PropertyNotNull(receiver, nameof(Receiver)); var adapter = new JsonContentAdapter(); while (!disposed) { var data = receiver.ReceiveAsync <EventWrapper>().Result; var decodedData = adapter.ToObject(data.Data.ToString(), data.DataType); internalEventBus.Post(decodedData, data.Stick); } }
private void WaitForClientIfNeeded() { var sessionFactory = SessionFactory; Precondition.PropertyNotNull(sessionFactory, nameof(SessionFactory)); var protocolFactory = ProtocolFactory; Precondition.PropertyNotNull(protocolFactory, nameof(ProtocolFactory)); if (session == null) { var client = listener.AcceptTcpClient(); var protocol = protocolFactory(client.GetStream()); session = sessionFactory(protocol); } }
private void ConnectIfNeeded() { var factory = ProtocolFactory; Precondition.PropertyNotNull(factory, nameof(ProtocolFactory)); lock (lockObj) { if (protocol == null) { var client = new TcpClient(hostname, port); var stream = client.GetStream(); protocol = factory(stream); } } }
public void Save() { Precondition.PropertyNotNull(Settings, nameof(Settings)); if (string.IsNullOrEmpty(Settings.ConfigDir)) { throw new ConfigException("Config directory is null."); } if (!Directory.Exists(Settings.ConfigDir)) { Directory.CreateDirectory(Settings.ConfigDir); } lock (_configMap) { foreach (var configPair in _configMap) { SaveConfig(configPair.Key, configPair.Value); } } }
private void StartIfNeeded() { var sessionFactory = SessionFactory; Precondition.PropertyNotNull(sessionFactory, nameof(SessionFactory)); var protocolFactory = ProtocolFactory; Precondition.PropertyNotNull(protocolFactory, nameof(ProtocolFactory)); if (server == null) { server = new NamedPipeServerStream( pipeName, PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Byte, PipeOptions.WriteThrough); server.WaitForConnection(); var protocol = protocolFactory(server); session = sessionFactory(protocol); } }
private void ConnectIfNeeded() { var factory = ProtocolFactory; Precondition.PropertyNotNull(factory, nameof(ProtocolFactory)); lock (lockObj) { if (client == null) { client = new NamedPipeClientStream( serverName, pipeName, PipeDirection.InOut, PipeOptions.WriteThrough, TokenImpersonationLevel.None); if (!client.IsConnected) { client.Connect(connectTimeout); } protocol = factory(client); } } }