static void Main(string[] args) { IParser ourParser = new Converter.Converter(); string path = AppDomain.CurrentDomain.BaseDirectory; OptionsManager <DataAccessOptions> optionsManager = new OptionsManager <DataAccessOptions>(path, ourParser); LoggingOptions loggingOptions = new LoggingOptions(); // Getting options using OptionsManager. loggingOptions.ConnectionOptions = optionsManager.GetOptions <ConnectionOptions>() as ConnectionOptions; SendingOptions sendingOptions = optionsManager.GetOptions <SendingOptions>() as SendingOptions; ConnectionOptions connectionOptions = optionsManager.GetOptions <ConnectionOptions>() as ConnectionOptions; ILogger logger = new Logger.Logger(loggingOptions, ourParser); ServiceLayer.ServiceLayer sl = new ServiceLayer.ServiceLayer(connectionOptions, ourParser); logger.Log(optionsManager.log); // Getting info from DB. logger.Log("Pulling of the data has been started..."); var people = sl.GetPersonInfoList(200); logger.Log("Pulling of the data has been done successfully!"); // Creating XMl file. XmlGenerator.XmlGenerator generator = new XmlGenerator.XmlGenerator(sendingOptions); generator.CreateXML(people); logger.Log("Xml file was created successfully"); }
static void Main(string[] args) { string appDirectory = AppDomain.CurrentDomain.BaseDirectory; Parser.Parser parser = new Parser.Parser(); IValidator validator = new Validator(); OptionsManager <DataAccessOptions> options = new OptionsManager <DataAccessOptions>(appDirectory, parser, validator); LoggerOptions loggerOptions = new LoggerOptions(); loggerOptions.ConnectionOptions = options.GetOptions <ConnectionOptions>() as ConnectionOptions; Logger.Logger logger = new Logger.Logger(loggerOptions); logger.Log(options.LogString); ServiceLayer.ServiceLayer SL = new ServiceLayer.ServiceLayer( options.GetOptions <ConnectionOptions>() as ConnectionOptions); SendingOptions sendingOptions = options.GetOptions <SendingOptions>() as SendingOptions; logger.Log("DataManager is fetching data"); PurchasingInfo purchasingInfo = SL.GetPurchasingInfo(); logger.Log("DataManager has fetch all data successfully!"); XmlGeneratorService xmlGenerator = new XmlGeneratorService(sendingOptions); xmlGenerator.SerializeXML(purchasingInfo); logger.Log("DataManager has sent all data tp FTP server successfully!"); }
static async Task Main(string[] args) { IParser parser = new Converter.Converter(); string path = AppDomain.CurrentDomain.BaseDirectory; OptionsManager <DataAccessOptions> optionsManager = new OptionsManager <DataAccessOptions>(path, parser); LoggingOptions loggingOptions = new LoggingOptions(); loggingOptions.ConnectionOptions = optionsManager.GetOptions <ConnectionOptions>() as ConnectionOptions; SendingOptions sendingOptions = optionsManager.GetOptions <SendingOptions>() as SendingOptions; ConnectionOptions connectionOptions = optionsManager.GetOptions <ConnectionOptions>() as ConnectionOptions; ILogger logger = new Logger.Logger(loggingOptions, parser); ServiceLayer.ServiceLayer sl = new ServiceLayer.ServiceLayer(connectionOptions, parser); List <PersonInfo> people; XmlGenerator.XmlGenerator generator = new XmlGenerator.XmlGenerator(sendingOptions); logger.Log(optionsManager.log); var watch = System.Diagnostics.Stopwatch.StartNew(); logger.Log("Pulling of the data has been started..."); Console.WriteLine("Pulling of the data has been started..."); people = await sl.GetPersonInfoListAsync(5000); Console.WriteLine("Pulling of the data has been done successfully!"); watch.Stop(); Console.WriteLine($"Total execution time: {watch.ElapsedMilliseconds}"); logger.Log("Pulling of the data has been done successfully!"); generator.CreateXML(people); logger.Log("Xml file was created successfully"); Console.ReadLine(); }
static void Main(string[] args) { string appDirectory = AppDomain.CurrentDomain.BaseDirectory; Parser.Parser parser = new Parser.Parser(); IValidator validator = new Validator(); OptionsManager <DataAccessOptions> options = new OptionsManager <DataAccessOptions>(appDirectory, parser, validator); LoggerOptions loggerOptions = new LoggerOptions(); loggerOptions.ConnectionOptions = options.GetOptions <ConnectionOptions>() as ConnectionOptions; Logger.Logger logger = new Logger.Logger(loggerOptions); logger.Log(options.LogString); ServiceLayer.ServiceLayer SL = new ServiceLayer.ServiceLayer( options.GetOptions <ConnectionOptions>() as ConnectionOptions); SendingOptions sendingOptions = options.GetOptions <SendingOptions>() as SendingOptions; logger.Log("DataManager is retrieving data"); PersonData personInfo = SL.GetPersonInfo(); logger.Log("DataManager retrieved data"); XmlGeneratorService xmlGenerator = new XmlGeneratorService(sendingOptions); xmlGenerator.SerializeXML(personInfo); logger.Log("DataManager sent data to server"); }
/// <summary> /// Send a new outbound message. /// </summary> /// <param name="options">Message sending options</param> /// <returns></returns> public SendingResult SendMessage(SendingOptions options) { var request = new RestRequest(Method.POST); request = _makeSendingRequest(request, options); return(Execute <SendingResult>(request)); }
public ContactSendingOption(IContact contact, SendableDocumentCategories sendableDocumentCategory, SendingOptions sendingOption, bool value) { Contact = contact; SendableDocumentCategory = sendableDocumentCategory; SendingOption = sendingOption; Value = value; }
/// <summary> /// Send a new outbound message. /// </summary> /// <param name="text">Message text</param> /// <param name="phones">Array of phone number in international E.164 format message will be sent to</param> /// <returns></returns> public SendingResult SendMessage(string text, string[] phones) { var options = new SendingOptions { Text = text, Phones = phones }; return(SendMessage(options)); }
/// <summary> /// Check pricing for a new outbound message. /// </summary> /// <param name="options"></param> /// <returns></returns> public Pricing GetPrice(SendingOptions options) { var request = new RestRequest(Method.POST); request = _makeSendingRequest(request, options); request.Method = Method.GET; request.Resource = "messages/price"; request.AddParameter("dummy", "1"); return(Execute <Pricing>(request)); }
public PushMessage GetSampleMessage(SendingOptions opts) { var message = new PushMessage(); message.To = GetRecipientString(opts); message.Message = new InnerMessage { Title = "From C#", Preview = "Preview" }; return(message); }
public string Topic = ConfigurationManager.AppSettings["Topic"]; //"/topics/news"; /// <summary> /// Формирует информационное сообщение для отправки в Firebase /// </summary> /// <param name="title">Заголовок сообщения</param> /// <param name="preview">Превью сообщения</param> /// <param name="sendOptions">Адресат</param> /// <returns>Модель push-сообщения в формате для Firebase</returns> /// Метод для отправки сообщения, где можно напрямую задать Title и Preview public PushMessage FormMessageToFirebase(string title, string preview, SendingOptions sendOptions) { var message = new PushMessage(); message.To = GetRecipientString(sendOptions); message.Message = new InnerMessage { Title = title, Preview = preview }; return(message); }
static void Main(string[] args) { IParser parser = new Converter.Converter(); IValidator validator = new Validator(); string directory = AppDomain.CurrentDomain.BaseDirectory; OptionsManager <DataAccessOptions> options = new OptionsManager <DataAccessOptions>(directory, parser, validator); LoggingOptions loggingOptions = new LoggingOptions(); //loggingOptions.ConnectingOptions = options.GetOptions<ConnectingOptions>() as ConnectingOptions; loggingOptions.EnableLogging = true; ILogger logger = new Logger.Logger(loggingOptions, parser); ServiceLayer.ServiceLayer SL = new ServiceLayer.ServiceLayer( options.GetOptions <ConnectingOptions>() as ConnectingOptions, parser, logger); SendingOptions sendingOptions = options.GetOptions <SendingOptions>() as SendingOptions; logger.Log("Starting pulling data"); if (sendingOptions.PullingMode == SendingOptions.PullingModes.FullTable) { int curIndex = 1; int maxID = SL.DAL.EmployeeMaxID(); List <HumanResourcesInfo> info; while (curIndex < maxID) { info = SL.GetPersonsRange(curIndex, sendingOptions.BatchSize); int lastID = info.Last().Employee.BusinessEntityID; string s = parser.SerializeXML(info); using (StreamWriter sw = new StreamWriter($@"{sendingOptions.Target}\file{curIndex}-{lastID}.txt")) { sw.Write(s); } curIndex = lastID + 1; } } else if (sendingOptions.PullingMode == SendingOptions.PullingModes.ByBatches) { List <HumanResourcesInfo> info = SL.GetEmployees(); SplitOnBatches(info, sendingOptions, parser); } else if (sendingOptions.PullingMode == SendingOptions.PullingModes.FullJoin) { List <HumanResourcesInfo> info = SL.GetHumanResourcesByJoin(); SplitOnBatches(info, sendingOptions, parser); } logger.Log("Pulled all data successfully"); }
/// <summary> /// Convert SendingOptions to RestRequest parameters /// </summary> /// <param name="request"></param> /// <param name="options"></param> /// <returns></returns> protected RestRequest _makeSendingRequest(RestRequest request, SendingOptions options) { request.Resource = "messages"; if (!string.IsNullOrEmpty(options.Text)) { request.AddParameter("text", options.Text); } if (options.Phones != null && options.Phones.Length > 0) { request.AddParameter("phones", string.Join(",", options.Phones)); } if (options.ContactIds != null && options.ContactIds.Length > 0) { request.AddParameter("contacts", string.Join(",", options.ContactIds)); } if (options.ListIds != null && options.ListIds.Length > 0) { request.AddParameter("lists", string.Join(",", options.ListIds)); } if (options.CutExtra.HasValue) { request.AddParameter("cutExtra", (bool)options.CutExtra ? "1" : "0"); } if (options.PartsCount.HasValue) { request.AddParameter("partsCount", options.PartsCount.ToString()); } if (!string.IsNullOrEmpty(options.ReferenceId)) { request.AddParameter("referenceId", options.ReferenceId); } if (!string.IsNullOrEmpty(options.From)) { request.AddParameter("from", options.From); } if (!string.IsNullOrEmpty(options.Rrule)) { request.AddParameter("rrule", options.Rrule); } if (options.SendingTime.HasValue) { request.AddParameter("sendingTime", DateTimeToTimestamp((DateTime)options.SendingTime).ToString()); } if (options.TemplateId.HasValue) { request.AddParameter("templateId", options.TemplateId.ToString()); } return(request); }
/// <summary> /// Формирует строку адресата сообщения /// </summary> /// <param name="sendOptions"></param> /// <returns></returns> private string GetRecipientString(SendingOptions sendOptions) { switch (sendOptions) { case (SendingOptions.SendToDevice): { return(GetDeviceId()); } case (SendingOptions.SendToTopic): { return(GetTopicId()); } default: return(string.Empty); } }
static void Main(string[] args) { IConverter converter = new Converter.Converter(); string based = AppDomain.CurrentDomain.BaseDirectory; OptionsManager <DataAccessOptions> optionsManager = new OptionsManager <DataAccessOptions>(based, converter); LoggingOptions loggingOptions = optionsManager.GetOptions <LoggingOptions>() as LoggingOptions; SendingOptions sendingOptions = optionsManager.GetOptions <SendingOptions>() as SendingOptions; ConnectionOptions connectionOptions = optionsManager.GetOptions <ConnectionOptions>() as ConnectionOptions; ServiceLayer.ServiceLayer sl = new ServiceLayer.ServiceLayer(converter, connectionOptions); Logger.Logger logger = new Logger.Logger(connectionOptions, converter); List <Human> people; logger.Log(optionsManager.logs); people = sl.GetHumanList(100); XmlGenerator generator = new XmlGenerator(sendingOptions); generator.CreateXML(people); }
static void SplitOnBatches(List <HumanResourcesInfo> info, SendingOptions sendingOptions, IParser parser) { int curIndex = 0; while (curIndex < info.Count) { List <HumanResourcesInfo> subInfo = info.GetRange(curIndex, Math.Min(sendingOptions.BatchSize, info.Count - curIndex)); int firstID = subInfo.First().Employee.BusinessEntityID; int lastID = subInfo.Last().Employee.BusinessEntityID; string s = parser.SerializeXML(subInfo); using (StreamWriter sw = new StreamWriter($@"{sendingOptions.Target}\file{firstID}-{lastID}.txt")) { sw.Write(s); } curIndex += sendingOptions.BatchSize; } }
public XmlGenerator(SendingOptions sendingOptions) { this.sendingOptions = sendingOptions; Directory.CreateDirectory(this.sendingOptions.TargetDirectory); }
// Used only for testing (for now) public static List<IContact> GetContacts(IDalSession session, SendableDocumentCategories category, SendingOptions sendingOption, bool value) { Hashtable parameters = new Hashtable(); parameters.Add("Category", (int)category); parameters.Add("SendingOption", (int)sendingOption); parameters.Add("Value", value); string hql = @"from Contact C left join fetch C.contactSendingOptions SO where SO.SendableDocumentCategory = :Category and SO.SendingOption = :SendingOption and SO.Value = :Value order by C.CurrentNAW.Name"; return session.GetTypedListByHQL<IContact>(hql, parameters); }
public XmlGeneratorService(SendingOptions options) { this.options = options; Directory.CreateDirectory(this.options.SourceDir); }
private static void setSendingOption(int contactId, SendingOptions sendingOption, bool value) { using (IDalSession session = NHSessionFactory.CreateSession()) { IContact contact = SecurityLayerAdapter.GetOwnedContact(session, contactId); if (contact.ContactSendingOptions.Exists(SendableDocumentCategories.NotasAndQuarterlyReports, sendingOption)) contact.ContactSendingOptions.SetValue(SendableDocumentCategories.NotasAndQuarterlyReports, sendingOption, value); else contact.ContactSendingOptions.Add(SendableDocumentCategories.NotasAndQuarterlyReports, sendingOption, value); session.Update(contact); } }