Ejemplo n.º 1
0
        /// <summary>
        /// Opens the connection to the remote host.
        /// </summary>
        public void Open()
        {
            string destStr = _destId.ToString();

            LOGGER.Log(Level.Verbose, "Network service opening connection to {0}...", destStr);

            IPEndPoint destAddr = _nameClient.CacheLookup(_destId.ToString());

            if (destAddr == null)
            {
                throw new RemotingException("Cannot register Identifier with NameService");
            }

            try
            {
                _remoteSender = _remoteManager.GetRemoteObserver(destAddr);
                LOGGER.Log(Level.Verbose, "Network service completed connection to {0}.", destStr);
            }
            catch (SocketException)
            {
                LOGGER.Log(Level.Error, "Network Service cannot open connection to " + destAddr);
                throw;
            }
            catch (ObjectDisposedException)
            {
                LOGGER.Log(Level.Error, "Network Service cannot open connection to " + destAddr);
                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Opens the connection to the remote host.
        /// </summary>
        public void Open()
        {
            string destStr = _destId.ToString();

            Logger.Log(Level.Verbose, "Network service opening connection to {0}...", destStr);

            IPEndPoint destAddr = _nameClient.Lookup(destStr);

            if (null == destAddr)
            {
                throw new RemotingException("Destination Address identifier cannot be found");
            }

            try
            {
                _remoteSender = _remoteManager.GetRemoteObserver(destAddr);
                Logger.Log(Level.Verbose, "Network service completed connection to {0}.", destStr);
            }
            catch (SocketException)
            {
                Logger.Log(Level.Error, "Network Service cannot open connection to " + destAddr);
                throw;
            }
            catch (ObjectDisposedException)
            {
                Logger.Log(Level.Error, "Network Service cannot open connection to " + destAddr);
                throw;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Register the identifier for the NetworkService with the NameService.
        /// </summary>
        /// <param name="id">The identifier to register</param>
        public void Register(IIdentifier id)
        {
            Logger.Log(Level.Verbose, "Registering id {0} with network service.", id);

            _localIdentifier = id;
            NamingClient.Register(id.ToString(), _remoteManager.LocalEndpoint);

            Logger.Log(Level.Verbose, "End of Registering id {0} with network service.", id);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Matcheses the identifier.
        /// </summary>
        /// <param name="otherIdentifier">
        /// The other identifier.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public virtual bool MatchesIdentifier(IIdentifier otherIdentifier)
        {
            if (otherIdentifier is MultipleIdentifier)
            {
                return(otherIdentifier.MatchesIdentifier(this));
            }

            var directMatch = $"{otherIdentifier}" == $"{this}";

            if (directMatch)
            {
                return(true);
            }

            var otherDescription = otherIdentifier?.ToString();
            var myDescription    = this.ToString();

            if (this.ToString() == "*" || otherIdentifier?.ToString() == "*")
            {
                // Super Joker
                return(true);
            }

            if (otherIdentifier?.HasWildcardSuffix == true && this.HasWildcardSuffix)
            {
                otherDescription = otherDescription.Substring(otherDescription.Length - 2);
                myDescription    = myDescription.Substring(myDescription.Length - 2);
                return(myDescription.StartsWith(otherDescription) || otherDescription.StartsWith(myDescription));
            }

            if (otherIdentifier?.HasWildcardSuffix == true)
            {
                otherDescription = otherDescription.Substring(otherDescription.Length - 2);
                return(this.ToString().StartsWith(otherDescription));
            }

            if (!this.HasWildcardSuffix)
            {
                return(false);
            }

            myDescription = myDescription.Substring(myDescription.Length - 2);
            return(otherDescription?.StartsWith(myDescription) == true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Unregister the identifier for the NetworkService with the NameService.
        /// </summary>
        public void Unregister()
        {
            if (_localIdentifier == null)
            {
                throw new IllegalStateException("Cannot unregister a non existant identifier");
            }

            NamingClient.Unregister(_localIdentifier.ToString());
            _localIdentifier = null;
            _messageHandlerDisposable.Dispose();
        }
        public void Remove(IIdentifier psnLogInformationId)
        {
            _relayOnStorage.Remove(psnLogInformationId);

            var infosToRemove = _psnDataInformations.Where(i => i.Id.ToString() == psnLogInformationId.ToString()).ToList();

            foreach (var psnDataInformation in infosToRemove)
            {
                _psnDataInformations.Remove(psnDataInformation);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Register the identifier for the NetworkService with the NameService.
        /// </summary>
        /// <param name="id">The identifier to register</param>
        public void Register(IIdentifier id)
        {
            LOGGER.Log(Level.Info, "Registering id {0} with network service.", id);

            _localIdentifier = id;
            NamingClient.Register(id.ToString(), _remoteManager.LocalEndpoint);

            // Create and register incoming message handler
            var anyEndpoint = new IPEndPoint(IPAddress.Any, 0);

            _messageHandlerDisposable = _remoteManager.RegisterObserver(anyEndpoint, _messageHandler);
        }
        /// <summary>
        /// Добавляет новые пользовательские данные в хранилище
        /// </summary>
        /// <param name="psnDataCustomConfigurationId">Идентификатор данных</param>
        /// <param name="psnConfigruationId">Идентификатор конфигурации ПСН</param>
        /// <param name="customLogName">Пользоваетльское название данных ПСН</param>
        public void Add(IIdentifier psnDataCustomConfigurationId, IIdentifier psnConfigruationId, string customLogName)
        {
            var doc = ReadXDocFromStream();

            doc.Element("PsnLogCustomConfigurations").
            Add(
                new XElement(
                    "PsnLogCustomConfiguration",
                    new XAttribute("Id", psnDataCustomConfigurationId.ToString()),
                    new XAttribute("PsnConfigurationId", psnConfigruationId.IdentyString),
                    new XAttribute("CustomLogName", customLogName)));
            WriteOutXml(doc);
        }
Ejemplo n.º 9
0
        public SQLiteCommand CreateInsertCommand(SQLiteConnection connection, IIdentifier id, object value, IImmutableDictionary <string, object> where)
        {
            /*
             *  INSERT OR REPLACE INTO Setting([Name], [Value])
             *  VALUES('{setting.Name.FullNameEx}', '{setting.Value}')
             */

            // --- build sql

            var sql = new StringBuilder();

            var dbProviderFactory = DbProviderFactories.GetFactory(connection);

            using (var commandBuilder = dbProviderFactory.CreateCommandBuilder())
            {
                string Sanitize(string identifier) => commandBuilder.QuoteIdentifier(identifier);

                var table = $"{Sanitize(_tableMetadata.TableName)}";

                var columns = where.Keys.Select(Sanitize).Aggregate(
                    $"[{EntityProperty.Name}], [{EntityProperty.Value}]",
                    (result, next) => $"{result}, {next}"
                    );

                sql.Append($"INSERT OR REPLACE INTO {table}({columns})").AppendLine();

                var parameterNames = where.Keys.Aggregate(
                    $"@{EntityProperty.Name}, @{EntityProperty.Value}",
                    (result, next) => $"{result}, @{next}"
                    );

                sql.Append($"VALUES ({parameterNames})").AppendLine();
            }

            var command = connection.CreateCommand();

            command.CommandType = CommandType.Text;
            command.CommandText = sql.ToString();

            // --- add parameters

            (command, _tableMetadata).AddParameter(
                ImmutableDictionary <string, object> .Empty
                .Add(EntityProperty.Name, id.ToString())
                .Add(EntityProperty.Value, value)
                .AddRange(where));

            return(command);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Register the identifier for the NetworkService with the NameService.
        /// </summary>
        /// <param name="id">The identifier to register</param>
        public void Register(IIdentifier id)
        {
            Logger.Log(Level.Info, "Registering id {0} with network service.", id);

            _localIdentifier = id;
            NamingClient.Register(id.ToString(), _remoteManager.LocalEndpoint);

            // Create and register incoming message handler
            // TODO[REEF-419] This should use the TcpPortProvider mechanism
            var anyEndpoint = new IPEndPoint(IPAddress.Any, 0);

            _messageHandlerDisposable = _remoteManager.RegisterObserver(anyEndpoint, _messageHandler);

            Logger.Log(Level.Info, "End of Registering id {0} with network service.", id);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Unregister the identifier for the NetworkService with the NameService.
        /// </summary>
        public void Unregister()
        {
            if (_localIdentifier == null)
            {
                throw new IllegalStateException("Cannot unregister a non existant identifier");
            }

            NamingClient.Unregister(_localIdentifier.ToString());

            _localIdentifier = null;

            if (_universalObserverDisposable != null)
            {
                _universalObserverDisposable.Dispose();
            }

            if (_remoteMessageUniversalObserver != null)
            {
                _remoteMessageUniversalObserver.Dispose();
            }
        }
Ejemplo n.º 12
0
        public SQLiteCommand CreateDeleteCommand(SQLiteConnection connection, IIdentifier id, IImmutableDictionary <string, object> where)
        {
            /*
             *
             * DELETE FROM [dbo].[Setting] WHERE [Name] LIKE 'baz%' AND [Environment] = 'boz'
             *
             */

            var sql = new StringBuilder();

            var dbProviderFactory = DbProviderFactories.GetFactory(connection);

            using (var commandBuilder = dbProviderFactory.CreateCommandBuilder())
            {
                string Sanitize(string identifier) => commandBuilder.QuoteIdentifier(identifier);

                var table = $"{Sanitize(_tableMetadata.TableName)}";

                sql.Append($"DELETE FROM {table}").AppendLine();
                sql.Append(where.Keys.Aggregate(
                               $"WHERE ([{EntityProperty.Name}] = @{EntityProperty.Name} OR [{EntityProperty.Name}] LIKE @{EntityProperty.Name} || '[%]')",
                               (result, key) => $"{result} AND {Sanitize(key)} = @{key} ")
                           );
            }

            var command = connection.CreateCommand();

            command.CommandType = CommandType.Text;
            command.CommandText = sql.ToString();

            // --- add parameters & values

            (command, _tableMetadata).AddParameter(
                ImmutableDictionary <string, object> .Empty
                .Add(EntityProperty.Name, id.ToString())
                .AddRange(where));

            return(command);
        }