Beispiel #1
0
 public UseCaseHandler
     (OnCompleteCallback <TOutput> onComplete = null, OnStartCallback onStart = null, OnErrorCallback onError = null)
 {
     OnStart    = onStart;
     OnError    = onError;
     OnComplete = onComplete;
 }
Beispiel #2
0
        public UseCaseHandler <M> FromResult <M>(
            NextAction <M> action, OnCompleteCallback <M> onComplete = null, OnStartCallback onStart = null,
            OnErrorCallback onError = null)
        {
            M   result      = default;
            var nextHandler = new UseCaseHandler <M>();

            nextHandler.ExecutingTask = ExecutingTask?.ContinueWith(t =>
            {
                onStart?.Invoke();

                try
                {
                    result = action.Invoke(Result);

                    onComplete?.Invoke(result);
                }
                catch (Exception e)
                {
                    onError?.Invoke(e);
                }

                nextHandler.Result = result;
            });

            return(nextHandler);
        }
    public KeyframeInfo(float timeMu, float timeSigma, List <string> kfs, OnStartCallback onStart = null)
    {
        time = new Vector2(timeMu, timeSigma);

        keyframes = new List <KeyFrame>();
        foreach (var kf in kfs)
        {
            var obj = GameObject.Find(kf);
            if (obj != null)
            {
                {
                    var keyframe = obj.GetComponent <KeyFrame>();
                    if (keyframe != null)
                    {
                        keyframes.Add(keyframe);
                    }
                }

                for (int i = 0; i < obj.transform.childCount; i++)
                {
                    var child    = obj.transform.GetChild(i);
                    var keyframe = child.GetComponent <KeyFrame>();
                    if (keyframe != null)
                    {
                        keyframes.Add(keyframe);
                    }
                }
            }
        }

        this.onStart = onStart;
    }
        public void Connect()
        {
            if (this.connection != null && this.connection.IsOpen)
            {
                this.connection.Close();
            }

            var factory = new ConnectionFactory()
            {
                HostName = this.BrokerHostname,
                UserName = this.BrokerUsername,
                Password = this.BrokerPassword,
                Port     = this.BrokerPort
            };

            this.connection = factory.CreateConnection();
            var rmqChannel = this.connection.CreateModel();

            rmqChannel.ExchangeDeclare(exchange: "shift_control_exchange", type: "fanout");

            var queueName = rmqChannel.QueueDeclare().QueueName;

            rmqChannel.QueueBind(queue: queueName,
                                 exchange: "shift_control_exchange",
                                 routingKey: "shift_control_key");

            var consumer = new EventingBasicConsumer(rmqChannel);

            consumer.Received += (model, ea) =>
            {
                var body = ea.Body;
                var data = Encoding.UTF8.GetString(body);

                JObject control_message = JObject.Parse(data);

                if (ea.BasicProperties.CorrelationId == "links_data")
                {
                    var is_master   = (bool)control_message["is_master"];
                    var routing_key = (string)control_message["routing_key"];

                    if (is_master && !string.IsNullOrWhiteSpace(routing_key))
                    {
                        if (this.StartingUp)
                        {
                            this.StartingUp         = false;
                            this.TopologyRoutingKey = routing_key;

                            OnStartCallback?.Invoke(routing_key);
                        }

                        if (routing_key != this.TopologyRoutingKey)
                        {
                            this.TopologyRoutingKey = routing_key;

                            OnTopologyQueueChangeCallback?.DynamicInvoke(routing_key);
                        }
                    }
                }
            };

            rmqChannel.BasicConsume(queue: queueName, consumer: consumer, autoAck: true);
        }