/// <summary> /// Gemmer XML dokumentet indeholdende lokale synkroniserede data i det lokale datalager. /// </summary> /// <param name="localeDataDocument">XML dokumentet indeholdende lokale synkroniserede data.</param> public virtual void StoreSyncDocument(XDocument localeDataDocument) { if (localeDataDocument == null) { throw new ArgumentNullException("localeDataDocument"); } if (OnCreateWriterStream == null) { throw new IntranetGuiRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.EventHandlerNotDefined, "OnCreateWriterStream")); } try { lock (SyncRoot) { var handleStreamCreationEventArgs = new HandleStreamCreationEventArgs(true); OnCreateWriterStream.Invoke(this, handleStreamCreationEventArgs); using (var writerStream = handleStreamCreationEventArgs.Result) { if (PrepareLocaleData != null) { PrepareLocaleData.Invoke(this, new PrepareLocaleDataEventArgs(localeDataDocument, false, true, true)); } WriteDocument(localeDataDocument, writerStream); } } } catch (IntranetGuiRepositoryException) { throw; } catch (Exception ex) { throw new IntranetGuiRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.RepositoryError, "StoreSyncDocument", ex.Message), ex); } }
/// <summary> /// Gemmer synkroniseringsdata i det lokale datalager. /// </summary> /// <typeparam name="T">Typen på synkroniseringsdata, der skal gemmes i det lokale datalager.</typeparam> /// <param name="model">Synkroniseringsdata, der skal gemmes i det lokale datalager.</param> public virtual void StoreSyncData <T>(T model) where T : IModel { if (Equals(model, null)) { throw new ArgumentNullException("model"); } if (OnCreateWriterStream == null) { throw new IntranetGuiRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.EventHandlerNotDefined, "OnCreateWriterStream")); } try { lock (SyncRoot) { var handleStreamCreationEventArgs = new HandleStreamCreationEventArgs(true); OnCreateWriterStream.Invoke(this, handleStreamCreationEventArgs); using (var writerStream = handleStreamCreationEventArgs.Result) { XDocument localeDataDocument; if (writerStream.Length == 0) { var localeDataSchema = Schema; var localeDataNamespace = localeDataSchema.Root.GetDefaultNamespace().NamespaceName; var localeDataRootName = localeDataSchema.Root.Element(XName.Get("element", "http://www.w3.org/2001/XMLSchema")).Attribute(XName.Get("name", string.Empty)).Value; localeDataDocument = new XDocument(new XDeclaration("1.0", "utf-8", null)); localeDataDocument.Add(new XElement(XName.Get(localeDataRootName, localeDataNamespace))); } else { localeDataDocument = ReadDocument(writerStream); } StoreInDocument(model, localeDataDocument, true); if (PrepareLocaleData != null) { PrepareLocaleData.Invoke(this, new PrepareLocaleDataEventArgs(localeDataDocument, false, true, true)); } WriteDocument(localeDataDocument, writerStream); } } } catch (IntranetGuiRepositoryException) { throw; } catch (Exception ex) { throw new IntranetGuiRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.RepositoryError, "StoreSyncData", ex.Message), ex); } }
/// <summary> /// Henter data fra det lokale datalager. /// </summary> /// <returns>XDocument, der indeholder data fra det lokale datalager.</returns> public virtual XDocument GetLocaleData() { if (OnCreateReaderStream == null) { throw new IntranetGuiRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.EventHandlerNotDefined, "OnCreateReaderStream")); } try { lock (SyncRoot) { var handleStreamCreationEventArgs = new HandleStreamCreationEventArgs(this); OnCreateReaderStream.Invoke(this, handleStreamCreationEventArgs); using (var readerStream = handleStreamCreationEventArgs.Result) { if (readerStream == null) { throw new IntranetGuiRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.IllegalArgumentValue, "readerStream", null)); } var localeDataDocument = ReadDocument(readerStream); if (PrepareLocaleData != null) { PrepareLocaleData.Invoke(this, new PrepareLocaleDataEventArgs(localeDataDocument, true, false, false)); } return(localeDataDocument); } } } catch (IntranetGuiRepositoryException) { throw; } catch (Exception ex) { throw new IntranetGuiRepositoryException(Resource.GetExceptionMessage(ExceptionMessage.RepositoryError, "GetLocaleData", ex.Message), ex); } }