示例#1
0
        public async Task <bool> RemindAsync(string tenant, ReminderMessage message)
        {
            await Task.Delay(0).ConfigureAwait(false);

            if (string.IsNullOrWhiteSpace(message.Contact.MobileNumbers))
            {
                return(false);
            }

            int alarm = message.Event.Alarm ?? 0;

            if (alarm == 0)
            {
                return(false);
            }

            string timezone = message.Contact.TimeZone.Or(message.Event.TimeZone);

            string template  = Configs.GetNotificationEmailTemplate(tenant);
            string eventDate = TimeZoneInfo.ConvertTime(DateTime.UtcNow.AddMinutes(alarm), TimeZoneInfo.FindSystemTimeZoneById(timezone)).Date.ToString("D");
            string startTime = TimeZoneInfo.ConvertTime(message.Event.StartsAt, TimeZoneInfo.FindSystemTimeZoneById(timezone)).ToString("t");
            string endTime   = TimeZoneInfo.ConvertTime(message.Event.EndsOn, TimeZoneInfo.FindSystemTimeZoneById(timezone)).ToString("t");

            template = template.Replace("{Name}", message.Event.Name);
            template = template.Replace("{StartTime}", startTime);
            template = template.Replace("{EndTime}", endTime);
            template = template.Replace("{Date}", eventDate);
            template = template.Replace("{Location}", message.Event.Location);
            template = template.Replace("{Note}", message.Event.Note);


            var processor = SmsProcessor.GetDefault(tenant);

            if (processor == null)
            {
                return(false);
            }

            var textMessage = new SmsQueue
            {
                AddedOn    = DateTimeOffset.UtcNow,
                SendOn     = DateTimeOffset.UtcNow,
                SendTo     = message.Contact.MobileNumbers,
                FromName   = processor.Config.FromName,
                FromNumber = processor.Config.FromNumber,
                Subject    = string.Format(I18N.CalendarNotificationEmailSubject, message.Event.Name, startTime),
                Message    = template
            };

            var manager = new SmsQueueManager(tenant, textMessage);
            await manager.AddAsync().ConfigureAwait(false);

            await manager.ProcessQueueAsync(processor).ConfigureAwait(false);

            return(true);
        }
示例#2
0
        public static async Task <bool> SendAsync(string tenant, SmsViewModel model, LoginView meta)
        {
            var processor = SmsProcessor.GetDefault(tenant);

            if (processor == null)
            {
                return(false);
            }

            foreach (var contactId in model.Contacts)
            {
                var contact = await DAL.Contacts.GetContactAsync(tenant, model.UserId, contactId).ConfigureAwait(false);

                if (string.IsNullOrWhiteSpace(contact?.MobileNumbers) || !contact.MobileNumbers.Split(',').Any())
                {
                    continue;
                }

                //Only select the first cell number
                string cellNumber = contact.MobileNumbers.Split(',').Select(x => x.Trim()).FirstOrDefault();

                if (string.IsNullOrWhiteSpace(cellNumber))
                {
                    continue;
                }

                string message = model.Message;
                message = MessageParser.ParseMessage(message, contact);

                var sms = new SmsQueue
                {
                    AddedOn    = DateTimeOffset.UtcNow,
                    SendOn     = DateTimeOffset.UtcNow,
                    SendTo     = cellNumber,
                    FromName   = processor.Config.FromName.Or(meta.OfficeName),
                    FromNumber = processor.Config.FromNumber.Or(meta.Phone),
                    Subject    = model.Subject,
                    Message    = message
                };

                await new SmsQueueManager(tenant, sms).AddAsync().ConfigureAwait(false);
            }

            var queue = new SmsQueueManager
            {
                Database = tenant
            };

            await queue.ProcessQueueAsync(processor).ConfigureAwait(false);

            return(true);
        }
        static void Main(string[] args)
        {
            //TyUserProcessor.Processor();

            SmsProcessor.Processor();

            //double aaa = dsInfo.early;
            //if (aaa == 0.0)
            //{
            //    aaa = 0;
            //}

            //float bb = (float)aaa;

            //// Gets a NumberFormatInfo associated with the en-US culture.
            //NumberFormatInfo nfi = new CultureInfo("zh-CN", false).NumberFormat;

            //// Displays a negative value with the default number of decimal digits (2).
            //float aa = 28.656599f;
            ////float bb = float.Parse(aa.ToString("N1"));

            //nfi.PercentSymbol = "%";
            //Console.WriteLine(aa.ToString("F", nfi));

            //Console.WriteLine("aa");

            //RunFirstGameProcessor.Processor();

            //EmailProcessor.Processor();

            //List<UserBetLotteryInfo> list = new List<UserBetLotteryInfo>
            //{
            //    new UserBetLotteryInfo{UserId = "0001",BetValue = "012",BetPrice = 1,WinPrice = 45},
            //    new UserBetLotteryInfo{UserId = "0002",BetValue = "013",BetPrice = 2,WinPrice = 90},
            //    new UserBetLotteryInfo{UserId = "0002",BetValue = "01x2",BetPrice = 3,WinPrice = 2550},
            //    new UserBetLotteryInfo{UserId = "0003",BetValue = "0124",BetPrice = 3,WinPrice = 2550},
            //    new UserBetLotteryInfo{UserId = "0001",BetValue = "0124",BetPrice = 3,WinPrice = 2550},
            //    new UserBetLotteryInfo{UserId = "0001",BetValue = "0x13",BetPrice = 5,WinPrice = 4250}
            //};

            //string sTicketNum = "0124";

            //int payTotalUser = 0;
            //decimal payTotalPrice = 0;

            //var currUblList = list.Where(m => sTicketNum.Contains(m.BetValue) && !m.BetValue.ToUpper().Contains("X"));
            //payTotalUser = currUblList.GroupBy(m => m.UserId).Count();
            //payTotalPrice = currUblList.Sum(m => m.WinPrice);

            //string a = "0012";
            //string b = "001X";
            //bool isc = a.Contains(b);
            //return;

            //int a = (int)DateTime.Now.DayOfWeek;
            //string d1 = string.Format("{0:dddd}", DateTime.Now);
            //string d2 = DateTime.Now.ToString("dddd");
            //string d3 = string.Format("{0:ddd}", DateTime.Now);
            //string d4 = string.Format("{0:d}", DateTime.Now);
            //string d5 = DateTime.Now.ToString("d");
            //var names = Enum.GetNames(typeof(DayOfWeek));
            //var values = Enum.GetValues(typeof(DayOfWeek));
            //DayOfWeek dayOfWeek = DateTime.Now.DayOfWeek;

            Console.WriteLine("按任意键结束");
            Console.ReadLine();
        }
示例#4
0
        protected override void OnStart(string[] args)
        {
            TyUserProcessor.Processor();

            SmsProcessor.Processor();
        }