public static string SerializeVersionToXmlString(SmsInfo info) { XmlSerializer serializer = new XmlSerializer(typeof(SmsInfo)); using (MemoryStream stream = new MemoryStream()) { serializer.Serialize(stream, info); return System.Text.Encoding.Default.GetString(stream.ToArray()); } }
public static void ScheduleMessage(SmsInfo sms) { string id = sms.PaperId + "_" + sms.StateId + "_" + Guid.NewGuid().ToString(); sms.Id = id; string cronString = String.Empty; cronString = Cron.Daily(15); RecurringJob.AddOrUpdate(id, () => SMSSender.SendSms(sms), cronString); }
public static SMSResponse SendSms(SmsInfo info) { string to = info.To.Replace("(", string.Empty).Replace(")", string.Empty).Replace("-", string.Empty).Replace(" ", string.Empty); try { Regex responseParse = new Regex("([0-9])*=(.)*"); using (WebClient client = new WebClient()) { Uri url = new Uri("https://gate.smsaero.ru/send/?user="******"&password="******"&to=" + to + "&text=" + info.Body + "&from=" + sign); string response = client.DownloadString(url); Match m = responseParse.Match(response); if (m.Success) { string id = m.Groups[0].Value; string responseMessage = m.Groups[1].Value; SMSResponse result = new SMSResponse(); result.ID = id; result.Message = responseMessage; logger.Info("SMS sent to " + to + " message: " + info.Body); return result; } else throw new InvalidOperationException("Unrecognized sms service response: " + response); } } catch (Exception ex) { logger.Error("Sms sending error: " + ex.Message + " number: " + to + " message: " + info.Body); return null; } }
public static void ScheduleMessage(string to, string body, TimeSpan interval, int paperId, int stateId) { string id = paperId + "_" + stateId + "_" + Guid.NewGuid().ToString(); SmsInfo sms = new SmsInfo(body, to, Convert.ToInt32(interval.TotalHours), paperId, stateId, id); string cronString = String.Empty; cronString = Cron.Daily(15); RecurringJob.AddOrUpdate(id, () => SMSSender.SendSms(sms), cronString); }