/// <summary>
        /// insert a new IDBCommand to the queue
        /// </summary>
        /// <param name="command">Command</param>
        public void Insert(IDBCommand command)
        {
            lock (_locker)
            {
                _queues[command.Priority].Add(command.SourceName, command);
                command.SetQueueInsertionTimeToNow();
            }

            // Command insertions per minute
            DateTime now = DateTime.Now;

            if (_lastCommandInsertionTime.Minute == now.Minute)
            {
                _commandsInsertedInLastMinute++;
            }
            else
            {
                _commandsInsertedInLastMinute = 0;
            }
            _lastCommandInsertionTime = now;

            if (!isProcessing)
            {
                isProcessing = true;
                GatLogger.Instance.AddMessage("DB Queue has messages please do not exit.", LogMode.LogAndScreen);
            }
        }
示例#2
0
        private void _ExecuteCommand(IDBCommand command)
        {
            if (command != null)
            {
                if (command.QueryId != null && _cancelledQueries.Contains(command.QueryId))
                {
                    command.CancelCommand = true;
                }

                //if (command.Blocking)
                //    Interlocked.Decrement(ref blockingCommandsCount);


                try
                {
                    TimeSpan waitInQueueSpanTime = DateTime.Now.Subtract(command.GetQueueInsertionTime());
                    DateTime executionStartTime  = DateTime.Now;

                    //if (!isDummy)
                    //    GeneralLogger.Instance.AddLine(LogMessageType.CommandsQueueBlocking, command, command.Blocking);

                    command.Execute(_dbConnection);

                    // Writing Command DONE message to log
                    TimeSpan executionSpanTime = DateTime.Now.Subtract(executionStartTime);
                    /******************************************/

                    // Queue size exceeded - issuing warning, activating callback
                    if (Count > ct_commandQueueSizeExceededWarningThreshold)
                    {
                        GatLogger.Instance.AddMessage("Commands queue threshold exceeded", LogMode.LogAndScreen);
                    }
                    //GeneralLogger.Instance.AddLine(
                    //    LogMessageType.CommandsQueueNumberOfDBCommandsExceeded,
                    //    commandQueueSizeExceededWarningThreshold, Count);


                    // Command executions per minute
                    DateTime now = DateTime.Now;
                    if (_lastCommandExecutionTime.Minute == now.Minute)
                    {
                        _commandsExecutedInLastMinute++;
                    }
                    else
                    {
                        //GeneralLogger.Instance.AddLine(LogMessageType.CommandsQueueCurrExecutionRate, commandsExecutedInLastMinute);
                        _commandsExecutedInLastMinute = 0;
                    }

                    _lastCommandExecutionTime = now;
                }
                catch (Exception e)
                {
                    s_LogAndThrowException(command, e);
                    command.ErrorEventHandler();
                }
            }
        }
 /// <summary>
 /// Logs the exception.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <param name="e">The e.</param>
 private static void s_LogAndThrowException(IDBCommand command, Exception e)
 {
     if (e != null)
     {
         while (e.InnerException != null)
         {
             e = e.InnerException;
             GatLogger.Instance.AddMessage(string.Format("{0}: Exception Executing Command [{1}] - \n{2}",
                                                         ct_sourceName, e.Message, e.StackTrace), LogMode.LogAndScreen);
         }
     }
     throw new GatDataBaseException(string.Format("Exception was thrown while executing command: {0} Exception: {1}", command, e == null ? "Null" : e.Message), new InvalidOperationException());
 }
示例#4
0
        public override void Execute()
        {
            Console.WriteLine("{0}: Execute", GetType());

            using (IConnection session = ConnectionFactory.makeConnection())
            {
                IDBCommand cmd = session.getCommand("Z$SCRIPTS_LIB_API.mt_exec");
                cmd.withParam("P_SESSION_FILE_NAME", m_conf["SessionId"]);
                cmd.withParam("P_TEST_MT", m_conf["mt_test"]);
                cmd.withParam("P_CONDITION", m_conf["condition"]);
                cmd.Execute();

                session.Commit();
            };
        }
示例#5
0
        private static void buildAuditLogCommandParameters(AuditLog auditLog, IDBCommand command, bool useLocalTime, bool addRecord)
        {
            if (addRecord)
            {
                command.AddParameter("@id", ParameterDirection.InputOutput, auditLog.ID);
            }
            else
            {
                command.AddInParameter("@id", auditLog.ID);
            }
            command.AddInParameter("@UID", auditLog.UID);
            command.AddInParameter("@OUID", auditLog.OUID);
            command.AddInParameter("@trackingUID", auditLog.TrackingUID);
            command.AddInParameter("@entitycode", auditLog.EntityCode);
            command.AddInParameter("@entitykeys", auditLog.EntityKeys);
            command.AddInParameter("@clientMachine", auditLog.ClientMachine);
            command.AddInParameter("@relatedentitycode", auditLog.RelatedEntityCode);
            command.AddInParameter("@relatedentitykeys", auditLog.RelatedEntityKeys);
            command.AddInParameter("@action", auditLog.Action);
            if (auditLog.Created.HasValue)
            {
                command.AddInParameter("@created", auditLog.Created);
            }
            else
            {
                command.AddInParameter("@created", useLocalTime ? DateTime.Now : DateTime.UtcNow);
            }
            command.AddInParameter("@success", auditLog.Success ? "Y" : "N");
            command.AddInParameter("@processed", auditLog.Processed);
            command.AddInParameter("@createdBy", auditLog.CreatedBy);

            if (auditLog.Before == null || auditLog.Before.Count == 0)
            {
                command.AddInParameter("@before", null);
            }
            else
            {
                command.AddInParameter("@before", JsonConvert.SerializeObject(auditLog.Before));
            }
            if (auditLog.After == null || auditLog.After.Count == 0)
            {
                command.AddInParameter("@after", null);
            }
            else
            {
                command.AddInParameter("@after", JsonConvert.SerializeObject(auditLog.After));
            }
        }
        /// <summary>
        /// Filters and executes the commands until multi queue getting full again and or command is new is queue
        /// </summary>
        private void _FilterAndExecuteCommands(ThreadSafeMultiQueue <string, IDBCommand> multiQueue, CommandPriority currentPriority)
        {
            bool queueTooLoaded = multiQueue.Count() > ct_queueThreshold;

            while (_commandsToExecute.Count > 0)
            {
                if (_GetHighestNonEmptyPriority() < currentPriority)
                {
                    return;
                }

                if (queueTooLoaded)
                {
                    //if filtering process began when queue was too loaded or there is blocking command in queue
                    //all commands that passed in the filter will be executed regardless of
                    //how much time they were in queue
                    _ExecuteCommand(_commandsToExecute.Dequeue());
                }
                else if (_MinimumCommandQueueTime.HasValue)
                {
                    //If commands was not in queue for enough time the execution process is halted
                    IDBCommand nextCommand     = _commandsToExecute.Peek();
                    DateTime   filterThreshold = nextCommand.GetQueueInsertionTime() + _MinimumCommandQueueTime.Value;
                    if (_lastFilterEndTime < filterThreshold)
                    {
                        return;
                    }

                    _ExecuteCommand(_commandsToExecute.Dequeue());
                }
                else
                {
                    throw new GatDataBaseException(
                              "filterAndExecuteCommands was called when queueTooLoaded = false and !parameters.MinimumCommandQueueTime.HasValue");
                }

                //If queue is getting loaded the execution process is halted
                if (multiQueue.Count() >= ct_queueThreshold)
                {
                    return;
                }
            }
        }
示例#7
0
        protected void internalInit()
        {
            string procName = "Z$ATT_TEST_SCRIPT_LIB.GenNewSession";

            DataTable dt = null;

            using (IbsoConnection conn = new IbsoConnection())
            {
                conn.Open();
                IDBCommand cmd = conn.getCommand(procName, testSet.Session.Timeout);
                cmd.withParam("p_ext_scr_code", ScenarioId);
                cmd.withCursor("P_XML_CLOB");
                cmd.withParam("p_contur", ConturId);
                cmd.withParam("p_profile", ProfileId);
                cmd.withParam("p_testset", TestSetId);
                cmd.withParam("p_jour_id", JournalId);
                cmd.withParam("p_log_path", logsFolder);
                dt = (DataTable)cmd.Execute();
                conn.Commit();
                conn.Close();
            }

            if (dt.Rows.Count != 1 || dt.Columns.Count != 2)
            {
                throw new TestRunException(String.Format("Вызов процедуры \"{0}\" вернул неверный набор данных. Вернулось строк: {1}, стобцов: {2}. Ожидалось строк: {3}, столбцов: {4}", procName, dt.Rows.Count, dt.Columns.Count, 1, 2));
            }

            string testRunId = dt.Rows[0][1].ToString();

            if (String.IsNullOrEmpty(testRunId))
            {
                throw new TestRunException("Не заполнено обязательное поле \"Имя файла сценария\"");
            }

            IDictionary <string, string> dict = new Dictionary <string, string>();

            dict.Add("testRunId", dt.Rows[0][1].ToString());
            m_conf.updateFrom(dict);

            XmlDocument doc = new XmlDocument();

            try
            {
                doc.LoadXml(dt.Rows[0][0].ToString());
            }
            catch (Exception e)
            {
                throw new TestRunException("Не удалось разобрать xml-содержимое файла сценария", e);
            }

            XmlNode test_node = doc.DocumentElement.FirstChild;

            while (test_node != null)
            {
                Dictionary <string, string> p = new Dictionary <string, string>();
                foreach (XmlAttribute attrib in test_node.Attributes)
                {
                    p.Add(attrib.Name, attrib.Value);
                }
                ITest t = new Test(this, p, test_node);
                m_testList.Add(t);
                test_node = test_node.NextSibling;
            }
        }
示例#8
0
 public void Add(IDBCommand command)
 {
     commandList.Add(command);
 }
示例#9
0
        public IList <IDictionary <string, string> > getCases()
        {
            const string procName = "Z$att_test_script_lib.GETTESTS";


            List <IDictionary <string, string> > list = new List <IDictionary <string, string> >();

            Dictionary <string, string> dict = null;

            DataTable dt = new DataTable();

            using (IbsoConnection conn = new IbsoConnection(m_conf["db_user"], m_conf["db_password"], m_conf["db_name"]))
            {
                conn.Open();
                IDBCommand cmd = conn.getCommand(procName, Timeout);
                cmd.withParam("P_COMP", compName);
                cmd.withParam("P_USER", userName);
                cmd.withParam("P_RUN_ERR", failuresOnly);
                cmd.withCursor("P_RECORDSET");
                dt = (DataTable)cmd.Execute();
                conn.Commit();
                conn.Close();
            }

            foreach (DataRow r in dt.Rows)
            {
                dict = new Dictionary <string, string>();

                foreach (DataColumn c in dt.Columns)
                {
                    dict.Add(c.ColumnName, r[c].ToString());
                }

                list.Add(dict);
            }

            /*
             * if (dt.Columns.Count < 6)
             * {
             *  throw new Exception("Выполнение тест сета невозможно. При получении списка тестов получено " + dt.Columns.Count + " полей. Ожидалось не менее 6 полей");
             * }
             *
             * if (dt.Rows.Count > 0)
             * {
             *  for (int i = 0; i < dt.Rows.Count; i++)
             *  {
             *      ScenarioRunConfig config = new ScenarioRunConfig();
             *      config.TestSetId = dt.Rows[i][0].ToString();
             *      config.ScenarioId = dt.Rows[i][1].ToString();
             *      config.ProfileId = dt.Rows[i][2].ToString();
             *      config.ConturId = dt.Rows[i][3].ToString();
             *      string tuneErrString = dt.Rows[i][4].ToString();
             *      if (tuneErrString == null || tuneErrString.Equals("")) tuneErrString = "0";
             *      config.TuneErrRun = int.Parse(tuneErrString);
             *      config.JournalId = dt.Rows[i][5].ToString();
             *
             *      if (dt.Columns.Count > 6)
             *      {
             *          List<string> additionalValues = new List<string>();
             *          for (int k = 6; k < dt.Columns.Count; k++)
             *          {
             *              additionalValues.Add(dt.Rows[i][k].ToString());
             *          }
             *          config.AdditionalValues = additionalValues.ToArray();
             *      }
             *      else
             *      {
             *          config.AdditionalValues = new string[] { };
             *      }
             *
             *      res.Add(config);
             *  }
             * }*/

            return(list);
        }
示例#10
0
 /// <summary>
 /// Executes query in database.
 /// </summary>
 /// <param name="query">Query to execute.</param>
 protected virtual void ExecuteDbQuery(IDBCommand query)
 {
     query.Execute();
 }
 protected int ExecuteQuery(IDBCommand query)
 {
     return(_dbExecutor != null?query.Execute(_dbExecutor) : query.Execute());
 }