Beispiel #1
0
            public void PerformSearch( )
            {
                // is there something to search?
                if (SearchField.GetCurrentValue( ).Length > Settings.General_MinSearchLength)
                {
                    SearchField.ResignFirstResponder( );

                    // disable the button, reset the results, and show the blocker
                    SearchButton.Enabled = false;

                    ClearResults( );

                    SearchField.ResignFirstResponder( );

                    Parent.BlockerView.BringToFront( );

                    Parent.BlockerView.Show(
                        delegate
                    {
                        // search for the family
                        RockApi.Get_Groups_FamiliesByPersonNameSearch(SearchField.GetCurrentValue( ),
                                                                      delegate(System.Net.HttpStatusCode statusCode, string statusDescription, List <Rock.Client.Family> model)
                        {
                            // re-enable the search button
                            SearchButton.Enabled = true;

                            // if results came back, populate our list
                            if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true && model != null && model.Count > 0)
                            {
                                foreach (Rock.Client.Family family in model)
                                {
                                    FamilyManagerApi.SortFamilyMembers(family.FamilyMembers);

                                    FamilyResult result = new FamilyResult(this, family);
                                    Results.Add(result);

                                    // tell our parent to re-layout so we position the results
                                    ParentView.SetNeedsLayout( );
                                }
                            }
                            else
                            {
                                // just create a single entry that represents a 'no result' entry
                                FamilyResult result = new FamilyResult(this, null);
                                Results.Add(result);

                                ParentView.SetNeedsLayout( );
                            }

                            Parent.BlockerView.Hide( );
                        });
                    });
                }
            }
        public static void MakeWordFamiliyFromDataBase()
        {
            var entity  = new EnglishWordsEntities();
            var allroot = entity.Roots.ToList();
            var roots   = allroot.Where(x => x.Parent == null && x.Count != null && x.Grouped == false).OrderBy(c => c.Word).ToList();


            List <Task> taskList = new List <Task>();

            foreach (var r in roots)
            {
                taskList.Add(Task.Factory.StartNew(() =>
                {
                    FindAllDependency(allroot, r.ID, r.ID, 0);
                    Console.WriteLine($"Grouped {r.Word} {family[r.ID].Count}");
                }));
                if (taskList.Count > 10)
                {
                    Task.WaitAll(taskList.ToArray());
                    taskList.Clear();
                }
            }


            foreach (var f in family)
            {
                taskList.Add(Task.Factory.StartNew(() =>
                {
                    StringBuilder currentSb = new StringBuilder();
                    var root = allroot.FirstOrDefault(x => x.ID == f.Key);
                    if (root != null)
                    {
                        var count = 0;

                        count += root.Count ?? 0;

                        currentSb.Append(root.Word);
                        currentSb.Append(",");

                        if (f.Value != null && f.Value.Count > 0)
                        {
                            var words = allroot.Where(x => f.Value.Contains(x.ID)).OrderBy(x => x.Word).ToList();
                            count    += words.Sum(x => x.Count ?? 0);

                            var familiy = words.Select(x => x.Word)
                                          .Aggregate((x, y) => x + "," + y).Trim(',');
                            currentSb.Append($"\"{familiy}\"");
                        }

                        currentSb.Append(",");
                        currentSb.Append(count);
                        Console.WriteLine(currentSb);
                        var model = new FamilyResult()
                        {
                            Count = count,
                            SVC   = currentSb.ToString().Replace("\r", "").Replace("\n", "")
                        };
                        FamilyGrouped.TryAdd(f.Key, model);

                        Console.WriteLine($"FamilyGrouped {f.Key} {model.SVC}");
                    }
                }));
                if (taskList.Count > 10)
                {
                    Task.WaitAll(taskList.ToArray());
                    taskList.Clear();
                }
            }
            Task.WaitAll(taskList.ToArray());
            Console.WriteLine("Aggrigating...");
            try
            {
                var ordered = FamilyGrouped.Values.OrderByDescending(x => x.Count).ToList().Select(x => x.SVC).Aggregate((x, y) => x + "\r\n" + y);
                Console.WriteLine("Aggrigatined");
                Console.WriteLine("Writing to file...");
                File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "\\WordFamily_NotGrouped.txt", ordered, Encoding.UTF8);
                Console.WriteLine("Wroted file");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }