public static string GetSequencePrefix(IDataLayer dataLayer) { if (dataLayer == null) throw new ArgumentNullException("dataLayer"); lock (SyncRoot) { if (dataLayerForCachedServerPrefix/*.Target*/ != dataLayer) { using (var session = new Session(dataLayer)) { var sid = session.GetObjectByKey<XpoServerId>(0); if (sid == null) { // we can throw exception here instead of creating random prefix sid = new XpoServerId(session) { SequencePrefix = XpoDefault.NewGuid().ToString() }; try { sid.Save(); } catch { sid = session.GetObjectByKey<XpoServerId>(0, true); if (sid == null) throw; } } cachedSequencePrefix = sid.SequencePrefix; dataLayerForCachedServerPrefix = dataLayer; // dataLayerForCachedServerPrefix.Target = dataLayer; <<< if WeakReference } } return cachedSequencePrefix; } }
public static string GetSequencePrefix(IDataLayer dataLayer) { if (dataLayer == null) { throw new ArgumentNullException("dataLayer"); } lock (SyncRoot) { if (dataLayerForCachedServerPrefix /*.Target*/ != dataLayer) { using (var session = new Session(dataLayer)) { var sid = session.GetObjectByKey <XpoServerId>(0); if (sid == null) { // we can throw exception here instead of creating random prefix sid = new XpoServerId(session) { SequencePrefix = XpoDefault.NewGuid().ToString() }; try { sid.Save(); } catch { sid = session.GetObjectByKey <XpoServerId>(0, true); if (sid == null) { throw; } } } cachedSequencePrefix = sid.SequencePrefix; dataLayerForCachedServerPrefix = dataLayer; // dataLayerForCachedServerPrefix.Target = dataLayer; <<< if WeakReference } } return(cachedSequencePrefix); } }