コード例 #1
0
        /// <summary>
        ///     Execute all the services
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DoWork(object sender, DoWorkEventArgs e)
        {
            Logger.Info("starting irc");

            if (Config.GetBoolValue(Globals.YokXmlUseirc))
            {
                if (!IrcEngine.GetInstance().Start())
                {
                    Logger.Error("Irc start failed");
                }
            }
            else
            {
                if (!IrcEngine.GetInstance().Stop())
                {
                    Logger.Error("Irc stop failed");
                }

                Logger.Info("IRC DISABLED");
            }

            Logger.Info("starting email");

            if (Config.GetBoolValue(Globals.YokXmlUseemail))
            {
                if (ScheduleEngine.Check())
                {
                    if (!EmailEngine.Send())
                    {
                        Logger.Error("Email send failed");
                    }
                }
                else
                {
                    Logger.Info("Data not ready to send");
                }
            }
            else
            {
                Logger.Info("EMAIL DISABLED");
            }
        }
コード例 #2
0
        public OperationResult <bool> SendTechnicianBio(int techId, string recipients)
        {
            var result = new OperationResult <bool>();

            try
            {
                var renderResult = GetBioInternal(techId, false);

                if (!renderResult.Success)
                {
                    result.Message = renderResult.Message;
                    return(result);
                }

                var e         = new EmailEngine();
                var cacheItem = BioCache[techId];
                using (var s = new MemoryStream(cacheItem.Data))
                {
                    s.Seek(0, SeekOrigin.Begin);
                    s.Position = 0;

                    var att = new Attachment(s, cacheItem.FileName, "application/pdf");
                    e.Send(null, recipients, null, null, "Technician Bio", "", new[] { att }, true);
                }

                result.Success    = true;
                result.ResultData = true;
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }

            return(result);
        }
コード例 #3
0
        public OperationResult <bool> SendToCustomer(int id, string to)
        {
            var result  = new OperationResult <bool>();
            var invoice = TransformJobToInvoice(id);

            if (invoice == null)
            {
                result.Success    = false;
                result.ResultData = false;
                result.Message    = string.Format("Job '{0}' not found.", id);
                return(result);
            }

            var client        = GetInvoiceGen();
            var genResultPdf  = GetInvoiceInternal(id);
            var genResultHtml = client.RenderHtml(invoice);
            var docType       = invoice.IsEstimate ? "Estimate" : "Invoice";

            if (!genResultPdf.Success || !genResultHtml.Success)
            {
                result.Success    = false;
                result.ResultData = false;
                result.Message    = string.Format("Could not send {0} to customer: {1}", docType, (genResultPdf.Message ?? genResultHtml.ExceptionMessage));
                return(result);
            }

            var html    = Encoding.Unicode.GetString(genResultHtml.Data);
            var engine  = new EmailEngine();
            var subject = string.Format("{0} - {1}", docType, id);
            var from    = invoice.FranchiseTypeID == 6
                ? GlobalConfiguration.PlumberInvoiceFromAddress
                : GlobalConfiguration.ConnectUsProInvoiceFromAddress;


            //Do not send invoices to customers when running in test mode.
            if (GlobalConfiguration.TestMode)
            {
                to = string.Empty;
            }

            bool sent;

            using (var data = new MemoryStream(genResultPdf.ResultData.Value))
            {
                sent = engine.Send(from, to, null, GlobalConfiguration.InvoiceSendBcc, subject, html,
                                   new[] { new Attachment(data, genResultPdf.ResultData.Key) },
                                   true);
            }

            result.Success = sent;

            if (!result.Success)
            {
                result.Message = string.Format("The {0} failed to send.", docType);
            }
            else
            {
                MarkInvoiced(id, DateTime.Now);
            }

            return(result);
        }