public static RemindersState <T> Get(ICorePropertyBag propertyBag, PropertyDefinition propertyDefinition) { Util.ThrowOnNullArgument(propertyBag, "propertyBag"); Util.ThrowOnNullArgument(propertyDefinition, "propertyDefinition"); ExTraceGlobals.RemindersTracer.TraceDebug <PropertyDefinition>(0L, "RemindersState.Get - from property bag propertyDefinition={0}", propertyDefinition); return(RemindersState <T> .GetFromStream(new RemindersState <T> .OpenPropertyStreamDelegate(propertyBag.OpenPropertyStream), propertyDefinition)); }
public static void Set(IItem item, PropertyDefinition propertyDefinition, RemindersState <T> newState) { Util.ThrowOnNullArgument(item, "item"); Util.ThrowOnNullArgument(propertyDefinition, "propertyDefinition"); Util.ThrowOnMismatchType <byte[]>(propertyDefinition, "propertyDefinition"); ExTraceGlobals.RemindersTracer.TraceDebug <StoreObjectId, PropertyDefinition>(0L, "RemindersState.Set - item={0}, propertyDefinition={1}", item.StoreObjectId, propertyDefinition); if (newState == null) { ExTraceGlobals.RemindersTracer.TraceDebug <PropertyDefinition>(0L, "RemindersState.Set - newState is null, deleting property={0}", propertyDefinition); item.Delete(propertyDefinition); return; } RemindersState <T> .ValidateStateIdentifiers(newState); ExTraceGlobals.RemindersTracer.TraceDebug <int>(0L, "RemindersState.Set - Serializing reminder states, count={0}", newState.StateList.Count); using (Stream stream = item.OpenPropertyStream(propertyDefinition, PropertyOpenMode.Create)) { if (newState.StateList.Count > 0) { IReminderState reminderState = newState.StateList[0]; newState.Version = reminderState.GetCurrentVersion(); } using (XmlWriter xmlWriter = XmlWriter.Create(stream)) { DataContractSerializer dataContractSerializer = new DataContractSerializer(typeof(RemindersState <T>)); dataContractSerializer.WriteObject(xmlWriter, newState); } } }
public static RemindersState <T> Get(IItem item, PropertyDefinition propertyDefinition) { Util.ThrowOnNullArgument(item, "item"); Util.ThrowOnNullArgument(propertyDefinition, "propertyDefinition"); ExTraceGlobals.RemindersTracer.TraceDebug <StoreObjectId, PropertyDefinition>(0L, "RemindersState.Get - item={0}, propertyDefinition={1}", item.StoreObjectId, propertyDefinition); return(RemindersState <T> .GetFromStream(new RemindersState <T> .OpenPropertyStreamDelegate(item.OpenPropertyStream), propertyDefinition)); }
private static RemindersState <T> GetFromStream(RemindersState <T> .OpenPropertyStreamDelegate openPropertyStreamMethod, PropertyDefinition propertyDefinition) { RemindersState <T> result; try { using (Stream stream = openPropertyStreamMethod(propertyDefinition, PropertyOpenMode.ReadOnly)) { DataContractSerializer dataContractSerializer = new DataContractSerializer(typeof(RemindersState <T>)); result = (RemindersState <T>)dataContractSerializer.ReadObject(stream); } } catch (ObjectNotFoundException arg) { ExTraceGlobals.RemindersTracer.TraceError <ObjectNotFoundException>(0L, "RemindersState.Get - object not found, exception={0}", arg); result = null; } catch (Exception ex) { ExTraceGlobals.RemindersTracer.TraceError <Exception>(0L, "RemindersState.Get - exception={0}", ex); if (!RemindersState <T> .IsCorruptDataException(ex)) { throw; } result = new RemindersState <T>(); } return(result); }
internal static void ValidateStateIdentifiers(RemindersState <T> newState) { ExTraceGlobals.RemindersTracer.TraceDebug(0L, "RemindersState.ValidateStateIdentifiers"); List <T> list = newState.StateList; Util.ThrowOnNullArgument(list, "newStateList"); ExTraceGlobals.RemindersTracer.TraceDebug <int>(0L, "RemindersState.ValidateStateIdentifiers - newStateList count={0}", list.Count); foreach (T t in list) { if (t.Identifier == Guid.Empty) { throw new ArgumentException("state.Identifier is Guid.Empty", "state.Identifier"); } } }