Ejemplo n.º 1
0
 public void ClearTimeout(ITimeoutHandle handle)
 {
     lock (timeoutMutex)
     {
         this.timeouts.Remove((TimeoutCallbackHandle)handle);
     }
 }
Ejemplo n.º 2
0
 private void ScheduleNextSave()
 {
     if (scheduleHandler != null)
     {
         return;
     }
     scheduleHandler = kernel.SetTimeout(SaveChanges, SaveInterval);
 }
Ejemplo n.º 3
0
 private void ScheduleNextBackup()
 {
     if (backupHandler != null)
     {
         return;
     }
     backupHandler = kernel.SetTimeout(CreateBackup, BackupInterval);
 }
Ejemplo n.º 4
0
        private void SaveChanges()
        {
            kernel.ClearTimeout(scheduleHandler);
            scheduleHandler = null;
            try
            {
                lock (SyncLock)
                {
                    var queue = BuildSaveQueue();
                    if (queue.Count > 0)
                    {
                        logger.LogDebug("Saving all pending changes to the database.");
                    }

                    using (var con = db.GetConnection())
                    {
                        con.Open();
                        while (queue.TryPeek(out var saveData))
                        {
                            var query = queryBuilder.Build(saveData);
                            if (query == null)
                            {
                                return;
                            }

                            var command = con.CreateCommand();
                            command.CommandText = query.Command;

                            var result = command.ExecuteNonQuery();
                            if (result == 0)
                            {
                                logger.LogError("Unable to save data! Abort Query failed");
                                return;
                            }

                            ClearChangeSetState(saveData);

                            queue.Dequeue();
                        }
                        con.Close();
                    }
                }
            }

            catch (Exception exc)
            {
                logger.LogInformation("ERROR SAVING DATA!! " + exc);
            }
            finally
            {
                ScheduleNextSave();
            }
        }
Ejemplo n.º 5
0
        private void BroadcastDiscordServer()
        {
            if (discordBroadcast != null)
            {
                this.kernel.ClearTimeout(discordBroadcast);
                if (this.allowDiscordNotification)
                {
                    this.Broadcast(
                        "Don't forget to join our awesome Discord. https://discord.gg/W2tgTSh Stay connected and always be in the loop!");
                    this.allowDiscordNotification = false;
                }
            }

            this.discordBroadcast = kernel.SetTimeout(BroadcastDiscordServer, DiscordNotificationInterval);
        }
Ejemplo n.º 6
0
        private void SaveChanges()
        {
            kernel.ClearTimeout(scheduleHandler);
            scheduleHandler = null;
            try
            {
                lock (SyncLock)
                {
                    logger.LogDebug("Saving all pending changes to the database.");

                    var queue = BuildSaveQueue();

                    while (queue.TryPeek(out var saveData))
                    {
                        using (var con = db.GetConnection())
                        {
                            con.Open();

                            var query = queryBuilder.Build(saveData);
                            if (query == null)
                            {
                                return;
                            }

                            var command = con.CreateCommand();
                            command.CommandText = query.Command;

                            var result = command.ExecuteNonQuery();
                            if (result == 0)
                            {
                                logger.LogError("Unable to save data! Abort Query failed");
                                return;
                            }

                            ClearChangeSetState(saveData);

                            queue.Dequeue();

                            con.Close();
                        }
                    }

                    backupProvider.ClearRestorePoint();
                    //ClearChangeSetState();
                }
            }
            catch (SqlException exc)
            {
                CreateBackup();

                backupProvider.CreateRestorePoint(entitySets);

                //foreach (SqlErrorCollection error in exc.Errors)
                //{
                //    var saveError = ParseSqlError(error.ToString());
                //    HandleSqlError(saveError);
                //}

                logger.LogError("ERROR SAVING DATA!! " + exc);
            }
            catch (Exception exc)
            {
                logger.LogError("ERROR SAVING DATA!! " + exc);
                // log this
            }
            finally
            {
                ScheduleNextSave();
            }
        }
Ejemplo n.º 7
0
 public void ClearEntityTimeout(ITimeoutHandle handle)
 {
     kernel.ClearTimeout(handle);
 }