public static Predicate <Entry> IsInEntryIdCacheEntryCollection(EntryCollection collection)
            {
                FilterContainer container = new FilterContainer();

                container.EntryCollection = collection;

                return(new Predicate <Entry>(container.IsInEntryCollection));
            }
Beispiel #2
0
        internal void Load(DataManager data)
        {
            if (Loaded)
            {
                return;
            }

            lock (entriesLock)
            {
                if (Loaded)                   //SDH: standard thread-safe double check
                {
                    return;
                }

                string     fullPath   = data.ResolvePath(FileName);
                FileStream fileStream = FileUtils.OpenForRead(fullPath);
                if (fileStream != null)
                {
                    try
                    {
                        XmlSerializer ser = new XmlSerializer(typeof(DayEntry), Data.NamespaceURI);
                        using (StreamReader reader = new StreamReader(fileStream))
                        {
                            //XmlNamespaceUpgradeReader upg = new XmlNamespaceUpgradeReader( reader, "", Data.NamespaceURI );
                            DayEntry e = (DayEntry)ser.Deserialize(reader);
                            Entries = e.Entries;
                        }
                    }
                    catch (Exception e)
                    {
                        ErrorTrace.Trace(System.Diagnostics.TraceLevel.Error, e);
                    }
                    finally
                    {
                        fileStream.Close();
                    }
                }

                Entries.Sort((left, right) => right.CreatedUtc.CompareTo(left.CreatedUtc));

                Loaded = true;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Creates a shallow copy of the <see cref="EntryCollection"/>.
        /// </summary>
        /// <returns>A shallow copy of the <see cref="EntryCollection"/>.</returns>
        /// <remarks>Please refer to <see cref="ICloneable.Clone"/> for details.</remarks>
        public virtual object Clone()
        {
            EntryCollection collection = new EntryCollection(this.ToArray());

            return(collection);
        }
        private bool Build(DataManager data)
        {
            EntryCollection entriesCacheCopy = new EntryCollection();

            Dictionary <string, DateTime> entryIdToDateCopy         = new Dictionary <string, DateTime>(StringComparer.InvariantCultureIgnoreCase);
            Dictionary <string, DateTime> compressedTitleToDateCopy = new Dictionary <string, DateTime>(StringComparer.InvariantCultureIgnoreCase);

            try
            {
                foreach (DayEntry day in data.Days)
                {
                    day.Load(data);

                    foreach (Entry entry in day.Entries)
                    {
                        // create a lite entry for faster searching
                        Entry copy = entry.Clone();
                        copy.Content     = "";
                        copy.Description = "";

                        copy.AttachmentsArray = null;
                        copy.CrosspostArray   = null;

                        entriesCacheCopy.Add(copy);

                        entryIdToDateCopy.Add(copy.EntryId, copy.CreatedUtc.Date);

                        //SDH: Only the first title is kept, in case of duplicates
                        // TODO: should be able to fix this, but it's a bunch of work.
                        string compressedTitle = copy.CompressedTitle;
                        compressedTitle = compressedTitle.Replace("+", "");
                        if (compressedTitleToDateCopy.ContainsKey(compressedTitle) == false)
                        {
                            compressedTitleToDateCopy.Add(compressedTitle, copy.CreatedUtc.Date);
                        }
                    }
                }
            }

            //TODO: SDH: Temporary, as sometimes we get collection was modified from the EntryCollection...why does this happen? "Database" corruption?
            // Misaligned Entries?
            catch (InvalidOperationException) //something wrong enumerating the entries?
            {
                //set flags to start over to prevent getting stuck...
                booting      = true;
                changeNumber = 0;
                throw;
            }

            //try to be a little more "Atomic" as others have been enumerating this list...
            entryIDToDate.Clear();
            entryIDToDate = entryIdToDateCopy;

            compressedTitleToDate.Clear();
            compressedTitleToDate = compressedTitleToDateCopy;

            entriesCache = entriesCacheCopy;

            changeNumber = data.CurrentEntryChangeCount;

            return(true);
        }