Esempio n. 1
0
 internal Broker(Brokers parent, string name, AssetClass assetClass)
 {
     this.parent     = parent;
     this.name       = name;
     this.assetClass = assetClass;
     strategies      = new BrokerStrategies(this);
 }
Esempio n. 2
0
        public async Task <IActionResult> PutBrokers(int id, Brokers brokers)
        {
            if (id != brokers.Id)
            {
                return(BadRequest());
            }

            _context.Entry(brokers).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BrokersExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(brokers));
        }
Esempio n. 3
0
        /// <summary>选择队列</summary>
        /// <returns></returns>
        public MessageQueue SelectQueue()
        {
            if (_robin == null)
            {
                var list = Brokers.Where(e => e.Permission.HasFlag(Permissions.Write) && e.WriteQueueNums > 0).ToList();
                if (list.Count == 0)
                {
                    return(null);
                }

                var total = list.Sum(e => e.WriteQueueNums);
                if (total <= 0)
                {
                    return(null);
                }

                _brokers = list;
                _robin   = new WeightRoundRobin(list.Select(e => e.WriteQueueNums).ToArray());
            }

            // 构造排序列表。希望能够均摊到各Broker
            var idx = _robin.Get(out var times);
            var bk  = _brokers[idx];

            return(new MessageQueue {
                BrokerName = bk.Name, QueueId = (times - 1) % bk.WriteQueueNums
            });
        }
Esempio n. 4
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="Cluster" /> class.
 /// </summary>
 /// <param name="brokers">
 ///     The set of active brokers.
 /// </param>
 public Cluster(IEnumerable <Broker> brokers) : this()
 {
     foreach (var broker in brokers)
     {
         Brokers.Add(broker.Id, broker);
     }
 }
Esempio n. 5
0
        /// <summary>获取代理客户端</summary>
        /// <param name="name"></param>
        /// <returns></returns>
        protected BrokerClient GetBroker(String name)
        {
            if (_Brokers.TryGetValue(name, out var client))
            {
                return(client);
            }

            var bk = Brokers?.FirstOrDefault(e => name == null || e.Name == name);

            if (bk == null)
            {
                return(null);
            }

            // 实例化客户端
            client = new BrokerClient(bk.Addresses)
            {
                Id     = ClientId,
                Name   = bk.Name,
                Config = this,
                Log    = Log,
            };

            // 尝试添加
            var client2 = _Brokers.GetOrAdd(name, client);

            if (client2 != client)
            {
                return(client2);
            }

            client.Start();

            return(client);
        }
Esempio n. 6
0
        public async Task <IActionResult> PostBrokers(Brokers brokers)
        {
            _context.Brokers.Add(brokers);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetBrokers", new { id = brokers.Id }, brokers));
        }
Esempio n. 7
0
        /// <summary>
        /// Gets a user-friendly string for Broker and TradeLink error messages.
        /// </summary>
        /// <param name="errorcode">The errorcode.</param>
        /// <returns></returns>
        public static string PrettyError(Brokers broker, int errorcode)
        {
            TL2 message = (TL2)errorcode;

            switch (message)
            {
            // tradelink messages
            case TL2.FEATURE_NOT_IMPLEMENTED: return("Feature not implemented yet.");

            case TL2.UNKNOWNSYM: return("Unknown symbol.");

            case TL2.UNKNOWNMSG: return("Unknown message.");

            case TL2.TL_CONNECTOR_MISSING: return("TradeLink Server not found.");

            case TL2.GOTNULLORDER: return("Unable to read order.");

            case TL2.OK: return("Ok");

            default:
                // broker-specific messages
                if (broker == Brokers.Assent)
                {
                    return(Enum.GetName(typeof(AnvilSendOrderError), errorcode));
                }
                if (broker == Brokers.Echo)
                {
                    return(Enum.GetName(typeof(SterlingSubmitOrderError), errorcode));
                }
                break;
            }
            return("Unknown error: " + errorcode.ToString());
        }
Esempio n. 8
0
        public ConsumerSettingsProcessedEvents()
        {
            Brokers.Add("localhost:9092");
            Topic = "bruteflow-events-after-pipeline";
            var dateTime = DateTime.Now;

            GroupId  = $"bruteflow-{dateTime:yyyyMMdd}-{dateTime:HH:mm:ss}";
            TestMode = true;
        }
Esempio n. 9
0
        public ConsumerSettingsTestEvents()
        {
            Brokers.Add("localhost:9092");
            Topic = "bruteflow-incoming-events";
            var dateTime = DateTime.Now;

            GroupId  = $"bruteflow-{dateTime:yyyyMMdd}-{dateTime:HH:mm:ss}";
            TestMode = true;
        }
Esempio n. 10
0
 /// <inheritdoc />
 public override int GetHashCode()
 {
     unchecked {
         var hashCode = Brokers?.GetHashCode() ?? 0;
         hashCode = (hashCode * 397) ^ (ControllerId?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (ClusterId?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Topics?.GetHashCode() ?? 0);
         return(hashCode);
     }
 }
Esempio n. 11
0
 public ActionResult addbroker(Brokers brokers)//ajouter de nouveaux courtiers
 {
     if (ModelState.IsValid)
     {
         dbobj.Brokers.Add(brokers);
         dbobj.SaveChanges();
         TempData["SuccessMessage"] = "C'est dans la boite !";
         return(RedirectToAction("BrokersList"));
     }
     return(View(brokers));
 }
Esempio n. 12
0
        public override string ToString()
        {
            var result = new StringBuilder();

            result.Append($"{{ \"OriginatingBrokerId\": {OriginatingBrokerId}, \"OriginatingBrokerName\": \"{OriginatingBrokerName}\", \"Brokers\": [");
            result.Append(string.Join(",", Brokers.Select(b => $" {b.ToString()}")));
            result.Append($" ], \"Topics\": [");
            result.Append(string.Join(",", Topics.Select(t => $" {t.ToString()}")));
            result.Append("] }");
            return(result.ToString());
        }
Esempio n. 13
0
        public Broker FindBrokerByPartition(String topic, Int32 partition)
        {
            var meta = TopicMetadatas.Where(x => x.TopicName.Equals(topic, StringComparison.OrdinalIgnoreCase))
                       .SelectMany(x => x.PartitionMetadatas)
                       .SingleOrDefault(x => x.PartitionId == partition);

            if (meta == null)
            {
                throw new ArgumentOutOfRangeException();
            }
            return(Brokers.SingleOrDefault(r => r.NodeId == meta.Leader));
        }
Esempio n. 14
0
        public string Pop(string topicName)
        {
            var broker = Brokers.FirstOrDefault(x => x.TopicName == topicName);

            if (broker == null)
            {
                return(null);
            }
            var msg = broker.GetMessage();

            return(msg);
        }
Esempio n. 15
0
 public ActionResult Edit(Brokers brk) //modifier et enregistrer les nouvelles données courtiers
 {
     if (ModelState.IsValid)
     {
         if (TryUpdateModel(brk))
         {
             dbobj.Entry(brk).State = EntityState.Modified;
             dbobj.SaveChanges();
             TempData["SuccessMessage"] = "Yeah c'est modifié !";
             return(RedirectToAction("BrokersList"));
         }
     }
     return(View(brk));
 }
Esempio n. 16
0
 /// <inheritdoc />
 public bool Equals(MetadataResponse other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Brokers.HasEqualElementsInOrder(other.Brokers) &&
            ControllerId == other.ControllerId &&
            ClusterId == other.ClusterId &&
            Topics.HasEqualElementsInOrder(other.Topics));
 }
        public SetupWindowVM()
        {
            this.CmdFinish = new DelegateCommand <Window>(new Action <Window>(this.CmdFinishImpl));
            this.CmdCancel = new DelegateCommand <Window>(new Action <Window>(this.CmdCancelImpl));
            this.CmdBack   = new DelegateCommand(this.CmdBackImpl);
            this.CmdNext   = new DelegateCommand <Window>(new Action <Window>(this.CmdNextImpl));
            this.CmdDonate = new DelegateCommand(this.CmdDonateImpl);

            if (Brokers != null && Brokers.Count() > 0)
            {
                CurrentBroker = Brokers.First().Name;
            }
            CurrentScreen = EScreens.Welcome;
            _setupProcess.PropertyChanged += ModelPropertyChanged;
        }
Esempio n. 18
0
        public void Push(string topicName, string message)
        {
            var broker = Brokers.FirstOrDefault(x => x.TopicName == topicName);

            if (broker is null)
            {
                broker = new Broker(topicName);
                Brokers.Add(broker);
            }

            broker.AddMessage(message);
            new Thread(() => MsgReceived(topicName, message))
            {
                IsBackground = true
            }.Start();
        }
Esempio n. 19
0
        /// <summary>获取代理客户端</summary>
        /// <param name="name"></param>
        /// <returns></returns>
        protected BrokerClient GetBroker(String name)
        {
            if (_Brokers.TryGetValue(name, out var client))
            {
                return(client);
            }

            var bk = Brokers?.FirstOrDefault(e => name == null || e.Name == name);

            if (bk == null)
            {
                return(null);
            }

            lock (_Brokers)
            {
                if (_Brokers.TryGetValue(name, out client))
                {
                    return(client);
                }

                // 实例化客户端
                client = new BrokerClient(bk.Addresses)
                {
                    Id     = ClientId,
                    Name   = bk.Name,
                    Config = this,
                    Log    = Log,
                };

                client.Received += (s, e) =>
                {
                    e.Arg = OnReceive(e.Arg);
                };

                client.Start();

                // 尝试添加
                _Brokers.TryAdd(name, client);

                return(client);
            }
        }
Esempio n. 20
0
        public async Task <IActionResult> Create([Bind("Id,Name,Surname,BirthDate,PhoneNum,Adress,Passport,Email,Photo")] BrokerCreateEditModel brokerModel)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = null;
                if (brokerModel.Photo != null)
                {
                    string uploadFolder = Path.Combine(hostingEnvironment.WebRootPath, "brokerImages");
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + brokerModel.Photo.FileName;
                    string filePath   = Path.Combine(uploadFolder, uniqueFileName);
                    var    fileStream = new FileStream(filePath, FileMode.Create);
                    brokerModel.Photo.CopyTo(fileStream);
                    fileStream.Close();
                }
                if (brokerModel.Adress == null)
                {
                    brokerModel.Adress = "вул. Матеюка 20";
                }
                var client        = new MapsAPIClient("AIzaSyBfckBchOpn-lM4oJ9V9nBDBZmmlousIRQ");
                var geocodeResult = client.Geocoding.Geocode(brokerModel.Adress).Results.FirstOrDefault().Geometry.Location;

                Brokers newBroker = new Brokers
                {
                    Name         = brokerModel.Name,
                    Surname      = brokerModel.Surname,
                    BirthDate    = brokerModel.BirthDate,
                    PhoneNum     = brokerModel.PhoneNum,
                    Adress       = brokerModel.Adress,
                    GeoLatitude  = (Double)geocodeResult.Latitude,
                    GeoLongitude = (Double)geocodeResult.Longitude,
                    Passport     = brokerModel.Passport,
                    Email        = brokerModel.Email,
                    ImagePath    = uniqueFileName
                };
                _context.Add(newBroker);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(brokerModel));
        }
Esempio n. 21
0
        public void AddToQueue(string token, NotificationViewModel model, bool isTest)
        {
            lock (_notification)
            {
                _notification.IsTest = isTest;
                byte[] appleCertificate;
                string appleCertificatePassword;
                string gcmAuthorizationToken;
                using (var db = new ApplicationDbContext())
                {
                    var app = db.Apps.SingleOrDefault(p => p.AppToken == token);
                    if (app == null)
                    {
                        throw new UnauthorizedAccessException();
                    }
                    _notification.AppId      = app.Id;
                    gcmAuthorizationToken    = app.GcmAuthorizationToken;
                    appleCertificate         = app.AppleCertificate;
                    appleCertificatePassword = app.AppleCertificatePassword;
                }

                _notification.Json         = model.Json;
                _notification.DeviceTokens = new List <NotificationDeviceToken>();
                _notification.CreateDate   = DateTime.Now;

                foreach (var registrationId in model.AndroidRegistrationIds)
                {
                    _notification.DeviceTokens.Add(new NotificationDeviceToken()
                    {
                        DeviceToken = registrationId,
                        Device      = Device.Android
                    });
                }


                foreach (var deviceToken in model.AppleDeviceTokens)
                {
                    _notification.DeviceTokens.Add(new NotificationDeviceToken()
                    {
                        DeviceToken = deviceToken,
                        Device      = Device.iOS
                    });
                }

                if (gcmAuthorizationToken != null && _notification.DeviceTokens.Where(p => p.Device == Device.Android).Count() > 0)
                {
                    var itemsPerBulk       = 1000;
                    var totalAndroidTokens = _notification.DeviceTokens
                                             .Where(p => p.Device == Device.Android).Count();
                    var bulks = totalAndroidTokens <= itemsPerBulk ? 1 : Convert.ToInt32(Math.Ceiling((double)totalAndroidTokens / itemsPerBulk));
                    for (var bulk = 0; bulk < bulks; bulk++)
                    {
                        var broker = new PushBroker();
                        SetEvents(broker);
                        broker.RegisterGcmService(new GcmPushChannelSettings(gcmAuthorizationToken), new PushServiceSettings()
                        {
                            NotificationSendTimeout = 60000
                        });
                        var tokens = _notification.DeviceTokens
                                     .Where(p => p.Device == Device.Android).Skip(itemsPerBulk * bulk).Take(itemsPerBulk)
                                     .Select(p => p.DeviceToken).ToList();
#if DEBUG
                        // Set test mode, when google will return a response without really send the notifications
                        broker.QueueNotification(new GcmNotification()
                                                 .ForDeviceRegistrationId(tokens)
                                                 .WithJson(_notification.Json)
                                                 .WithDryRun());
#else
                        if (isTest)
                        {
                            broker.QueueNotification(new GcmNotification()
                                                     .ForDeviceRegistrationId(tokens)
                                                     .WithJson(_notification.Json)
                                                     .WithDryRun());
                        }
                        else
                        {
                            broker.QueueNotification(new GcmNotification()
                                                     .ForDeviceRegistrationId(tokens)
                                                     .WithJson(_notification.Json));
                        }
#endif
                        Brokers.Add(broker);
                    }
                }
                if (appleCertificate != null && _notification.DeviceTokens.Where(p => p.Device == Device.iOS).Count() > 0)
                {
                    var broker = new PushBroker();
                    SetEvents(broker);
                    broker.RegisterAppleService(new ApplePushChannelSettings(appleCertificate, appleCertificatePassword));

                    foreach (var deviceToken in _notification.DeviceTokens.Where(p => p.Device == Device.iOS).Select(d => d.DeviceToken))
                    {
                        broker.QueueNotification(new AppleNotification()
                                                 .ForDeviceToken(deviceToken)
                                                 .WithAlert(JObject.Parse(_notification.Json)["message"].Value <string>())
                                                 .WithSound("sound.caf")
                                                 .WithCustomItem("data", _notification.Json));
                    }
                    Brokers.Add(broker);
                }
            }
        }
Esempio n. 22
0
        public IActionResult BrokersAdd(Brokers s)
        {
            var list = _bll.BrokersAdd(s);

            return(Ok(new { data = list, msg = list > 0 ? "添加成功" : "添加失败", state = list > 0 ? true : false }));
        }
Esempio n. 23
0
        public IActionResult BrokersUpt(Brokers s)
        {
            var list = _bll.BrokersUpt(s);

            return(Ok(new { data = list, msg = list > 0 ? "修改成功" : "修改失败", state = list > 0 ? true : false }));
        }
 public ProducerSettingsTestEvents()
 {
     Brokers.Add("localhost:9092");
     Topic = "bruteflow-incoming-events";
 }
 public ProducerSettingsProcessedEvents()
 {
     Brokers.Add("localhost:9092");
     Topic = "bruteflow-events-after-pipeline";
 }
Esempio n. 26
0
        /// <summary>
        /// 经纪人修改
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>z
        public int BrokersUpt(Brokers s)
        {
            string sql = $"update  Brokers set Bname='{s.Bname}',Btel='{s.Btel}',BserType='{s.BserType}',States='{s.States}' where Bid={s.Bid}";

            return(_db.ExecuteNonQuery(sql));
        }
Esempio n. 27
0
 /// <summary>
 /// Gets a user-friendly string for Broker and TradeLink error messages.
 /// </summary>
 /// <param name="errorcode">The errorcode.</param>
 /// <returns></returns>
 public static string PrettyError(Brokers broker, int errorcode)
 {
     TL2 message = (TL2)errorcode;
     switch (message)
     {
         // tradelink messages
         case TL2.FEATURE_NOT_IMPLEMENTED: return "Feature not implemented yet.";
         case TL2.UNKNOWNSYM: return "Unknown symbol.";
         case TL2.UNKNOWNMSG: return "Unknown message.";
         case TL2.TL_CONNECTOR_MISSING: return "TradeLink Server not found.";
         case TL2.GOTNULLORDER: return "Unable to read order.";
         case TL2.OK: return "Ok";
         default:
             // broker-specific messages
             if (broker == Brokers.Assent)
                 return Enum.GetName(typeof(AnvilSendOrderError), errorcode);
             if (broker == Brokers.Echo)
                 return Enum.GetName(typeof(SterlingSubmitOrderError), errorcode);
             break;
     }
     return "Unknown error: " + errorcode.ToString();
 }
Esempio n. 28
0
 public BrokerTypeAttribute(Brokers broker)
 {
     this.Broker = broker;
 }
Esempio n. 29
0
        /// <summary>
        /// 经纪人添加
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public int BrokersAdd(Brokers s)
        {
            string sql = $"insert into Brokers values ('{s.Bname}','{s.Btel}','{s.BserType}','{s.States}')";

            return(_db.ExecuteNonQuery(sql));
        }