예제 #1
0
        public List <CJob> GetAll()
        {
            List <CJob> jobs = new List <CJob>();

            String sqlExpression = "sp_GetAllJobs";

            //    @"SELECT Job.ID AS JobID, CurPairNamed.BaseCurrency, CurPairNamed.QuotedCurrency,Country.Name AS Country, Tag.Name AS Tag
            //FROM[ONLOOKER].[dbo].[Job] AS Job
            //JOIN[ONLOOKER].[dbo].[Country] AS Country
            //ON Job.[CountryID] = Country.ID
            //Join[ONLOOKER].[dbo].[Tag] AS Tag
            //ON Job.TagID = Tag.ID
            //JOIN(
            //    SELECT CurPair.ID, CurTypeBase.CurrencyName AS BaseCurrency, CurTypeQuoted.CurrencyName AS QuotedCurrency

            //FROM[ONLOOKER].[dbo].[CurrencyPair] AS CurPair

            //JOIN[ONLOOKER].[dbo].[CurrencyType] AS CurTypeBase

            //ON CurPair.BaseCurrencyID = CurTypeBase.ID

            //JOIN[ONLOOKER].[dbo].[CurrencyType] AS CurTypeQuoted

            //ON CurPair.BaseCurrencyID = CurTypeQuoted.ID
            //    ) AS CurPairNamed

            //ON CurPairNamed.ID = Job.CurrencyPairID
            //";
            using (SqlConnection conn = CDbConnection.GetConnection())
            {
                SqlCommand command = new SqlCommand(sqlExpression, conn);
                command.CommandType = CommandType.StoredProcedure;
                using (var reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            CJob job = new CJob();
                            job.CurrencyPair = new CCurrencyPair()
                            {
                                BaseCurrency = (CurrencyInfo)reader["BaseCurrency"], QuotedCurrency = (CurrencyInfo)reader["QuotedCurrency"]
                            };
                            job.ID  = (Int32)reader["JobID"];
                            job.Tag = new CTag((String)reader["Tag"]);
                            jobs.Add(job);
                        }
                    }
                    else
                    {
                        jobs = null;
                    }
                }
            }
            return(jobs);
        }
예제 #2
0
        public static void getInputsAndOutputs(string exe, string args, ref CJob job)
        {
            var process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName               = exe,
                    Arguments              = args + " -printIOfiles",
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    CreateNoWindow         = true
                }
            };

            string processOutput = "";

            process.Start();
            while (!process.StandardOutput.EndOfStream)
            {
                processOutput += process.StandardOutput.ReadLine();
            }
            int startPos = processOutput.IndexOf("<Files>");
            int endPos   = processOutput.IndexOf("</Files>");

            if (startPos > 0 && endPos > 0)
            {
                string xml = processOutput.Substring(startPos, endPos - startPos + ("</Files>").Length);

                XDocument  doc        = XDocument.Parse(xml);
                XElement[] inputFiles = doc.Descendants()
                                        .Where(e => e.Name == "Input")
                                        .ToArray();
                XElement[] outputFiles = doc.Descendants()
                                         .Where(e => e.Name == "Output")
                                         .ToArray();
                foreach (XElement e in inputFiles)
                {
                    if (!job.inputFiles.Contains(e.Value))
                    {
                        job.inputFiles.Add(e.Value);
                    }
                }
                foreach (XElement e in outputFiles)
                {
                    if (!job.outputFiles.Contains(e.Value))
                    {
                        job.outputFiles.Add(e.Value);
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Generic progress report of any CJob type object
        /// Changes progress bar and sets simple status messages
        /// </summary>
        /// <param name="s">JobStatus</param>
        /// <param name="j">Job</param>
        private void genericJobProgressReport(CJobStatus s, CJob j)
        {
            switch (s)
            {
            case CJobStatus.start:
                lastTaskName = null;
                break;

            case CJobStatus.taskStart:

                if (j.TASK_LAST.FLAG_PROGRESS_DISABLE)
                {
                    lastTaskName = null;
                    return;
                }

                if (!string.IsNullOrEmpty(j.TASK_LAST.desc))
                {
                    lastTaskName = j.TASK_LAST.desc;
                }
                else
                {
                    lastTaskName = j.TASK_LAST.name;
                }

                form_setText(lastTaskName, 0);
                break;

            case CJobStatus.progress:
                form_setProgress((int)Math.Ceiling(j.PROGRESS_TOTAL));
                form_setText($"[{j.PROGRESS_TOTAL.ToString("0.#")}%] {lastTaskName}", 0);
                break;

            case CJobStatus.complete:
                form_setText(j.name + " Complete ", 2);
                LOG.line(40);
                LOG.log("");                 // newline
                form_setProgress(100);
                FormTools.invoke(this, () => {
                    TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.NoProgress);
                    FormTools.FlashWindow(this.Handle);
                });
                break;

            case CJobStatus.fail:
                form_setText(j.name + " Failed ", 3);
                break;
            }
        }// -----------------------------------------
    public static unsafe void Done()
    {
        var aJob = new CJob()
        {
            m_Str = "Hello world".NewNativeWrapper()
        };

        try
        {
            aJob.Schedule().Complete();
        }
        finally
        {
            aJob.m_Str.Dispose();
        }
    }
예제 #5
0
        }// -----------------------------------------

        // ============================================================
        // == EVENTS
        // ============================================================


        /// <summary>
        /// Generic progress report of any CJob type object
        /// Changes progress bar and sets simple status messages
        /// </summary>
        /// <param name="s">JobStatus</param>
        /// <param name="j">Job</param>
        private void genericJobProgressReport(CJobStatus s, CJob j)
        {
            switch (s)
            {
            case CJobStatus.taskStart:

                if (j.TASK_LAST.PROGRESS_UNKNOWN)
                {
                    form_setProgress(-1);
                    // ("PROGRESS BAR WORKING-----------");
                }

                if (string.IsNullOrEmpty(j.TASK_LAST.desc))
                {
                    form_setText(j.TASK_LAST.name, 0);
                }
                else
                {
                    form_setText(j.TASK_LAST.desc, 0);
                }
                break;

            case CJobStatus.taskEnd:

                if (j.TASK_LAST.PROGRESS_UNKNOWN)
                {
                    form_setProgress(0);                     // Restore the progress bar to normal
                }
                else
                {
                    form_setProgress(j.TASKS_COMPLETION_PERCENT);
                }

                break;

            case CJobStatus.complete:
                form_setText(j.name + " complete ", 2);
                FLAG_CLEAR_STATUS = true;
                break;

            case CJobStatus.fail:
                form_setText(j.name + " failed ", 3);
                FLAG_CLEAR_STATUS = true;
                break;
            }
        }// -----------------------------------------
예제 #6
0
        private CJob getJob()
        {
            CJob job = new CJob();

            job.name = m_name;

            //tasks, inputs and outputs
            foreach (MonitoredExperimentViewModel experiment in m_monitoredExperiments)
            {
                CTask task = new CTask();
                //we are assuming the same exe file is used in all the experiments!!!
                //IMPORTANT
                task.name      = experiment.name;
                task.exe       = experiment.exeFile;
                task.arguments = experiment.filePath + " -pipe=" + experiment.pipeName;
                task.pipe      = experiment.pipeName;
                job.tasks.Add(task);
                //add EXE files

                if (!job.inputFiles.Contains(task.exe))
                {
                    job.inputFiles.Add(task.exe);
                }
                //add prerrequisites
                foreach (string pre in experiment.prerrequisites)
                {
                    if (!job.inputFiles.Contains(pre))
                    {
                        job.inputFiles.Add(pre);
                    }
                }

                //add experiment file to inputs
                if (!job.inputFiles.Contains(experiment.filePath))
                {
                    job.inputFiles.Add(experiment.filePath);
                }

                Utility.getInputsAndOutputs(experiment.exeFile, experiment.filePath, ref job);
            }
            return(job);
        }
예제 #7
0
        public CReport PutRequest(QueryInfo dataInput)
        {
            CJob    job    = _gates.JobGateway.GetByQueryInfo(dataInput);
            CReport report = new CReport();

            if (job != null)
            {
                job.UpdateReports();   //it's happen to update db
                return(job.Report);
            }
            else
            {
                CJob newJob = new CJob(dataInput, _parsingExpressions, _gates);
                report = newJob.CreateReport(dataInput);
            }
            //check for job existance
            //if job exists - > find get reports and update them
            //if not exists -> create job and push it work
            return(report);
        }
예제 #8
0
        public async Task <ExperimentBatch> sendJobAndMonitor()
        {
            m_failedExperiments.Clear();
            try
            {
                //SEND THE JOB DATA
                m_monitoredExperiments.ForEach((exp) => exp.state = MonitoredExperimentViewModel.ExperimentState.WAITING_EXECUTION);
                CJob job = getJob();

                bool bConnected = m_shepherd.connectToHerdAgent(m_herdAgent.ipAddress);
                if (bConnected)
                {
                    logMessage("Sending job to herd agent " + m_herdAgent.ipAddress);
                    m_monitoredExperiments.ForEach((exp) => exp.state = MonitoredExperimentViewModel.ExperimentState.SENDING);
                    m_herdAgent.status = "Sending job query";
                    m_shepherd.SendJobQuery(job, m_cancelToken);
                    logMessage("Job sent to herd agent " + m_herdAgent.ipAddress);
                    //await m_shepherd.waitAsyncWriteOpsToFinish();
                    m_monitoredExperiments.ForEach((exp) => exp.state = MonitoredExperimentViewModel.ExperimentState.RUNNING);
                    m_herdAgent.status = "Executing job query";
                }
                else
                {
                    foreach (MonitoredExperimentViewModel exp in m_monitoredExperiments)
                    {
                        m_failedExperiments.Add(exp);
                    }
                    m_monitoredExperiments.ForEach((exp) => exp.state = MonitoredExperimentViewModel.ExperimentState.ERROR);
                    logMessage("Failed to connect to herd agent " + m_herdAgent.ipAddress);
                    return(this);
                }
                logMessage("Monitoring remote job run by herd agent " + m_herdAgent.ipAddress);
                //MONITOR THE REMOTE JOB
                while (true)
                {
                    int numBytesRead = await m_shepherd.readAsync(m_cancelToken);

                    m_cancelToken.ThrowIfCancellationRequested();

                    string xmlItem = m_shepherd.m_xmlStream.processNextXMLItem();

                    while (xmlItem != "")
                    {
                        string experimentId = m_shepherd.m_xmlStream.getLastXMLItemTag();
                        string message      = m_shepherd.m_xmlStream.getLastXMLItemContent();
                        MonitoredExperimentViewModel experimentVM = m_monitoredExperiments.Find(exp => exp.name == experimentId);
                        string messageId      = m_shepherd.m_xmlStream.getLastXMLItemTag(); //previous call to getLastXMLItemContent reset lastXMLItem
                        string messageContent = m_shepherd.m_xmlStream.getLastXMLItemContent();
                        if (experimentVM != null)
                        {
                            if (messageId == "Progress")
                            {
                                double progress = double.Parse(messageContent, CultureInfo.InvariantCulture);
                                experimentVM.progress = Convert.ToInt32(progress);
                            }
                            else if (messageId == "Evaluation")
                            {
                                //<Evaluation>0.0,-1.23</Evaluation>
                                string [] values     = messageContent.Split(',');
                                string    seriesName = experimentVM.name;
                                int       seriesId;
                                if (values.Length == 2)
                                {
                                    if (!m_experimentSeriesId.Keys.Contains(experimentVM.name))
                                    {
                                        seriesId = m_evaluationPlot.addLineSeries(seriesName);
                                        m_experimentSeriesId.Add(seriesName, seriesId);
                                    }
                                    else
                                    {
                                        seriesId = m_experimentSeriesId[seriesName];
                                    }

                                    m_evaluationPlot.addLineSeriesValue(seriesId, double.Parse(values[0], CultureInfo.InvariantCulture)
                                                                        , double.Parse(values[1], CultureInfo.InvariantCulture));
                                }
                            }
                            else if (messageId == "Message")
                            {
                                experimentVM.addStatusInfoLine(messageContent);
                            }
                            else if (messageId == "End")
                            {
                                if (messageContent == "Ok")
                                {
                                    logMessage("Job finished sucessfully");
                                    experimentVM.state = MonitoredExperimentViewModel.ExperimentState.WAITING_RESULT;
                                }
                                else
                                {
                                    logMessage("Remote job execution wasn't successful");
                                    //Right now, my view on adding failed experiments back to the pending exp. list:
                                    //Some experiments may fail because the parameters are just invalid (i.e. FAST)
                                    //Much more likely than a network-related error or some other user-related problem
                                    //m_failedExperiments.Add(experimentVM);
                                    experimentVM.state = MonitoredExperimentViewModel.ExperimentState.ERROR;
                                }
                            }
                        }
                        else
                        {
                            if (experimentId == XMLStream.m_defaultMessageType)
                            {
                                //if (content == CJobDispatcher.m_endMessage)
                                {
                                    //job results can be expected to be sent back even if some of the tasks failed
                                    logMessage("Receiving job results");
                                    m_monitoredExperiments.ForEach((exp) => exp.state = MonitoredExperimentViewModel.ExperimentState.RECEIVING);
                                    m_herdAgent.status = "Receiving output files";
                                    bool bret = await m_shepherd.ReceiveJobResult(m_cancelToken);

                                    m_monitoredExperiments.ForEach((exp) => exp.state = MonitoredExperimentViewModel.ExperimentState.FINISHED);
                                    m_herdAgent.status = "Finished";
                                    logMessage("Job results received");
                                    return(this);
                                }
                            }
                        }
                        xmlItem = m_shepherd.m_xmlStream.processNextXMLItem();
                    }
                }
            }

            catch (OperationCanceledException)
            {
                //quit remote jobs

                logMessage("Cancellation requested by user");
                m_shepherd.writeMessage(Shepherd.m_quitMessage, true);
                await m_shepherd.readAsync(new CancellationToken()); //we synchronously wait until we get the ack from the client

                m_monitoredExperiments.ForEach((exp) => { exp.resetState(); });
                m_herdAgent.status = "";
            }
            catch (Exception ex)
            {
                logMessage("Unhandled exception in Badger.sendJobAndMonitor(). Agent " + m_herdAgent.ipAddress);
                logMessage(ex.ToString());
                m_failedExperiments.Clear();
                foreach (MonitoredExperimentViewModel exp in m_monitoredExperiments)
                {
                    m_failedExperiments.Add(exp);
                }
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                logMessage("Disconnected from herd agent " + m_herdAgent.ipAddress);
                m_shepherd.disconnect();
            }
            return(this);
        }
예제 #9
0
 public void Update(CJob entity)
 {
     throw new System.NotImplementedException();
 }
예제 #10
0
        public CJob GetByQueryInfo(QueryInfo info)
        {
            CCountryGateway countryGateway = new CCountryGateway();
            CJob            job            = new CJob();
            String          sqlExpression  = "sp_GetJobByUserQuery";

            //               $@" WITH JobTable AS (SELECT Job.ID AS JobID, CurPairNamed.BaseCurrency, CurPairNamed.QuotedCurrency,Country.Name AS Country, Tag.Name AS Tag
            // FROM [ONLOOKER].[dbo].[Job] AS Job
            // JOIN [ONLOOKER].[dbo].[Country] AS Country
            // ON Job.[CountryID] = Country.ID
            // Join [ONLOOKER].[dbo].[Tag] AS Tag
            // ON Job.TagID = Tag.ID
            // JOIN(
            //SELECT CurPair.ID, CurTypeBase.CurrencyCode AS BaseCurrency, CurTypeQuoted.CurrencyCode AS QuotedCurrency
            //FROM [ONLOOKER].[dbo].[CurrencyPair] AS CurPair
            //JOIN [ONLOOKER].[dbo].[CurrencyType] AS CurTypeBase
            //ON CurPair.BaseCurrencyID = CurTypeBase.ID
            //JOIN [ONLOOKER].[dbo].[CurrencyType] AS CurTypeQuoted
            //ON CurPair.BaseCurrencyID = CurTypeQuoted.ID
            //) AS CurPairNamed
            //ON  CurPairNamed.ID = Job.CurrencyPairID)
            //SELECT * FROM JobTable
            //WHERE BaseCurrency = '{info.CurrencyPair.BaseCurrency.Code}' AND QuotedCurrency = '{info.CurrencyPair.QuotedCurrency.Code}' AND Country = '{info.Country.Name}' AND Tag = '{info.Tag.Value}'";
            using (SqlConnection conn = CDbConnection.GetConnection())
            {
                SqlCommand command = new SqlCommand(sqlExpression, conn);
                command.CommandType = CommandType.StoredProcedure;
                SqlParameter baseParam = new SqlParameter
                {
                    ParameterName = "@base",
                    Value         = info.CurrencyPair.BaseCurrency.Code
                };
                command.Parameters.Add(baseParam);
                SqlParameter quotedParam = new SqlParameter
                {
                    ParameterName = "@quoted",
                    Value         = info.CurrencyPair.QuotedCurrency.Code
                };
                command.Parameters.Add(quotedParam);
                SqlParameter countryParam = new SqlParameter
                {
                    ParameterName = "@country",
                    Value         = info.Country.Name
                };
                command.Parameters.Add(countryParam);
                SqlParameter tagParam = new SqlParameter
                {
                    ParameterName = "@tag",
                    Value         = info.Tag.Value
                };
                command.Parameters.Add(tagParam);

                using (var reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            job.CurrencyPair = new CCurrencyPair()
                            {
                                BaseCurrency = (CurrencyInfo)reader["BaseCurrency"], QuotedCurrency = (CurrencyInfo)reader["QuotedCurrency"]
                            };
                            job.ID      = (Int32)reader["JobID"];
                            job.Tag     = new CTag((String)reader["Tag"]);
                            job.Country = countryGateway.GetAll().FirstOrDefault(x => String.Compare(x.Name, (String)reader["Country"], StringComparison.InvariantCulture) == 0);
                        }
                    }
                    else
                    {
                        job = null;
                    }
                }
            }
            return(job);
        }
예제 #11
0
        public Int32 Create(CJob entity)
        {
            Int32  id                = 0;
            Int32  CurrencyPairID    = 0;
            String getCurrencyPairID =
                $@"WITH CurPairNamed AS (SELECT CurPair.ID, CurTypeBase.CurrencyCode AS BaseCurrency, CurTypeQuoted.CurrencyCode AS QuotedCurrency

            FROM[ONLOOKER].[dbo].[CurrencyPair] AS CurPair

            JOIN[ONLOOKER].[dbo].[CurrencyType] AS CurTypeBase

            ON CurPair.BaseCurrencyID = CurTypeBase.ID

            JOIN[ONLOOKER].[dbo].[CurrencyType] AS CurTypeQuoted

            ON CurPair.BaseCurrencyID = CurTypeQuoted.ID)
            SELECT ID FROM CurPairNamed

            WHERE BaseCurrency = '{entity.CurrencyPair.BaseCurrency.Code}' AND QuotedCurrency = '{entity.CurrencyPair.QuotedCurrency.Code}'";
            String insertJob =
                $@"INSERT INTO Job (CurrencyPairID, CountryID, TagID) values ({CurrencyPairID},{entity.Country.ID},{entity.Tag.ID}) SELECT SCOPE_IDENTITY()";

            using (SqlConnection conn = CDbConnection.GetConnection())
            {
                SqlCommand cmdGetCurPairId = new SqlCommand(getCurrencyPairID, conn);
                cmdGetCurPairId.CommandType = CommandType.Text;

                using (var reader = cmdGetCurPairId.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            CurrencyPairID = (Int32)reader["ID"];
                        }
                    }
                }


                SqlCommand cmdInsertJob = new SqlCommand(insertJob, conn);
                cmdInsertJob.CommandType = CommandType.Text;

                //SqlParameter curPairParam = new SqlParameter
                //{
                //    ParameterName = "@curPair",
                //    Value = CurrencyPairID
                //};
                //cmdInsertJob.Parameters.Add(curPairParam);
                //SqlParameter countryParam = new SqlParameter
                //{
                //    ParameterName = "@country",
                //    Value = entity.Country.ID
                //};
                //cmdInsertJob.Parameters.Add(countryParam);
                //SqlParameter tagParam = new SqlParameter
                //{
                //    ParameterName = "@tag",
                //    Value = entity.Tag.ID
                //};
                //cmdInsertJob.Parameters.Add(tagParam);
                try
                {
                    var result = cmdInsertJob.ExecuteScalar();
                    Console.WriteLine("Id добавленного объекта: {0}", result);
                    id = 1;
                }
                catch (Exception e)
                {
                    throw new Exception("Unexpected termination" + e.Message);
                    //SLogger.Log.Fatal($"CArticleGateway.Create method. Exception: {e.Message}")
                }

                return(id);
            }
        }