public void Run() { DataContext.EnsureStartup(); BusContext.SetOutsideBus(Bus); CreditCardApplicationRepositoryFactory.RepositoryBuilder = () => new CreditCardApplicationRepository(); }
public static IEnumerable <BusRoute> GetRoutes(BusContext db) { var queryResult = from r in db.BusRoutes select BusRoute.FromMemento(r); return(queryResult.AsEnumerable()); }
public static IEnumerable <Bus> GetBuses(BusContext db) { var queryResult = from b in db.Buses select Bus.FromMemento(b); return(queryResult.AsEnumerable()); }
public ActionResult Category(Type type) { switch (type) { case Type.Tour: var ViewedList = new List <TourView>(); using (var context = new TourContext()) { foreach (Tour tour in context.Tour) { ViewedList.Add(new TourView(tour)); } } return(View("Tours", ViewedList.AsEnumerable <TourView>())); case Type.Bus: List <BusView> BusList = new List <BusView>(); using (var context = new BusContext()) { foreach (Bus bus in context.Bus) { BusList.Add(new BusView(bus)); } } return(View("Buses", BusList)); } return(View()); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, BusContext busContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCors("OpenPolicy"); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); endpoints.MapControllers(); endpoints.MapHub <BusHub>("/busHub"); }); busContext.Database.Migrate(); }
private void ContextBeginRequest(object sender, EventArgs e) { DataContext.EnsureStartup(); BusContext.EnsureWebStartup(); CreditCardApplicationRepositoryFactory.RepositoryBuilder = () => new CreditCardApplicationRepository(); }
public BusHandlerResponse HandleMessage(BusContext busContext, BusMessage busMessage) { var x = 10; //WriteShareClass shareClass = busMessage.Payload as WriteShareClass; log.Info($"Handling: order for bus Event"); return(new BusHandlerResponse()); }
public static void AddRoute(BusContext db, string name) { var id = new BusRouteId(int.Parse(name)); var r = new BusRoute(id, name); db.Add(r.State); db.SaveChanges(); }
public static void AddBus(BusContext db, string number, string seated, string standing) { var seatingCapacity = int.Parse(seated); var standingCapacity = int.Parse(standing); var id = new BusId(Guid.NewGuid()); var b = new Bus(id, number, seatingCapacity, standingCapacity); db.Add(b.State); db.SaveChanges(); }
public BusHandlerResponse HandleMessage(BusContext busContext, BusMessage busMessage) { var x = 10; //WriteShareClass shareClass = busMessage.Payload as WriteShareClass; busContext.Bus.Publish( "ShareClassCreated", new BusEvent { TopicName = "ShareClassCreated", Payload = "Test" }); return(new BusHandlerResponse()); }
public static IEnumerable <ScheduleDto> GetSchedule(BusContext db) { var queryResult = from s in db.Services join b in db.Buses on s.BusId equals b.Id join r in db.BusRoutes on s.RouteId equals r.Id select new ScheduleDto { RouteNumber = r.Id, BusNumber = b.BusNumber, IsActive = s.IsActive }; return(queryResult.AsEnumerable()); }
public void Send(BusMessage message) { var handlers = this.busHandlers.FindAll(bh => bh.CanHandleMessage(message)); var busContext = new BusContext(this); try { Task.WaitAll(handlers.Select(busHandler => Task.Run(() => busHandler.HandleMessage(busContext, message))).Cast <Task>().ToArray()); } catch (AggregateException ae) { throw ae.Flatten(); } }
public static void ScheduleBus(BusContext db, string busNumber, string routeName) { //pretend this is in a repository var bus = Bus.FromMemento(db.Buses.Single(b => b.BusNumber == busNumber)); var route = BusRoute.FromMemento(db.BusRoutes.Single(r => r.Id == int.Parse(routeName))); var schedule = new ScheduledService(new ScheduledServiceId(Guid.NewGuid()), bus.Id, route.Id); if (busNumber.StartsWith("A")) { schedule.Activate(); } db.Services.Add(schedule.State); db.SaveChanges(); }
public void Publish(string queueName, BusEvent message) { var subscribers = this.busSubscribers.FindAll(bs => bs.TopicName == queueName); var busContext = new BusContext(this); var busMessage = new BusMessage { Payload = message.Payload, TopicName = message.TopicName }; try { Task.WaitAll(subscribers.Select(busHandler => Task.Run(() => busHandler.Handler(busContext, busMessage))).Cast <Task>().ToArray()); } catch (AggregateException ae) { throw ae.Flatten(); } }
public override Task <Response> AddBus(Bus request, ServerCallContext context) { Response response = new Response(); try { var optionsBuilder = new DbContextOptionsBuilder <BusContext>(); optionsBuilder.UseSqlite("Data sourse = tdb.mdf"); using var con = new BusContext(optionsBuilder.Options); con.Buses.Add(request); con.SaveChangesAsync(); } catch (Exception e) { _logger.LogInformation(e.Message); response.ModificationResponse = Changes.AddFailed; return(Task.FromResult(response)); } response.ModificationResponse = Changes.AddOk; return(Task.FromResult(response)); }
public Task Handle(TMessage message, IMessageHandlerContext context) { var busMessage = this.Convert(message); var handlers = this.busHandlerProvider.GetHandlers().Where(bh => bh.CanHandleMessage(busMessage)); var busContext = new BusContext(this.bus); try { Task.WaitAll(handlers.Select(busHandler => Task.Run(() => busHandler.HandleMessage(busContext, busMessage))).Cast <Task>().ToArray()); } catch (AggregateException ae) { foreach (var e in ae.Flatten().InnerExceptions) { this.exceptionAction(e); } } return(Task.CompletedTask); }
public static CANResult SendTimestamp(BusInterfaces busInterface, UInt32 timeStamp) { CANResult result = CANResult.ERR_BUSOFF; int busIndex = (int)busInterface; if (null == context[busIndex]) { context[busIndex] = new BusContext(); } if (false != context[busIndex].active) { TCLightMsg msg; msg = new TCLightMsg(); msg.ID = (uint)0x100; msg.Len = (byte)4; msg.MsgType = MsgTypes.MSGTYPE_STANDARD; msg.Data[0] = (byte)((timeStamp >> 0) & 0xFF); msg.Data[1] = (byte)((timeStamp >> 8) & 0xFF); msg.Data[2] = (byte)((timeStamp >> 16) & 0xFF); msg.Data[3] = (byte)((timeStamp >> 24) & 0xFF); result = PCANLight.Write(context[busIndex].activeHardware, msg); if (CANResult.ERR_OK != result) { Tracer.WriteError(context[busIndex].traceGroup, "", "timestamp send failure {0}", timeStamp); } else { Tracer.WriteError(context[busIndex].traceGroup, "", "timestamp"); } } return (result); }
public BusesController(BusContext context) { _context = context; }
public static CANResult Send(BusInterfaces busInterface, int id, byte[] data) { CANResult result = CANResult.ERR_BUSOFF; int busIndex = (int)busInterface; if (null == context[busIndex]) { context[busIndex] = new BusContext(); } if (false != context[busIndex].active) { TCLightMsg msg; msg = new TCLightMsg(); msg.ID = (uint)id; msg.Len = (byte)data.Length; msg.MsgType = MsgTypes.MSGTYPE_STANDARD; for (int i = 0; i < data.Length; i++) { msg.Data[i] = data[i]; } result = PCANLight.Write(context[busIndex].activeHardware, msg); if (CANResult.ERR_OK != result) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < data.Length; i++) { sb.AppendFormat("{0:X2}", data[i]); } Tracer.WriteError(context[busIndex].traceGroup, "", "send failure {0} data {1}", result, sb.ToString()); } } return (result); }
public static CANResult SendSync(BusInterfaces busInterface) { CANResult result = CANResult.ERR_BUSOFF; int busIndex = (int)busInterface; if (null == context[busIndex]) { context[busIndex] = new BusContext(); } if (false != context[busIndex].active) { TCLightMsg msg; msg = new TCLightMsg(); msg.ID = (uint)0x080; msg.Len = (byte)0; msg.MsgType = MsgTypes.MSGTYPE_STANDARD; result = PCANLight.Write(context[busIndex].activeHardware, msg); if (CANResult.ERR_OK != result) { Tracer.WriteError(context[busIndex].traceGroup, "", "sync send failure {0}", result.ToString()); } else { Tracer.WriteError(context[busIndex].traceGroup, "", "sync"); } } return (result); }
public static CANResult Start(BusInterfaces busInterface, int bitRate, FramesType messageType, TraceGroup traceGroup, ReceiveDelegateHandler receiveHandler, int ioPort = -1, short interrupt = -1) { int busIndex = (int)busInterface; if (null == context[busIndex]) { context[busIndex] = new BusContext(); } HardwareType hardwareType = GetHardwareType(busInterface); Baudrates interfaceBaudRate = GetInterfaceBaudRate(bitRate); CANResult result = CANResult.ERR_NETINUSE; if (false == context[busIndex].active) { result = CANResult.ERR_OK; string dllVersionString = ""; uint nodeId = 0; if (CANResult.ERR_OK == result) { CANResult dllVersionResult = PCANLight.DllVersionInfo(hardwareType, out dllVersionString); if (CANResult.ERR_OK == dllVersionResult) { int majorVersion = 0; String[] versionTabInfo = dllVersionString.Split('.'); if (versionTabInfo.Length > 0) { Int32.TryParse(versionTabInfo[0].ToString(), out majorVersion); } if (majorVersion < 2) { Tracer.WriteError(traceGroup, "", "DLL version 2.x or higher needed, version \"{0}\" invalid", dllVersionString); } } else { Tracer.WriteError(traceGroup, "", "DLL version error {0}", dllVersionResult.ToString()); result = dllVersionResult; } } if (CANResult.ERR_OK == result) { CANResult initResult = CANResult.ERR_OK; if ((-1 != ioPort) && (-1 != interrupt)) { initResult = PCANLight.Init(hardwareType, interfaceBaudRate, messageType, (uint)ioPort, (ushort)interrupt); } else { initResult = PCANLight.Init(hardwareType, interfaceBaudRate, messageType); } if (CANResult.ERR_OK != initResult) { Tracer.WriteError(traceGroup, "", "DLL init error {0}", initResult.ToString()); result = initResult; } } if (CANResult.ERR_OK == result) { CANResult resetResult = PCANLight.ResetClient(hardwareType); if (CANResult.ERR_OK != resetResult) { Tracer.WriteError(traceGroup, "", "DLL reset error {0}", resetResult.ToString()); result = resetResult; } } if ((HardwareType.USB_1CH == hardwareType) || (HardwareType.USB_2CH == hardwareType)) { if (CANResult.ERR_OK == result) { CANResult deviceNumberResult = CANResult.ERR_OK; deviceNumberResult = PCANLight.GetUSBDeviceNr(hardwareType, out nodeId); if (CANResult.ERR_OK != deviceNumberResult) { Tracer.WriteError(traceGroup, "", "DLL device number error {0}", deviceNumberResult.ToString()); result = deviceNumberResult; } } } if (CANResult.ERR_OK == result) { CANResult setEventResult = CANResult.ERR_OK; context[busIndex].receiveEvent = new AutoResetEvent(false); setEventResult = PCANLight.SetRcvEvent(hardwareType, context[busIndex].receiveEvent); if (CANResult.ERR_OK != setEventResult) { Tracer.WriteError(traceGroup, "", "DLL receive event error {0}", setEventResult.ToString()); result = setEventResult; } } if (CANResult.ERR_OK == result) { context[busIndex].traceGroup = traceGroup; context[busIndex].receiverHandler = new ReceiveDelegateHandler(receiveHandler); context[busIndex].receiveThread = new Thread(() => ReceiveProcess(context[busIndex])); context[busIndex].receiveThread.IsBackground = true; context[busIndex].receiveThread.Name = "CAN " + busInterface.ToString() + " reader"; context[busIndex].receiveThreadExecute = true; context[busIndex].receiveThread.Start(); } if (CANResult.ERR_OK == result) { context[busIndex].activeHardware = hardwareType; context[busIndex].active = true; Tracer.WriteHigh(traceGroup, "", "started, version {0}, node id {1}", dllVersionString, nodeId); } } return (result); }
/// <summary> /// Function to stop interface. /// </summary> /// <remarks> /// PCAN returns error when another application is monitoring bus. /// </remarks> /// <param name="busInterface">interface to access</param> public static void Stop(BusInterfaces busInterface) { int busIndex = (int)busInterface; if (null == context[busIndex]) { context[busIndex] = new BusContext(); } if (null != context[busIndex].receiveThread) { context[busIndex].receiveThreadExecute = false; context[busIndex].receiveEvent.Set(); context[busIndex].receiveThread.Join(3000); context[busIndex].receiveThread = null; } if (null != context[busIndex].receiveEvent) { context[busIndex].receiveEvent.Close(); context[busIndex].receiveEvent = null; } if (false != context[busIndex].active) { CANResult closeResult = CANResult.ERR_OK; closeResult = PCANLight.Close(context[busIndex].activeHardware); if (CANResult.ERR_OK == closeResult) { Tracer.WriteHigh(context[busIndex].traceGroup, "", "stopped"); } else { Tracer.WriteError(context[busIndex].traceGroup, "", "stop error {0}", closeResult.ToString()); } context[busIndex].active = false; } }
public static List <Bus> TestBusList() { BusContext busContext = new BusContext(); return(busContext.bus.ToList()); }
private static void ReceiveProcess(BusContext busContext) { for (;busContext.receiveThreadExecute; ) { bool moreMsgs; TCLightMsg msg; TCLightTimestamp timeStamp; busContext.receiveEvent.WaitOne(); do { CANResult receiveResult = CANResult.ERR_OK; receiveResult = PCANLight.ReadEx(busContext.activeHardware, out msg, out timeStamp); moreMsgs = !Convert.ToBoolean(receiveResult & CANResult.ERR_QRCVEMPTY); if ((CANResult.ERR_OK == receiveResult) && (null != busContext.receiverHandler)) { CanFrame frame = new CanFrame((int)msg.ID, msg.Data, (int)msg.Len); busContext.receiverHandler(frame); } } while (false != moreMsgs); } }
public PricesController(BusContext context) { _context = context; }
public GenericDalEf(BusContext context) { _context = context; }
public TypesController(BusContext context) { _context = context; }
public ApplicationUserDalEf(BusContext context) : base(context) { }
static void Main(string[] args) { Console.WriteLine("Let's just pretend this is a great UI, ok?"); Console.WriteLine(@" Commands are: [Add Bus, Number, standing, seating]: AB xyz nnn nnn [Add Route: name]: AR nnn [Schedule Bus: number name]: SB xyz nnn "); var options = new DbContextOptionsBuilder <BusContext>() .UseSqlServer(@"Server=(LocalDB)\MSSQLLocalDB;Database=BusRoutes;Trusted_Connection=True;") // .UseInMemoryDatabase(databaseName: "Add_writes_to_database") .Options; using (var db = new BusContext(options)) { while (true) { Console.Write("Command | "); var input = Console.ReadLine(); if (string.IsNullOrWhiteSpace(input)) { break; } var command = input.Substring(0, 2); var opt = input.Split(' '); switch (command) { case "AB": AddBus(db, opt[1], opt[2], opt[3]); break; case "AR": AddRoute(db, opt[1]); break; case "SB": ScheduleBus(db, opt[1], opt[2]); break; default: Console.WriteLine("Huh?"); break; } } Console.WriteLine("--- Buses and Routes ---"); var buses = GetBuses(db); foreach (var b in buses) { Console.WriteLine($"Bus {b.BusNumber} can seat {b.SeatedCapacity} and stand {b.StandingCapacity}"); } var routes = GetRoutes(db); foreach (var r in routes) { Console.WriteLine($"Route {r.Name}"); } Console.WriteLine("--- YOUR BUS SCHEDULE ---"); var schedule = GetSchedule(db); foreach (var s in schedule) { Console.WriteLine($"Trip: Bus {s.BusNumber} on Route {s.RouteNumber} is {(s.IsActive ? "active" : "inactive")} "); } } Console.ReadLine(); }
public AddressService(BusContext busContext) { _busContext = busContext; }
public RoleDalEf(BusContext context) : base(context) { }