Esempio n. 1
0
        public void WriteLog(PullValue logValue, DateTime logDate, string RegionId)
        {
            if (!Directory.Exists(globalLogPath + "\\" + RegionId + "\\" + String.Format("{0}", logValue.Id)))
            {
                Directory.CreateDirectory(globalLogPath + "\\" + RegionId + "\\" + String.Format("{0}", logValue.Id));
            }
            var logFileName = globalLogPath + "\\" + RegionId + "\\" + String.Format("{0}", logValue.Id) + "\\" + String.Format("{0:ddMMyyyy}.log", logDate);

            File.AppendAllText(logFileName, String.Format("[{0}] {1:HH:mm:ss} Message: {2}", (logValue.Status == TaskRunningStatus.Failure) ? "ERROR" : "MESSAGE", logDate, logValue.Log) + Environment.NewLine);
        }
        private async void OperateAsyncCommand(SqlCommand _command)
        {
            var    commandLocal  = _command;
            var    timer         = new Stopwatch();
            var    token         = new CancellationToken();
            var    pullValue     = new PullValue();
            var    eventArgs     = new AsyncLogEventArgs();
            string directionPath = "";

            try
            {
                commandLocal.CommandTimeout = 99999;
                timer.Start();
                tokens.Add(token);
                pullValue.Id = _command.Parameters[0].Value.ToString();
                if (commandLocal.Connection.State == System.Data.ConnectionState.Closed)
                {
                    commandLocal.Connection.Open();
                }
                if (workDirectories.ContainsKey(pullValue.Id))
                {
                    commandLocal.CommandText += ", N'" + workDirectories[pullValue.Id] + "'";
                }
                pullValue.ISError = false;
                pullValue.Status  = TaskRunningStatus.Running;
                pullValue.Log     = "Начинается обработка значения...";
                FileLogger.GetInstance().WriteLog(pullValue, DateTime.Now, this.RegionID);
                var task = await commandLocal.ExecuteNonQueryAsync(token);

                directionPath = workDirectories[pullValue.Id];
                pullValue.Log = "Ожидается обработка реплики...";
                FileLogger.GetInstance().WriteLog(pullValue, DateTime.Now, this.RegionID);
                var waitTask = WaitForFile(directionPath + "\\gmmq.package.end");
                waitTask.Wait(OperationsAPI.PackageExistWaitTimeOut);
                pullValue.Log     = string.Format("Операция успешна");
                pullValue.ISError = false;
                pullValue.Status  = TaskRunningStatus.Success;
                FileLogger.GetInstance().WriteLog(pullValue, DateTime.Now, this.RegionID);
            }
            catch (Exception e)

            {
                pullValue.Log     = string.Format("Операция завершилась со следующей ошибкой:{0}", e.Message);
                pullValue.ISError = true;
                pullValue.Status  = TaskRunningStatus.Failure;
                FileLogger.GetInstance().WriteLog(pullValue, DateTime.Now, this.RegionID);
                if (commandLocal.Connection.State == System.Data.ConnectionState.Open)
                {
                    commandLocal.Connection.Close();
                }
            }
            finally
            {
                timer.Stop();
                lock (this)
                {
                    --lastElementCount;
                }
                pullValue.Time = string.Format("{0:d2}:{1:d2}:{2:d4}", timer.Elapsed.Minutes, timer.Elapsed.Seconds, timer.Elapsed.Milliseconds);
                logs.Add(pullValue);

                tokens.Remove(token);
                if (commandLocal.Connection.State == System.Data.ConnectionState.Open)
                {
                    commandLocal.Connection.Close();
                }
                FinishProcess();
            }
        }