Пример #1
0
        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);
                    }
                }
            }
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
 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));
 }
Пример #4
0
        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));
        }
Пример #5
0
        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));
        }
Пример #6
0
        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);
            }
        }
Пример #7
0
        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);
            }
        }
Пример #8
0
        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);
                }
            }
        }
Пример #9
0
        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);
                }
            }
        }
Пример #10
0
        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);
            }
        }
Пример #11
0
        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);
                }
            }
        }