Exemplo n.º 1
0
 private static CompetitionItemRoiRow[] BuildResult(DbStoredProc proc, SportType sportType, int[] competitionUniqueIDs, BrokerType[] brokerTypes)
 {
     if (brokerTypes != null) {
         proc = proc.WithParam("argbrokerids", brokerTypes.Select(b => (short)b), DbType.Int16);
     }
     if (competitionUniqueIDs != null) {
         proc = proc.WithParam("argcompetitionuniqueids", competitionUniqueIDs, DbType.Int32);
     }
     if (sportType != SportType.Unknown) {
         proc = proc.WithParam("argsporttype", (short) sportType);
     }
     var data = proc.MultiRowExec(DatabaseActions.GetAdapter(TargetDB.MASTER), "fn_getbetroi").Data;
     var result = new CompetitionItemRoiRow[data.Count];
     for (var i = 0; i < result.Length; i++) {
         var row = data[i];
         var betData = (int[])row[1];
         var betIDs = new Dictionary<BetOddType, int>();
         for (var j = 0; j < betData.Length; j+=2) {
             betIDs[(BetOddType) (short) betData[j]] = betData[j + 1];
         }
         result[i] = new CompetitionItemRoiRow {
             ID = (int)row[0],
             BetIDs = betIDs,
             Roi = (float) row[2],
             RoiType = (RoiType) (short) row[3]
         };
     }
     return result;
 }
Exemplo n.º 2
0
 public PushTokenInfo(Unpacker unpacker)
 {
     BrokerType = (BrokerType)unpacker.UnpackByte();
     unpacker.Unpack(out ChallengeCode);
     unpacker.Unpack(out Token);
     unpacker.Unpack(out AccountId);
 }
Exemplo n.º 3
0
        private static List<RawCompetitor> CreateRawCompetitor(string[] names, List<RawCompetitor> competitorsRaw, BrokerType brokerType, LanguageType languageType, SportType sportType, GenderType genderType)
        {
            var existNames = competitorsRaw.Select(cr => cr.Name).ToList();
            names = names
                .Where(name => !existNames.Contains(name))
                .ToArray();
            if (names.Any()) {
                var lastCompetitorUniqueID = competitorsRaw.Any()
                    ? competitorsRaw.First().CompetitoruniqueID
                    : default(int);
                var raw = competitorsRaw;
                names
                    .Where(name => !raw.Any(c => c.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)))
                    .Each(name => {
                        RawCompetitor competitorRaw = null;
                        try {
                            competitorRaw = BrokerEntityIfaceCreator.CreateEntity<RawCompetitor>(brokerType, languageType, sportType, genderType, LinkEntityStatus.Unlinked, new[] { name },
                                competitor => {
                                    if (lastCompetitorUniqueID != default(int)) {
                                        competitor.CompetitoruniqueID = lastCompetitorUniqueID;
                                        competitor.Linkstatus = LinkEntityStatus.LinkByStatistics | LinkEntityStatus.Linked;
                                    }
                                });
                            competitorRaw.Save();
                            raw.Add(competitorRaw);
                        } catch (Exception ex) {
                            _logger.Error("{0}\r\n{1}", competitorRaw?.ToString(), ex);
                            throw;
                        }
                    });
            }

            return competitorsRaw;
        }
Exemplo n.º 4
0
 public static RawCompetitionItem GetCompetitionItem(BrokerType brokerType, RawTemplateObj<CompetitorParsedTransport>[] competitors, RawTemplateObj<CompetitionSpecifyTransport> competitionSpecifyTransport, DateTime eventDateUtc, DateTime utcNow)
 {
     var competitionItem = RawCompetitionItem.DataSource
                 .WhereEquals(RawCompetitionItem.Fields.Rawcompetitorid1, competitors[0].RawObject.ID)
                 .WhereEquals(RawCompetitionItem.Fields.Rawcompetitorid2, competitors[1].RawObject.ID)
                 .WhereEquals(RawCompetitionItem.Fields.Sporttype, (short)competitionSpecifyTransport.Object.SportType)
                 .WhereEquals(RawCompetitionItem.Fields.Brokerid, (short)brokerType)
                 .WhereEquals(RawCompetitionItem.Fields.Languagetype, (short)competitionSpecifyTransport.Object.LanguageType)
                 .WhereEquals(RawCompetitionItem.Fields.RawcompetitionID, competitionSpecifyTransport.RawObject.ParentID)
                 .WhereEquals(RawCompetitionItem.Fields.RawcompetitionspecifyID, competitionSpecifyTransport.RawObject.ID)
                 .Where(eventDateUtc > DateTime.MinValue
                     ? new DaoFilterAnd(
                         new DaoFilter(RawCompetitionItem.Fields.Dateeventutc, Oper.GreaterOrEq, eventDateUtc.AddDays(-1.5)),
                         new DaoFilter(RawCompetitionItem.Fields.Dateeventutc, Oper.LessOrEq, eventDateUtc.AddDays(1.5))
                     )
                     : new DaoFilterAnd(
                         new DaoFilter(RawCompetitionItem.Fields.Dateeventutc, Oper.GreaterOrEq, utcNow.AddDays(-1.5)),
                         new DaoFilter(RawCompetitionItem.Fields.Dateeventutc, Oper.LessOrEq, utcNow.AddDays(1.5))
                     )
                 )
                 .Sort(RawCompetitionItem.Fields.ID, SortDirection.Desc)
                 .First(RawCompetitionItem.Fields.ID, RawCompetitionItem.Fields.Dateeventutc, RawCompetitionItem.Fields.Rawcompetitorid1, RawCompetitionItem.Fields.Rawcompetitorid2, RawCompetitionItem.Fields.RawcompetitionID, RawCompetitionItem.Fields.CompetitionitemID);
     if (eventDateUtc > DateTime.MinValue && competitionItem != null) {
         if (Math.Abs((competitionItem.Dateeventutc - eventDateUtc).TotalMinutes) > 5) {
             competitionItem.Dateeventutc = eventDateUtc;
             competitionItem.Save();
         }
     }
     return competitionItem;
 }
Exemplo n.º 5
0
 private static List<RawCompetitor> GetRawCompetitorInt(BrokerType brokerType, LanguageType languageType, SportType sportType, GenderType genderType, string[] names)
 {
     if (genderType == GenderType.Unknown) {
         _logger.Error("{0}: {1}", names.StrJoin(", "), genderType);
     }
     var competitorsRaw = RawCompetitor.DataSource.FilterByLanguage(languageType).FilterBySportType(sportType).FilterByBroker(brokerType)
                                         .FilterByNameCompetitor(names)
                                         .FilterByGender(genderType,
                 RawCompetitor.Fields.CompetitoruniqueID,
                 RawCompetitor.Fields.Name,
                 RawCompetitor.Fields.Linkstatus);
     if (competitorsRaw.Count > 1) {
         var groupBy = competitorsRaw.Where(c => c.CompetitoruniqueID != default(int)).GroupBy(c => c.CompetitoruniqueID).ToArray();
         if (groupBy.Length > 1) {
             _logger.Error("{0} {1} {2} {3} {4} <=> {5}", brokerType, sportType, genderType,
                 competitorsRaw.Select(cr => cr.ID).StrJoin(", "), names.StrJoin(", "), groupBy.Select(g => g.Select(ge => ge.Name).StrJoin(", ")).StrJoin(" | "));
             return groupBy.First().ToList();
         }
         if (groupBy.Length == 1) {
             foreach (var rawCompetitor in competitorsRaw.Where(cr => cr.CompetitoruniqueID == default(int))) {
                 rawCompetitor.CompetitoruniqueID = groupBy[0].Key;
                 rawCompetitor.Save();
             }
         }
     }
     return CreateRawCompetitor(names, competitorsRaw, brokerType, languageType, sportType, genderType);
 }
Exemplo n.º 6
0
 public PushTokenInfo(BrokerType brokerType, string token, long accountId, long challengeCode)
 {
     BrokerType    = brokerType;
     ChallengeCode = challengeCode;
     Token         = token;
     AccountId     = accountId;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Get broker model based on input
        /// </summary>
        /// <param name="accounttype"></param>
        /// <param name="brokertype"></param>
        /// <returns></returns>
        public static BrokerModel GetBroker(AccountType accounttype, BrokerType brokertype)
        {
            //defaults
            LatencyModel  latencymodel  = new FixedLatencyModel(0);
            SlippageModel slippagemodel = new FixedAbsoluteSlippageModel(0);

            //Build return object
            switch (brokertype)
            {
            case BrokerType.Binance:
                return(new BinanceBrokerModel(accounttype, latencymodel, slippagemodel));

            case BrokerType.Bittrex:
                return(new BittrexBrokerModel(accounttype, latencymodel, slippagemodel));

            case BrokerType.Robinhood:
                return(new RobinHoodBrokerModel(accounttype, latencymodel, slippagemodel));

            case BrokerType.HitBtc:
                return(new HitBtcBrokerModel(accounttype, latencymodel, slippagemodel));

            case BrokerType.Cobinhood:
                return(new CobinHoodBrokerModel(accounttype, latencymodel, slippagemodel));

            case BrokerType.FreeTrade:
                return(new CobinHoodBrokerModel(accounttype, latencymodel, slippagemodel));

            default:
                throw new Exception($"Unknown broker type {brokertype}");
            }
        }
Exemplo n.º 8
0
 public static CompetitionItemRoiRow[] GetDataForCompetitionItem(int competitionItemID, BrokerType[] brokerTypes = null, int limitRows = 1)
 {
     var proc = new DbStoredProc()
         .NotRepeatable()
         .WithParam("argcompetitionitemid", competitionItemID)
         .WithParam("arglimittocompetition", limitRows);
     return BuildResult(proc, SportType.Unknown, null, brokerTypes);
 }
Exemplo n.º 9
0
 public static CompetitionItemRoiRow[] GetDataForDate(DateTime fromDate, DateTime toDate, SportType sportType = SportType.Unknown, int[] competitionUniqueIDs = null, BrokerType[] brokerTypes = null)
 {
     var proc = new DbStoredProc()
         .NotRepeatable()
         .WithParam("argcompetitionmindate", fromDate)
         .WithParam("argcompetitionmaxdate", toDate);
     return BuildResult(proc, sportType, competitionUniqueIDs, brokerTypes);
 }
Exemplo n.º 10
0
 public AvailableBrokerInfo(string broker, string dataFeed, List <string> accounts, string url, BrokerType brokerType)
 {
     BrokerName   = broker;
     DataFeedName = dataFeed;
     Accounts     = accounts;
     Url          = url;
     BrokerType   = brokerType;
 }
Exemplo n.º 11
0
 private static BrokerRole BrokerTypeToBrokerRole(BrokerType brokerType)
 {
     return(brokerType == BrokerType.AgentBroker
             ? BrokerRole.AgentBroker
             : brokerType == BrokerType.ResellerBroker
                 ? BrokerRole.ResellerBroker
                 : BrokerRole.NoBroker);
 }
Exemplo n.º 12
0
 /// <summary>
 /// Sets any broker in the in-memory configuration.
 /// </summary>
 public MessagingConfigBuilder WithBroker(string brokerName, BrokerType configType, Dictionary <string, string> configurations, bool setAsDefault = false)
 {
     _config.SetBroker(brokerName, GetBrokerConfigType(configType), configurations);
     if (setAsDefault)
     {
         _config.DefaultBrokerName = brokerName;
     }
     return(this);
 }
Exemplo n.º 13
0
 /// <summary>
 /// 获取用户设置的登录有效时间(分钟)
 /// </summary>
 /// <param name="brokerAccount"></param>
 /// <param name="brokerType"></param>
 /// <returns>有效时间(分钟)</returns>
 public int GetLoginAvailableTime(string brokerAccount, BrokerType brokerType)
 {
     using (var conn = factory.Create(DatabaseName.DB_IQFTrade))
     {
         using (var reader = conn.QueryMultiple("proc_LoginLength_Get", new { brokerAccount, brokerType }, null, null, CommandType.StoredProcedure))
         {
             return(reader.Read <int>().FirstOrDefault());
         }
     }
 }
Exemplo n.º 14
0
 public static CompetitionItemRoiRow[] GetDataForNow(float minRoi = float.MinValue, SportType sportType = SportType.Unknown, int[] competitionUniqueIDs = null, BrokerType[] brokerTypes = null)
 {
     var proc = new DbStoredProc()
         .NotRepeatable();
     if (minRoi != float.MinValue) {
         proc = proc
             .WithParam("argroimin", minRoi);
     }
     return BuildResult(proc, sportType, competitionUniqueIDs, brokerTypes);
 }
Exemplo n.º 15
0
 public Brokers this[BrokerType type]
 {
     get
     {
         Brokers result = new Brokers();
         foreach (var brk in this)
         {
             if (brk.Value.BrokerType == type)
             {
                 result.Add(brk.Key, brk.Value);
             }
         }
         return(result);
     }
 }
Exemplo n.º 16
0
 public static RawCompetitionItem CreateCompetitionItem(BrokerType brokerType, RawTemplateObj<CompetitorParsedTransport>[] competitors, RawTemplateObj<CompetitionSpecifyTransport> competitionSpecifyTransport, DateTime eventDateUtc, DateTime utcNow)
 {
     RawCompetitionItem competitionItemRaw = null;
     if (competitionSpecifyTransport.RawObject.ID != default(int) && competitors[0].RawObject.ID != default(int) && competitors[0].RawObject.ID != default(int)) {
         competitionItemRaw = BrokerEntityIfaceCreator.CreateEntity<RawCompetitionItem>(brokerType, competitionSpecifyTransport.Object.LanguageType, competitionSpecifyTransport.Object.SportType,
             LinkEntityStatus.Unlinked, item => {
                 item.RawcompetitionID = competitionSpecifyTransport.RawObject.ParentID;
                 item.RawcompetitionspecifyID = competitionSpecifyTransport.RawObject.ID;
                 item.Rawcompetitorid1 = competitors[0].RawObject.ID;
                 item.Rawcompetitorid2 = competitors[1].RawObject.ID;
                 item.Dateeventutc = eventDateUtc != DateTime.MinValue ? eventDateUtc : utcNow;
             });
         competitionItemRaw.Save();
     }
     return competitionItemRaw;
 }
Exemplo n.º 17
0
        public void CreateMarketApi(BrokerType type)
        {
            switch (type)
            {
            case BrokerType.XSpeed:
                IMarketApi = new XMduserApi();
                break;

            case BrokerType.QDP:
                //MarketApi =
                break;

            default:
                throw new NotImplementedException();
            }
            ProgramTradeEvents.AddRspHandler(RspSpiModules.RtnMarket, OnMarketDataReturn);
        }
Exemplo n.º 18
0
        private Type GetBrokerConfigType(BrokerType brokerType)
        {
            switch (brokerType)
            {
            case BrokerType.ActiveMQ:
                return(typeof(ActiveMQConfig));

            case BrokerType.AmazonSQS:
                return(typeof(AmazonSQSConfig));

            case BrokerType.AzureQueue:
                return(typeof(AzureQueueConfig));

            case BrokerType.RabbitMQ:
                return(typeof(RabbitMQConfig));

            default:
                return(null);
            }
        }
Exemplo n.º 19
0
 /// <summary>
 /// 设置登录有效时间
 /// </summary>
 /// <param name="brokerAccount"></param>
 /// <param name="brokerType"></param>
 /// <param name="length">有效时间(分钟)</param>
 /// <returns></returns>
 public bool SetLoginAvailableTime(string brokerAccount, BrokerType brokerType, int minute, out string error)
 {
     error = string.Empty;
     using (var conn = factory.Create(DatabaseName.DB_IQFTrade))
     {
         var list = conn.Query("proc_LoginLength_Set", new { brokerAccount, brokerType, length = minute }, null, true, null, System.Data.CommandType.StoredProcedure).FirstOrDefault();
         var ret  = list as IDictionary <string, object>;
         if (ret == null || ret.Count != 2)
         {
             return(false);
         }
         var errorNo = (int)ret.Values.First();
         if (errorNo != 0)
         {
             error = ret.Values.ElementAt(1).ToString();
             return(false);
         }
     }
     return(true);
 }
        private static async Task <IBroker> GetInstalledBrokerAsync(CoreUIParent uIParent, ICoreLogger logger)
        {
            AndroidBrokerHelper brokerHelper = new AndroidBrokerHelper(Application.Context, logger);

            if (brokerHelper.IsBrokerInstalledAndInvokable(AuthorityType.Aad)) //authorityType is actually not used by the brokerHelper.IsBrokerInstalledAndInvokable
            {
                try
                {
                    var broker = new AndroidContentProviderBroker(uIParent, logger);
                    await broker.InitiateBrokerHandShakeAsync().ConfigureAwait(false);

                    s_installedBroker = BrokerType.ContentProvider;
                    logger.Info("[Android broker] Content provider broker is available and will be used.");
                    return(broker);
                }
                catch (Exception exContentProvider)
                {
                    logger.Error("[Android broker] Unable to communicate with the broker via Content Provider. Attempting to fall back to account manager communication.");
                    logger.Error(exContentProvider.Message);

                    try
                    {
                        var broker = new AndroidAccountManagerBroker(uIParent, logger);
                        await broker.InitiateBrokerHandshakeAsync().ConfigureAwait(false);

                        s_installedBroker = BrokerType.AccountManager;
                        logger.Info("[Android broker] Account manager broker is available and will be used.");
                        return(broker);
                    }
                    catch (Exception exAccountManager)
                    {
                        logger.Error("[Android broker] Unable to communicate with the broker via the Account manager.");
                        logger.Error(exAccountManager.Message);
                    }
                }
            }

            // Return a default broker in case no broker is installed to handle install URL
            return(new AndroidContentProviderBroker(uIParent, logger));
        }
Exemplo n.º 21
0
        public void CreateTradeApi(BrokerType type)
        {
            switch (type)
            {
            case BrokerType.XSpeed:
                ITradeApi = new XTradeApi();
                break;

            case BrokerType.QDP:
                ITradeApi = new QTradeApi();
                break;

            default:
                throw new NotImplementedException();
            }

            ProgramTradeEvents.AddRspHandler(RspSpiModules.FrontConnected, OnFrontConnected);
            ProgramTradeEvents.AddRspHandler(RspSpiModules.UserLogin, OnUserLogin);
            ProgramTradeEvents.AddRspHandler(RspSpiModules.QryPosition, OnRspQryPosition);
            ProgramTradeEvents.AddRspHandler(RspSpiModules.QryOrders, OnRspQryOrder);
            ProgramTradeEvents.AddRspHandler(RspSpiModules.OrderDeal, OnOrderDeal);
            ProgramTradeEvents.AddRspHandler(RspSpiModules.RtnOrder, OnOrderReturn);
        }
        public void UpdateDataBase(List <ParsedDataFromPage> PD, int key)
        {
            if (PD.Count == 0)
            {
                return;
            }
            BrokerType type = Bookmakers[key].Type;
            DataBase   DB   = new DataBase(this);

            switch (type)
            {
            case BrokerType.LAY: DB.UpLay(FootData, PD, key); break;

            case BrokerType.BACK: DB.UpBack(FootData, PD, key); break;

            case BrokerType.HANDICAP: DB.UpHand(FootData, PD, key); break;

            default: return;
            }
            if (DB.changecolor)
            {
                this.Dispatcher.Invoke((Action)(() => { BackgroundGrid.Background = new SolidColorBrush(Colors.Salmon); }));
            }
        }
Exemplo n.º 23
0
 private static RawCompetitionSpecify GetRawCompetitionSpecifyInt(BrokerType brokerType, LanguageType language,
     SportType sportType, GenderType genderDetected, string[] nameOrigin)
 {
     return RawCompetitionSpecify.DataSource.FilterByBroker(brokerType).FilterByLanguage(language).FilterBySportType(sportType)
         .FilterByNameCompetition(nameOrigin)
         .FilterByGender(genderDetected,
             RawCompetitionSpecify.Fields.CompetitionuniqueID,
             RawCompetitionSpecify.Fields.CompetitionspecifyuniqueID,
             RawCompetitionSpecify.Fields.Name,
             RawCompetitionSpecify.Fields.ID,
             RawCompetitionSpecify.Fields.RawCompetitionID)
         .FirstOrDefault();
 }
Exemplo n.º 24
0
 public RawCompetitorCacheKey(BrokerType brokerType, LanguageType languageType, SportType sportType, GenderType genderType, string[] names)
 {
     BrokerType = brokerType;
     LanguageType = languageType;
     SportType = sportType;
     GenderType = genderType;
     Names = names;
 }
        /// <summary>
        /// 获取帐号信息
        /// </summary>
        /// <param name="brokerType"></param>
        /// <param name="brokerAccount"></param>
        /// <returns></returns>
        public LoginAccountInfo GetAccountInfo(BrokerType brokerType, string brokerAccount)
        {
            string key = GetAccountKey(brokerType, brokerAccount);

            return(this.distributedCache.Get <LoginAccountInfo>(key));
        }
Exemplo n.º 26
0
 private IBrokerBase GetBroker(BrokerType brokerType) => BookPage.Instance.GetBrokerProvider(brokerType);
Exemplo n.º 27
0
 public BrokerData(BrokerType brokerType, LanguageType language, List<CompetitionParsed> competitions = null)
 {
     Broker = brokerType;
     Language = language;
     Competitions = competitions ?? new List<CompetitionParsed>();
 }
Exemplo n.º 28
0
        public CompetitionItemRawTransport GetCompetitionItem(ProcessStat competitorStat, BrokerType brokerType, RawTemplateObj<CompetitorParsedTransport>[] competitors, RawTemplateObj<CompetitionSpecifyTransport> competitionSpecifyTransport, DateTime eventDateUtc, GatherBehaviorMode algoMode, BrokerCompetitionSettings brokerSettings)
        {
            return InvokeSafeSingleCall(() => {
                var utcNow = DateTime.UtcNow;
                if (eventDateUtc > utcNow.AddDays(14) || competitors.Any(c => c.RawObject.ID == default(int))) {
                    return null;
                }
                var competitionItemRaw = new BrokerEntityBuilder<RawCompetitionItem>(competitorStat)
                    .SetupValidateObject(item => item.CompetitionitemID != default(int))
                    .SetupGetRaw(() => RawCompetitionItemHelper.GetCompetitionItem(brokerType, competitors, competitionSpecifyTransport, eventDateUtc, utcNow))
                    .SetupCreateRaw(() => RawCompetitionItemHelper.CreateCompetitionItem(brokerType, competitors, competitionSpecifyTransport, eventDateUtc, utcNow))
                    .SetupTryMatchRaw(GatherBehaviorMode.TryDetectAll, item => {
                        /*brokerSettings*/
                        var ciDs = CompetitionItem.DataSource
                            .Where(new DaoFilterOr(
                                new DaoFilterAnd(
                                    new DaoFilterEq(CompetitionItem.Fields.Competitoruniqueid1, competitors[0].Object.ID),
                                    new DaoFilterEq(CompetitionItem.Fields.Competitoruniqueid2, competitors[1].Object.ID)
                                    ),
                                new DaoFilterAnd(
                                    new DaoFilterEq(CompetitionItem.Fields.Competitoruniqueid2, competitors[0].Object.ID),
                                    new DaoFilterEq(CompetitionItem.Fields.Competitoruniqueid1, competitors[1].Object.ID)
                                    )
                                ))
                            .WhereEquals(CompetitionItem.Fields.Sporttype, (short)competitionSpecifyTransport.Object.SportType)
                            .Where(new DaoFilterOr(
                                new DaoFilterNull(CompetitionItem.Fields.CompetitionSpecifyUniqueID, true),
                                new DaoFilterEq(CompetitionItem.Fields.CompetitionSpecifyUniqueID, competitionSpecifyTransport.Object.ID)))
                            .Where(eventDateUtc > DateTime.MinValue
                                ? new DaoFilterAnd(
                                    new DaoFilter(CompetitionItem.Fields.Dateeventutc, Oper.GreaterOrEq, eventDateUtc.AddDays(-0.7)),
                                    new DaoFilter(CompetitionItem.Fields.Dateeventutc, Oper.LessOrEq, eventDateUtc.AddDays(0.7))
                                )
                                : new DaoFilterAnd(
                                    new DaoFilter(CompetitionItem.Fields.Dateeventutc, Oper.GreaterOrEq, utcNow.AddDays(-0.7)),
                                    new DaoFilter(CompetitionItem.Fields.Dateeventutc, Oper.LessOrEq, utcNow.AddDays(0.7))
                                )
                            )
                            .Sort(CompetitionItem.Fields.ID, SortDirection.Desc);
                        if (!brokerSettings.HasFlag(BrokerCompetitionSettings.NoCompareCompetitionUnique)) {
                            ciDs = ciDs
                                .WhereEquals(CompetitionItem.Fields.CompetitionuniqueID, competitionSpecifyTransport.Object.CompetitionUniqueID);
                        }
                        var ci = ciDs.First(CompetitionItem.Fields.ID);
                        if (ci != null) {
                            item.CompetitionitemID = ci.ID;
                            item.Linkstatus = LinkEntityStatus.LinkByStatistics | LinkEntityStatus.Linked;
                        }
                        return item;
                    })
                    .SetupCreateOriginal(algoMode, item => {
                        CreateCompetitionItem(competitors, competitionSpecifyTransport, eventDateUtc, utcNow, item);
                        return item;
                    })
                    .SetupFinally(item => {
                        if (algoMode.HasFlag(GatherBehaviorMode.CreateOriginalIfMatchedAll) && item.CompetitionitemID == default(int) &&
                                                                                                  competitionSpecifyTransport.Object.CompetitionUniqueID != default(int) &&
                                                                                                  //NOTE competitionSpecifyTransport.Object.CompetitionSpecifyUniqueID != default(int) &&
                                                                                                  competitors[0].Object.ID != default(int) &&
                                                                                                  competitors[1].Object.ID != default(int)) {
                            CreateCompetitionItem(competitors, competitionSpecifyTransport, eventDateUtc, utcNow, item);
                        }
                        item.Save();
                        return item;
                    })
                    .MakeObject();
                if (competitionItemRaw.CompetitionitemID == default(int)) {
                    return null;
                }
                var competitionItem = CompetitionItem.DataSource.GetByKey(competitionItemRaw.CompetitionitemID, CompetitionItem.Fields.ID, CompetitionItem.Fields.Dateeventutc, CompetitionItem.Fields.Competitoruniqueid1, CompetitionItem.Fields.Competitoruniqueid2, CompetitionItem.Fields.CompetitionSpecifyUniqueID);
                if (competitionSpecifyTransport.Object.ID != default(int) && competitionItem.CompetitionSpecifyUniqueID == default(int)) {
                    competitionItem.CompetitionSpecifyUniqueID = competitionSpecifyTransport.Object.ID;
                    competitionItem.Save();
                }

                if (eventDateUtc > DateTime.MinValue && ((algoMode & (GatherBehaviorMode.CreateOriginal | GatherBehaviorMode.CreateOriginalIfMatchedAll)) != 0)) {
                    if (Math.Abs((competitionItem.Dateeventutc - eventDateUtc).TotalMinutes) > 5) {
                        competitionItem.Dateeventutc = eventDateUtc;
                        competitionItem.Save();
                    }
                }

                return new CompetitionItemRawTransport {
                    CompetitionItemID = competitionItem.Competitoruniqueid1 == competitors[0].Object.ID &&
                                           competitionItem.Competitoruniqueid2 == competitors[1].Object.ID
                                    ? competitionItem.ID
                                    : -competitionItem.ID,
                    RawCompetitionItemID = competitionItemRaw.ID
                };
            }, null);
        }
Exemplo n.º 29
0
 public RawTemplateObj<CompetitorParsedTransport> GetCompetitor(ProcessStat competitorStat, BrokerType brokerType, LanguageType languageType, SportType sportType, GenderType genderType, string[] names, GatherBehaviorMode algoMode)
 {
     return InvokeSafeSingleCall(() => {
         names = names
             .Where(name => !string.IsNullOrWhiteSpace(name))
             .Select(name => {
                 var indexOf = name.IndexOf("(", StringComparison.InvariantCultureIgnoreCase);
                 var cleanedName = (indexOf > 0 ? name.Substring(0, indexOf) : name).Trim(_trimChars);
                 return cleanedName.RemoveDiacritics();
             })
             .Where(name => !string.IsNullOrWhiteSpace(name))
             .ToArray();
         if (!names.Any()) {
             throw new Exception("nameFull.IsNullOrWhiteSpace() && nameShort.IsNullOrWhiteSpace()");
         }
         var competitors = new BrokerEntityBuilder<List<RawCompetitor>>(competitorStat)
             .SetupValidateObject(competitorsRaw => competitorsRaw.SafeAny() && competitorsRaw.All(c => c.CompetitoruniqueID != default(int)))
             .SetupGetRaw(() => RawCompetitorHelper.GetRawCompetitor[new RawCompetitorHelper.RawCompetitorCacheKey(brokerType, languageType, sportType, genderType, names)])
             .SetupCreateOriginal(algoMode, list => {
                 var uniqueID = new CompetitorUnique {
                     IsUsed = true
                 };
                 uniqueID.Save();
                 var competitor = new Competitor {
                     CompetitoruniqueID = uniqueID.ID,
                     SportType = sportType,
                     Datecreatedutc = DateTime.UtcNow,
                     Languagetype = languageType,
                     Name = names[0],
                     Gendertype = genderType
                 };
                 competitor.Save();
                 list.Each(el => el.Linkstatus = LinkEntityStatus.Original | LinkEntityStatus.Linked);
                 return list;
             })
             .SetupFinally(list => {
                 var firstElement = list.First();
                 if (algoMode.HasFlag(GatherBehaviorMode.CreateNewLanguageName) && firstElement.CompetitoruniqueID != default(int) && !Competitor.DataSource
                             .WhereEquals(Competitor.Fields.CompetitoruniqueID, firstElement.CompetitoruniqueID)
                             .WhereEquals(Competitor.Fields.Languagetype, (short)languageType)
                             .IsExists()) {
                     new Competitor {
                         CompetitoruniqueID = firstElement.CompetitoruniqueID,
                         SportType = sportType,
                         Datecreatedutc = DateTime.UtcNow,
                         Languagetype = languageType,
                         Name = names[0],
                         Gendertype = genderType
                     }.Save();
                 }
                 list.Each(el => el.Save());
                 return list;
             })
             .MakeObject();
         return competitors.Any()
             ? competitors.Select(c => new RawTemplateObj<CompetitorParsedTransport> {
                 RawObject = {
                     ID = c.ID
                 },
                 Object = {
                     LanguageType = languageType,
                     SportType = sportType,
                     GenderType = genderType,
                     ID = c.CompetitoruniqueID
                 }
             }).First()
             : new RawTemplateObj<CompetitorParsedTransport>();
     }, new RawTemplateObj<CompetitorParsedTransport>());
 }
Exemplo n.º 30
0
 public RawTemplateObj<CompetitionSpecifyTransport> GetCompetitionSpecify(ProcessStat competitionStat, ProcessStat competitionSpecifyStat, BrokerType brokerType, LanguageType language, SportType sportType, string[] nameOrigin, CompetitionParsed competitionToSave, GatherBehaviorMode algoMode)
 {
     return InvokeSafeSingleCall(() => {
         var genderDetected = GenderDetectorHelper.Instance[nameOrigin];
         if (genderDetected == GenderType.Unknown) {
             _logger.Error("{0}: {1}", nameOrigin, genderDetected);
         }
         nameOrigin = CleanCompetitionName(nameOrigin);
         var rawCompetitionSpecify = new BrokerEntityBuilder<RawCompetitionSpecify>(competitionSpecifyStat)
             .SetupValidateObject(specify => true/*NOTE!! && specify.CompetitionSpecifyUniqueID != default(int)*/)
             .SetupGetRaw(() => RawCompetitionHelper.GetRawCompetitionSpecify[new RawCompetitionHelper.RawCompetitorSpecifyKey(brokerType, language, sportType, genderDetected, nameOrigin)])
             .SetupCreateRaw(() => RawCompetitionHelper.CreateCompetitionSpecify(competitionStat, brokerType, language, sportType, genderDetected, nameOrigin, competitionToSave, algoMode))
             .SetupCreateOriginal(algoMode, specify => {
                 if (specify.CompetitionSpecifyUniqueID == default(int)) {
                     var competitionSpecifyUnique = new CompetitionSpecifyUnique {
                         CompetitionuniqueID = specify.CompetitionuniqueID
                     };
                     competitionSpecifyUnique.Save();
                     specify.CompetitionSpecifyUniqueID = competitionSpecifyUnique.ID;
                     specify.Save();
                 }
                 var competitionSpecify = new CompetitionSpecify {
                     Datecreatedutc = DateTime.UtcNow,
                     Languagetype = language,
                     SportType = sportType,
                     Name = CompetitionHelper.ListStringToName(nameOrigin),
                     Gendertype = genderDetected,
                     CompetitionuniqueID = specify.CompetitionuniqueID
                 };
                 specify.CompetitionSpecifyUniqueID = competitionSpecify.CompetitionSpecifyUniqueID;
                 if (competitionSpecify.CompetitionuniqueID != specify.CompetitionuniqueID) {
                     _logger.Error("{0} != {1}. {2}. SKIP", competitionSpecify.CompetitionuniqueID, specify.CompetitionuniqueID, CompetitionHelper.ListStringToName(nameOrigin));
                     return null;
                 }
                 specify.Linkstatus = LinkEntityStatus.Original | LinkEntityStatus.Linked;
                 return specify;
             })
             .SetupFinally(specify => {
                 if (specify.CompetitionSpecifyUniqueID != default(int)) {
                     if (algoMode.HasFlag(GatherBehaviorMode.CreateNewLanguageName)) {
                         if (specify.CompetitionSpecifyUniqueID != default(int) &&
                             specify.CompetitionuniqueID != default(int) && !CompetitionSpecify.DataSource
                                 .WhereEquals(CompetitionSpecify.Fields.CompetitionSpecifyUniqueID, specify.CompetitionSpecifyUniqueID)
                                 .FilterByLanguage(language)
                                 .IsExists()) {
                             new CompetitionSpecify {
                                 Languagetype = language,
                                 Name = CompetitionHelper.ListStringToName(nameOrigin),
                                 CompetitionSpecifyUniqueID = specify.CompetitionSpecifyUniqueID,
                                 CompetitionuniqueID = specify.CompetitionuniqueID,
                                 Datecreatedutc = DateTime.UtcNow,
                                 Gendertype = genderDetected,
                                 SportType = sportType
                             }.Save();
                         }
                     }
                 }
                 specify.Save();
                 return specify;
             })
             .MakeObject();
         return RawCompetitionHelper.CreateCompetitionSpecifyRawObject(rawCompetitionSpecify.ID, rawCompetitionSpecify.RawCompetitionID, rawCompetitionSpecify, language, sportType, genderDetected);
     }, new RawTemplateObj<CompetitionSpecifyTransport>());
 }
Exemplo n.º 31
0
        public static RawCompetitionSpecify CreateCompetitionSpecify(ProcessStat competitionStat, BrokerType brokerType, LanguageType language, SportType sportType, GenderType genderDetected, string[] nameOrigin, CompetitionParsed competitionToSave, GatherBehaviorMode algoMode)
        {
            var nameOriginShort = CompetitionHelper.GetShortCompetitionName(nameOrigin, sportType);
            var competitionRaw = new BrokerEntityBuilder<RawCompetition>(competitionStat)
                .SetupValidateObject(rawCompetition => rawCompetition.CompetitionuniqueID != default(int))
                .SetupGetRaw(() => {
                    return RawCompetition.DataSource.FilterByBroker(brokerType).FilterByLanguage(language).FilterBySportType(sportType)
                        .FilterByNameCompetition(nameOriginShort)
                        .FilterByGender(genderDetected, RawCompetition.Fields.CompetitionuniqueID, RawCompetition.Fields.Linkstatus).FirstOrDefault();
                })
                .SetupCreateRaw(() => BrokerEntityIfaceCreator.CreateEntity<RawCompetition>(brokerType, language, sportType, genderDetected, LinkEntityStatus.Unlinked, nameOriginShort))
                .SetupCreateOriginal(algoMode, rawCompetition => {
                    var competition = Competition.DataSource.FilterByLanguage(language).FilterBySportType(sportType)
                        .FilterByNameCompetition(nameOriginShort)
                        .FilterByGender(genderDetected, Competition.Fields.CompetitionuniqueID)
                        .FirstOrDefault();
                    if (competition == null) {
                        var competitionUnique = new CompetitionUnique {
                            IsUsed = true
                        };
                        competitionUnique.Save();
                        competition = new Competition {
                            Datecreatedutc = DateTime.UtcNow,
                            Languagetype = language,
                            SportType = sportType,
                            Name = CompetitionHelper.ListStringToName(nameOriginShort),
                            Gendertype = genderDetected,
                            CompetitionuniqueID = competitionUnique.ID
                        };
                        competition.Save();
                    }
                    rawCompetition.CompetitionuniqueID = competition.CompetitionuniqueID;
                    rawCompetition.Linkstatus = LinkEntityStatus.Original | LinkEntityStatus.Linked;
                    return rawCompetition;
                })
                .SetupFinally(rawCompetition => {
                    if (algoMode.HasFlag(GatherBehaviorMode.CreateNewLanguageName)) {
                        if (rawCompetition.CompetitionuniqueID != default(int) && !Competition.DataSource
                            .WhereEquals(Competition.Fields.CompetitionuniqueID, rawCompetition.CompetitionuniqueID)
                            .FilterByLanguage(language)
                            .IsExists()) {
                            new Competition {
                                CompetitionuniqueID = rawCompetition.CompetitionuniqueID,
                                Datecreatedutc = DateTime.UtcNow,
                                Gendertype = genderDetected,
                                SportType = sportType,
                                Name = CompetitionHelper.ListStringToName(nameOriginShort),
                                Languagetype = language
                            }.Save();
                        }
                    }
                    rawCompetition.Save();
                    return rawCompetition;
                })
                .MakeObject();

            return BrokerEntityIfaceCreator.CreateEntity<RawCompetitionSpecify>(brokerType, language, sportType, genderDetected, LinkEntityStatus.Unlinked, nameOrigin, specify => {
                specify.RawCompetitionID = competitionRaw.ID;
                if (specify.CompetitionuniqueID == default(int) && competitionRaw.CompetitionuniqueID != default(int)) {
                    specify.CompetitionuniqueID = competitionRaw.CompetitionuniqueID;
                }
            });
        }
 private static string GetAccountKey(BrokerType brokerType, string accountID)
 {
     return(string.Format("IQFAccount:{0}:{1}", (int)brokerType, accountID));
 }
Exemplo n.º 33
0
        //Live Settings
        //TODO

        public BrokerConfigurationModel(BrokerType type)
        {
            Type = type;
        }
Exemplo n.º 34
0
 public FrontServers(BrokerType type)
 {
     BrokerType = type;
 }
Exemplo n.º 35
0
 public RawCompetitorSpecifyKey(BrokerType brokerType, LanguageType language, SportType sportType,
     GenderType genderDetected, string[] nameOrigin)
 {
     BrokerType = brokerType;
     Language = language;
     SportType = sportType;
     GenderDetected = genderDetected;
     NameOrigin = nameOrigin;
 }
Exemplo n.º 36
0
 /// <summary>
 /// Instantiates the builder with default configuration already
 /// </summary>
 /// <param name="defaultBrokerName">The broker name to set as default broker.</param>
 /// <param name="defaultBrokerConfigType">The broker service to set as default.</param>
 /// <param name="defaultBrokerSettings"></param>
 public MessagingConfigBuilder(string defaultBrokerName, BrokerType defaultBrokerConfigType, Dictionary <string, string> defaultBrokerSettings)
 {
     _config = new MessagingConfig(defaultBrokerName, GetBrokerConfigType(defaultBrokerConfigType), defaultBrokerSettings);
 }