Guest User

Untitled

a guest
Aug 14th, 2015
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. /// <summary>
  2. /// Pass the given data-object to the service hosted at Aucxis.
  3. /// </summary>
  4. /// <param name="data">The data-object to be passed</param>
  5. /// <param name="fromDb">Whether the data-object originates from the local database or not.</param>
  6. /// <returns>A bool to check if the transmission was successfull. False when flooding or when the Aucxis service is offline.
  7. /// When false is returned, the client is told to delete the </returns>
  8. private static void Send(Data data, bool fromDb)
  9. {
  10.     /* If the error is flooding and doesn't originate from the database,
  11.         * we increment the count of the error in the buffer and delete the screenshot. */
  12.     if (IsFlooding(data.AucxisErrorId) && !fromDb)
  13.     {
  14.         var tuple = Buffer[data.AucxisErrorId];
  15.         Buffer[data.AucxisErrorId] = Tuple.Create(tuple.Item1, tuple.Item2 + 1);
  16.         File.Delete(data.BitmapLocation);
  17.         return;
  18.     }
  19.     /* If the error doesn't originate from the database and isn't already in the buffer,
  20.         * we add it to the buffer. */
  21.     if (!fromDb && !Buffer.ContainsKey(data.AucxisErrorId))
  22.         Buffer.Add(data.AucxisErrorId, Tuple.Create(DateTime.Now, 1));
  23.     Console.WriteLine("Data object received!\n > Subject: {0}\n > Bitmap url: {1}", data.Subject, data.BitmapLocation);
  24.     try
  25.     {
  26.         /* An attempt is made to send the data to the Aucxis service. If an EndpointNotFoundException is thrown
  27.         * the service is offline. If a screenshot url is passed, we send the bitmap over FTP to Aucxis
  28.             * and remove it from the shared folder. */
  29.         GetService().SendData(data);
  30.         if (!data.BitmapLocation.Equals(""))
  31.             SendAndDeleteBitmap(data.BitmapLocation);
  32.     }
  33.     catch (EndpointNotFoundException)
  34.     {
  35.         /* The service hosted at Aucxis is offline so we save the errorlog to our local database */
  36.         DbConnection.SaveData(data);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment