Ejemplo n.º 1
0
        /// <summary>
        /// Merges two ILists of type T where each item is only added if there isn't already one there with the same value in the specified field
        /// </summary>
        /// <param name="collection1">
        /// The collection 1.
        /// </param>
        /// <param name="collection2">
        /// The collection 2.
        /// </param>
        /// <param name="fieldName">
        /// The field name.
        /// </param>
        /// <typeparam name="T">
        /// The generic type parameter
        /// </typeparam>
        public static void DistinctAdd <T>(this System.Collections.Generic.IList <T> collection1, System.Collections.Generic.IList <T> collection2, string fieldName)
        {
            if ((collection1 == null) || (collection2 == null))
            {
                return;
            }

            foreach (var item in collection2)
            {
                var anotherItem = item;
                var prop        = typeof(T).GetProperty(fieldName);
                var field       = typeof(T).GetField(fieldName);
                System.Collections.Generic.IEnumerable <T> results = null;
                if (prop != null)
                {
                    // ReSharper disable ImplicitlyCapturedClosure
                    results = collection1.Where(x => prop.GetValue(x, null) == prop.GetValue(anotherItem, null));
                    // ReSharper restore ImplicitlyCapturedClosure
                }

                if (field != null)
                {
                    // ReSharper disable ImplicitlyCapturedClosure
                    results = collection1.Where(x => field.GetValue(x) == field.GetValue(anotherItem));
                    // ReSharper restore ImplicitlyCapturedClosure
                }

                if (results == null || !results.Any())
                {
                    collection1.Add(item);
                }
            }
        }
    public void SkipEventsFromProjectX()
    {
        VCalendarParser calendar = new VCalendarParser();

        calendar.ParseFile("SampleCalendar.ics");

        EWSoftware.PDI.Objects.VEvent ev_projectX = calendar.VCalendar.Events.AddNew();
        ev_projectX.UniqueId.Value = Guid.NewGuid().ToString();
        ev_projectX.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01);
        ev_projectX.EndDateTime.DateTimeValue   = ev_projectX.StartDateTime.DateTimeValue.AddDays(1);
        ev_projectX.Description.Value           =
            @"Proyecto: Project X\n\nCompletar este elemento: \nhttp://todoist.com/#project/999999999";

        EWSoftware.PDI.Objects.VEvent ev_projectY = calendar.VCalendar.Events.AddNew();
        ev_projectY.UniqueId.Value = Guid.NewGuid().ToString();
        ev_projectY.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01).AddHours(2);
        ev_projectY.EndDateTime.DateTimeValue   = ev_projectY.StartDateTime.DateTimeValue.AddDays(1).AddHours(-2);
        ev_projectY.Description.Value           =
            @"Proyecto: Project Y\n\nCompletar este elemento: \nhttp://todoist.com/#project/999999999";

        EWSoftware.PDI.Objects.VEvent ev_projectZ = calendar.VCalendar.Events.AddNew();
        ev_projectZ.UniqueId.Value = Guid.NewGuid().ToString();
        ev_projectZ.StartDateTime.DateTimeValue = new DateTime(2015, 01, 01).AddHours(2);
        ev_projectZ.EndDateTime.DateTimeValue   = ev_projectZ.StartDateTime.DateTimeValue.AddDays(1).AddHours(-2);
        ev_projectZ.Description.Value           =
            @"Proyecto: Project\n\nCompletar este elemento: \nhttp://todoist.com/#project/999999999";


        Assert.AreEqual(1, calendar.VCalendar.Events.Count(ev => ev.UniqueId == ev_projectX.UniqueId));
        Assert.AreEqual(1, calendar.VCalendar.Events.Count(ev => ev.UniqueId == ev_projectY.UniqueId));
        Assert.AreEqual(1, calendar.VCalendar.Events.Count(ev => ev.UniqueId == ev_projectZ.UniqueId));

        // filter out all-day events
        EventManager em = new EventManager(calendar);

        em.Filter(new FilteringOptions("&pr=Project X"));
        System.Collections.Generic.IList <EWSoftware.PDI.Objects.VEvent> eventsAfterFiltering = em.GetEventList();

        Assert.AreEqual(0, eventsAfterFiltering.Where(ev => ev.UniqueId == ev_projectX.UniqueId).Count());
        Assert.AreEqual(1, eventsAfterFiltering.Where(ev => ev.UniqueId == ev_projectY.UniqueId).Count());
        Assert.AreEqual(1, eventsAfterFiltering.Where(ev => ev.UniqueId == ev_projectZ.UniqueId).Count());
    }
Ejemplo n.º 3
0
 public static Bundle[] GetBundleByProducts(this System.Collections.Generic.IList <Bundle> bundles, Product[] products)
 {
     return(bundles
            .Where(b =>
                   Enumerable.SequenceEqual
                   (
                       products.OrderBy(x => x),
                       b.Products.OrderBy(x => x),
                       new ProductComparer())
                   ).ToArray());
 }
        protected string RepalceParamValue(string pattern, System.Collections.Generic.IList<Suite.TestDataKeyNamePair> actionParams)
        {
            MatchCollection matches = Regex.Matches(pattern, "({{(\\w+)}})");
            foreach (Match match in matches)
            {
                string paramKey = match.Value.Replace("{{", string.Empty).Replace("}}", string.Empty).ToLower();
                TestDataKeyNamePair testDataParam = actionParams.Where(item => item.Key.ToLower() == paramKey).FirstOrDefault();
                if (testDataParam == null) { continue; }
                pattern = Regex.Replace(pattern, match.Value, testDataParam.Value, RegexOptions.IgnoreCase);
            }

            return pattern;
        }
Ejemplo n.º 5
0
 private void GetDataBasedOnUserType(vmDashBoard objDashboard, System.Collections.Generic.IList <BatchModel> batch, UserType CurrentUserType, string CurrentUserEmail)
 {
     if (CurrentUserType == UserType.Trainer)
     {
         objDashboard.BatchList = batch;
         var LastBatchID = batch.LastOrDefault().Id;
         var IndList     = _Inductee.Get(20, 0);
         objDashboard.InducteeList = IndList.Where(i => i.BatchID == LastBatchID).OrderByDescending(i => i.Batch.BatchDates.OrderBy(f => f.BatchDate).First()).ToList();
     }
     else if (CurrentUserType == UserType.Trainee)
     {
         var inducteeBatchId = _Inductee.Get(CurrentUserEmail).BatchID;
         var traineesBatch   = batch.Where(B => B.Id == inducteeBatchId).Select(B => B).ToList <BatchModel>();
         if (traineesBatch.Any())
         {
             objDashboard.BatchList = traineesBatch;
             var IndList = _Inductee.Get(20, 0);
             objDashboard.InducteeList = IndList.Where(i => i.BatchID == inducteeBatchId).OrderByDescending(i => i.Id).ToList();
         }
     }
 }
Ejemplo n.º 6
0
        public override HealthCheckResult PerformCheck()
        {
            System.Collections.Generic.IList <ScheduledTask> tasks        = _session.QueryOver <ScheduledTask>().List();
            System.Collections.Generic.List <ScheduledTask>  stalledTasks = tasks.Where(x => x.LastComplete <= CurrentRequestData.Now.AddSeconds(-(x.EveryXSeconds + 120)) || x.LastComplete == null).ToList();

            if (stalledTasks.Any())
            {
                System.Collections.Generic.List <string> messages = stalledTasks.Select(task =>
                {
                    DateTime?lastComplete = task.LastComplete;
                    return(lastComplete.HasValue
                        ? string.Format("{0} has not been ran since {1}", task.TypeName, lastComplete)
                        : string.Format("{0} has never been run", task.TypeName));
                }).ToList();
                return(new HealthCheckResult
                {
                    Messages = messages,
                    OK = false
                });
            }
            return(HealthCheckResult.Success);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Prepare paged topic list model
        /// </summary>
        /// <param name="searchModel">Topic search model</param>
        /// <returns>Topic list model</returns>
        public virtual TopicListModel PrepareTopicListModel(TopicSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get topics
            System.Collections.Generic.IList <Topic> topics = _topicService.GetAllTopics(showHidden: true,
                                                                                         storeId: 0,
                                                                                         ignorAcl: true);

            //filter topics
            //TODO: move filter to topic service
            if (!string.IsNullOrEmpty(searchModel.SearchKeywords))
            {
                topics = topics.Where(topic => (topic.Title?.Contains(searchModel.SearchKeywords) ?? false) ||
                                      (topic.Body?.Contains(searchModel.SearchKeywords) ?? false)).ToList();
            }

            //prepare grid model
            TopicListModel model = new TopicListModel
            {
                Data = topics.PaginationByRequestModel(searchModel).Select(topic =>
                {
                    //fill in model values from the entity
                    TopicModel topicModel = topic.ToModel <TopicModel>();

                    //little performance optimization: ensure that "Body" is not returned
                    topicModel.Body = string.Empty;

                    return(topicModel);
                }),
                Total = topics.Count
            };

            return(model);
        }
 public void Receive(System.Collections.Generic.IList <StepCountEntry> list, System.Collections.Generic.IList <Stateless.Change> changeset)
 {
     this.weeklyStepCountValue.Text = list.Where(s => (DateTime.Now - s.StartEntryDateTime).TotalDays < 7).Sum(s => s.Count).ToString();
 }
Ejemplo n.º 9
0
 public static Bundle[] GetBundleByAnswers(this System.Collections.Generic.IList <Bundle> bundles, Answers answers)
 {
     return(bundles
            .Where(b => b.Rules.All(r => ExecuteRule(r, answers, b)))
            .ToArray());
 }