Пример #1
0
        public static ResultGeneric BatchRegistration(string logJobName, string batchNumber, string batchAlias, JobExtended job)
        {
            ResultGeneric result = new ResultGeneric();

            result.ReturnCode   = 0;
            result.Message      = "";
            result.RecordsCount = 0;

            try
            {
                lock (lockObj)
                {
                    LogManager.Configuration.Variables["JobName"] = logJobName;
                    Batch batch = new Batch();

                    HttpClient client = new HttpClient();
                    client.Timeout = TimeSpan.FromMinutes(15);
                    string URL           = "";
                    string bodyString    = "";
                    string returnMessage = "";
                    string batchJS       = "";

                    batch.BatchNumber   = batchNumber;
                    batch.StatusFlag    = "Ready to Scan";
                    batch.SubmittedBy   = "Auto Import Service";
                    batch.SubmittedDate = DateTime.Now;
                    batch.Customer      = job.CustomerName;
                    batch.ProjectName   = job.ProjectName;
                    batch.JobType       = job.JobName;
                    batch.DepName       = job.DepartmentName;
                    batch.BatchAlias    = batchAlias;

                    batchJS = JsonConvert.SerializeObject(batch, Newtonsoft.Json.Formatting.Indented);
                    batchJS = batchJS.Replace(@"\", "\\\\");

                    URL = LoadBalancerService.BaseURL + "Batches/BatchRegistration";

                    bodyString = "'" + batchJS + "'";
                    HttpContent body_for_new = new StringContent(bodyString);
                    body_for_new.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                    HttpResponseMessage response_for_new = client.PostAsync(URL, body_for_new).Result;

                    if (!response_for_new.IsSuccessStatusCode)
                    {
                        nlogger.Error("Error:" + "\r\n" + response_for_new.ReasonPhrase + "\r\n" + response_for_new.RequestMessage);
                        Console.WriteLine("Error:" + "\r\n" + response_for_new.ReasonPhrase + "\r\n" + response_for_new.RequestMessage);
                        result.Message    = "Error:" + "\r\n" + response_for_new.ReasonPhrase + "\r\n" + response_for_new.RequestMessage;
                        result.ReturnCode = -1;
                    }
                    else
                    {
                        using (HttpContent content = response_for_new.Content)
                        {
                            Task <string> resultTemp = content.ReadAsStringAsync();
                            returnMessage = resultTemp.Result;
                            result        = JsonConvert.DeserializeObject <ResultGeneric>(returnMessage);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                lock (lockObj)
                {
                    LogManager.Configuration.Variables["JobName"] = logJobName;
                    nlogger.Fatal(General.ErrorMessage(ex));
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(General.ErrorMessage(ex));
                    Console.ForegroundColor = ConsoleColor.White;
                    result.Message          = General.ErrorMessage(ex);
                    result.ReturnCode       = -2;
                }
            }
            return(result);
        }
Пример #2
0
        private void ProcessForm_Load(object sender, EventArgs e)
        {
            try
            {
                this.Text = (currentProcessName + " Service Configuration").ToUpper();

                ResultJobsExtended    resultJobs         = new ResultJobsExtended();
                ResultProcesses       resultProcess      = new ResultProcesses();
                List <JobExtended>    jobs               = new List <JobExtended>();
                List <ServiceStation> serviceStations    = new List <ServiceStation>();
                List <ServiceStation> pdfServiceStations = new List <ServiceStation>();

                // Load Process List View
                string returnMessage = "";
                Cursor.Current = Cursors.WaitCursor;

                string urlParameters         = "";
                string URL                   = "";
                HttpResponseMessage response = new HttpResponseMessage();

                // Get Jobs
                HttpClient client1 = new HttpClient();
                client1.Timeout     = TimeSpan.FromMinutes(15);
                URL                 = BaseURL + "Jobs/GetJobs";
                urlParameters       = "";
                client1.BaseAddress = new Uri(URL);
                response            = client1.GetAsync(urlParameters).Result;
                using (HttpContent content = response.Content)
                {
                    Task <string> resultTemp = content.ReadAsStringAsync();
                    returnMessage = resultTemp.Result;
                    resultJobs    = JsonConvert.DeserializeObject <ResultJobsExtended>(returnMessage);
                }
                if (response.IsSuccessStatusCode)
                {
                    jobs = resultJobs.ReturnValue;
                    // Add especial Job tothe Jobs List
                    JobExtended job = new JobExtended();
                    job.JobName = "ALL";
                    job.JobID   = 0;
                    jobs.Add(job);
                    JobsComboBox.Items.Add("");
                    foreach (var item in jobs)
                    {
                        JobsComboBox.Items.Add(item.JobName.Trim());
                    }
                }
                else
                {
                    MessageBox.Show("Error:" + "\r\n" + response.ReasonPhrase + "\r\n" + response.RequestMessage,
                                    "Transaction Error...", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (!string.IsNullOrEmpty(Data.GlovalVariables.currentJobName))
                {
                    // This is the case where this template is called from a Job configuration
                    JobsComboBox.Enabled = false;
                    JobsComboBox.Text    = Data.GlovalVariables.currentJobName.Trim();
                }

                // Get Service Stations
                HttpClient client2 = new HttpClient();
                client2.Timeout = TimeSpan.FromMinutes(15);
                ResultServiceStations resultResultStations = new ResultServiceStations();
                URL                 = BaseURL + "GeneralSettings/GetServiceStations";
                urlParameters       = "";
                client2.BaseAddress = new Uri(URL);
                response            = client2.GetAsync(urlParameters).Result;
                using (HttpContent content = response.Content)
                {
                    Task <string> resultTemp = content.ReadAsStringAsync();
                    returnMessage        = resultTemp.Result;
                    resultResultStations = JsonConvert.DeserializeObject <ResultServiceStations>(returnMessage);
                }
                if (response.IsSuccessStatusCode)
                {
                    ServiceStationsComboBox.Items.Add("");
                    PDFServiceStationsComboBox.Items.Add("");
                    serviceStations = resultResultStations.ReturnValue;
                    foreach (ServiceStation serviceStation in serviceStations)
                    {
                        ServiceStationsComboBox.Items.Add(serviceStation.StationName.Trim());
                        // Identify if Station is use for PDF Conversion
                        if (serviceStation.PDFStationFlag)
                        {
                            pdfServiceStations.Add(serviceStation);
                            PDFServiceStationsComboBox.Items.Add(serviceStation.StationName.Trim());
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Error:" + "\r\n" + response.ReasonPhrase + "\r\n" + response.RequestMessage,
                                    "Transaction Error...", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                resultProcess = GetProcess();
                string enableFlag      = "";
                string cronDescription = "";
                string cronJob         = "";

                // Table Definition - We will use this definition for Any Process in the System
                DataTable dt = new DataTable("Processes");
                dt.Columns.Add("ProcessID", typeof(string));
                dt.Columns.Add("JobID", typeof(string));
                dt.Columns.Add("StationID", typeof(string));
                dt.Columns.Add("PDFStationID", typeof(string));

                dt.Columns.Add("Status", typeof(string));
                dt.Columns.Add("CustomerName", typeof(string));
                dt.Columns.Add("JobName", typeof(string));
                dt.Columns.Add("ServiceStation", typeof(string));
                dt.Columns.Add("PDFServiceStation", typeof(string));
                dt.Columns.Add("Schedule", typeof(string));
                dt.Columns.Add("CronDescription", typeof(string));

                // Load Table Information
                // this condition is to support load balancing associated to FIle Conversion Stations
                if (Data.GlovalVariables.currentProcessName == "Load Balancer???")
                {
                    ServiceStationsComboBox.Enabled    = true;
                    PDFServiceStationsComboBox.Enabled = true;
                    foreach (JobExtended job in jobs)
                    {
                        foreach (ServiceStation serviceStation in serviceStations)
                        {
                            foreach (ServiceStation pdfserviceStation in pdfServiceStations)
                            {
                                enableFlag      = "No Configured";
                                cronDescription = "";
                                cronJob         = "";
                                foreach (var process in resultProcess.ReturnValue)
                                {
                                    if (process.ProcessID.ToString() == Data.GlovalVariables.currentProcessID.ToString() && process.JobID.ToString() == job.JobID.ToString() &&
                                        process.StationID.ToString() == serviceStation.StationID.ToString() && process.PDFStationID.ToString() == pdfserviceStation.StationID.ToString())
                                    {
                                        enableFlag      = Convert.ToString(process.EnableFlag);
                                        cronDescription = process.CronDescription;
                                        cronJob         = process.ScheduleCronFormat;
                                        break;
                                    }
                                }

                                if (Data.GlovalVariables.currentJobName == job.JobName || string.IsNullOrEmpty(Data.GlovalVariables.currentJobName))
                                {
                                    DataRow dr = dt.NewRow();
                                    dr["ProcessID"]    = Data.GlovalVariables.currentProcessID.ToString();
                                    dr["JobID"]        = job.JobID.ToString();
                                    dr["StationID"]    = serviceStation.StationID.ToString();
                                    dr["PDFStationID"] = pdfserviceStation.StationID.ToString();
                                    dr["Status"]       = enableFlag;
                                    if (job.JobName.Trim() == "ALL")
                                    {
                                        dr["CustomerName"] = "";
                                    }
                                    else
                                    {
                                        dr["CustomerName"] = job.CustomerName.Trim();
                                    }
                                    dr["JobName"]           = job.JobName.Trim();
                                    dr["ServiceStation"]    = serviceStation.StationName.Trim();
                                    dr["PDFServiceStation"] = pdfserviceStation.StationName.Trim();
                                    dr["Schedule"]          = cronJob;
                                    dr["CronDescription"]   = cronDescription;
                                    dt.Rows.Add(dr);
                                }
                            }
                        }
                    }
                }
                else
                {
                    ServiceStationsComboBox.Enabled    = true;
                    PDFServiceStationsComboBox.Enabled = false;
                    string serviceStation   = "";
                    string serviceStationID = "";
                    foreach (JobExtended job in jobs)
                    {
                        enableFlag      = "No Configured";
                        serviceStation  = "";
                        cronDescription = "";
                        cronJob         = "";
                        foreach (var process in resultProcess.ReturnValue)
                        {
                            if (process.ProcessID.ToString() == Data.GlovalVariables.currentProcessID.ToString() && process.JobID.ToString() == job.JobID.ToString())
                            {
                                enableFlag       = Convert.ToString(process.EnableFlag);
                                serviceStationID = process.StationID.ToString();
                                serviceStation   = process.StationName;
                                cronDescription  = process.CronDescription;
                                cronJob          = process.ScheduleCronFormat;
                                break;
                            }
                        }
                        DataRow dr = dt.NewRow();
                        dr["ProcessID"] = Data.GlovalVariables.currentProcessID.ToString();
                        dr["JobID"]     = job.JobID.ToString();
                        dr["StationID"] = serviceStationID;
                        //dr["PDFStationID"] = pdfserviceStation.StationID.ToString();
                        dr["Status"] = enableFlag;
                        if (job.JobName.Trim() == "ALL")
                        {
                            dr["CustomerName"] = "";
                        }
                        else
                        {
                            dr["CustomerName"] = job.CustomerName.Trim();
                        }
                        dr["JobName"]        = job.JobName.Trim();
                        dr["ServiceStation"] = serviceStation.Trim();
                        //dr["PDFServiceStation"] = pdfserviceStation.StationName.Trim();
                        dr["Schedule"]        = cronJob;
                        dr["CronDescription"] = cronDescription;
                        dt.Rows.Add(dr);
                    }
                }

                bs.DataSource = dt;

                // Define DataGrid
                // Filter Header based on Process Type { Synchronizer, Indexer, Load Balancer, Batch Delivery, etc }
                ProcessGridView.DataSource = dt;
                ProcessGridView.Columns["ProcessID"].Visible           = false;
                ProcessGridView.Columns["JobID"].Visible               = false;
                ProcessGridView.Columns["StationID"].Visible           = false;
                ProcessGridView.Columns["PDFStationID"].Visible        = false;
                ProcessGridView.Columns["CustomerName"].Visible        = false;
                ProcessGridView.Columns["CustomerName"].AutoSizeMode   = DataGridViewAutoSizeColumnMode.AllCells;
                ProcessGridView.Columns["CustomerName"].HeaderText     = "Customer Name";
                ProcessGridView.Columns["Status"].AutoSizeMode         = DataGridViewAutoSizeColumnMode.AllCells;
                ProcessGridView.Columns["Status"].ReadOnly             = true;
                ProcessGridView.Columns["JobName"].AutoSizeMode        = DataGridViewAutoSizeColumnMode.AllCells;
                ProcessGridView.Columns["JobName"].ReadOnly            = true;
                ProcessGridView.Columns["JobName"].HeaderText          = "Job Name";
                ProcessGridView.Columns["ServiceStation"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                ProcessGridView.Columns["ServiceStation"].ReadOnly     = true;
                ProcessGridView.Columns["ServiceStation"].HeaderText   = "Service Station";
                // The following condition is to be considered for future implementation
                if (Data.GlovalVariables.currentProcessName == "Load Balancer ???")
                {
                    ProcessGridView.Columns["PDFServiceStation"].Visible = true;
                }
                else
                {
                    ProcessGridView.Columns["PDFServiceStation"].Visible = false;
                }
                ProcessGridView.Columns["PDFServiceStation"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                ProcessGridView.Columns["PDFServiceStation"].ReadOnly     = true;
                ProcessGridView.Columns["PDFServiceStation"].HeaderText   = "PDF Service Station";
                ProcessGridView.Columns["Schedule"].AutoSizeMode          = DataGridViewAutoSizeColumnMode.AllCells;
                ProcessGridView.Columns["Schedule"].ReadOnly            = true;
                ProcessGridView.Columns["CronDescription"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                ProcessGridView.Columns["CronDescription"].ReadOnly     = true;
                ProcessGridView.Columns["CronDescription"].HeaderText   = "Cron Description";

                ProcessGridView.AllowUserToAddRows    = false;
                ProcessGridView.RowHeadersVisible     = true;
                ProcessGridView.AllowUserToAddRows    = false;
                ProcessGridView.AllowUserToResizeRows = false;
            }
            catch (Exception ex)
            {
                //MainForm.ErrorMessage(ex);
                nlogger.Fatal(General.ErrorMessage(ex));
                MessageBox.Show(General.ErrorMessage(ex), "Error ...", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }