コード例 #1
0
 public static string GetSequencePrefix(IDataLayer dataLayer)
 {
     if (dataLayer == null)
     {
         throw new ArgumentNullException("dataLayer");
     }
     lock (SyncRoot) {
         if (dataLayerForCachedServerPrefix /*.Target*/ != dataLayer)
         {
             using (Session session = new Session(dataLayer)) {
                 XpoServerId sid = session.GetObjectByKey <XpoServerId>(0);
                 if (sid == null)
                 {
                     // we can throw exception here instead of creating random prefix
                     sid = new XpoServerId(session);
                     sid.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);
     }
 }
コード例 #2
0
        static void Do(string seqPrefix)
        {
            int nextUniqueValue = XpoServerId.GetNextUniqueValue(seqPrefix);

            Console.WriteLine("seq '{0}': {1}", seqPrefix, nextUniqueValue);
        }