public static XmlDocument TestListRequest() { ReferenceDataManager.SetSource(ReferenceDataManager.SourceTypes.ConfigFile); IConfigurationRepository configurationRepository = new ConfigFileConfigurationRepository(); ILoggingService loggingService = new Log4NetLoggingService(configurationRepository, new ThreadContextService()); GovTalkMessageCreator listRequestCreator = new GovTalkMessageCreator(new ListRequestMessageBuilder(loggingService), loggingService); listRequestCreator.CreateGovTalkMessage(); XmlDocument xd = listRequestCreator.SerializeGovTalkMessage(); xd.Save(@"C:\Temp\listrequest-" + DateTime.Now.ToString("_yyyy_MM_dd_HH_mm_ss", System.Globalization.CultureInfo.InvariantCulture) + ".xml"); // Helpers.SerializeToFile(listRequestCreator.GetGovTalkMessage(), @"C:\Temp\listrequest-" + DateTime.Now.ToString("_yyyy_MM_dd_HH_mm_ss", System.Globalization.CultureInfo.InvariantCulture) + ".xml"); GovTalkMessageHelper helper = new GovTalkMessageHelper(configurationRepository, loggingService); XmlDocument outputXml = new XmlDocument(); outputXml.PreserveWhitespace = true; outputXml = helper.AddPassword(xd.ToXDocument(), "ListRequestPassword").ToXmlDocument(); return(outputXml); //outputXml.Save(@"C:\Temp\listrequest-newpwd-" + // DateTime.Now.ToString("_yyyy_MM_dd_HH_mm_ss", System.Globalization.CultureInfo.InvariantCulture) + ".xml"); //XDocument listRequest = new XDocument(); //listRequest = helper.AddPassword(xd.ToXDocument(), "listrequestpassword"); //listRequest.Save(@"C:\Temp\XDocListRequest.xml"); }
static void Main(string[] args) { IProductRepository productRepository = new ProductRepository(); ICacheStorage cacheStorage = new SystemRuntimeCacheStorage(); IConfigurationRepository configurationRepository = new ConfigFileConfigurationRepository(); IContextService contextService = new ThreadContextService(); IFileService fileService = new DefaultFileService(); ILoggingService loggingService = new Log4NetLoggingService(configurationRepository, contextService); // loggingService = new ConsoleLoggingService(); IEmailService emailService = new EmailService(); var productService = new ProductService(productRepository, cacheStorage, configurationRepository, loggingService); var response = productService.GetProduct(new GetProductRequest { Id = 12 }); if (response.Success) { Console.WriteLine(string.Concat("Product name: ", response.Product.Name)); } else { Console.WriteLine(response.Exception); } Console.ReadKey(); }
public static void TestGovTalkCompressedMessageCreation() { DataTableRepaymentPopulater.GiftAidDonations = DataHelpers.GetDataTableFromCsv(@"C:\enterprise_tfs\GAVIN\CO\test_data\sample2.csv", true); DataTableRepaymentPopulater.OtherIncome = DataHelpers.GetDataTableFromCsv(@"C:\Temp\OtherInc.csv", true); // C:\Temp\Donations.csv ReferenceDataManager.SetSource(ReferenceDataManager.SourceTypes.ConfigFile); IConfigurationRepository configurationRepository = new ConfigFileConfigurationRepository(); ILoggingService loggingService = new Log4NetLoggingService(configurationRepository, new ThreadContextService()); GovTalkMessageCreator compressedSubmissionCreator = new GovTalkMessageCreator(new SubmitRequestCompressedMessageBuilder(loggingService), loggingService); compressedSubmissionCreator.CreateGovTalkMessage(); XmlDocument xd = compressedSubmissionCreator.SerializeGovTalkMessage(); GovTalkMessageHelper gtmHelper = new GovTalkMessageHelper(configurationRepository, loggingService); XmlDocument finalXd = gtmHelper.SetIRmark(xd); GovTalkMessageFileName filename = (new GovTalkMessageFileName.FileNameBuilder() .AddFilePath(@"C:\Temp\") .AddEnvironment("Test") .AddMessageIntention("CompressedGovTalkMessage") .AddTimestamp(DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss", System.Globalization.CultureInfo.InvariantCulture)) .AddCustomNamePart("File" + 1) .BuildFileName() ); finalXd.Save(filename.ToString()); }
static XmlDocument TestSend(string filename = "") { IConfigurationRepository configurationRepository = new ConfigFileConfigurationRepository(); ILoggingService loggingService = new Log4NetLoggingService(configurationRepository, new ThreadContextService()); string uri = configurationRepository.GetConfigurationValue <string>("SendURIDev"); XmlDocument xd = new XmlDocument(); xd.PreserveWhitespace = true; if (filename == "") { filename = @"C:\Temp\test_GatewaySubmission_20150818163247_EmptyRepayment.xml"; } xd.Load(filename); CharitiesOnline.MessageService.Client client = new MessageService.Client(loggingService); XmlDocument reply = client.SendRequest(xd, uri); Console.WriteLine(reply.InnerXml); return(reply); }
public static void TestOtherIncome() { DataTableRepaymentPopulater.GiftAidDonations = DataHelpers.GetDataTableFromCsv(@"C:\Temp\Donations.csv", true); DataTableRepaymentPopulater.OtherIncome = DataHelpers.GetDataTableFromCsv(@"C:\Temp\OtherInc.csv", true); ReferenceDataManager.SetSource(ReferenceDataManager.SourceTypes.ConfigFile); IConfigurationRepository configurationRepository = new ConfigFileConfigurationRepository(); ILoggingService loggingService = new Log4NetLoggingService(configurationRepository, new ThreadContextService()); GovTalkMessageCreator submitMessageCreator = new GovTalkMessageCreator(new SubmitRequestMessageBuilder(loggingService), loggingService); submitMessageCreator.CreateGovTalkMessage(); hmrcclasses.GovTalkMessage submitMessage = submitMessageCreator.GetGovTalkMessage(); XmlDocument xd = submitMessageCreator.SerializeGovTalkMessage(); GovTalkMessageHelper gtmHelper = new GovTalkMessageHelper(configurationRepository, loggingService); XmlDocument finalXd = gtmHelper.SetIRmark(xd); GovTalkMessageFileName filename = (new GovTalkMessageFileName.FileNameBuilder() .AddFilePath(@"C:\Temp\") .AddEnvironment("Test") .AddMessageIntention("GovTalkMsgWithOtherIncome") .AddTimestamp(DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss", System.Globalization.CultureInfo.InvariantCulture)) .BuildFileName() ); finalXd.Save(filename.ToString()); }
protected void Application_Error(Object sender, EventArgs e) { Exception ex = Server.GetLastError(); //Context.ClearError(); Log4NetLoggingService logger = (Log4NetLoggingService)DependencyResolver.Current.GetService(typeof(ILoggingService)); logger.LogFatal(this, "", ex); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); Log4NetLoggingService logger = (Log4NetLoggingService)DependencyResolver.Current.GetService(typeof(ILoggingService)); logger.LogInfo(this, "Application start"); }
private static void RegisterServices(this IContainer container) { // register services eg. //container.Register<IUserService, UserService>(); // NOTE: Registers ISession provider to work with injected Request container.Register <ISession>(Made.Of(() => GetSession(Arg.Of <HttpRequestMessage>()))); //TODO: Register ILoggerFactory in DryIoc container using Microsoft.Extensions.Logging - https://stackoverflow.com/questions/48911710/register-iloggerfactory-in-dryioc-container?rq=1 // https://dotnetfiddle.net/GE2Dp2 var log = new Log4NetLoggingService(); container.UseInstance <ILoggingService>(log); //container.Register<IAppSettingsService, AppSettingsService>(Reuse.Singleton); }
public static Action <string, ConsoleColor, bool> WriteLineMethod; // message, color, isDebug static Global() { Logger = new Log4NetLoggingService(); JsonSerializer = new ObjectJsonSerializer(); MessageDispatcher = new MessageDispatcher(); CommandBus = new DirectCommandBus(MessageDispatcher); EventBus = new DirectEventBus(MessageDispatcher); WriteLineMethod = (line, color, isDebug) => { ConsoleColor oldColor = Console.ForegroundColor; Console.ForegroundColor = color; Console.WriteLine(line); Console.ForegroundColor = oldColor; }; StartTimer(); }
public static void TestReadSuccessResponse() { IConfigurationRepository configurationRepository = new ConfigFileConfigurationRepository(); ILoggingService loggingService = new Log4NetLoggingService(configurationRepository, new ThreadContextService()); XmlDocument successResponse = new XmlDocument(); successResponse.Load(@"C:\Temp\success_response_78503626913182048.xml"); ReadResponseStrategy reader = new ReadResponseStrategy(loggingService, configurationRepository); if (reader.IsMatch(successResponse.ToXDocument())) { SuccessResponse success = reader.GetBody <SuccessResponse>(); } }
public static void TestReadMessage() { IConfigurationRepository configurationRepository = new ConfigFileConfigurationRepository(); ILoggingService loggingService = new Log4NetLoggingService(configurationRepository, new ThreadContextService()); // vep200pc // XDocument xd = XDocument.Load(@"C:\Temp\Compressed Data Samples\GAValidSample_GZIP.xml"); XDocument xd = XDocument.Load(@"C:\Temp\GAValidSample_GZIP.xml"); ReadSubmitRequestStrategy read = new ReadSubmitRequestStrategy(loggingService); read.ReadMessage(xd); read.IsMatch(xd); DataTable dt = read.GetMessageResults <DataTable>(); }
public static XmlDocument TestPollrequest() { ReferenceDataManager.SetSource(ReferenceDataManager.SourceTypes.ConfigFile); IConfigurationRepository configurationRepository = new ConfigFileConfigurationRepository(); ILoggingService loggingService = new Log4NetLoggingService(configurationRepository, new ThreadContextService()); GovTalkMessageCreator submitPollCreator = new GovTalkMessageCreator(new SubmitPollMesageBuilder(loggingService), loggingService); submitPollCreator.SetCorrelationId("FDE7675B3DCA4EFF89DACECA07751B98"); submitPollCreator.CreateGovTalkMessage(); XmlDocument xd = submitPollCreator.SerializeGovTalkMessage(); xd.Save(@"c:\Temp\pollsubmit-" + DateTime.Now.ToString("_yyyy_MM_dd_HH_mm_ss", System.Globalization.CultureInfo.InvariantCulture) + ".xml"); return(xd); }
public void TestInitialize() { // Not fake... _dataContextAsync = new SimpleMembershipDataContextAsync(); // Is fake... _fakeConfigurationRepository = new FakeConfigFileConfigurationRepository(); _fakeConfigurationRepository.FakeSettingsDictionary.Clear(); _fakeConfigurationRepository.FakeSettingsDictionary.Add("Log4NetSettingsFile", "Log4Net.config.xml"); _fakeConfigurationRepository.FakeSettingsDictionary.Add("LogEverythingViaWCF", "false"); _fakeConfigurationRepository.FakeSettingsDictionary.Add("DontLogAnythingViaWCF", "false"); _fakeConfigurationRepository.FakeSettingsDictionary.Add("LogEverythingToFile", "true"); _fakeConfigurationRepository.FakeSettingsDictionary.Add("LoggingServiceURL", "http://localhost:63247/LogWCF.svc"); var dir = Directory.GetCurrentDirectory(); var resourceFileInfo = new FileInfo(Path.Combine(dir, "Log4Net.config.xml")); // Is fake... _fakeContextService = new FakeThreadContextService { FakeGetContextualFullFilePath = resourceFileInfo.FullName, FakeUserNameForTestingPurposes = "SimpleMembershipServiceUnitTest" }; // Is fake... _fakewcfAppenderService = new FakeWcfAppenderService(_fakeConfigurationRepository); // Not fake... _loggingService = new Log4NetLoggingService(_fakeConfigurationRepository, _fakeContextService, _fakewcfAppenderService, true); // Not fake... _uow = new SimpleMembershipUnitOfWorkAsync(_dataContextAsync, _loggingService); // Not fake... MembershipService = new WebSecurity(_uow, _loggingService); InitDb(); }
public static XmlDocument TestDeleteRequest() { ReferenceDataManager.SetSource(ReferenceDataManager.SourceTypes.ConfigFile); IConfigurationRepository configurationRepository = new ConfigFileConfigurationRepository(); ILoggingService loggingService = new Log4NetLoggingService(configurationRepository, new ThreadContextService()); GovTalkMessageCreator deleteRequestCreator = new GovTalkMessageCreator(new DeleteRequestMessageBuilder(loggingService), loggingService); deleteRequestCreator.SetCorrelationId("87E1E8A7F16147A6B87962E07933B406"); deleteRequestCreator.CreateGovTalkMessage(); XmlDocument xd = deleteRequestCreator.SerializeGovTalkMessage(); GovTalkMessageHelper helper = new GovTalkMessageHelper(configurationRepository, loggingService); xd = helper.UpdateMessageForProductionGateway(xd); return(xd); }
private static void RegisterServices(this IContainer container) { // NOTE: Registers ISession provider to work with injected Request container.Register <ISession>(Made.Of(() => GetSession(Arg.Of <HttpRequestMessage>()))); var log = new Log4NetLoggingService(); container.UseInstance <ILoggingService>(log); iDom.IAzureStorageConfig azureStorageConfig = new Domain.AzureStorageConfig() { AccountKey = ConfigurationManager.AppSettings[dom.Consts.AzureStorageConfig_AccountKey], AccountName = ConfigurationManager.AppSettings[dom.Consts.AzureStorageConfig_AccountName], ImageContainer = ConfigurationManager.AppSettings[dom.Consts.AzureStorageConfig_ImageContainer], QueueName = ConfigurationManager.AppSettings[dom.Consts.AzureStorageConfig_QueueName], ThumbnailContainer = ConfigurationManager.AppSettings[dom.Consts.AzureStorageConfig_ThumbnailContainer] }; container.UseInstance <iDom.IAzureStorageConfig>(azureStorageConfig); container.Register <iDom.IAzureStorageManager, dom.AzureStorageManager>(); container.Register <iDom.IUser, dom.User>(); }
public static void TestGovTalkMessageCreation(string SourceDataFileName, string Filename = "") { IConfigurationRepository configurationRepository = new ConfigFileConfigurationRepository(); ILoggingService loggingService = new Log4NetLoggingService(configurationRepository, new ThreadContextService()); ReferenceDataManager.SetSource(ReferenceDataManager.SourceTypes.ConfigFile); ReferenceDataManager.governmentGatewayEnvironment = GovernmentGatewayEnvironment.localtestservice; DataTableRepaymentPopulater.SetLogger(loggingService); if (!string.IsNullOrEmpty(SourceDataFileName)) { DataTableRepaymentPopulater.GiftAidDonations = DataHelpers.GetDataTableFromCsv(@SourceDataFileName, true); } GovTalkMessageCreator submitMessageCreator = new GovTalkMessageCreator(new SubmitRequestMessageBuilder(loggingService), loggingService); submitMessageCreator.CreateGovTalkMessage(); GovTalkMessage submitMessage = submitMessageCreator.GetGovTalkMessage(); GovTalkMessageHelper helper = new GovTalkMessageHelper(configurationRepository, loggingService); helper.SetPassword(submitMessage, "testing1"); XmlDocument xd = submitMessageCreator.SerializeGovTalkMessage(); xd.PreserveWhitespace = true; xd = helper.AddPassword(xd.ToXDocument(), "xdocpassword", "clear").ToXmlDocument(); byte[] xmlDocumentSize = xd.XmlToBytes(); Console.WriteLine("The document is {0} bytes big.", xmlDocumentSize.Length); XmlDocument outputXmlDocument = new XmlDocument(); outputXmlDocument.PreserveWhitespace = true; //if (xmlDocumentSize.Length > 1000000) //{ // XmlDocument compressedVersion = submitMessageCreator.CompressClaim(); // outputXmlDocument = GovTalkMessageHelper.SetIRmark(compressedVersion); //} //else //{ GovTalkMessageHelper gtmHelper = new GovTalkMessageHelper(configurationRepository, loggingService); outputXmlDocument = gtmHelper.SetIRmark(xd); //} string filename; if (Filename == "") { GovTalkMessageFileName FileNamer = new GovTalkMessageFileName.FileNameBuilder() .AddLogger(loggingService) .AddMessageIntention("GatewaySubmission") .AddFilePath(@"C:\Temp\") .AddTimestamp(DateTime.Now.ToString("yyyyMMddHHmmss")) .AddEnvironment(ReferenceDataManager.governmentGatewayEnvironment.ToString()) .BuildFileName(); filename = FileNamer.ToString(); } else { filename = Filename; } outputXmlDocument.Save(filename); #region old //BodyCreator bodyCreator = new BodyCreator(new SubmitRequestBodyBuilder()); //bodyCreator.CreateBody(); //GovTalkMessageBody body = bodyCreator.GetBody(); //BodyCreator pollBodyCreator = new BodyCreator(new SubmitPollBodyBuilder()); //pollBodyCreator.CreateBody(); //GovTalkMessageBody pollBody = pollBodyCreator.GetBody(); #endregion old }
public static void DemonstrateLocalProcess() { // Set up the logging IConfigurationRepository configurationRepository = new ConfigFileConfigurationRepository(); ILoggingService loggingService = new Log4NetLoggingService(configurationRepository, new ThreadContextService()); DataTableRepaymentPopulater.SetLogger(loggingService); // Create a file of donations records DataTableRepaymentPopulater.GiftAidDonations = DataHelpers.GetDataTableFromCsv(@"C:\Temp\Donations.csv", true); // Set up app.config as a source for the reference data ReferenceDataManager.SetSource(ReferenceDataManager.SourceTypes.ConfigFile); // Build a GovTalkMessage GovTalkMessageCreator submitMessageCreator = new GovTalkMessageCreator(new SubmitRequestMessageBuilder(loggingService), loggingService); submitMessageCreator.CreateGovTalkMessage(); // Get the GovTalkMessage that has been built GovTalkMessage submitMessage = submitMessageCreator.GetGovTalkMessage(); // Serialize the GovTalkMessage to an XmlDocument XmlDocument xd = submitMessageCreator.SerializeGovTalkMessage(); // Set the IRmark for the GovTalkMessage XmlDocument GovTalkMessageHelper gtmHelper = new GovTalkMessageHelper(configurationRepository, loggingService); XmlDocument finalXd = gtmHelper.SetIRmark(xd); // Set the URI to send the file to string uri = configurationRepository.GetConfigurationValue <string>("SendURILocal"); // Create a client to send the file to the target gateway CharitiesOnline.MessageService.Client client = new MessageService.Client(loggingService); // Create an XmlDocument of the reply from the endpoint XmlDocument reply = client.SendRequest(xd, uri); // Set up a message reading strategy IMessageReader _messageReader = new DefaultMessageReader(loggingService, configurationRepository, reply.ToXDocument()); _messageReader.ReadMessage(); string[] results = _messageReader.GetMessageResults <string[]>(); //int correlationIdIndex = Array.IndexOf(results, "CorrelationId"); int correlationIdPosition = Array.FindIndex(results, element => element.StartsWith("CorrelationId")); if (correlationIdPosition < 0) { throw new ArgumentNullException("CorrelationId"); } int qualifierPosition = Array.FindIndex(results, element => element.StartsWith("Qualifier")); if (qualifierPosition < 0) { throw new ArgumentNullException("Qualifier"); } Console.WriteLine(string.Join("\n", results)); #region old // This bit, bunch of if-thens, should be covered by the reader strategy ... //string bodytype = _messageReader.GetBodyType(reply.ToXDocument()); //if(bodytype == null) //{ // //acknowledgment // Console.WriteLine("CorrelationId is {0}",_messageReader.ReadMessage<string>(reply.ToXDocument())); //} //else if(bodytype == "hmrcclasses.SuccessResponse") //{ // //success // string[] success = _messageReader.ReadMessage<string[]>(reply.ToXDocument()); // Console.WriteLine(string.Join("\n", success)); //} //else if(bodytype == "hmrcclasses.ErrorResponse") //{ // //error // string[] error = _messageReader.ReadMessage<string[]>(reply.ToXDocument()); // Console.WriteLine(string.Join("\n", error)); //} #endregion old // Need to get correlationId GovTalkMessageFileName fileNamer = new GovTalkMessageFileName.FileNameBuilder() .AddLogger(loggingService) .AddFilePath(configurationRepository.GetConfigurationValue <string>("TempFolder")) .AddEnvironment("local") .AddMessageIntention("reply") .AddCorrelationId(results[correlationIdPosition].Substring(results[correlationIdPosition].IndexOf("::") + 2)) .AddMessageQualifier(results[qualifierPosition].Substring(results[qualifierPosition].IndexOf("::") + 2)) //could check for < 0 here and pass empty string .BuildFileName(); string filename = fileNamer.ToString(); reply.Save(filename); // reply.Save(@"C:\Temp\localreply.xml"); }