private static void Main(string [] args) { log4net.Config.XmlConfigurator.Configure(); TlsHelper.AllowTls12(); var unitySections = new [] { "unity", "scheduledDataUnity" }; var container = new UnityContainer(); foreach (var sectionName in unitySections) { var section = (UnityConfigurationSection)ConfigurationManager.GetSection(sectionName); container.LoadConfiguration(section); } var argString = args == null ? string.Empty : string.Join(" ", args); Log.Info($"Starting ScheduledDataUpdate with arguments: {argString}"); var program = container.Resolve <Program>(); var exitCode = program.Run(args); Log.Info($"Completed Scheduled Data Update, exit code {exitCode}"); Environment.Exit(exitCode); }
private static void Main() { var section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity"); var container = new UnityContainer(); section.Configure(container); TlsHelper.AllowTls12(); AutoMapperConfig.RegisterMappings(); try { Log.Info("Starting Bulk Email Synchronization"); var syncService = container.Resolve <IBulkEmailSyncService>(); syncService.RunService(); Log.Info("Finished Bulk Email Synchronization successfully"); } catch (Exception ex) { Log.Error("Bulk Email Synchronization Process failed.", ex); Environment.Exit(9999); } }
private static void Main() { var container = new UnityContainer(); var unitySections = new[] { "crossroadsCommonUnity", "unity" }; foreach (var section in unitySections.Select(sectionName => (UnityConfigurationSection)ConfigurationManager.GetSection(sectionName))) { container.LoadConfiguration(section); } TlsHelper.AllowTls12(); AutoMapperConfig.RegisterMappings(); try { Log.Info("Starting Bulk Email Synchronization"); var syncService = container.Resolve <IBulkEmailSyncService>(); syncService.RunService(); Log.Info("Finished Bulk Email Synchronization successfully"); } catch (Exception ex) { Log.Error("Bulk Email Synchronization Process failed.", ex); Environment.Exit(9999); } }
/// <summary> /// Creates a channel/client pair with the appropriate options and interceptors. /// </summary> /// <returns>A tuple of the channel and client</returns> private async Task <GrpcClient> CreateClientAsync(DnsEndPoint remoteEndpoint) { var certificate = await RetrieveServerCertificateAsync(remoteEndpoint); if (certificate == null) { return(null); } Logger.LogDebug($"Upgrading connection to TLS: {certificate}."); ChannelCredentials credentials = new SslCredentials(TlsHelper.ObjectToPem(certificate), _clientKeyCertificatePair); var channel = new Channel(remoteEndpoint.ToString(), credentials, new List <ChannelOption> { new ChannelOption(ChannelOptions.MaxSendMessageLength, GrpcConstants.DefaultMaxSendMessageLength), new ChannelOption(ChannelOptions.MaxReceiveMessageLength, GrpcConstants.DefaultMaxReceiveMessageLength), new ChannelOption(ChannelOptions.SslTargetNameOverride, GrpcConstants.DefaultTlsCommonName) }); var nodePubkey = AsyncHelper.RunSync(() => _accountService.GetPublicKeyAsync()).ToHex(); var interceptedChannel = channel.Intercept(metadata => { metadata.Add(GrpcConstants.PubkeyMetadataKey, nodePubkey); return(metadata); }).Intercept(new RetryInterceptor()); var client = new PeerService.PeerServiceClient(interceptedChannel); return(new GrpcClient(channel, client, certificate)); }
private static void Main() { var section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity"); var container = new UnityContainer(); section.Configure(container); TlsHelper.AllowTls12(); var exitCode = 0; var childcareService = container.Resolve <ChildcareService>(); try { Log.Info("Sending notifications for cancellations"); childcareService.SendChildcareCancellationNotification(); } catch (Exception ex) { Log.Error("Childcare Cancellation Notifcation Failed", ex); exitCode += 1; } try { Log.Info("Sending childcare reminders"); childcareService.SendChildcareReminders(); } catch (Exception ex) { Log.Error("Sending Childcare Reminders failed", ex); exitCode += 2; } Environment.Exit(exitCode); }
public void ThreadStaticProviderTest() { //make sure the http context is cleared. HttpContext.Current = null; var var1 = new TlsHelper<string>("var1", () => "initial"); Assert.AreEqual(typeof(Providers.ThreadStaticProvider<string>), var1.Provider.GetType()); Thread t1 = new Thread(delegate() { var1.Value = "thread 1"; Assert.AreEqual(var1.Value, "thread 1"); }); Thread t2 = new Thread(delegate() { var1.Value = "thread 2"; Assert.AreEqual(var1.Value, "thread 2"); }); Thread t3 = new Thread(delegate() { var1.Value = "thread 3"; Assert.AreEqual(var1.Value, "thread 3"); }); t1.Start(); t2.Start(); t3.Start(); t1.Join(); t2.Join(); t3.Join(); Assert.AreEqual(var1.Value, "initial"); }
private SslServerCredentials CreateCredentials() { var keyCertificatePair = TlsHelper.GenerateKeyCertificatePair(); return(new SslServerCredentials(new List <KeyCertificatePair> { keyCertificatePair })); }
private void CreateClientKeyCertificatePair() { var commonCertifName = "CN=" + GrpcConstants.DefaultTlsCommonName; var rsaKeyPair = TlsHelper.GenerateRsaKeyPair(); var clientCertificate = TlsHelper.GenerateCertificate(new X509Name(commonCertifName), new X509Name(commonCertifName), rsaKeyPair.Private, rsaKeyPair.Public); _clientKeyCertificatePair = new KeyCertificatePair(TlsHelper.ObjectToPem(clientCertificate), TlsHelper.ObjectToPem(rsaKeyPair.Private)); }
protected void Application_Start(object sender, EventArgs e) { AreaRegistration.RegisterAllAreas(); AutoMapperConfig.RegisterMappings(); UnityConfig.RegisterComponents(); GlobalConfiguration.Configure(WebApiConfig.Register); ApplicationPreload.StartJobProcessor(); TlsHelper.AllowTls12(); XmlConfigurator.Configure(new FileInfo(Server.MapPath("~/Web.config"))); }
static void Main(string[] args) { AutoMapperConfig.RegisterMappings(); var container = new UnityContainer(); var unitySections = new[] { "crossroadsCommonUnity", "unity" }; foreach (var section in unitySections.Select(sectionName => (UnityConfigurationSection)ConfigurationManager.GetSection(sectionName))) { container.LoadConfiguration(section); } TlsHelper.AllowTls12(); var exitCode = 0; try { // Dependency Injection _eventService = container.Resolve <EventService>(); _eventService.SendReminderEmails(); } catch (Exception ex) { exitCode = 1; Log.Error("Event Reminder Process failed.", ex); } try { _eventService = container.Resolve <EventService>(); _eventService.SendPrimaryContactReminderEmails(); } catch (Exception ex) { exitCode = 1; Log.Error("Event Primary Contact Reminder Process failed.", ex); } try { _serveService = container.Resolve <ServeService>(); _serveService.SendReminderEmails(); } catch (Exception ex) { exitCode += 2; Log.Error("Serve Reminder Process failed.", ex); } Log.Info("all done"); Environment.Exit(exitCode); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); UnityConfig.RegisterComponents(); //GlobalConfiguration.Configure(WebApiConfig.Register); GlobalConfiguration.Configure(VersionConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AutoMapperConfig.RegisterMappings(); TlsHelper.AllowTls12(); log4net.Config.XmlConfigurator.Configure(new FileInfo(Server.MapPath("~/Web.config"))); }
public static void Main(string[] args) { var section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity"); var container = new UnityContainer(); section.Configure(container); TlsHelper.AllowTls12(); var program = container.Resolve <Program>(); program.run(args); }
static void Main(string[] args) { AutoMapperConfig.RegisterMappings(); var section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity"); var container = new UnityContainer(); section.Configure(container); TlsHelper.AllowTls12(); var exitCode = 0; try { // Dependency Injection _eventService = container.Resolve <EventService>(); _eventService.SendReminderEmails(); } catch (Exception ex) { exitCode = 1; Log.Error("Event Reminder Process failed.", ex); } try { _eventService = container.Resolve <EventService>(); _eventService.SendPrimaryContactReminderEmails(); } catch (Exception ex) { exitCode = 1; Log.Error("Event Primary Contact Reminder Process failed.", ex); } try { _serveService = container.Resolve <ServeService>(); _serveService.SendReminderEmails(); } catch (Exception ex) { exitCode += 2; Log.Error("Serve Reminder Process failed.", ex); } Log.Info("all done"); Environment.Exit(exitCode); }
private SslServerCredentials CreateCredentials() { var commonCertifName = "CN=" + GrpcConstants.DefaultTlsCommonName; // Generate the servers rsa key pair and self-signed certificate. var rsaKeyPair = TlsHelper.GenerateRsaKeyPair(); var certificate = TlsHelper.GenerateCertificate(new X509Name(commonCertifName), new X509Name(commonCertifName), rsaKeyPair.Private, rsaKeyPair.Public); var keyCertificatePair = new KeyCertificatePair(TlsHelper.ObjectToPem(certificate), TlsHelper.ObjectToPem(rsaKeyPair.Private)); return(new SslServerCredentials(new List <KeyCertificatePair> { keyCertificatePair })); }
public static void Main(string[] args) { var container = new UnityContainer(); var unitySections = new[] { "crossroadsCommonUnity", "unity" }; foreach (var section in unitySections.Select(sectionName => (UnityConfigurationSection)ConfigurationManager.GetSection(sectionName))) { container.LoadConfiguration(section); } TlsHelper.AllowTls12(); var program = container.Resolve <Program>(); program.run(args); }
public void HttpContextProviderTest() { //create a fake http request. SimpleWorkerRequest request = new SimpleWorkerRequest("","","", null, new StringWriter()); HttpContext context = new HttpContext(request); HttpContext.Current = context; var var2 = new TlsHelper<string>("var2", () => "initial"); //test that the TLS helper picked the right provider and is storing values correctly. Assert.AreEqual(typeof(Providers.HttpContextProvider<string>), var2.Provider.GetType()); Assert.AreEqual(var2.Value, "initial"); var2.Value = "New Value"; Assert.AreEqual(var2.Value, "New Value"); }
private static void Main() { var container = new UnityContainer(); var unitySections = new[] { "crossroadsCommonUnity", "unity" }; foreach (var section in unitySections.Select(sectionName => (UnityConfigurationSection)ConfigurationManager.GetSection(sectionName))) { container.LoadConfiguration(section); } TlsHelper.AllowTls12(); var exitCode = 0; var childcareService = container.Resolve <ChildcareService>(); try { Log.Info("Sending notifications for cancellations"); childcareService.SendChildcareCancellationNotification(); } catch (Exception ex) { Log.Error("Childcare Cancellation Notifcation Failed", ex); exitCode += 1; } try { Log.Info("Sending childcare reminders"); childcareService.SendChildcareReminders(); } catch (Exception ex) { Log.Error("Sending Childcare Reminders failed", ex); exitCode += 2; } Environment.Exit(exitCode); }
private void CreateClientKeyCertificatePair() { _clientKeyCertificatePair = TlsHelper.GenerateKeyCertificatePair(); }
private static void Main() { var container = new UnityContainer(); var unitySections = new[] { "crossroadsCommonUnity", "unity" }; foreach (var section in unitySections.Select(sectionName => (UnityConfigurationSection)ConfigurationManager.GetSection(sectionName))) { container.LoadConfiguration(section); } TlsHelper.AllowTls12(); var eventService = container.Resolve <EventService>(); var groupService = container.Resolve <GroupService>(); var userApiService = container.Resolve <ApiUserRepository>(); var mpRestRepository = container.Resolve <MinistryPlatformRestRepository>(); // use childcare grouptype and eventtype var groupTypeId = Convert.ToInt32(ConfigurationManager.AppSettings["ChildcareGroupType"]); var eventTypeId = Convert.ToInt32(ConfigurationManager.AppSettings["ChildcareEventType"]); var defaultMinistryId = Convert.ToInt32(ConfigurationManager.AppSettings["ChildcareDefaultMinistryId"]); var configSettingsPageId = Convert.ToInt32(ConfigurationManager.AppSettings["ConfigurationSettingsPageId"]); try { //////////////////////////////////////////////////////////////////////// // Update the childcare events that are properly set up in a series //////////////////////////////////////////////////////////////////////// Log.Info("Updating Childcare events in series."); var apiToken = userApiService.GetToken(); AutoMapperConfig.RegisterMappings(); var parms = new Dictionary <string, object>() { { "@Group_Type", groupTypeId }, { "@Event_type", eventTypeId } }; //Call Andy's stored proc and loop through var results = mpRestRepository.UsingAuthenticationToken(apiToken).GetFromStoredProc <MpEventsMissingGroups>("api_crds_MissingChildcareGroup", parms); var eventList = results.FirstOrDefault() ?? new List <MpEventsMissingGroups>(); Log.Info("Updating " + eventList.Count.ToString() + " series events."); foreach (var item in eventList) { var groupdto = groupService.GetGroupDetails(item.GroupId); //change the date var mpevent = eventService.GetEvent(item.EventId); groupdto.StartDate = mpevent.EventStartDate; groupdto.Participants?.Clear(); groupdto.Events?.Clear(); groupdto.MeetingDayId = null; groupdto.MeetingFrequencyID = null; //change the dates var newgroupdto = groupService.CreateGroup(groupdto); //link the new group to the event eventService.AddEventGroup(item.EventId, newgroupdto.GroupId, apiToken); } //////////////////////////////////////////////////////////////////////// // Update the childcare events that are orphans (Use defaults) //////////////////////////////////////////////////////////////////////// //get default values 10,25,100 var maxAgeObject = MinistryPlatformService.GetRecordsDict(configSettingsPageId, apiToken, ",ChildcareMaxAge", string.Empty).FirstOrDefault()?["Value"]; var defaultMaximumAge = maxAgeObject != null?Convert.ToInt32(maxAgeObject) : 10; var minParticipantsObject = MinistryPlatformService.GetRecordsDict(configSettingsPageId, apiToken, ",ChildcareMinParticipants", string.Empty).FirstOrDefault()?["Value"]; var defaultMinimumParticipants = minParticipantsObject != null?Convert.ToInt32(minParticipantsObject) : 25; var targetSizeObject = MinistryPlatformService.GetRecordsDict(configSettingsPageId, apiToken, ",ChildcareTargetSize", string.Empty).FirstOrDefault()?["Value"]; var defaultTargetSize = targetSizeObject != null?Convert.ToInt32(targetSizeObject) : 100; Log.Info("Updating orphan Childcare events."); var orphanresults = mpRestRepository.UsingAuthenticationToken(apiToken).GetFromStoredProc <MpOrphanEventsMissingGroups>("api_crds_GetOrphanChildcareEvents", new Dictionary <string, object>()); var orphaneventList = orphanresults.FirstOrDefault() ?? new List <MpOrphanEventsMissingGroups>(); Log.Info("Updating " + eventList.Count.ToString() + " orphan events."); foreach (var item in orphaneventList) { var groupdto = new GroupDTO(); var mpevent = eventService.GetEvent(item.EventId); groupdto.StartDate = mpevent.EventStartDate; groupdto.Participants?.Clear(); groupdto.Events?.Clear(); groupdto.MeetingDayId = null; groupdto.MeetingFrequencyID = null; groupdto.CongregationId = mpevent.CongregationId; groupdto.Congregation = mpevent.Congregation; groupdto.ContactId = mpevent.PrimaryContact.ContactId; groupdto.MaximumAge = defaultMaximumAge; groupdto.MinimumParticipants = defaultMinimumParticipants; groupdto.TargetSize = defaultTargetSize; groupdto.GroupName = "__childcaregroup"; groupdto.GroupTypeId = groupTypeId; groupdto.MinistryId = defaultMinistryId; var newgroupdto = groupService.CreateGroup(groupdto); //link the new group to the event eventService.AddEventGroup(item.EventId, newgroupdto.GroupId, apiToken); } Log.Info("Childcare Group update Complete."); } catch (Exception ex) { Log.Error("Childcare Group Update Notifcation Failed", ex); Environment.Exit(9999); } Environment.Exit(0); }