Esempio n. 1
0
        protected override void ExecuteProcedure(Imi.Framework.Job.JobArgumentCollection args)
        {
            if (args.ContainsKey("Log"))
            {
                logEnabled = args["Log"].ToString().ToLower().Equals("true");
            }

            if (args.ContainsKey("LogFile"))
            {
                logFileName = args["LogFile"];
            }

            if (args.ContainsKey("LogLevel"))
            {
                logLevel = Convert.ToInt16(args["LogLevel"]);
            }

            Tracing.TraceEvent(TraceEventType.Verbose, 0, "Start");
            long start = DateTime.Now.Ticks;

            // Process any available EDIOUT messages

            int cc;

            do
            {
                cc = WriteMessageFile();
            } while (cc == 0);

            long     stop = DateTime.Now.Ticks;
            TimeSpan ts   = new TimeSpan(stop - start);

            Tracing.TraceEvent(TraceEventType.Verbose, 0, String.Format("Stop (used {0}s)", ts.TotalSeconds.ToString("0.00")));
        }
        /// <summary>
        /// ExecuteProcedure is the main activity method, this is the code that is run
        /// when the Job is activated/signalled.
        /// </summary>
        protected override void ExecuteProcedure(Imi.Framework.Job.JobArgumentCollection args)
        {
            if (args.ContainsKey("recycleThresholdWP"))
            {
                _recycleThresholdWP = Convert.ToInt32(args["recycleThresholdWP"]);
            }

            if (args.ContainsKey("processingTimeoutInMinutesWP"))
            {
                _processingTimeoutInMinutesWP = Convert.ToInt32(args["processingTimeoutInMinutesWP"]);
            }

            string PBROWGRP_ID_O         = "";
            string PZID_O                = "";
            string WHID_O                = "";
            string ALLOW_PBROWSPLIT_O    = "0";
            string CARTYPID_O            = "";
            string SHIPWSID_O            = "";
            double?SHIPXCORD_O           = 0;
            double?SHIPYCORD_O           = 0;
            double?MAXLDVOL_O            = 0;
            double?MAXLDWGT_O            = 0;
            double?OFR_DISTANCE_FACTOR_O = 0;
            int?   MAXPBROWCAR_O         = 0;
            int?   OFR_MAX_ITER_FILL_O   = 0;
            int?   OFR_MAX_TME_FILL_O    = 0;
            int?   OFR_MAX_ITER_STORE_O  = 0;
            int?   OFR_MAX_TME_STORE_O   = 0;
            int?   OFR_MAX_ITER_DIST_O   = 0;
            int?   OFR_MAX_TME_DIST_O    = 0;

            IList <PBROW>          rows      = null;
            IList <AISLE_WAYPOINT> waypoints = null;

            try
            {
                StartTransaction();

                IDataReader rowReader;
                IDataReader waypointReader;

                _pickOrderCarrierBuild.GetGroup(10,
                                                ref PBROWGRP_ID_O,
                                                ref OFR_DISTANCE_FACTOR_O,
                                                ref OFR_MAX_ITER_FILL_O,
                                                ref OFR_MAX_TME_FILL_O,
                                                ref OFR_MAX_ITER_STORE_O,
                                                ref OFR_MAX_TME_STORE_O,
                                                ref OFR_MAX_ITER_DIST_O,
                                                ref OFR_MAX_TME_DIST_O,
                                                ref PZID_O,
                                                ref WHID_O,
                                                ref ALLOW_PBROWSPLIT_O,
                                                ref MAXPBROWCAR_O,
                                                ref CARTYPID_O,
                                                ref MAXLDVOL_O,
                                                ref MAXLDWGT_O,
                                                ref SHIPWSID_O,
                                                ref SHIPXCORD_O,
                                                ref SHIPYCORD_O,
                                                out waypointReader,
                                                out rowReader);

                if (string.IsNullOrEmpty(PBROWGRP_ID_O))
                {
                    Commit();
                    return;
                }

                Tracing.TraceEvent(TraceEventType.Information, 0,
                                   string.Format("Found group {0}", PBROWGRP_ID_O));

                rows      = ReadPickOrderLines(rowReader);
                waypoints = ReadWaypoints(waypointReader);

                Commit();

                if (rows.Count < 1)
                {
                    Tracing.TraceEvent(TraceEventType.Warning, 0, "No rows to process, aborting.");

                    return;
                }

                LCASettings lcaSettings = new LCASettings();

                lcaSettings.DistanceFactor             = OFR_DISTANCE_FACTOR_O.Value;
                lcaSettings.DoBeautyPhase              = OFR_MAX_ITER_STORE_O > 0 && OFR_MAX_TME_STORE_O > 0;
                lcaSettings.DoDistPhase                = OFR_MAX_ITER_DIST_O > 0 && OFR_MAX_TME_DIST_O > 0;
                lcaSettings.DoLCPhase                  = OFR_MAX_ITER_FILL_O > 0 && OFR_MAX_TME_FILL_O > 0;
                lcaSettings.GroupId                    = PBROWGRP_ID_O;
                lcaSettings.MaxmSecBeauty              = OFR_MAX_TME_STORE_O.Value * 1000;
                lcaSettings.MaxmSecDistance            = OFR_MAX_TME_DIST_O.Value * 1000;
                lcaSettings.MaxmSecLC                  = OFR_MAX_TME_FILL_O.Value * 1000;
                lcaSettings.NumberOfIterationsBeauty   = OFR_MAX_ITER_STORE_O.Value;
                lcaSettings.NumberOfIterationsDistance = OFR_MAX_ITER_DIST_O.Value;
                lcaSettings.NumberOfIterationsLC       = OFR_MAX_ITER_FILL_O.Value;
                lcaSettings.PZId            = PZID_O;
                lcaSettings.WHId            = WHID_O;
                lcaSettings.StrekArea       = SHIPWSID_O;
                lcaSettings.StrekXCoord     = SHIPXCORD_O.GetValueOrDefault();
                lcaSettings.StrekYCoord     = SHIPYCORD_O.GetValueOrDefault();
                lcaSettings.AllowPBRowSplit = ALLOW_PBROWSPLIT_O == "1";
                lcaSettings.MaxLDWgt        = MAXLDWGT_O.GetValueOrDefault(double.MaxValue);
                lcaSettings.MaxLDVol        = MAXLDVOL_O.GetValueOrDefault(double.MaxValue);

                lcaSettings.MaxPBRowCar = MAXPBROWCAR_O.GetValueOrDefault(int.MaxValue);
                lcaSettings.OnlyAptean  = false;

                Tracing.TraceEvent(TraceEventType.Information, 0,
                                   string.Format("Parameters:{0}{1}", Environment.NewLine, lcaSettings.ToString()));

                Tracing.TraceEvent(TraceEventType.Information, 0,
                                   string.Format("Processing group {0} ({1} lines, {2} waypoints)...", PBROWGRP_ID_O, rows.Count, waypoints.Count));


                LCAWrapperResult result = null;
                int retry = 1;

                while (retry < 3)
                {
                    // Process Group in Worker Process.
                    try
                    {
                        result = SendGroupToWorkerProcess(rows, waypoints, lcaSettings);  //ProcessGroup(rows, waypoints, lcaSettings);
                        retry  = 3;
                    }
                    catch (TimeoutException)
                    {
                        throw;
                    }
                    catch (Exception)
                    {
                        //Make three tries at processing data in the algorithm if any anknown exception occurs.
                        lock (_syncLock)
                        {
                            AbortClients();
                            retry++;
                        }

                        Thread.Sleep(3000);
                    }
                }

                StringBuilder sb = new StringBuilder();

                foreach (var entry in MapErrors(PBROWGRP_ID_O, result.Errors)) //These are actually warnings
                {
                    foreach (string errorMessage in entry.Value)
                    {
                        string formattedMessage = string.Format("{0} [{1}]", errorMessage, entry.Key);
                        Tracing.TraceEvent(TraceEventType.Warning, 0, formattedMessage);
                        sb.AppendLine(string.Format("{0} Warning: {1}", this.Name, formattedMessage));
                    }
                }

                if (sb.Length > 0)
                {
                    LogGroupError(PBROWGRP_ID_O, sb.ToString());
                }

                Tracing.TraceEvent(TraceEventType.Information, 0,
                                   string.Format("Connecting {0} result lines...", result.Lines.Count));

                StartTransaction();

                ConnectPickOrderLines(PBROWGRP_ID_O, CARTYPID_O, result.Lines);

                _pickOrderCarrierBuild.FinishGroup(PBROWGRP_ID_O);

                Tracing.TraceEvent(TraceEventType.Information, 0,
                                   string.Format("Done processing.", PBROWGRP_ID_O));
                Commit();
            }
            catch (Exception ex)
            {
                try
                {
                    Rollback();
                }
                finally
                {
                    try
                    {
                        LogGroupError(PBROWGRP_ID_O, string.Format("Error - {0}", ex.ToString()));
                    }
                    finally
                    {
                        _pickOrderCarrierBuild.CancelGroup(PBROWGRP_ID_O);
                    }
                }

                throw;
            }
        }
Esempio n. 3
0
        protected override void ExecuteProcedure(Imi.Framework.Job.JobArgumentCollection args)
        {
            if (!CheckParameters())
            {
                return;
            }

            // Find msg
            ArrayList transList = FindMessagesToSend();

            foreach (MailBoxMessage m in transList)
            {
                Tracing.TraceEvent(TraceEventType.Verbose, 0, String.Format(" found MailId {0}", m.MailId));

                string error = "";

                try
                {
                    AppMailMessage aMsg = new AppMailMessage(args["ReturnAddress"] as string, m.XmlMessageBody);

                    try
                    {
                        using (MailMessage eMail = new MailMessage())
                        {
                            if (args["FromAddress"] == null)
                            {
                                eMail.From = new MailAddress(args["Job"] as string);
                            }
                            else
                            {
                                eMail.From = new MailAddress(args["FromAddress"] as string, args["Job"] as string);
                            }

                            foreach (string address in aMsg.ToList)
                            {
                                eMail.To.Add(new MailAddress(address));
                            }


                            eMail.Subject = aMsg.Subject;
                            eMail.Body    = aMsg.MessageBody;

                            SmtpClient sc = new SmtpClient(args["MailServer"] as string);

                            if (args.ContainsKey("MailServerPort"))
                            {
                                if ((args["MailServerPort"] != null) && (!args["MailServerPort"].Equals("")))
                                {
                                    sc.Port = Convert.ToInt32(args["MailServerPort"] as string);
                                }
                            }

                            if ((args.ContainsKey("MailServerUser")) && (args.ContainsKey("MailServerPassword")))
                            {
                                if (((args["MailServerUser"] != null) && (!args["MailServerUser"].Equals(""))) && ((args["MailServerPassword"] != null) && (!args["MailServerPassword"].Equals(""))))
                                {
                                    sc.UseDefaultCredentials = false;

                                    sc.Credentials = new System.Net.NetworkCredential(args["MailServerUser"] as string, args["MailServerPassword"] as string);
                                }
                                else
                                {
                                    sc.UseDefaultCredentials = true;
                                }
                            }
                            else
                            {
                                sc.UseDefaultCredentials = true;
                            }

                            sc.Send(eMail);
                        }
                    }
                    catch (FormatException fe)
                    {
                        error = String.Format("Problems sending the email due to faulty email address list {0}. {1} {2}\n{3}",
                                              aMsg.ToList,
                                              fe.GetType().Name,
                                              fe.Message,
                                              fe.StackTrace);

                        Tracing.TraceEvent(TraceEventType.Error, 0, error);
                    }
                    catch (SmtpException e)
                    {
                        error = String.Format("Problems sending the email. {0} {1}\n{2}",
                                              e.GetType().Name,
                                              e.Message,
                                              e.StackTrace);

                        Tracing.TraceEvent(TraceEventType.Error, 0, error);
                    }
                }
                catch (ConfigurationErrorsException e)
                {
                    error = String.Format("Problems decoding email. {0} {1}\n{2}",
                                          e.GetType().Name,
                                          e.Message,
                                          e.StackTrace);

                    Tracing.TraceEvent(TraceEventType.Error, 0, error);
                }

                // -------------------------------------------
                // --- Update MAILBOX record
                // -------------------------------------------
                string ALMID_W = "";
                StartTransaction();

                if (error == "")
                {
                    dbMailAgent.ModifySend(m.MailId, ref ALMID_W);
                }
                else
                {
                    dbMailAgent.ModifyError(m.MailId, error, ref ALMID_W);
                }

                Commit();

                #region TracingOfResult
                if (error != "")
                {
                    Tracing.TraceEvent(TraceEventType.Error, 0,
                                       String.Format("MAILID {0} error while sending.\n{1}.", m.MailId, error));
                }
                else
                {
                    Tracing.TraceEvent(TraceEventType.Verbose, 0,
                                       String.Format("MAILID {0} was sent successfully.", m.MailId));
                }

                if (ALMID_W != "")
                {
                    Tracing.TraceEvent(TraceEventType.Error, 0,
                                       String.Format("Error {0} when updating MAILBOX record status.", ALMID_W));
                }
                #endregion
            }  // foreach ( MailMessage t in transList )
        }