Ejemplo n.º 1
0
 /// <summary>
 /// Convert a DJKey to a DJID.
 /// </summary>
 /// <param name="DJKey">The DJKey.</param>
 /// <param name="DJID">OUT parameter for the DJID.</param>
 /// <returns>The outcome of the operation.</returns>
 private Response DJKeyToID(long DJKey, out int DJID, DatabaseConnectivity db)
 {
     DJID = -1;
     Response r  = db.DJGetIDFromKey(DJKey);
     if (r.error)
         return r;
     if (r.message.Trim().Length == 0)
     {
         r.error = true;
         r.message = "DJKey is not valid";
         return r;
     }
     if (!int.TryParse(r.message.Trim(), out DJID))
     {
         r.error = true;
         r.message = "Exception in DJKeyToID: DJID Parse Fail";
         return r;
     }
     return r;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Convert a DJID to a DJKey.
 /// </summary>
 /// <param name="DJID">The DJID</param>
 /// <param name="DJKey">OUT parameter for the DJKey</param>
 /// <returns></returns>
 private Response DJGenerateKey(int DJID, out long DJKey, DatabaseConnectivity db)
 {
     DJKey = -1;
     Response r = new Response();
     System.Security.Cryptography.SHA1 sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     Random rand = new Random();
     byte[] randomBytes = new byte[64];
     byte[] result;
     long tempKey;
     for (; ; )
     {
         rand.NextBytes(randomBytes);
         result = sha.ComputeHash(randomBytes);
         tempKey = BitConverter.ToInt64(result, 0);
         r = db.DJGetIDFromKey(tempKey);
         if (r.error)
             return r;
         if (r.message.Trim().Length != 0)
             continue;
         r = db.DJSetKey(DJID, tempKey);
         if (r.error)
             return r;
         DJKey = tempKey;
         return r;
     }
 }