private void FlushCategoryUsageLog() { foreach (KeyValuePair <StoreObjectId, MasterCategoryList.PerFolderCategoryUsageLog> keyValuePair in this.categoryUsageLog) { if (keyValuePair.Key != MasterCategoryList.invalidId && keyValuePair.Value.OutlookModule == null) { try { using (Folder folder = Folder.Bind(this.session, keyValuePair.Key)) { keyValuePair.Value.OutlookModule = new OutlookModule?(MasterCategoryList.GetModuleForObjectClass(folder.ClassName)); } } catch (ObjectNotFoundException) { keyValuePair.Value.OutlookModule = new OutlookModule?(OutlookModule.None); } } } foreach (KeyValuePair <StoreObjectId, MasterCategoryList.PerFolderCategoryUsageLog> keyValuePair2 in this.categoryUsageLog) { foreach (KeyValuePair <MasterCategoryList.CategoryUsageRecord, ExDateTime> keyValuePair3 in keyValuePair2.Value.CategoryUsageRecords) { Category category = this[keyValuePair3.Key.CategoryName]; if (category != null) { category.UpdateLastTimeUsed(keyValuePair3.Value, (keyValuePair2.Value.OutlookModule != null && keyValuePair2.Value.OutlookModule != OutlookModule.None) ? keyValuePair2.Value.OutlookModule : new OutlookModule?(keyValuePair3.Key.ModuleForItem)); } } keyValuePair2.Value.CategoryUsageRecords.Clear(); } }
private MasterCategoryList MergeCopies(SaveMode saveMode, UserConfiguration mclConfigurationItem, Stream mclXmlStream) { MasterCategoryList masterCategoryList = new MasterCategoryList(); switch (saveMode) { case SaveMode.ResolveConflicts: try { using (Stream stream = new BoundedStream(mclXmlStream, false, 0L, 524288L)) { using (XmlReader xmlReader = XmlReader.Create(stream)) { new MasterCategoryListSerializer(xmlReader).Deserialize(masterCategoryList); } } } catch (CorruptDataException ex) { Exception ex2 = new SaveConflictException(ServerStrings.ExMclCannotBeResolved, ex); ExTraceGlobals.StorageTracer.TraceDebug <SaveMode, string>((long)this.GetHashCode(), "Failed to load the Server copy of MCL for conflict resolution (SaveMode={0}): {1}", saveMode, ex.Message); throw ex2; } return(MasterCategoryList.Resolve(this, masterCategoryList, this.originalMcl)); case SaveMode.FailOnAnyConflict: throw new SaveConflictException(ServerStrings.ExSaveFailedBecauseOfConflicts(mclConfigurationItem.Id), null); case SaveMode.NoConflictResolution: return(this); default: throw new ArgumentOutOfRangeException("saveMode"); } }
private static MasterCategoryList Resolve(MasterCategoryList client, MasterCategoryList server, MasterCategoryList original) { MasterCategoryList masterCategoryList = new MasterCategoryList(); masterCategoryList.SetProperties(MasterCategoryList.ResolveProperties(client.propertyBag, server.propertyBag, original.propertyBag, AcrProfile.MasterCategoryListProfile)); HashSet <Category> hashSet = new HashSet <Category>(server.Count); Util.AddRange <Category, Category>(hashSet, server); foreach (Category category in client) { Category category2 = server.FindMatch(category); Category original2 = original.FindMatch(category); Category category3 = Category.Resolve(category, category2, original2); if (category3 != null && masterCategoryList.FindMatch(category3) == null) { masterCategoryList.Add(category3); } if (category2 != null) { hashSet.Remove(category2); } } foreach (Category category4 in hashSet) { Category original3 = original.FindMatch(category4); Category category5 = Category.Resolve(null, category4, original3); if (category5 != null && masterCategoryList.FindMatch(category5) == null) { masterCategoryList.Add(category5); } } return(masterCategoryList); }
private MasterCategoryList(MasterCategoryList copyFrom) : this(new MemoryPropertyBag(copyFrom.propertyBag)) { foreach (Category category in copyFrom) { this.Add(category.Clone()); } }
internal void AssignMasterCategoryList(MasterCategoryList masterCategoryList) { this.CheckAbandoned("AssignMasterCategoryList"); if (this.masterCategoryList == null) { this.masterCategoryList = masterCategoryList; return; } throw new InvalidOperationException("Category cannot be added to more than one MasterCategoryList"); }
private Category FindMatchingCategory(MasterCategoryList mcl) { string text = (string)this.ReadAttributeForProperty(InternalSchema.CategoryName); Guid? guid = (Guid?)this.ReadAttributeForProperty(InternalSchema.CategoryGuid); if (text == null || guid == null) { return(null); } return(mcl[guid.Value] ?? mcl[text]); }
internal static void Serialize(MasterCategoryList mcl, XmlWriter xmlWriter) { MasterCategoryListSerializer.CatchSerializationException(delegate { xmlWriter.WriteStartElement("categories", "CategoryList.xsd"); IEnumerable <PropValue> properties = MasterCategoryListSerializer.GetProperties(new MasterCategoryListSerializer.TryGetPropertyDelegate(mcl.TryGetProperty), MasterCategoryListSchema.Instance.AllProperties); MasterCategoryListSerializer.WriteAttributesForProperties(xmlWriter, MasterCategoryListSerializer.PropValuesToAttributeNameValues(properties)); MasterCategoryListSerializer.WriteCategoryElements(xmlWriter, mcl); xmlWriter.WriteEndElement(); }); }
internal static IEnumerable <PropValue> ResolveProperties(MemoryPropertyBag client, MemoryPropertyBag server, MemoryPropertyBag original, AcrProfile profile) { ConflictResolutionResult resolutionResult = profile.ResolveConflicts(MasterCategoryList.GetPropValuesToResolve(client, server, original, profile)); if (resolutionResult.SaveStatus == SaveResult.IrresolvableConflict) { throw new Exception(); } foreach (PropertyConflict conflict in resolutionResult.PropertyConflicts) { yield return(new PropValue(InternalSchema.ToStorePropertyDefinition(conflict.PropertyDefinition), conflict.ResolvedValue)); } yield break; }
private void LoadCategory(MasterCategoryList mcl) { Category category = null; try { category = Category.Load(this.ReadAttributes(CategorySchema.Instance)); } catch (CorruptDataException ex) { ExTraceGlobals.StorageTracer.TraceDebug <string>(0L, "Data for 1 category is malformed and cannot be corrected. Skipping. Error: {0}", ex.Message); this.ReportFault(); } if (category != null) { this.AddResolvingDuplicates(mcl, category); } this.xmlReader.Skip(); }
internal void Deserialize(MasterCategoryList mcl) { MasterCategoryListSerializer.CatchSerializationException(delegate { bool flag = false; this.xmlReader.Read(); while (!this.xmlReader.EOF) { if (this.xmlReader.NodeType == XmlNodeType.Element && this.IsFromCategoriesNamespace()) { this.EnsureLocationIsExpectedForKnownElements(flag); string localName; if ((localName = this.xmlReader.LocalName) != null) { if (localName == "categories") { mcl.SetProperties(this.ReadAttributes(MasterCategoryListSchema.Instance)); flag = true; this.xmlReader.Read(); continue; } if (localName == "category") { this.LoadCategory(mcl); continue; } } this.xmlReader.Skip(); } else { this.xmlReader.Skip(); } } if (!flag) { this.ReportFault(); } }); }
private void AddResolvingDuplicates(MasterCategoryList mcl, Category categoryToLoad) { Category category = mcl.FindMatch(categoryToLoad); if (category == null) { mcl.Add(categoryToLoad); return; } this.ReportFault(); ExTraceGlobals.StorageTracer.TraceDebug((long)this.GetHashCode(), "Duplicate Category found while deserializing a MasterCategoriesList: Name = \"{0}\" ({1}), Guid = \"{2}\" ({3})", new object[] { categoryToLoad.Name, (categoryToLoad.Name == category.Name) ? "same" : "different", categoryToLoad.Guid, (categoryToLoad.Guid == category.Guid) ? "same" : "different" }); Category item = Category.Resolve(categoryToLoad, category, null); mcl.Remove(category.Name); mcl.Add(item); }
private void MovePersistentContent(MasterCategoryList sourceMcl) { if (this == sourceMcl) { List <Category> list = new List <Category>(this.Count); foreach (Category category in this) { list.Add(category.Clone()); } this.Clear(); Util.AddRange <Category, Category>(this, list); return; } this.Clear(); foreach (Category category2 in sourceMcl.categories.Values) { category2.Detach(); this.Add(category2); } sourceMcl.categories.Clear(); this.propertyBag = sourceMcl.propertyBag; sourceMcl.propertyBag = new MemoryPropertyBag(); }
private static Category Merge(Category client, Category server, Category original) { return(Category.Load(MasterCategoryList.ResolveProperties(client.propertyBag, server.propertyBag, (original != null) ? original.propertyBag : null, AcrProfile.CategoryProfile))); }
internal void CategoryWasUsed(StoreId itemId, string itemClass, string categoryName) { if (this.IsLoaded && !this.Contains(categoryName)) { return; } if (this.categoryUsageLogSize >= 500) { ExTraceGlobals.StorageTracer.TraceDebug((long)this.GetHashCode(), "Category usage log size has reached its maximum of {0} entries. Cannot add this: category=\"{1}\", class=\"{2}\", id=\"{3}\"", new object[] { 500, categoryName, itemClass, itemId }); return; } StoreObjectId parentFolderId; if (itemId != null) { StoreObjectId storeObjectId = StoreId.GetStoreObjectId(itemId); parentFolderId = this.session.GetParentFolderId(storeObjectId); } else { parentFolderId = MasterCategoryList.invalidId; } MasterCategoryList.PerFolderCategoryUsageLog perFolderCategoryUsageLog; if (!this.categoryUsageLog.TryGetValue(parentFolderId, out perFolderCategoryUsageLog)) { perFolderCategoryUsageLog = new MasterCategoryList.PerFolderCategoryUsageLog(); this.categoryUsageLog.Add(parentFolderId, perFolderCategoryUsageLog); } MasterCategoryList.CategoryUsageRecord key = new MasterCategoryList.CategoryUsageRecord(categoryName, MasterCategoryList.GetModuleForObjectClass(itemClass)); perFolderCategoryUsageLog.CategoryUsageRecords[key] = ExDateTime.GetNow(ExTimeZone.UtcTimeZone); this.categoryUsageLogSize++; }
internal void SerializeUsingSource(MasterCategoryList mcl, XmlWriter xmlWriter) { MasterCategoryListSerializer.CatchSerializationException(delegate { bool flag = false; HashSet <Category> hashSet = new HashSet <Category>(mcl.Count); Util.AddRange <Category, Category>(hashSet, mcl); this.xmlReader.Read(); while (!this.xmlReader.EOF) { if (this.xmlReader.NodeType == XmlNodeType.Element && this.IsFromCategoriesNamespace()) { this.EnsureLocationIsExpectedForKnownElements(flag); string localName; if ((localName = this.xmlReader.LocalName) != null) { if (localName == "categories") { xmlWriter.WriteStartElement(this.xmlReader.Prefix, this.xmlReader.LocalName, this.xmlReader.NamespaceURI); this.CopyOrOverrideAttributes(xmlWriter, MasterCategoryListSerializer.GetProperties(new MasterCategoryListSerializer.TryGetPropertyDelegate(mcl.TryGetProperty), MasterCategoryListSchema.Instance.AllProperties)); flag = true; if (this.xmlReader.IsEmptyElement) { MasterCategoryListSerializer.WriteCategoryElements(xmlWriter, hashSet); xmlWriter.WriteEndElement(); } this.xmlReader.Read(); continue; } if (localName == "category") { Category category = this.FindMatchingCategory(mcl); if (category != null && hashSet.Contains(category)) { xmlWriter.WriteStartElement(this.xmlReader.Prefix, this.xmlReader.LocalName, this.xmlReader.NamespaceURI); this.CopyOrOverrideAttributes(xmlWriter, MasterCategoryListSerializer.GetProperties(new MasterCategoryListSerializer.TryGetPropertyDelegate(category.TryGetProperty), CategorySchema.Instance.AllProperties)); if (this.xmlReader.IsEmptyElement) { xmlWriter.WriteEndElement(); this.xmlReader.Skip(); } else { this.xmlReader.Read(); int depth = this.xmlReader.Depth; while (this.xmlReader.Depth >= depth) { xmlWriter.WriteNode(this.xmlReader, false); } } hashSet.Remove(category); continue; } this.xmlReader.Skip(); continue; } } xmlWriter.WriteNode(this.xmlReader, false); } else if (this.xmlReader.NodeType == XmlNodeType.EndElement && this.xmlReader.LocalName == "categories") { MasterCategoryListSerializer.WriteCategoryElements(xmlWriter, hashSet); xmlWriter.WriteNode(this.xmlReader, false); } else { xmlWriter.WriteNode(this.xmlReader, false); } } if (!flag) { if (hashSet.Count > 0) { ExTraceGlobals.StorageTracer.TraceDebug((long)mcl.GetHashCode(), "The source XML didn't contain the root element we expect. Reverting to source-less serialization."); throw new CorruptDataException(ServerStrings.ExInvalidMclXml); } this.ReportFault(); } }); }