private static ConfigurationDocumentHeader GetDocumentHeader(ConfigurationDocument document) { var key = new ConfigurationDocumentKey( document.DocumentName, VersionUtils.FromPaddedVersionString(document.DocumentVersionString), document.User, document.InstanceKey); return(new ConfigurationDocumentHeader(key, document.CreationTime, document.Body.ModifiedTime)); }
public override bool Equals(object obj) { ConfigurationDocument that = obj as ConfigurationDocument; if (that == null) { return(false); } return(this._documentName == that._documentName && this._documentVersionString == that._documentVersionString && this._instanceKey == that._instanceKey && this._user == that._user); }
internal static SystemIdentityStore Load() { if (_store != null) return _store; lock (_syncroot) { if (_store == null) { const string userName = "******"; var serializer = new XmlSerializer(typeof (SystemIdentityStore)); var documentName = typeof (SystemIdentityStore).FullName; var versionString = VersionUtils.ToPaddedVersionString(new Version(0, 0), false, false); var criteria = new ConfigurationDocumentSearchCriteria(); criteria.User.EqualTo(userName); criteria.DocumentName.EqualTo(documentName); criteria.DocumentVersionString.EqualTo(versionString); SystemIdentityStore store = null; using (var scope = new PersistenceScope(PersistenceContextType.Read)) { var broker = scope.Context.GetBroker<IConfigurationDocumentBroker>(); var document = broker.Find(criteria).FirstOrDefault(); if (document != null) { try { using (var reader = new StringReader(document.Body.DocumentText)) store = (SystemIdentityStore) serializer.Deserialize(reader); } catch (Exception) { store = null; } } scope.Complete(); } if (store == null || store.SecretKey == null || store.SecretKey.Length == 0) { if (store == null) store = new SystemIdentityStore(); store.SecretKey = new byte[128]; using (var crng = new RNGCryptoServiceProvider()) crng.GetBytes(store.SecretKey); using (var scope = new PersistenceScope(PersistenceContextType.Update)) using (var writer = new StringWriter()) { serializer.Serialize(writer, store); var broker = scope.Context.GetBroker<IConfigurationDocumentBroker>(); var document = broker.Find(criteria).FirstOrDefault(); if (document != null) { document.Body.DocumentText = writer.ToString(); } else { document = new ConfigurationDocument(documentName, versionString, userName, null); document.Body.DocumentText = writer.ToString(); scope.Context.Lock(document, DirtyState.New); } scope.Complete(); } } Interlocked.Exchange(ref _store, store); } return _store; } }
private static ConfigurationDocumentHeader GetDocumentHeader(ConfigurationDocument document) { var key = new ConfigurationDocumentKey( document.DocumentName, VersionUtils.FromPaddedVersionString(document.DocumentVersionString), document.User, document.InstanceKey); return new ConfigurationDocumentHeader(key, document.CreationTime, document.Body.ModifiedTime); }
internal static SystemIdentityStore Load() { if (_store != null) { return(_store); } lock (_syncroot) { if (_store == null) { const string userName = "******"; var serializer = new XmlSerializer(typeof(SystemIdentityStore)); var documentName = typeof(SystemIdentityStore).FullName; var versionString = VersionUtils.ToPaddedVersionString(new Version(0, 0), false, false); var criteria = new ConfigurationDocumentSearchCriteria(); criteria.User.EqualTo(userName); criteria.DocumentName.EqualTo(documentName); criteria.DocumentVersionString.EqualTo(versionString); SystemIdentityStore store = null; using (var scope = new PersistenceScope(PersistenceContextType.Read)) { var broker = scope.Context.GetBroker <IConfigurationDocumentBroker>(); var document = broker.Find(criteria).FirstOrDefault(); if (document != null) { try { using (var reader = new StringReader(document.Body.DocumentText)) store = (SystemIdentityStore)serializer.Deserialize(reader); } catch (Exception) { store = null; } } scope.Complete(); } if (store == null || store.SecretKey == null || store.SecretKey.Length == 0) { if (store == null) { store = new SystemIdentityStore(); } store.SecretKey = new byte[128]; using (var crng = new RNGCryptoServiceProvider()) crng.GetBytes(store.SecretKey); using (var scope = new PersistenceScope(PersistenceContextType.Update)) using (var writer = new StringWriter()) { serializer.Serialize(writer, store); var broker = scope.Context.GetBroker <IConfigurationDocumentBroker>(); var document = broker.Find(criteria).FirstOrDefault(); if (document != null) { document.Body.DocumentText = writer.ToString(); } else { document = new ConfigurationDocument(documentName, versionString, userName, null); document.Body.DocumentText = writer.ToString(); scope.Context.Lock(document, DirtyState.New); } scope.Complete(); } } Interlocked.Exchange(ref _store, store); } return(_store); } }