private static int ErrorHandler(CommandContext?ctx, Exception exception) { var errorWriter = (ctx?.Console.Error ?? Console.Error); exception.Print(errorWriter.WriteLine, includeProperties: true, includeData: true, includeStackTrace: false); // use CommandLogger if it has not already logged for this CommandContext if (ctx is not null && !CommandLogger.HasLoggedFor(ctx)) { CommandLogger.Log(ctx, writer: errorWriter.WriteLine, includeSystemInfo: true, includeMachineAndUser: true, includeAppConfig: false ); } // print help for the target command or root command // if the exception occurred before a command could be parsed ctx?.PrintHelp(); return(ExitCodes.Error.Result); }
// // GET: /Test/ public void TestEventCommandLogging() { var db = new PortugalVillasContext(); var log = new CommandLogger(db); log.Log(35, new EventCommand()); }
public void TestFullDocumentGenerateStack() { var db = new PortugalVillasContext(); //Test WITH PARENT //TEST WITH BOOKING Booking booking = db.Bookings.Where(x => x.BookingID.Equals(4)).FirstOrDefault(); booking.PropertyID = 221; /* Booking booking = null;*/ //TEST WITH CUSTOMER Customer aCustomer = db.Customers.Where(x => x.CustomerID == 1).FirstOrDefault(); //TEST WITH BES var bes = db.BookingExtraSelections.Where(x => x.BookingExtraSelectionID == 3).First(); bes.BookingExtraID = 1; //set up vars var type = PRCDocument.PRCDocumentType.UK_WineTasting; //create event - need to give it type thus name var anEvent = new Event(); anEvent.Documents = new List <Document>(); //TEST ADD ID - PLEASE REMOVE anEvent.EventID = 2; //END TEST CODE anEvent.WhenCreated = DateTime.Now; var commandsAndResultsToLog = new List <EventCommand>(); //create correct command //doc //email out with doc EventCommandCreateDocument createDocCommand; EventCommandSendEmail sendEmail; //HOW DO WE DECIDE WHAT TYPE OF EVENT WE WANT??? depends on type?? if (booking != null) { createDocCommand = new EventCommandCreateDocument(anEvent, aCustomer, type, booking); /* sendEmail = new EventCommandSendEmail(anEvent, aCustomer, booking);*/ } else { createDocCommand = new EventCommandCreateDocument(anEvent, aCustomer, type, null, bes); /*/sendEmail = new EventCommandSendEmail(anEvent, aCustomer, null, bes);*/ } //create all commands anEvent.EventCommands.Add(createDocCommand); /* anEvent.EventCommands.Add(sendEmail);*/ //create document using executes var result = new EventCommandResult(); foreach (var command in anEvent.EventCommands) { command.EventCommandResults.Add(command.ExecuteCommand()); commandsAndResultsToLog.Add(command); } //render //save to DB with all correct commands etc var EventCommandLogger = new CommandLogger(db); var eventLogger = new EventLogger(db, EventCommandLogger); //save event eventLogger.LogEvent(anEvent); //save eventcoomand and result foreach (var commandAndResult in commandsAndResultsToLog) { EventCommandLogger.Log(anEvent.EventID, commandAndResult); } //save document generated //NEED TO ADD CORRECT PARAMS (which are what??) //if there's any docs, write them to the DB foreach (var doc in anEvent.Documents) { doc.EventID = anEvent.EventID; doc.DocumentDescription = type.ToString(); doc.EmailTo = aCustomer.EmailAddress; doc.CustomerID = aCustomer.CustomerID; db.Documents.Add(doc); db.SaveChanges(); } }
private static int Main(string[] args) { Debugger.AttachIfDebugDirective(args); AppDomain.CurrentDomain.UnhandledException += (_, eventArgs) => ((Exception)eventArgs.ExceptionObject).Print(); try { var configs = AppConfigs.Load(); var appSettings = new AppSettings { Arguments = { DefaultOptionSplit = ',', DefaultPipeTargetSymbol = "$*" }, ArgumentTypeDescriptors = { new DelegatedTypeDescriptor <Regex>("regex", p => { // make it easier to specify NOT matching if (p.StartsWith("$!")) { p = $"^((?!{p.Substring(2)}).)*$"; } return(new Regex(p, RegexOptions.Compiled)); }) } }; var appRunner = new AppRunner <GitApplication>(appSettings) .UseDefaultMiddleware() .GiveCancellationTokenToFlurl() .Configure(c => c.UseParameterResolver(_ => AnsiConsole.Console)) .UseNameCasing(Case.KebabCase) .UseDataAnnotationValidations(showHelpOnError: true) .UseTimerDirective() .UseDefaultsFromAppSetting(configs.Settings, true) .UseErrorHandler((ctx, ex) => { var errorWriter = (ctx?.Console.Error ?? Console.Error); ex.Print(errorWriter.WriteLine, includeProperties: true, includeData: true, includeStackTrace: false); // use CommandLogger if it has not already logged for this CommandContext if (ctx is not null && !CommandLogger.HasLoggedFor(ctx)) { CommandLogger.Log(ctx, writer: errorWriter.WriteLine, includeSystemInfo: true, includeAppConfig: false ); errorWriter.WriteLine(); } // print help for the target command or root command // if the exception occurred before a command could be parsed ctx?.PrintHelp(); return(ExitCodes.Error.Result); }) .UseCommandLogger() .RegisterContainer(configs); return(appRunner.Run(args)); } catch (OperationCanceledException) { return(1); } catch (Exception e) { e.Print(); return(1); } }
public ActionResult AddBookingEvent(FormCollection eventAndBooking) { try { var bookingId = Convert.ToInt32(eventAndBooking["BookingID"]); var eventTypeId = Convert.ToInt32(eventAndBooking["EventTypeID"]); //get the booking var booking = db.Bookings.Where(x => x.BookingID.Equals(bookingId)).FirstOrDefault(); var property = booking.Property; //get the customer var customer = db.Customers.FirstOrDefault(x => x.CustomerID.Equals(booking.CustomerID)); var documentType = new PRCDocument.PRCDocumentType(); //create new event and assign the correct typeID HERE, then can make event creation generic var eventToAdd = CreateBookingEventViaFactory(eventTypeId, booking); /*var whatAmIReturning = FullyInstantiateAndRunEvent(customer, booking);*/ //////////GET TYPE OF DOCUMENT////// //STORE IN EVENT - DocumentEnum and Email Enum if (eventToAdd.EventType.DocumentEnumID != null) { documentType = (PRCDocument.PRCDocumentType)eventToAdd.EventType.DocumentEnumID; } ////BEGIN GENERIC CODE ///////////////////////////////////////// ////////CREATE EVENT DEPENDING ON SUB TYPE EventCommandCreateDocument createDocCommand; EventCommandSendEmail sendEmail; EventCommandDocumentOutDirectoryBundleAndEmail docBundle; switch (eventToAdd.EventType.EventSubTypeID) { case 1: //does nothing, just add event case 2: //email out sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailTemplateId, customer, booking); eventToAdd.EventCommands.Add(sendEmail); break; case 3: createDocCommand = new EventCommandCreateDocument(eventToAdd, customer, documentType, booking); sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailTemplateId, customer, booking); eventToAdd.EventCommands.Add(createDocCommand); eventToAdd.EventCommands.Add(sendEmail); //document out + email that document break; case 4: //email reminder sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailTemplateId, customer, booking); eventToAdd.EventCommands.Add(sendEmail); break; case 5: //create only sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailTemplateId, customer, booking); eventToAdd.EventCommands.Add(sendEmail); break; case 6: //composite bundle and email //get directory for docs var bundleDir = HttpRuntime.AppDomainAppPath + "FinalBookingDocuments\\" + property.LegacyReference.ToLower() + "\\"; docBundle = new EventCommandDocumentOutDirectoryBundleAndEmail(bundleDir, eventToAdd, customer, documentType, booking); sendEmail = new EventCommandSendEmail(eventToAdd, (int)eventToAdd.EventType.EmailEnumID, customer, booking); eventToAdd.EventCommands.Add(docBundle); eventToAdd.EventCommands.Add(sendEmail); break; } var commandsAndResultsToLog = new List <EventCommand>(); //execute the commands //create document using executes //create emails and bodies //do all sending var result = new EventCommandResult(); foreach (var command in eventToAdd.EventCommands) { command.EventCommandResults.Add(command.ExecuteCommand()); commandsAndResultsToLog.Add(command); } /////END CREATE EVENT //////////////////////////// //DO LOGGING //if successful log the event and the commands that ran //save event EventLogger log = new EventLogger(db); //strip out event wiring before loggin eventToAdd.EventCommands = null; var doLogging = log.LogEvent(eventToAdd); var EventCommandLogger = new CommandLogger(db); var eventLogger = new EventLogger(db, EventCommandLogger); //save eventcoomand and result foreach (var commandAndResult in commandsAndResultsToLog) { EventCommandLogger.Log(eventToAdd.EventID, commandAndResult); } //save document generated //if there's any docs, write them to the DB foreach (var doc in eventToAdd.Documents) { doc.EventID = eventToAdd.EventID; doc.DocumentDescription = documentType.ToString(); doc.EmailTo = customer.EmailAddress; doc.CustomerID = customer.CustomerID; db.Documents.Add(doc); db.SaveChanges(); } //for view ViewBag.Bookingid = bookingId; var eventsForDDL = db.EventTypes.Where(x => x.EventSchemeTypeID == 1 || x.EventSchemeTypeID == 2).ToList(); ViewBag.EventTypeDDL = eventsForDDL; } catch (Exception ex) { MaintainanceMailer mail = new MaintainanceMailer(); mail.theAsposeMessage.Subject = "Adding Booking Event Failed"; mail.theAsposeMessage.Body = ex.Message.ToString(); mail.theAsposeMessage.Body += "----------------------------------"; mail.theAsposeMessage.Body += ex.InnerException.ToStringDescriptive(); throw ex; } return(View()); }
/// <summary> /// A button click event,for connecting to server which is listening to given IP address and port in the text boxes. /// Once connection is success ReadTR will start to receive data from server. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ConnectBtn_Click(object sender, EventArgs e) { connection = new ULTMConnection(); string ip = IPAddressTB.Text; int port = Convert.ToInt32(PortNumberTB.Text); try { if (connection.ConnectToServer(ip, port)) { TerminalRTB.Text = "Connected to Simulator .." + Environment.NewLine; commandLogger.Log("Connected to Simulator .."); this.TerminalRTB.Invoke(new MethodInvoker(delegate() { TerminalRTB.AppendText(services.ReadReceive() + "\n"); })); ReadTR = new Thread(readThredServer); ReadTR.Start(); } } catch (Exception) { MessageBox.Show("Could not connect to server"); errorLogger.Log("Connection to server fails"); } }