Exemplo n.º 1
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.º 2
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;
                }
            });
        }