Beispiel #1
0
 public static void RemoveWhere(ICollection <TSource> collection, Func <TSource, bool> predicate)
 {
     if (collection != null)
     {
         var list = collection as IList <TSource>;
         if (list != null)
         {
             for (int i = list.Count - 1; i >= 0; i--)
             {
                 if (predicate(list[i]))
                 {
                     list.RemoveAt(i);
                 }
             }
         }
         else
         {
             var toRemove = SL.ToList(SL.Where(collection, predicate));
             foreach (var item in toRemove)
             {
                 collection.Remove(item);
             }
         }
     }
 }
Beispiel #2
0
        private bool ReadLibraryFromJson()
        {
            var jsonFormatter = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(Books[]));

            using (var fs = new System.IO.FileStream("Library.json", System.IO.FileMode.OpenOrCreate))
            {
                if (fs.Length == 0)
                {
                    System.Console.WriteLine("JSON is empty");
                }
                else
                {
                    var newBooks = (Books[])jsonFormatter.ReadObject(fs);
                    var lst      = Enumerable.ToList(Enumerable.OfType <Books>(newBooks));
                    System.Console.WriteLine("Done reading from json");
                    foreach (var b in lst)
                    {
                        var book = new Books
                        {
                            Author          = b.Author,
                            Title           = b.Title,
                            Annotation      = b.Annotation,
                            Isbn            = b.Isbn,
                            PublicationDate = b.PublicationDate
                        };

                        _books.Add(book);
                    }
                }
            }

            return(true);
        }
Beispiel #3
0
        public void ngram_search_not_empty()
        {
            using (GetNewServer())
                using (var database = new DocumentStore
                {
                    Url = "http://localhost:8079"
                }.Initialize())
                {
                    new ImageByName().Execute(database);

                    using (var session = database.OpenSession())
                    {
                        session.Store(new Image {
                            Id = "1", Name = "Great Photo buddy"
                        });
                        session.Store(new Image {
                            Id = "2", Name = "Nice Photo of the sky"
                        });
                        session.SaveChanges();
                    }
                    using (var session = database.OpenSession())
                    {
                        var images = Enumerable.ToList <Image>(session.Query <Image, ImageByName>()
                                                               .Customize(x => x.WaitForNonStaleResults())
                                                               .OrderBy(x => x.Name)
                                                               .Search(x => x.Name, "phot"));

                        Assert.NotEmpty(images);
                    }
                }
        }
Beispiel #4
0
        public override async Task SetOverdueNotificationsAsync(List <string> overdueNotifications)
        {
            CriteriaBuilder criteriaBuilder = new CriteriaBuilder();

            _overdueNotifications = overdueNotifications;
            _followUps            = await _followUpsController.GetManyByCriteria
                                    (
                criteriaBuilder
                .Add("Id", _overdueNotifications.ToArray(), ConjunctionsEnum.And, Operators.In)
                                    );

            List <Guid> followUpsToRemove = new List <Guid>();

            for (int i = 0; i < _followUps.Count; i++)
            {
                if ((await ProspectWasConverted(_followUps[i])))
                {
                    followUpsToRemove.Add(_followUps[i].Id);
                }
            }
            if (followUpsToRemove.Count > 0)
            {
                _followUps = Enumerable.ToList(Enumerable.Where(_followUps, followup => !followUpsToRemove.Contains(followup.Id)));
            }

            if (_followUps.Count == 1 && _singleProspect == null)
            {
                _singleProspect = await new ProspectsController().GetByIdAsync(_followUps[0].ProspectId);
                _singleProspect.ReminderTime = _followUps[0].ReminderTime;
            }
        }
Beispiel #5
0
        public static IList <T> GetInstances <T>(List <Type> excludedTypes = null)
        {
            List <TypeInfo> excludedTypeInfos = null;

            if (excludedTypes != null)
            {
                excludedTypeInfos = Enumerable.ToList(
                    Enumerable.Select(excludedTypes, type => type.GetTypeInfo()));
            }

            if (excludedTypes == null)
            {
                excludedTypes = new List <Type>();
            }

            var instances = new List <T>();
            var assemblie = GetAssembly(typeof(T));

            foreach (var type in assemblie.DefinedTypes)
            {
                if (!type.IsAbstract && type.IsSubclassOf(typeof(T)))
                {
                    try
                    {
                        if (!excludedTypeInfos.Contains(type))
                        {
                            instances.Add((T)Activator.CreateInstance(type.AsType()));
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            return(instances);
        }
Beispiel #6
0
        public override INotificationResult Notify(IList <INotificationResult> sources)
        {
            CollectionChangedNotificationResult <TSource> sourceChange  = null;
            CollectionChangedNotificationResult <TSource> source2Change = null;

            if (sources[0].Source == source)
            {
                sourceChange = (CollectionChangedNotificationResult <TSource>)sources[0];
            }
            else
            {
                source2Change = (CollectionChangedNotificationResult <TSource>)sources[0];
            }

            if (sources.Count > 1)
            {
                if (sources[1].Source == source)
                {
                    sourceChange = (CollectionChangedNotificationResult <TSource>)sources[1];
                }
                else
                {
                    source2Change = (CollectionChangedNotificationResult <TSource>)sources[1];
                }
            }

            var added   = new List <TSource>();
            var removed = new List <TSource>();

            if (source2Change != null)
            {
                if (source2Change.IsReset)
                {
                    sourceItems.Clear();
                    OnCleared();
                    return(new CollectionChangedNotificationResult <TSource>(this));
                }
                else
                {
                    NotifySource2(source2Change, added, removed);
                }
            }

            if (sourceChange != null)
            {
                if (sourceChange.IsReset)
                {
                    OnCleared();
                    return(new CollectionChangedNotificationResult <TSource>(this));
                }
                else
                {
                    NotifySource(sourceChange, added, removed);
                }
            }

            if (removed.Count == 0 && added.Count == 0)
            {
                return(UnchangedNotificationResult.Instance);
            }

            OnRemoveItems(removed);
            OnAddItems(added);
            return(new CollectionChangedNotificationResult <TSource>(this, SL.ToList(added), SL.ToList(removed)));
        }