Exemple #1
0
        public IList <ValidationSetting> GetListForProducts(List <int> productsIds)
        {
            using (var model = new gb_dvsstagingEntities())
            {
                var q = (from setting in model.val_validationsetting
                         join priority in model.val_priority on setting.PriorityId equals priority.Id
                         join product in model.dvs_product on setting.ProductId equals product.Id
                         where productsIds.Contains((int)setting.ProductId)
                         where setting.IsActive
                         select new ValidationSetting
                {
                    Id = setting.Id,
                    Name = setting.Name,
                    Description = setting.Description,
                    PriorityId = setting.PriorityId,
                    ProductId = setting.ProductId,
                    Expression = setting.Expression,
                    LastValidatedAt = setting.LastValidateAt,
                    Priority = new Priority
                    {
                        Id = priority.Id,
                        Name = priority.Name
                    },
                    Product = new Product
                    {
                        Id = product.Id,
                        Name = product.Name
                    },
                    IsSlackEnabled = setting.IsSlackEnabled,
                    SlackChannel = setting.SlackChannel
                }).ToList();

                return(q);
            }
        }
        public Dictionary <string, int> GetHistoricalDataByProductIdAndTimeFrame(int productId, DateTime from, DateTime to)
        {
            from = from.Date + new TimeSpan(0, 0, 0);
            to   = to.Date + new TimeSpan(23, 59, 59);

            using (var model = new gb_dvsstagingEntities())
            {
                model.Configuration.AutoDetectChangesEnabled = false;
                model.Configuration.ValidateOnSaveEnabled    = false;
                model.Database.CommandTimeout = ConnectionTimeout;

                List <DateTime> creations = null;

                creations = model.val_validationresult
                            .AsNoTracking()
                            .Where(res => res.IsActive && res.ProductId == productId && res.UpdatedOn >= from && res.UpdatedOn <= to)
                            .Select(x => x.UpdatedOn)
                            .ToList();

                var result = new Dictionary <string, int>();

                for (; to.CompareTo(from) >= 0; from = from.AddDays(1.0))
                {
                    result.Add(
                        from.ToString("yyyy-MM-dd"),
                        creations
                        .Count(creation => creation.Date.Equals(from.Date)));
                }

                return(result);
            }
        }
Exemple #3
0
        public IList <ValidationSetting> GetList()
        {
            using (var model = new gb_dvsstagingEntities())
            {
                var q = (from setting in model.val_validationsetting
                         join priority in model.val_priority on setting.PriorityId equals priority.Id
                         join product in model.dvs_product on setting.ProductId equals product.Id
                         where setting.IsActive
                         select new ValidationSetting
                {
                    Id = setting.Id,
                    Name = setting.Name,
                    Description = setting.Description,
                    ProductId = setting.ProductId,
                    PriorityId = setting.PriorityId,
                    Expression = setting.Expression,
                    LastValidatedAt = setting.LastValidateAt,
                    Priority = new Priority
                    {
                        Id = priority.Id,
                        Name = priority.Name
                    },
                    Product = new Product
                    {
                        Id = product.Id,
                        Name = product.Name
                    }
                }).ToList();

                return(q);
            }
        }
Exemple #4
0
        public int Update(ValidationSetting validationSetting)
        {
            using (var model = new gb_dvsstagingEntities())
            {
                val_validationsetting val_Setting = model.val_validationsetting.First(x => x.Id == validationSetting.Id);

                val_Setting.Name        = validationSetting.Name;
                val_Setting.Description = validationSetting.Description;

                val_Setting.PriorityId = validationSetting.PriorityId;
                val_Setting.ProductId  = validationSetting.ProductId;
                val_Setting.Expression = validationSetting.Expression;

                val_Setting.UpdatedBy = "Admin";
                val_Setting.UpdatedOn = DateTime.UtcNow;

                val_Setting.IsSlackEnabled = validationSetting.IsSlackEnabled;
                val_Setting.SlackChannel   = validationSetting.SlackChannel;

                model.Entry(val_Setting).State = EntityState.Modified;

                model.SaveChanges();

                return(val_Setting.Id);
            }
        }
Exemple #5
0
        public void BulkUpdate(IList <ArrivalMessage> arrivalMessages)
        {
            lock (thisLock)
            {
                using (var model = new gb_dvsstagingEntities())
                {
                    model.Database.CommandTimeout = 300;

                    foreach (ArrivalMessage arrivaleMessageIterator in arrivalMessages)
                    {
                        var val_message = model.dvs_arrivalmessage.Find(arrivaleMessageIterator.Id, arrivaleMessageIterator.ProductId);

                        if (val_message != null)
                        {
                            var arrivalMessage = arrivaleMessageIterator;

                            CopyFromTo(ref arrivalMessage, ref val_message);

                            model.Entry(val_message).State = EntityState.Modified;
                        }
                    }

                    model.SaveChanges();
                }
            }
        }
Exemple #6
0
        public void Update(ProductTree productTree)
        {
            lock (thisLock)
            {
                string xmlText;

                using (var textWriter = new StringWriter())
                {
                    new XmlSerializer(typeof(TreeNode)).Serialize(textWriter, productTree.Tree.core.data);

                    xmlText = textWriter.ToString();
                }

                using (var model = new gb_dvsstagingEntities())
                {
                    var productTreeModel = model.dvs_producttree.Find(productTree.Id);

                    productTreeModel.ProductId = productTree.ProductId;
                    productTreeModel.XmlText   = xmlText;
                    productTreeModel.UpdatedOn = DateTime.UtcNow;

                    model.Entry(productTreeModel).State = System.Data.Entity.EntityState.Modified;

                    model.SaveChanges();
                }
            }
        }
Exemple #7
0
        public int Insert(ValidationSetting validationSetting)
        {
            using (var model = new gb_dvsstagingEntities())
            {
                var val_valSetting = new val_validationsetting
                {
                    Name        = validationSetting.Name,
                    Description = validationSetting.Description,

                    PriorityId = validationSetting.PriorityId,
                    ProductId  = validationSetting.ProductId,
                    Expression = validationSetting.Expression,

                    CreatedBy = "Admin",
                    CreatedOn = DateTime.UtcNow,

                    UpdatedBy = "Admin",
                    UpdatedOn = DateTime.UtcNow,

                    IsSlackEnabled = validationSetting.IsSlackEnabled,
                    SlackChannel   = validationSetting.SlackChannel,

                    IsActive = true
                };
                model.val_validationsetting.Add(val_valSetting);

                model.SaveChanges();

                return(val_valSetting.Id);
            }
        }
Exemple #8
0
        public ProductTree GetItemByProductId(int productId)
        {
            lock (thisLock)
            {
                using (var model = new gb_dvsstagingEntities())
                {
                    var q = (from tree in model.dvs_producttree
                             where tree.IsActive
                             where tree.ProductId == productId
                             select new ProductTree
                    {
                        Id = tree.Id,
                        XmlText = tree.XmlText,
                        ProductId = tree.ProductId
                    }).FirstOrDefault();

                    if (q != null && !String.IsNullOrEmpty(q.XmlText))
                    {
                        using (var textReader = new StringReader(q.XmlText))
                        {
                            var resultNode = (TreeNode) new XmlSerializer(typeof(TreeNode)).Deserialize(textReader);
                            q.Tree = new TreeCore {
                                core = new TreeData {
                                    data = resultNode
                                }
                            };
                        }
                    }

                    return(q);
                }
            }
        }
Exemple #9
0
        public void Insert(int productId, TreeNode treeNode)
        {
            lock (thisLock)
            {
                string xmlText;

                using (var textWriter = new StringWriter())
                {
                    new XmlSerializer(typeof(TreeNode)).Serialize(textWriter, treeNode);

                    xmlText = textWriter.ToString();
                }

                using (var model = new gb_dvsstagingEntities())
                {
                    var productTree = new dvs_producttree
                    {
                        ProductId = productId,
                        XmlText   = xmlText,
                        CreatedBy = "Admin",
                        IsActive  = true
                    };
                    model.dvs_producttree.Add(productTree);
                    model.SaveChanges();
                }
            }
        }
        public int Update(ValidationRule validationRule)
        {
            using (var model = new gb_dvsstagingEntities())
            {
                val_validationrule val_Rule = model.val_validationrule.First(x => x.Id == validationRule.Id);

                val_Rule.ValidationSettingId = validationRule.ValidationSettingId;

                val_Rule.RuleName      = validationRule.RuleName;
                val_Rule.PropertyName  = validationRule.PropertyName;
                val_Rule.PropertyXPath = validationRule.PropertyName.Replace(".", "/");

                val_Rule.OperatorId = validationRule.OperatorId;

                val_Rule.ParameterId = validationRule.ParameterId;

                val_Rule.UpdatedBy = "Admin";
                val_Rule.UpdatedOn = DateTime.UtcNow;

                val_Rule.IsTime = validationRule.IsTime;

                val_Rule.IsForAllNodes = validationRule.IsForAllNodes;

                SetValueByParameter(validationRule, val_Rule);

                model.Entry(val_Rule).State = EntityState.Modified;

                model.SaveChanges();

                return(val_Rule.Id);
            }
        }
        public int Insert(ValidationRule validationRule)
        {
            using (var model = new gb_dvsstagingEntities())
            {
                val_validationrule val_Rule = new val_validationrule()
                {
                    ValidationSettingId = validationRule.ValidationSettingId,

                    RuleName      = validationRule.RuleName,
                    PropertyName  = validationRule.PropertyName,
                    PropertyXPath = validationRule.PropertyName.Replace(".", "/"),

                    ParameterId = validationRule.ParameterId,

                    OperatorId = validationRule.OperatorId,

                    CreatedBy = "Admin",
                    CreatedOn = DateTime.UtcNow,

                    IsTime = validationRule.IsTime,

                    IsForAllNodes = validationRule.IsForAllNodes,

                    IsActive = true
                };

                SetValueByParameter(validationRule, val_Rule);

                model.val_validationrule.Add(val_Rule);

                model.SaveChanges();

                return(val_Rule.Id);
            }
        }
Exemple #12
0
        public LastArrivalMessagesInfo LastArrivalMessagesInfo(int?productId)
        {
            using (var entities = new gb_dvsstagingEntities())
            {
                var info = new LastArrivalMessagesInfo();

                var lastArrivalMessage = entities.dvs_arrivalmessage
                                         .Where(x => (productId == null || x.ProductId == productId))
                                         .OrderByDescending(x => x.Id)
                                         .FirstOrDefault();

                if (lastArrivalMessage != null)
                {
                    info.LastDownloadedAt = lastArrivalMessage.CreatedOn;
                }

                var date = DateTime.UtcNow;
                date = date.AddHours(-1);

                var count = entities.dvs_arrivalmessage
                            .Count(x => x.CreatedOn > date && (productId == null || x.ProductId == productId));

                info.CountLastHour = count;

                return(info);
            }
        }
        // protected Object thisPushLock = new Object();

        public List <ValidationResult> GetLastValidationResults(string validationHashIndex, IList <ValidationSetting> settings)
        {
            using (var entities = new gb_dvsstagingEntities())
            {
                entities.Configuration.AutoDetectChangesEnabled = false;
                entities.Configuration.ValidateOnSaveEnabled    = false;
                entities.Database.CommandTimeout = ConnectionTimeout;

                var settingsIds = settings.Select(x => x.Id).ToArray();
                var newResults  =
                    entities.val_validationresult
                    .Where(x => x.HashValidationIndex == validationHashIndex)
                    .Where(x => x.IsActive)
                    .Where(x => settingsIds.Contains(x.ValidationSettingId))
                    .Select(x => new ValidationResult()
                {
                    Id                  = x.Id,
                    EventId             = x.EventId,
                    Market              = x.Market,
                    Provider            = x.Provider,
                    ProductId           = x.ProductId,
                    ValidationSettingId = x.ValidationSettingId
                });

                return(newResults.ToList());
            }
        }
Exemple #14
0
        public void Insert(SchedulerHistory history)
        {
            using (var model = new gb_dvsstagingEntities())
            {
                var newHistory = new dvs_schedulershistory
                {
                    CreatedBy = history.CreatedBy,
                    CreatedOn = history.CreatedOn,

                    StartedOn  = history.StartedOn,
                    FinishedOn = history.FinishedOn,

                    IsByError    = history.IsByError,
                    ErrorMessage = history.ErrorMessage,

                    AdditionalInfo = history.AdditionalInfo,

                    ArrivalMessageId = history.ArrivalMessageId,
                    ProductId        = history.ProductId,

                    Type = history.Type,

                    IsActive = true
                };

                model.dvs_schedulershistory.Add(newHistory);
                model.SaveChanges();
            }
        }
        public ValidationResult Get(int resultId)
        {
            using (var model = new gb_dvsstagingEntities())
            {
                var result = model.val_validationresult.AsNoTracking().FirstOrDefault(x => x.Id == resultId);

                return(NewValidationResultFromRepo(result));
            }
        }
 public int GetNumberOfResultsByProductId(int productId)
 {
     using (var model = new gb_dvsstagingEntities())
     {
         //if(productId == 1)
         return(model.val_validationresult.Count(res => res.ProductId == productId && res.IsActive));
         //else
         //    return model.val_validationresult_push.Count(res => res.ProductId == productId && res.IsActive);
     }
 }
Exemple #17
0
        public int GetNotMergedCount()
        {
            using (var model = new gb_dvsstagingEntities())
            {
                var count = model.dvs_eventhistory
                            .Count(@event => @event.IsActive && @event.IsMerged == false);

                return(count);
            }
        }
Exemple #18
0
        public int GetCountOfFilteredItemsByProductId(int productId, FilterObject filter)
        {
            if (filter == null)
            {
                filter = new FilterObject();
            }

            using (var model = new gb_dvsstagingEntities())
            {
                if (filter.Event == null)
                {
                    filter.Event = new FilterValue();
                }
                if (filter.Country == null)
                {
                    filter.Country = new FilterValue();
                }
                if (filter.EventStatus == null)
                {
                    filter.EventStatus = new FilterValue();
                }
                if (filter.League == null)
                {
                    filter.League = new FilterValue();
                }
                if (filter.Market == null)
                {
                    filter.Market = new FilterValue();
                }
                if (filter.Provider == null)
                {
                    filter.Provider = new FilterValue();
                }
                if (filter.Sport == null)
                {
                    filter.Sport = new FilterValue();
                }

                model.Database.CommandTimeout = CONNECTION_TIMEOUT;

                var count = model.dvs_arrivalmessage.Count(result => result.ProductId == productId &&
                                                           result.IsProcessed && result.IsActive &&
                                                           (filter.StartDate == null || result.CreatedOn >= filter.StartDate) &&
                                                           (filter.EndDate == null || result.CreatedOn <= filter.EndDate) &&
                                                           (!filter.Sport.ExternalId.HasValue || result.Sports.Contains(",") && result.Sports.Contains("," + filter.Sport.ExternalId) || result.Sports.Contains(filter.Sport.ExternalId.ToString())) &&
                                                           (!filter.Event.ExternalId.HasValue || result.Events.Contains(",") && result.Events.Contains("," + filter.Event.ExternalId) || result.Events.Contains(filter.Event.ExternalId.ToString())) &&
                                                           (!filter.Country.ExternalId.HasValue || result.Locations.Contains(",") && result.Locations.Contains("," + filter.Country.ExternalId) || result.Locations.Contains(filter.Country.ExternalId.ToString())) &&
                                                           (string.IsNullOrEmpty(filter.EventStatus.Name) || result.Statuses.Contains(",") && result.Statuses.Contains("," + filter.EventStatus.Name) || result.Statuses.Contains(filter.EventStatus.Name)) &&
                                                           (!filter.League.ExternalId.HasValue || (result.Leagues.Contains(",") && result.Leagues.Contains("," + filter.League.ExternalId) || result.Leagues.Contains(filter.League.ExternalId.ToString())) &&
                                                            (string.IsNullOrEmpty(filter.Market.Name) || result.Markets.Contains(",") && result.Markets.Contains("," + filter.Market.Name) || result.Markets.Contains(filter.Market.Name)) &&
                                                            (string.IsNullOrEmpty(filter.Provider.Name) || result.Markets.Contains(",") && result.Providers.Contains("," + filter.Provider.Name) || result.Markets.Contains(filter.Provider.Name))));

                return(count);
            }
        }
        public int GetCountForProduct(int productId)
        {
            using (var model = new gb_dvsstagingEntities())
            {
                var count = model.dvs_event

                            .Count(@event => @event.IsActive && @event.ProductId == productId);

                return(count);
            }
        }
Exemple #20
0
        public IList <ValidationOperator> GetValidationOperators()
        {
            using (var model = new gb_dvsstagingEntities())
            {
                var q = model.val_operator.Where(op => op.IsActive).Select(op => new ValidationOperator {
                    Id = op.Id, Name = op.Name
                }).ToList();

                return(q);
            }
        }
Exemple #21
0
        public IList <EventHistory> GetList()
        {
            using (var model = new gb_dvsstagingEntities())
            {
                var q = model.dvs_eventhistory
                        .Where(history => history.IsActive)
                        .ToList()
                        .Select(NewEventHistoryFrom);

                return(q.ToList());
            }
        }
        public List <long> GetListEventsIds()
        {
            using (var model = new gb_dvsstagingEntities())
            {
                var ids = model.dvs_event
                          .Where(@event => @event.IsActive)
                          .Select(@event => @event.EventId)
                          .ToList();

                return(ids);
            }
        }
        public IList <ValidationResult> GetValidationResultsByBorderDate(DateTime date)
        {
            using (var model = new gb_dvsstagingEntities())
            {
                var results = model.val_validationresult.AsNoTracking()
                              .Where(x => x.CreatedOn > date)
                              .Select(NewValidationResultFromRepo)
                              .ToList();

                return(results);
            }
        }
        public IList <ValidationRule> ListByParameters(List <int?> paramIds)
        {
            using (gb_dvsstagingEntities model = new gb_dvsstagingEntities())
            {
//                var rules = new List<ValidationRule>();

                var list = List()
                           .Where(rule => paramIds.Contains(rule.ParameterId))
                           .ToList();

                return(list);
            }
        }
        public IList <ValidationRule> List()
        {
            using (gb_dvsstagingEntities model = new gb_dvsstagingEntities())
            {
                var q = model.val_validationrule
                        .Where(rec => rec.IsActive && rec.ParameterId != null && rec.OperatorId != null)
                        .OrderBy(rec => rec.CreatedOn)
                        .ToList()
                        .Select(ValidationRuleFrom);

                return(q.ToList());
            }
        }
        public IList <Priority> List()
        {
            using (gb_dvsstagingEntities entities = new gb_dvsstagingEntities())
            {
                var q = entities.val_priority.Select(rec => new Priority()
                {
                    Id   = rec.Id,
                    Name = rec.Name
                }).OrderBy(rec => rec.Id);

                return(q.ToList());
            }
        }
Exemple #27
0
 public IList <ValidationParameter> GetValidationParameters()
 {
     using (var model = new gb_dvsstagingEntities())
     {
         var q = model.val_parameter
                 .Where(par => par.IsActive)
                 .Select(parameter => new ValidationParameter {
             Id = parameter.Id, Name = parameter.Name
         })
                 .ToList();
         return(q);
     }
 }
Exemple #28
0
        public Product GetProduct(int id)
        {
            using (var entities = new gb_dvsstagingEntities())
            {
                var val_product = entities.dvs_product.Find(id);

                return(new Product()
                {
                    Id = val_product.Id,
                    Name = val_product.Name
                });
            }
        }
Exemple #29
0
        /*
         * public async void SaveHistoriesGroups(List<HistoriesGroup> groups)
         * {
         *  using(var model = new gb_dvsstagingEntities())
         *  {
         *      // comment, because not saved is merged
         *      //model.Configuration.AutoDetectChangesEnabled = false;
         *      //model.Configuration.ValidateOnSaveEnabled = false;
         *      model.Database.CommandTimeout = CONNECTION_TIMEOUT;
         *
         *      var eventIds = groups.Select(x => x.EventId).ToList();
         *      var historiesIds = new List<int>();
         *
         *      foreach(var g in groups)
         *      {
         *          historiesIds.AddRange(g.EventHistories.Select(x => x.Id));
         *      }
         *
         *      // save events xmls
         *      var eventsQuery = (from @event in model.dvs_event
         *                        where @event.IsActive && eventIds.Contains(@event.EventId)
         *                        select @event);
         *
         *      var tasks = eventsQuery.ForEachAsync((@event) =>
         *      {
         *          var group = groups.Find(x => x.EventId == @event.EventId);
         *
         *          if (group != null)
         *          {
         *              @event.XmlText = group.BaseEventXmlText;
         *          }
         *      });
         *
         *      await Task.WhenAll(tasks);
         *
         *      await model.SaveChangesAsync();
         *
         *      // save as merged
         *      var historiesQuery = (from history in model.dvs_eventhistory
         *                            where history.IsActive && history.IsMerged == false && historiesIds.Contains(history.Id)
         *                            select history);
         *
         *      tasks = historiesQuery.ForEachAsync((history) =>
         *      {
         *          history.IsActive = false;
         *          history.IsMerged = true;
         *      });
         *
         *      await Task.WhenAll(tasks);
         *
         *      await model.SaveChangesAsync();
         *  }
         * }
         *
         * public List<HistoriesGroup> GetGroupsNotMergedByEvent(int count)
         * {
         *  using (var model = new gb_dvsstagingEntities())
         *  {
         *      model.Configuration.AutoDetectChangesEnabled = false;
         *      model.Configuration.ValidateOnSaveEnabled = false;
         *      model.Database.CommandTimeout = CONNECTION_TIMEOUT;
         *
         *      var histories = model.dvs_eventhistory
         *              .AsNoTracking()
         *              .Where(history => history.IsActive && history.IsMerged == false)
         *              .OrderBy(history=>history.CreatedOn)
         *              .Take(count)
         *              .ToList()
         *              .Select(NewEventHistoryFrom)
         *              .ToList();
         *
         *      var groups = histories.GroupBy(rec => rec.EventId)
         *          .Select(rec => new HistoriesGroup
         *          {
         *              EventId = rec.Key,
         *              EventHistories = rec.Select(x => x).ToList()
         *          });
         *
         *      var historiesGroups = groups as HistoriesGroup[] ?? groups.ToArray();
         *
         *      var eventIds = historiesGroups.Select(x => x.EventId);
         *
         *      var query = model.dvs_event
         *          .AsNoTracking()
         *          .Where(@event => @event.IsActive && eventIds.Contains(@event.EventId))
         *          .Select(x=> new { EventId = x.EventId, XmlText = x.XmlText});
         *
         *      var events = query.ToList();
         *
         *      foreach ( var group in historiesGroups)
         *      {
         *          foreach ( var @event in events)
         *          {
         *              if ( @event.EventId == group.EventId)
         *              {
         *                  group.BaseEventXmlText = @event.XmlText;
         *              }
         *          }
         *      }
         *
         *      return historiesGroups.Where(group=>group.BaseEventXmlText!=null).ToList();
         *  }
         * }
         */

        public EventHistory Insert(EventHistory history)
        {
            using (var model = new gb_dvsstagingEntities())
            {
                var newRecord = NewRepositoryEventHistoryFrom(history);

                model.dvs_eventhistory.Add(newRecord);
                model.SaveChanges();

                history.Id = newRecord.Id;

                return(history);
            }
        }
Exemple #30
0
        public void BulkInsert(List <ArrivalMessage> messages, string groupId)
        {
            lock (thisLock)
            {
                using (var model = new gb_dvsstagingEntities())
                {
                    var repositoryMessages = messages.Select(x => NewRepositoryArrivalMessage(x, groupId));

                    model.dvs_arrivalmessage.AddRange(repositoryMessages);

                    model.SaveChanges();
                }
            }
        }