async Task RefreshFromCache(GroupedItem group, int minuteThreshold)
 {
     if (m_BusyRefreshingFromCache.Contains(group.Feed))
     {
         return;
     }
     m_BusyRefreshingFromCache.Add(group.Feed);
     if (await group.Feed.ReadFromCache())
     {
         if (!group.Feed.Articles.Any())
         {
             await RefreshFromWeb(group);
         }
         else if (Math.Abs(group.Feed.Updated.Subtract(DateTime.Now).TotalMinutes) < minuteThreshold)
         {
             Refresh(group);
         }
         else
         {
             await RefreshFromWeb(group);
         }
     }
     else
     {
         await RefreshFromWeb(group);
     }
     m_BusyRefreshingFromCache.Remove(group.Feed);
 }
        async Task RefreshFromWeb(GroupedItem group)
        {
            if (!App.IsNetworkOkay)
            {
                await new Windows.UI.Popups.MessageDialog(Strings.NoInternetWarning).ShowAsync();
                return;
            }
            if (m_BusyRefreshingFromWeb.Contains(group.Feed))
            {
                return;
            }
            m_BusyRefreshingFromWeb.Add(group.Feed);
            if (await group.Feed.ReadFromWeb())
            {
                Refresh(group);
            }
            else if (group.Feed.InError)
            {
                // if a feed fails, we will not display it
                Debug.WriteLine("{0} removed because it is InError", group.Header);
                this.Feeds.Remove(group);
            }

            m_BusyRefreshingFromWeb.Remove(group.Feed);
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int id, [Bind("GroupedItemId,LogGroupingId,BlogPostId,GroupedItemComment,ItemCreateDate")] GroupedItem groupedItem)
        {
            if (id != groupedItem.GroupedItemId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(groupedItem);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GroupedItemExists(groupedItem.GroupedItemId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BlogPostId"]    = new SelectList(_context.BlogPost, "BlogPostId", "BlogText", groupedItem.BlogPostId);
            ViewData["LogGroupingId"] = new SelectList(_context.LogGrouping, "LogGroupingId", "LogGroupingComment", groupedItem.LogGroupingId);
            return(View(groupedItem));
        }
Esempio n. 4
0
 /// <summary>
 /// Make sure the root key is present or use a default.
 /// </summary>
 /// <param name="item">
 /// </param>
 private void EnsureNonNullRoot(GroupedItem item)
 {
     if (item.RootKey == null)
     {
         this.EnsureExtensionsTabExists();
         item.RootKey = HeaderControl.ExtensionsRootKey;
     }
 }
Esempio n. 5
0
        // GET: GroupedItems/EditItem
        public IActionResult EditItem(int?id)
        {
            GroupedItem myItem = _context.GroupedItem.Find(id);

//          //  int? myLog = ViewBag.thisLogged;
            //ViewBag.thisLogged2 = sid;
            return(View(myItem));
        }
Esempio n. 6
0
 public IActionResult EditItem([Bind("GroupedItemId,LogGroupingId,BlogPostId," +
                                     "GroupedItemComment,ItemCreateDate")] GroupedItem groupedItem)
 {
     if (ModelState.IsValid)
     {
         _context.Update(groupedItem);
         _context.SaveChanges();
         return(RedirectToAction(nameof(MyPersonalLog))); // index sometimes used as  equivalent to List() action
     }
     return(View(groupedItem));
 }
Esempio n. 7
0
 public IActionResult CreateItem([Bind("LogGroupingId,BlogPostId," +
                                       "GroupedItemComment,ItemCreateDate")] GroupedItem groupedItem)
 {
     if (ModelState.IsValid)
     {
         _context.Add(groupedItem);                       //wait scaffoled controllers Add to the table,not the dB
         _context.SaveChanges();
         return(RedirectToAction(nameof(MyPersonalLog))); //so now we tell the app where to return to!
     }
     return(View(groupedItem));
 }
        void Refresh(GroupedItem groupedItem)
        {
            Debug.Assert(groupedItem != null);
            Debug.Assert(groupedItem.Feed != null);
            Debug.Assert(groupedItem.Articles != null);

            var _Items = groupedItem.Feed.Articles.ToArray();

            foreach (var _Item in _Items)
            {
                FormatItem(_Item);
            }

            var _RemoveThese = groupedItem.Articles.ToArray()
                               .Where(x => !_Items.Select(y => y.Url).Contains(x.Url));

            foreach (var _Item in _RemoveThese)
            {
                groupedItem.Articles.Remove(_Item);
            }

            var _UpdateThese =
                from a in groupedItem.Articles
                join i in _Items on a.Url equals i.Url
                select new { Old = a, New = i };

            foreach (var _Item in _UpdateThese)
            {
                _Item.Old.MapProperties(_Item.New);
            }

            var _InsertThese = _Items.ToArray()
                               .Where(x => !groupedItem.Articles.Select(y => y.Url).Contains(x.Url));

            foreach (var _Item in _InsertThese.Select((x, i) => new { Item = x, Index = i }))
            {
                _Item.Item.Index = _Item.Index;
                FormatItem(_Item.Item);
                groupedItem.Articles.Insert(0, _Item.Item);
            }

            // update hero in the grid
            if (groupedItem.Articles.Any())
            {
                var _First = groupedItem.Articles.First();
                groupedItem.Articles.Remove(_First);
                _First.Index = 0;
                FormatItem(_First);
                groupedItem.Articles.Insert(0, _First);
            }

            // update and adverts
            FormatItems(groupedItem.Articles);
        }
Esempio n. 9
0
        private async void FilterGroupItems(string searchString)
        {
            try
            {
                searchString = searchString.ToLower();

                if (!string.IsNullOrEmpty(searchString))
                {
                    var groupedList  = new ObservableCollection <GroupedItem <Patient> >();
                    var xlist        = (await _patientsStorage.GetList());
                    var patientsList = xlist.Where(x => x.Fullname.ToLower().Contains(searchString)).ToList();

                    var headers = patientsList.Select(x => x.LastName.Substring(0, 1)).Distinct().OrderBy(x => x);

                    foreach (var headerkey in headers)
                    {
                        var patientGroup = new GroupedItem <Patient> {
                            HeaderKey = headerkey
                        };

                        var list = new List <Patient>();

                        foreach (var item in patientsList.Where(x => x.LastName.StartsWith(headerkey, StringComparison.OrdinalIgnoreCase)).ToList())
                        {
                            list.Add(item);
                        }

                        list = list.OrderBy((arg) => arg.Fullname).ToList();

                        foreach (var item in list)
                        {
                            patientGroup.Add(item);
                        }

                        groupedList.Add(patientGroup);
                    }

                    _filteredPatients = (ObservableCollection <GroupedItem <Patient> >)(object) groupedList;

                    ItemsSource = _filteredPatients;
                }
                else
                {
                    ItemsSource = Patients;
                    //await GetDataAsync();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Esempio n. 10
0
        public void Check_sorting(string path)
        {
            var unsorted   = new List <string[]>();
            var bufferSize = 65 * 1024 * 1024;

            var parser   = new TestLineParser();
            var comparer = new TestLineComparer();

            long lineNumber = 1;

            using (var fs =
                       new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, bufferSize, true))
                using (var sr = new StreamReader(fs))
                {
                    var line0 = new GroupedItem <TestLine> {
                        Item = parser.Parse(sr.ReadLine())
                    };

                    while (sr.Peek() > -1)
                    {
                        lineNumber++;

                        var line1 = new GroupedItem <TestLine> {
                            Item = parser.Parse(sr.ReadLine())
                        };

                        if (comparer.Compare(line0, line1) > 0)
                        {
                            unsorted.Add(new[] { parser.Unparse(line0.Item), parser.Unparse(line1.Item) });

                            if (unsorted.Count > 9)
                            {
                                break;
                            }
                        }

                        if (sr.Peek() > -1)
                        {
                            line0 = new GroupedItem <TestLine> {
                                Item = parser.Parse(sr.ReadLine())
                            }
                        }
                        ;
                    }
                }

            Assert.Empty(unsorted);
        }
Esempio n. 11
0
        public async Task <IActionResult> Create([Bind("GroupedItemId,LogGroupingId,BlogPostId," +
                                                       "GroupedItemComment,ItemCreateDate")] GroupedItem groupedItem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(groupedItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BlogPostId"] = new SelectList(_context.BlogPost, "BlogPostId", "BlogText",
                                                    groupedItem.BlogPostId);
            ViewData["LogGroupingId"] = new SelectList(_context.LogGrouping, "LogGroupingId",
                                                       "LogGroupingComment", groupedItem.LogGroupingId);
            return(View(groupedItem));
        }
Esempio n. 12
0
        protected override void Init()
        {
            var label = new Label {
                Text = Instructions,
            };

            grouped = new ObservableCollection <GroupedItem>();
            lstView = new ListView()
            {
                IsGroupingEnabled   = true,
                HasUnevenRows       = true,
                ItemTemplate        = new DataTemplate(typeof(MyViewCell)),
                GroupHeaderTemplate = new DataTemplate(typeof(MyHeaderViewCell)),
                ItemsSource         = grouped,
                AutomationId        = "TestReady"
            };

            var grp1 = new GroupedItem()
            {
                LongName = "Group 1", ShortName = "1"
            };
            var grp2 = new GroupedItem()
            {
                LongName = "Group 2", ShortName = "2"
            };

            for (int i = 1; i < 4; i++)
            {
                grp1.Add($"I am a short text #{i}");
                grp1.Add($"I am a long text that should cause the line to wrap, and I should not be cut off or overlapping in any way. #{i}");
                grp2.Add($"I am a short text #{i}");
                grp2.Add($"I am a long text that should cause the line to wrap, and I should not be cut off or overlapping in any way. #{i}");
            }

            grouped.Add(grp1);
            grouped.Add(grp2);

            Content = new StackLayout
            {
                Children =
                {
                    label,
                    lstView
                }
            };
        }
Esempio n. 13
0
        private void GroupItems(List <Patient> observableCollection)
        {
            try
            {
                var groupedList = new ObservableCollection <GroupedItem <Patient> >();

                var patientsList = observableCollection.Cast <Patient>().ToList();

                var headers = patientsList.Select(x => x.LastName.Substring(0, 1));

                headers = headers.Select(h => char.ToUpper(h[0]).ToString()).Distinct().OrderBy(x => x);

                foreach (var headerkey in headers)
                {
                    var patientGroup = new GroupedItem <Patient> {
                        HeaderKey = headerkey
                    };

                    var list = new List <Patient>();

                    foreach (var item in patientsList.Where(x => x.LastName.StartsWith(headerkey, StringComparison.OrdinalIgnoreCase)).ToList())
                    {
                        list.Add(item);
                    }

                    list = list.OrderBy((arg) => arg.Fullname).ToList();

                    foreach (var item in list)
                    {
                        patientGroup.Add(item);
                    }

                    groupedList.Add(patientGroup);
                }

                Patients = groupedList;

                ItemsSource = groupedList;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Esempio n. 14
0
        protected override void Init()
        {
            var label = new Label {
                Text = Instructions, AutomationId = "TestReady"
            };

            grouped = new ObservableCollection <GroupedItem>();
            lstView = new ListView(ListViewCachingStrategy.RecycleElement)
            {
                IsGroupingEnabled     = true,
                ItemTemplate          = new DataTemplate(typeof(AccessoryViewCell)),
                ItemsSource           = grouped,
                GroupDisplayBinding   = new Binding("LongName"),
                GroupShortNameBinding = new Binding("ShortName")
            };

            var grp1 = new GroupedItem()
            {
                LongName = "Group 1", ShortName = "1"
            };
            var grp2 = new GroupedItem()
            {
                LongName = "Group 2", ShortName = "2"
            };

            for (int i = 1; i < 4; i++)
            {
                grp1.Add($"Item #{i}");
                grp2.Add($"Item #{i}");
            }

            grouped.Add(grp1);
            grouped.Add(grp2);

            Content = new StackLayout
            {
                Children =
                {
                    label,
                    lstView
                }
            };
        }
Esempio n. 15
0
        /// ////// ADDS
        /// ******* Add Item
        // GET: GroupedItems/Add Item
        public IActionResult AddItem(int?id)
        {
            /*
             *         var enhancedBloggerContext = _context.NoteTopic.Include(n => n.UserProfile);
             *          //Make a list of the existing LogGroupings:
             *          List<LogGrouping> extgGroups = new List<LogGrouping>();
             *          foreach(var log in extgGroups)
             *          {
             *              @Html.DisplayFor(m => log.LogGroupingId)
             *              @Html.DisplayFor(m => log.LogGroupingtitle)
             *              @Html.DisplayFor(m => log.LogGroupingComment)
             *          };
             */
            GroupedItem GItem = new GroupedItem();

            //var thisblogsID = id;
            ViewBag.my2ID = id;


            return(View(GItem)); //we will return the view named CreateItem
        }
Esempio n. 16
0
        /// <summary>
        /// Gets the ribbon page or a default page based on the item RootKey.
        /// </summary>
        /// <param name="item">
        /// The item.
        /// </param>
        /// <returns>
        /// </returns>
        private RibbonPage GetRibbonPage(GroupedItem item)
        {
            this.EnsureNonNullRoot(item);

            RibbonPage existingPage = this.GetExistingRibbonPage(item.RootKey);

            if (existingPage == null)
            {
                // We create a new page and hope someone assigns a caption to it later by calling Add(rootitem)
                if (ShouldCreateRibbonPage(item.RootKey))
                {
                    RibbonPage page = new RibbonPage();
                    page.Name = item.RootKey;
                    _ribbon.Pages.Add(page);
                    Debug.WriteLine(item.RootKey + " ribbon page was created without a caption (perhaps one will be assigned later by creating a RootItem).");
                    return(page);
                }
            }

            return(existingPage);
        }
 async Task RefreshFromWeb(GroupedItem group)
 {
     if (!App.IsNetworkOkay)
     {
         await new Windows.UI.Popups.MessageDialog(Strings.NoInternetWarning).ShowAsync();
         return;
     }
     if (m_BusyRefreshingFromWeb.Contains(group.Feed))
     {
         return;
     }
     m_BusyRefreshingFromWeb.Add(group.Feed);
     if (await group.Feed.ReadFromWeb())
     {
         Refresh(group);
     }
     else
     {
         Debug.WriteLine("Error reading feed {0} from web", group.Feed.SourceUrl);
         Debugger.Break();
     }
     m_BusyRefreshingFromWeb.Remove(group.Feed);
 }
Esempio n. 18
0
        public void Grouped_Item_Total_Test(string sku, int quantity, string offer, double expectedAmount)
        {
            var groupedItem = new GroupedItem(GetItem(sku), quantity, GetSpecialOffer(offer));

            Assert.AreEqual(expectedAmount, groupedItem.TotalPrice);
        }
Esempio n. 19
0
        // GET: GroupedItems/CreateItem
        public IActionResult CreateItem()
        {
            GroupedItem myItem = new GroupedItem();

            return(View(myItem)); //we will return the view named CreateItem
        }
Esempio n. 20
0
 private string Serialize(GroupedItem <T> item)
 {
     return($"{item.Count}{GROUP_SEPARATOR}{_lineParser.Unparse(item.Item)}");
 }
Esempio n. 21
0
        private void SortFile(
            string sourcepath,
            string inputPath,
            string outputPath,
            int bufferSize,
            int blockSize
            )
        {
            var bufferPath = $"{sourcepath}.{_PassesMade}";

            _fileAdapter.Delete(bufferPath);

            var inputfileFileReader = _fileReader.CreateInstance();
            var bufferFileWriter    = _fileWriter.CreateInstance();
            var outputFileWriter    = _fileWriter.CreateInstance();

            try
            {
                if (_fileAdapter.GetFileInfo(inputPath).Length == 0)
                {
                    if (_PassesMade > 0)
                    {
                        _Status = SortStatus.Cleaning;
                        _fileAdapter.Delete(inputPath);
                    }

                    _Done = true;
                    return;
                }

                _Status = SortStatus.Cleaning;
                GC.Collect();

                inputfileFileReader.BeginRead(inputPath, bufferSize);
                bufferFileWriter.BeginWrite(bufferPath, bufferSize);
                outputFileWriter.BeginWrite(outputPath, bufferSize);

                outputFileWriter.StreamWriter.BaseStream.Position =
                    outputFileWriter.StreamWriter.BaseStream.Length;

                var  output      = new GroupedItem <T> [0];
                long readLength  = 0;
                long totalLength = inputfileFileReader.StreamReader.BaseStream.Length;

                _Status = SortStatus.Reading;

                foreach (var block in inputfileFileReader.ReadBlock(blockSize))
                {
                    readLength += block.Sum(x => x.Length + Environment.NewLine.Length);
                    _RowsRed   += block.Count();
                    _RedPercent = (int)(readLength / (double)totalLength * 100);

                    var grouped   = new GroupedItem <T> [0];
                    var sanitized = block.Select(x => Sanitize(x));

                    if (_PassesMade == 0)
                    {
                        grouped = Group(sanitized);
                    }
                    else
                    {
                        grouped = Deserialize(sanitized);
                    }

                    var sorted = SortBlock(grouped);

                    output = MergeBlocks(
                        bufferFileWriter,
                        blockSize,
                        output,
                        sorted
                        );

                    _Status = SortStatus.Reading;
                }

                WriteUngrouped(outputFileWriter, output);

                inputfileFileReader.EndRead();
                bufferFileWriter.EndWrite();
                outputFileWriter.EndWrite();

                if (_PassesMade > 0)
                {
                    _Status = SortStatus.Cleaning;
                    _fileAdapter.Delete(inputPath);
                }

                _PassesMade++;
                ResetProgressMarkers();

                RunFileSortTask(
                    sourcepath,
                    bufferPath,
                    outputPath,
                    bufferSize,
                    blockSize
                    );
            }
            finally
            {
                inputfileFileReader.EndRead();
                bufferFileWriter.EndWrite();
                outputFileWriter.EndWrite();
            }
        }
 public DataForm()     // this is your constructor
 {
     Item1          = new GroupedItem();
     Item2          = new GroupedItem();
     ItemCollection = new GroupCollectionItems("Group1");
 }