Exemplo n.º 1
0
        public void Start(MessageQueueOption option)
        {
            var hostOption = new HostOption
            {
                ClientName  = option.ClientName,
                Host        = option.Host,
                Port        = option.Port,
                VirtualHost = option.VirtualHost,
                UserName    = option.UserName,
                Password    = option.Password
            };

            var exchangeOption = new ExchangeOption
            {
                ExchangeName  = option.ExchangeName,
                ExchangeType  = option.ExchangeType,
                IsAutoDeleted = option.ExchangeAutoDelete,
                IsDurable     = option.ExchangeDurable,
                RoutingKey    = option.RoutingKey
            };

            var queueOption = new QueueOption
            {
                QueueName     = option.QueueName,
                IsDurable     = option.QueueDurable,
                IsAutoDeleted = option.QueueAutoDelete,
                IsExclusive   = option.QueueExclusive,
            };

            Start(hostOption, exchangeOption);
        }
        public ActionResult Create()
        {
            ExchangeOption m = new ExchangeOption();

            m.status = true;
            return(View(m));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Start publisher
        /// </summary>
        /// <param name="hostOption"></param>
        /// <param name="exchangeOption"></param>
        public void Start(HostOption hostOption, ExchangeOption exchangeOption, QueueOption queueOption)
        {
            mConnectionFactory = new ConnectionFactory()
            {
                ClientProvidedName = hostOption.ClientName,
                HostName           = hostOption.Host,
                Port        = hostOption.Port,
                VirtualHost = hostOption.VirtualHost,
                UserName    = hostOption.UserName,
                Password    = hostOption.Password,
                RequestedConnectionTimeout = TimeSpan.FromSeconds(hostOption.ConnectionTimeout),
                RequestedHeartbeat         = TimeSpan.FromSeconds(hostOption.HeartBeat)
            };

            mExchangeName = exchangeOption.ExchangeName;
            mExchangeType = exchangeOption.ExchangeType;
            mRoutingKey   = exchangeOption.RoutingKey;

            mConnection = mConnectionFactory.CreateConnection();

            mChannel = mConnection.CreateModel();
            if (queueOption != null && !string.IsNullOrWhiteSpace(queueOption.QueueName))
            {
                mQueueName       = queueOption.QueueName;
                mQueueDurable    = queueOption.IsDurable;
                mQueueAutoDelete = queueOption.IsAutoDeleted;
                mQueueExclusive  = queueOption.IsExclusive;

                mChannel.QueueDeclare(mQueueName, mQueueDurable, mQueueExclusive, mQueueAutoDelete);
            }

            mChannel.ExchangeDeclare(mExchangeName, mExchangeType);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Convert HostOption & ExchangeOption & QueueOption to MessageQueueOption
        /// </summary>
        /// <param name="option"></param>
        /// <returns></returns>
        protected (HostOption, ExchangeOption, QueueOption) ConvertOption(MessageQueueOption option)
        {
            var hostOption = new HostOption
            {
                ClientName  = option.ClientName,
                Host        = option.Host,
                Port        = option.Port,
                VirtualHost = option.VirtualHost,
                UserName    = option.UserName,
                Password    = option.Password
            };

            var exchangeOption = new ExchangeOption
            {
                ExchangeName  = option.ExchangeName,
                ExchangeType  = option.ExchangeType,
                IsAutoDeleted = option.ExchangeAutoDelete,
                IsDurable     = option.ExchangeDurable,
                RoutingKey    = option.RoutingKey
            };

            var queueOption = new QueueOption
            {
                ConsumerTag   = option.CustomerTag,
                IsAutoDeleted = option.QueueAutoDelete,
                IsDurable     = option.QueueDurable,
                IsExclusive   = option.QueueExclusive,
                QueueName     = option.QueueName,
                AutoAck       = option.QueueAutoAck
            };

            return(hostOption, exchangeOption, queueOption);
        }
        public void Edit(ExchangeOption entity)
        {
            var findItem = GetById(entity.Id);

            if (findItem != null)
            {
                var index = ExchangeOptions.IndexOf(findItem);
                ExchangeOptions[index] = entity;
            }
        }
        public ActionResult Edit(int id = 0)
        {
            ExchangeOption exchangeoption = db.ExchangeOptions.Find(id);

            if (exchangeoption == null)
            {
                return(HttpNotFound());
            }
            return(View(exchangeoption));
        }
Exemplo n.º 7
0
        public static string ExchangeOption([ExcelArgument("MathObject Id")] string id,
                                            [ExcelArgument("Id of stock 1")] string stock1Id,
                                            [ExcelArgument("Id of stock 2")] string stock2Id,
                                            [ExcelArgument("Correlation of two stocks")] double rho,
                                            [ExcelArgument("Option maturity")] double maturity)
        {
            var stock1 = Environment[stock1Id].To <Stock>();
            var stock2 = Environment[stock2Id].To <Stock>();

            Environment[id] = new ExchangeOption(id, stock1, stock2, rho, maturity);
            return(id);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Start consume
        /// </summary>
        /// <param name="hostOption"></param>
        /// <param name="exchangeOption"></param>
        /// <param name="queueOption"></param>
        public void Start(HostOption hostOption, ExchangeOption exchangeOption, QueueOption queueOption)
        {
            BindQueue(hostOption, exchangeOption, queueOption);

            //consuming by event
            mEventConsumer = new EventingBasicConsumer(mChannel);

            //registe events
            mEventConsumer.Received   += Consumer_Received;
            mEventConsumer.Registered += Consumer_Registered;
            mEventConsumer.Shutdown   += Consumer_Shutdown;

            mLastConsumerTag = mChannel.BasicConsume(mQueueName, mIsAutoAck, mLastConsumerTag, mEventConsumer);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ExchangeOption exchangeoption = db.ExchangeOptions.Find(id);

            db.ExchangeOptions.Remove(exchangeoption);
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                Session["FlashMessage"] = "Failed to delete exchange destination." + e.Message;
                return(View(exchangeoption));
            }
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit(ExchangeOption exchangeoption)
 {
     if (ModelState.IsValid)
     {
         db.Entry(exchangeoption).State = EntityState.Modified;
         try
         {
             db.SaveChanges();
         }
         catch (Exception e)
         {
             Session["FlashMessage"] = "Failed to edit exchange destination." + e.Message;
             return(View(exchangeoption));
         }
         return(RedirectToAction("Index"));
     }
     return(View(exchangeoption));
 }
        public ActionResult Create(ExchangeOption exchangeoption)
        {
            if (ModelState.IsValid)
            {
                db.ExchangeOptions.Add(exchangeoption);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    Session["FlashMessage"] = "Failed to create exchange destination." + e.Message;
                    return(View(exchangeoption));
                }
                return(RedirectToAction("Index"));
            }

            return(View(exchangeoption));
        }
Exemplo n.º 12
0
        private static void Demo_DynamicOptionsPricing()
        {
            var s1  = new Stock("s1", price: 100, sigma: 0.2, divd: 0.03);
            var s2  = new Stock("s2", price: 120, sigma: 0.3, divd: 0.02);
            var eo  = new ExchangeOption("eo", s1, s2, rho: 0.5, maturity: 1);
            var deo = new DeferredExchangeOption("deo", s1, s2, rho: 0.5, optionMaturity: 1, exchangeMaturity: 2);

            Console.WriteLine(s1);
            Console.WriteLine(s2);
            Console.WriteLine(eo);
            Console.WriteLine(deo);
            Console.WriteLine();

            s1.Price = 120.Wrap();
            s2.Divd  = 0.01.Wrap();
            eo.Rho   = 0.7.Wrap();
            Console.WriteLine(s1);
            Console.WriteLine(s2);
            Console.WriteLine(eo);
            Console.WriteLine(deo);
            Console.WriteLine();
        }
Exemplo n.º 13
0
 /// <summary>
 /// 声明交换机
 /// </summary>
 /// <param name="channel"></param>
 internal void ExchangeDeclare(IModel channel)
 {
     ExchangeOption.ExchangeDeclare(channel);
 }
Exemplo n.º 14
0
        /// <summary>
        /// BindQueue
        /// </summary>
        /// <param name="hostOption"></param>
        /// <param name="exchangeOption"></param>
        /// <param name="queueOption"></param>
        protected void BindQueue(HostOption hostOption, ExchangeOption exchangeOption, QueueOption queueOption)
        {
            mHostOption     = hostOption;
            mExchangeOption = exchangeOption;
            mQueueOption    = queueOption;

            mQueueName = queueOption.QueueName;
            mIsAutoAck = queueOption.AutoAck;

            mLastConsumerTag = queueOption.ConsumerTag;
            if (string.IsNullOrWhiteSpace(mLastConsumerTag))
            {
                mLastConsumerTag = string.Empty;
            }

            try
            {
                var factory = new ConnectionFactory()
                {
                    ClientProvidedName = hostOption.ClientName,
                    HostName           = hostOption.Host,
                    Port        = hostOption.Port,
                    VirtualHost = hostOption.VirtualHost,
                    UserName    = hostOption.UserName,
                    Password    = hostOption.Password,

                    RequestedConnectionTimeout = TimeSpan.FromSeconds(hostOption.ConnectionTimeout),
                    RequestedHeartbeat         = TimeSpan.FromSeconds(hostOption.HeartBeat)
                };

                mConnection = factory.CreateConnection();

                mChannel = mConnection.CreateModel();

                mChannel.ExchangeDeclare(exchangeOption.ExchangeName, exchangeOption.ExchangeType);
                mChannel.QueueDeclare(queueOption.QueueName, queueOption.IsDurable, queueOption.IsExclusive, queueOption.IsAutoDeleted);
                mChannel.QueueBind(queueOption.QueueName, exchangeOption.ExchangeName, exchangeOption.RoutingKey);
                mChannel.BasicQos(0, queueOption.Qos, false);
            }
            catch (BrokerUnreachableException bex)
            {
                ConnectFail?.Invoke(this, new ConnectionFailEventArgs {
                    Message = bex.Message
                });
            }
            catch (ConnectFailureException cex)
            {
                ConnectFail?.Invoke(this, new ConnectionFailEventArgs {
                    Message = cex.Message
                });
            }
            catch (SocketException sex)
            {
                ConnectFail?.Invoke(this, new ConnectionFailEventArgs {
                    Message = sex.Message
                });
            }
            catch (Exception ex)
            {
                UnknowError?.Invoke(this, new UnknownExceptionEventArgs {
                    Message = ex.Message
                });
            }
        }
 protected BaseExchangeSerialPort(ITransport serailPort, IBackground background, ExchangeOption exchangeOption)
 {
     _serailPort    = serailPort;
     _background    = background;
     ExchangeOption = exchangeOption;
 }
 public void Add(ExchangeOption entity)
 {
     entity.Id = CalcMaxId() + 1;
     ExchangeOptions.Add(entity);
 }
Exemplo n.º 17
0
 public void Start(HostOption hostOption, ExchangeOption exchangeOption)
 {
     Start(hostOption, exchangeOption, null);
 }
        public async Task AddAsync(ExchangeOption entity)
        {
            await Task.CompletedTask;

            Add(entity);
        }
 public ByRulesExchangeSerialPort(ISerailPort serailPort, IBackground background, ExchangeOption exchangeOption)
     : base(serailPort, background, exchangeOption)
 {
 }
 public void Delete(ExchangeOption entity)
 {
     ExchangeOptions.Remove(entity);
 }
        public async Task DeleteAsync(ExchangeOption entity)
        {
            await Task.CompletedTask;

            Delete(entity);
        }
        public async Task EditAsync(ExchangeOption entity)
        {
            await Task.CompletedTask;

            Edit(entity);
        }
Exemplo n.º 23
0
 //protected
 public BaseExchangeHttp(IHttp httpTransport, IBackground background, ExchangeOption exchangeOption)
 {
     _httpTransport = httpTransport;
     _background    = background;
     ExchangeOption = exchangeOption;
 }
 public BaseExchangeTcpIp(ITcpIp tcpIp, IBackground background, ExchangeOption exchangeOption) // todo: ПОМЕНЯТЬ НА protected
 {
     _tcpIp         = tcpIp;
     _background    = background;
     ExchangeOption = exchangeOption;
 }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            IConsumer consumer = new Consumer(new SimpleJsonMessageDecoder());

            IConsumer <TestModel> consumerT = new Consumer <TestModel>(new SimpleJsonMessageDecoder());


            HostOption hostOption = new HostOption
            {
                ClientName  = "TestCreamCustardBun",
                Host        = "192.168.1.10",
                Port        = 5672,
                VirtualHost = "/dev",
                UserName    = "******",
                Password    = "******",
            };

            ExchangeOption exchangeOption = new ExchangeOption
            {
                ExchangeName  = "temp.exchange",
                ExchangeType  = "direct",
                IsDurable     = false,
                IsAutoDeleted = false,
                RoutingKey    = "temp.routingkey",
            };

            QueueOption queueOption = new QueueOption
            {
                IsDurable     = false,
                IsAutoDeleted = false,
                IsExclusive   = false,
                QueueName     = "temp.queue",
                ConsumerTag   = "",
            };

            MessageQueueOption option = new MessageQueueOption
            {
                ClientName         = "TestCreamCustardBun",
                Host               = "192.168.1.10",
                Port               = 5672,
                VirtualHost        = "/dev",
                UserName           = "******",
                Password           = "******",
                ExchangeName       = "temp.exchange",
                ExchangeType       = "direct",
                ExchangeDurable    = false,
                ExchangeAutoDelete = false,
                RoutingKey         = "temp.routingkey",
                QueueDurable       = false,
                QueueAutoDelete    = false,
                QueueExclusive     = false,
                QueueName          = "temp.queue",
                CustomerTag        = "",
                QueueAutoAck       = true
            };

            consumerT.MessageArrived += Consumer_MessageArrivedT;
            consumerT.Start(option);


            consumer.MessageArrived += Consumer_MessageArrived;
            consumer.Start(option);

            Console.ReadLine();
        }