Beispiel #1
0
        public Task <bool> CalculateAndSave(SessionId sessionId)
        {
            return(Task <bool> .Factory.StartNew(() =>
            {
                try
                {
                    using (StoreKeeperDataContext context = new StoreKeeperDataContext())
                    {
                        if (context.Database.Connection.State == ConnectionState.Closed)
                        {
                            context.Database.Connection.Open();
                        }

                        SqlParameter publishParam = new SqlParameter("@Publish", SqlDbType.Bit)
                        {
                            Value = 1
                        };

                        DbCommand cmd = context.Database.Connection.CreateCommand();
                        cmd.CommandText = "exec CalculateData @Publish";
                        cmd.CommandTimeout = 0;
                        cmd.Parameters.Add(publishParam);
                        cmd.ExecuteNonQuery();
                    }
                    ISessionManager sessionManager = StoreKeeperServer.Service <ISessionManager>();
                    sessionManager.NotifyDataUpdated(sessionId);
                    return true;
                }
                catch (Exception ex)
                {
                    ApplicationContext.Log.Error(GetType(), ex);
                    return false;
                }
            }));
        }
Beispiel #2
0
        private bool GetAccountingData(SessionId callerSessionId, bool reloadAll)
        {
            try
            {
                ISessionManager sessionManager = StoreKeeperServer.Service <ISessionManager>();

                // parse data
                AccountingDataSync globalDataSync = ProcessAccountingData(false, reloadAll);

                using (StoreKeeperDataContext context = new StoreKeeperDataContext())
                {
                    // save to database
                    context.SaveLoadedData(globalDataSync);
                }
                return(true);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new DataSynchronizationError(GetType(), DataSyncErrorType.Runtime, ex.Message);
            }
        }
Beispiel #3
0
 public bool GetDatabaseLock(SessionId sessionId)
 {
     try
     {
         ISessionManager sessionManager = StoreKeeperServer.Service <ISessionManager>();
         using (StoreKeeperDataContext context = new StoreKeeperDataContext())
         {
             SqlParameter userIdParam = new SqlParameter("@UserId", sessionManager.GetRelatedUserId(sessionId));
             SqlParameter unlockParam = new SqlParameter("@Unlock", SqlDbType.Bit)
             {
                 Value = 0
             };
             context.Database.ExecuteSqlCommand("exec LockDatabase @UserId, @Unlock", userIdParam, unlockParam);
         }
         sessionManager.NotifyDatabaseLockChanged(sessionId);
         return(true);
     }
     catch (Exception ex)
     {
         ApplicationContext.Log.Error(GetType(), ex);
         return(false);
     }
 }
Beispiel #4
0
 public Task <bool> PublishData(SessionId sessionId)
 {
     return(Task <bool> .Factory.StartNew(() =>
     {
         try
         {
             lock (_lockObj)
             {
                 using (StoreKeeperDataContext context = new StoreKeeperDataContext())
                 {
                     context.Database.ExecuteSqlCommand("exec PublishData");
                 }
                 ISessionManager sessionManager = StoreKeeperServer.Service <ISessionManager>();
                 sessionManager.NotifyDataUpdated(sessionId);
                 return true;
             }
         }
         catch (Exception ex)
         {
             ApplicationContext.Log.Error(GetType(), ex);
             return false;
         }
     }));
 }