public void TestHelloResponse()
        {
            Exception ex = new Exception("foo");
            IDictionary <string, object> serverInfo = new Dictionary <string, object>(1);

            serverInfo.Add(HelloResponse.SERVER_START_TIME, DateTimeUtil.GetCurrentUtcTimeMillis());
            ConnectorKey            key  = new ConnectorKey("my bundle", "my version", "my connector");
            RemoteConnectorInfoImpl info = new RemoteConnectorInfoImpl();

            info.Messages     = (new ConnectorMessagesImpl());
            info.ConnectorKey = (key);
            ConfigurationPropertiesImpl configProperties = new ConfigurationPropertiesImpl();

            configProperties.Properties = (new List <ConfigurationPropertyImpl>());
            APIConfigurationImpl apiImpl = new APIConfigurationImpl();

            apiImpl.ConfigurationProperties = (configProperties);
            info.DefaultAPIConfiguration    = (apiImpl);
            info.ConnectorDisplayNameKey    = ("mykey");
            info.ConnectorCategoryKey       = ("");


            HelloResponse v1 = new HelloResponse(ex, serverInfo, CollectionUtil.NewReadOnlyList <ConnectorKey>(key), CollectionUtil.NewReadOnlyList <RemoteConnectorInfoImpl>(info));
            HelloResponse v2 = (HelloResponse)CloneObject(v1);

            Assert.IsNotNull(v2.Exception);
            Assert.IsNotNull(v2.ServerInfo[HelloResponse.SERVER_START_TIME]);
            Assert.IsNotNull(v2.ConnectorKeys.First());
            Assert.IsNotNull(v2.ConnectorInfos.First());
        }
예제 #2
0
        /// <summary>
        /// Resolves an Action Connector, given a <see cref="ConnectorKey"/>.
        /// </summary>
        public virtual IAction <TState, TInput> ResolveAction(ConnectorKey connectorKey)
        {
            if (connectorKey == null)
            {
                throw new ArgumentNullException(nameof(connectorKey));
            }

            IAction <TState, TInput> action;

            try
            {
                action = Actions[connectorKey.Identifier].SingleOrDefault();
            }
            catch (InvalidOperationException)
            {
                throw new ConnectorResolutionException($"Multiple Action versions exists with matching connectorKey: \"{connectorKey.Identifier}\".");
            }

            if (action == null)
            {
                throw new ConnectorResolutionException($"No Action exists matching connectorKey: \"{connectorKey.Identifier}\".");
            }

            return(action);
        }
예제 #3
0
 public ConnectorPoolKey(ConnectorKey connectorKey,
                         ConfigurationPropertiesImpl configProperties,
                         ObjectPoolConfiguration poolingConfig)
 {
     _connectorKey     = connectorKey;
     _configProperties = configProperties;
     _poolingConfig    = poolingConfig;
 }
예제 #4
0
 public ConnectorConfigurationNotFoundException(string schematicName, string machineId, ConnectorKey connectorKey)
     : base($"No connector configuration matched {connectorKey.Identifier} " +
            $"when entering a state on machine {machineId} which is defined with schematic {schematicName}.")
 {
     SchematicName = schematicName;
     MachineId     = machineId;
     ConnectorKey  = connectorKey;
 }
예제 #5
0
 public ConnectorInfo FindConnectorInfo(ConnectorKey key)
 {
     foreach (ConnectorInfo info in _connectorInfo)
     {
         if (info.ConnectorKey.Equals(key))
         {
             return(info);
         }
     }
     return(null);
 }
예제 #6
0
 public OperationRequest(ConnectorKey key,
                         String connectorFacadeKey,
                         SafeType <APIOperation> operation,
                         string operationMethodName,
                         IList <Object> arguments)
 {
     _connectorKey        = key;
     _connectorFacadeKey  = connectorFacadeKey;
     _operation           = operation;
     _operationMethodName = operationMethodName;
     _arguments           = CollectionUtil.NewReadOnlyList <object>(arguments);
 }
예제 #7
0
        public ITransitionBuilder <TState, TInput> WithPrecondition(
            ConnectorKey connectorKey,
            System.Action <IPreconditionBuilder> guard = null)
        {
            var preconditionBuilder = new PreconditionBuilder(connectorKey);

            guard?.Invoke(preconditionBuilder);

            Procondition = preconditionBuilder;

            return(this);
        }
예제 #8
0
        public PreconditionBuilder(ConnectorKey connectorKey)
        {
            if (connectorKey.Identifier == null)
            {
                throw new ArgumentNullException(nameof(connectorKey), "ConnectorKey.Identifier cannot be null.");
            }
            if (string.IsNullOrWhiteSpace(connectorKey.Identifier))
            {
                throw new ArgumentException("ConnectorKey.Identifier cannot be empty or whitespace.", nameof(connectorKey));
            }

            ConnectorKey = connectorKey;
        }
예제 #9
0
        /// <summary>
        /// Resolves an Action Connector, given a <see cref="ConnectorKey"/>.
        /// </summary>
        public virtual IAction <TState, TInput> ResolveAction(ConnectorKey connectorKey)
        {
            if (connectorKey == null)
            {
                throw new ArgumentNullException(nameof(connectorKey));
            }

            if (!Actions.TryGetValue(connectorKey.Identifier, out var action))
            {
                throw new ConnectorResolutionException($"No Action exists matching connectorKey: \"{connectorKey.Identifier}\".");
            }

            return(action);
        }
예제 #10
0
        private LocalConnectorInfoImpl CreateConnectorInfo(Assembly assembly,
                                                           Type rawConnectorClass,
                                                           ConnectorClassAttribute attribute)
        {
            String fileName = assembly.Location;

            if (!typeof(Connector).IsAssignableFrom(rawConnectorClass))
            {
                String MSG = ("File " + fileName +
                              " declares a connector " + rawConnectorClass +
                              " that does not implement Connector.");
                throw new ConfigurationException(MSG);
            }
            SafeType <Connector> connectorClass =
                SafeType <Connector> .ForRawType(rawConnectorClass);

            SafeType <Configuration> connectorConfigurationClass = attribute.ConnectorConfigurationType;

            if (connectorConfigurationClass == null)
            {
                String MSG = ("File " + fileName +
                              " contains a ConnectorInfo attribute " +
                              "with no connector configuration class.");
                throw new ConfigurationException(MSG);
            }
            String connectorDisplayNameKey =
                attribute.ConnectorDisplayNameKey;

            if (connectorDisplayNameKey == null)
            {
                String MSG = ("File " + fileName +
                              " contains a ConnectorInfo attribute " +
                              "with no connector display name.");
                throw new ConfigurationException(MSG);
            }
            ConnectorKey key =
                new ConnectorKey(assembly.GetName().Name,
                                 assembly.GetName().Version.ToString(),
                                 connectorClass.RawType.Namespace + "." + connectorClass.RawType.Name);
            LocalConnectorInfoImpl rv = new LocalConnectorInfoImpl();

            rv.ConnectorClass = connectorClass;
            rv.ConnectorConfigurationClass = connectorConfigurationClass;
            rv.ConnectorDisplayNameKey     = connectorDisplayNameKey;
            rv.ConnectorKey            = key;
            rv.DefaultAPIConfiguration = CreateDefaultAPIConfiguration(rv);
            rv.Messages = LoadMessages(assembly, rv, attribute.MessageCatalogPaths);
            return(rv);
        }
예제 #11
0
        public async Task A_Schematic_with_an_action_that_was_stored_can_be_retrieved_with_a_valid_ConnectorKey()
        {
            var uniqueId = Guid.NewGuid().ToString();

            var          schematicName = uniqueId;
            var          machineId     = uniqueId;
            var          state         = "initialState";
            ConnectorKey connectorKey  = "log info";

            await Runner.WithContext(Context).RunScenarioAsync(
                _ => Given_host_configuration_is_applied(),
                _ => _.Given_a_Schematic_with_an_action_is_stored(uniqueId, state, connectorKey),
                _ => _.When_a_Schematic_with_an_action_is_retrieved(uniqueId),
                _ => _.Then_the_connector_key_should_have_a_valid_identifier(state, connectorKey));
        }
 private static ConnectorInfo FindConnectorInfo
     (ConnectorInfoManager manager,
     string version,
     string connectorName)
 {
     foreach (ConnectorInfo info in manager.ConnectorInfos)
     {
         ConnectorKey key = info.ConnectorKey;
         if (version.Equals(key.BundleVersion) &&
             connectorName.Equals(key.ConnectorName))
         {
             //intentionally ineffecient to test
             //more code
             return(manager.FindConnectorInfo(key));
         }
     }
     return(null);
 }
예제 #13
0
        public IStateBuilder <TState, TInput> WithPrecondition(ConnectorKey connectorKey, System.Action <IPreconditionBuilder> precondition = null)
        {
            if (connectorKey == null)
            {
                throw new ArgumentNullException(nameof(connectorKey));
            }
            if (string.IsNullOrWhiteSpace(connectorKey.Identifier))
            {
                throw new ArgumentException("ConnectorKey must have a valid value", nameof(connectorKey));
            }

            var preconditionBuilder = new PreconditionBuilder(connectorKey);

            precondition?.Invoke(preconditionBuilder);

            Precondition = preconditionBuilder;

            return(this);
        }
예제 #14
0
        /// <summary>
        /// Resolves a Precondition Connector, given a <see cref="ConnectorKey"/>.
        /// </summary>
        public virtual IPrecondition <TState, TInput> ResolvePrecondition(ConnectorKey connectorKey)
        {
            if (connectorKey == null)
            {
                throw new ArgumentNullException(nameof(connectorKey));
            }

            do
            {
                try
                {
                    if (!Preconditions.TryGetValue(connectorKey.Identifier, out var precondition))
                    {
                        throw new ConnectorResolutionException($"No Precondition exists matching connectorKey: \"{connectorKey.Identifier}\".");
                    }

                    return(precondition);
                }
                catch (ConnectorResolutionException)
                {
                    var connectorType = Type.GetType(connectorKey.Identifier);

                    if (connectorType != null)
                    {
                        Agent.Configuration.Register(registrar =>
                                                     registrar.RegisterConnector(connectorType)
                                                     .WithConfiguration(new ConnectorConfiguration(connectorKey.Identifier)));

                        var precondition = (Agent.Configuration as HostConfiguration).Container
                                           .Resolve <IPrecondition <TState, TInput> >(connectorKey.Identifier);

                        Preconditions.TryAdd(connectorKey.Identifier, precondition);

                        continue;
                    }

                    throw;
                }
            }while (true);
        }
예제 #15
0
        /// <summary>
        /// Resolves a Precondition Connector, given a <see cref="ConnectorKey"/>.
        /// </summary>
        public virtual IPrecondition <TState, TInput> ResolvePrecondition(ConnectorKey connectorKey)
        {
            if (connectorKey == null)
            {
                throw new ArgumentNullException(nameof(connectorKey));
            }

            do
            {
                try
                {
                    if (!Preconditions.TryGetValue(connectorKey.Identifier, out var precondition))
                    {
                        throw new ConnectorResolutionException($"No Precondition exists matching connectorKey: \"{connectorKey.Identifier}\".");
                    }

                    return(precondition);
                }
                catch (ConnectorResolutionException connectorResolutionException)
                {
                    var connectorType = Type.GetType(connectorKey.Identifier);

                    if (connectorType != null)
                    {
                        lock (SyncRoot)
                        {
                            IPrecondition <TState, TInput> precondition = null;

                            var resolutionExceptions = new List <Exception>
                            {
                                connectorResolutionException
                            };

                            for (var i = 0; i <= 1; i++)
                            {
                                try
                                {
                                    precondition = (Agent.Configuration as HostConfiguration).Container
                                                   .Resolve <IPrecondition <TState, TInput> >(connectorKey.Identifier);
                                }
                                catch (Exception ex)
                                {
                                    resolutionExceptions.Add(ex);

                                    Agent.Configuration.Register(registrar =>
                                                                 registrar.RegisterConnector(connectorType)
                                                                 .WithConfiguration(new ConnectorConfiguration(connectorKey.Identifier)));
                                }
                            }

                            if (precondition == null)
                            {
                                throw new AggregateException(
                                          message: "Precondition resolution failed even after best attempt re-register.",
                                          innerExceptions: resolutionExceptions);
                            }

                            Preconditions.TryAdd(connectorKey.Identifier, precondition);

                            continue;
                        }
                    }

                    throw;
                }
            }while (true);
        }
예제 #16
0
        public Task Then_the_connector_key_should_have_a_valid_identifier(TState state, ConnectorKey connectorKey)
        {
            Assert.NotNull(CurrentSchematic);
            Assert.NotNull(CurrentSchematic.States[state].Action.ConnectorKey.Identifier);
            Assert.Equal(connectorKey.Identifier, CurrentSchematic.States[state].Action.ConnectorKey.Identifier);

            return(Task.CompletedTask);
        }
예제 #17
0
        public async Task Given_a_Schematic_with_an_action_is_stored(string schematicName, TState state, ConnectorKey connectorKey)
        {
            var schematic = CurrentHost.Agent()
                            .CreateSchematic <TState, TInput>(schematicName)
                            .WithState(state, _ => _
                                       .AsInitialState()
                                       .WithAction(connectorKey))
                            .Build();

            await CurrentHost.Agent()
            .GetStateEngine <TState, TInput>()
            .StoreSchematicAsync(schematic);
        }