public void NappingTestsDontCountTowardsLimit( ) { int i = 0; um = new UnityManager(1); ActionTask task = new ActionTask((_) => _.IsNapping = true, false); task.Extend((_) => i = 100); um.EnqueueTask(task); for (int j = 0; j < 5; j++) { ITask t = new ActionTask((_) => i++, false); um.EnqueueTask(t); } um.UnsafeUpdate(); Assert.IsTrue(task.IsNapping, "Task didn't start napping."); for (int j = 0; j < 5; j++) { um.UnsafeUpdate(); Assert.AreEqual(j + 1, i, "Didn't just run 1."); } task.IsNapping = false; um.UnsafeUpdate(); Assert.AreEqual(100, i, "Didn't run awakened task."); }
/// <summary> /// ActivateSigleTonData /// </summary> public static void ActivateSigleTonData() { IJsonServices jsServices = UnityManager.Resolve <IJsonServices>(); var model = jsServices.BasicCallAsync().GetAwaiter().GetResult(); AirportData = model; }
public void CanLimitTasksPerUpdate( ) { int i = 0; um = new UnityManager(2); for (int j = 0; j < 5; j++) { ITask task = new ActionTask((_) => i++, false); um.EnqueueTask(task); } um.UnsafeUpdate(); Assert.AreEqual(2, i, "Didn't just run 2."); um.UnsafeUpdate(); Assert.AreEqual(4, i, "Didn't just run 2."); um.UnsafeUpdate(); Assert.AreEqual(5, i, "Didn't run last one correctly."); i = 0; um = new UnityManager(1); for (int j = 0; j < 5; j++) { ITask task = new ActionTask((_) => i++, false); um.EnqueueTask(task); } for (int j = 0; j < 5; j++) { um.UnsafeUpdate(); Assert.AreEqual(j + 1, i, "Didn't just run 1."); } }
public static void Register(HttpConfiguration config) { // Web API configuration and services UnityManager.Register(config); // Web API routes config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); }
protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType) { if (controllerType == null) { throw new HttpException(404, String.Format("The controller for path '{0}' could not be found" + "or it does not implement IController.", requestContext.HttpContext.Request.Path)); } if (!typeof(IController).IsAssignableFrom(controllerType)) { throw new UnityControllerFactoryException(string.Format("Failed to create an instance of the controller from a non controller type was '{0}'", controllerType.AssemblyQualifiedName)); } var obj = UnityManager.Resolve(controllerType); return(obj as IController); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { //app.UseSignalR(routes => //{ // routes.MapHub<EventHub>("/events"); //}); UnityManager.RegisterTypes(); RouteManager.RegisterDefaultRoutes(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseCors(builder => builder.AllowAnyHeader().AllowAnyMethod().AllowCredentials().AllowAnyOrigin()); app.Use(ActionDelegator.ActionHandler); } app.UseMvc(); }
public void Init( ) { um = new UnityManager(); }
static CompareService() { Log = UnityManager.Resolve <ILogger>(); }
public CommandResponse Run(RouteRequest request, bool isCallFromAutomation = false) { var currentDir = Environment.CurrentDirectory; var jsonStr = (request.contentStr != null || request.contentStr != "") ? System.IO.File.ReadAllText(currentDir + $"/task 2 - hotelrates.json") : request.contentStr; var jsonObj = JObject.Parse(jsonStr); var values = (JArray)jsonObj["hotelRates"]; var fileName = "HotelRates.xlsx"; var path = currentDir + $"/Imports/"; //Creae an Excel application instance Application excelApp = new Application(); excelApp.DisplayAlerts = false; if (!Directory.Exists(currentDir + $"/Imports/")) { System.IO.Directory.CreateDirectory(currentDir + $"/Imports/"); } //create a file if does not exist if (!File.Exists(fileName)) { var wb = excelApp.Workbooks.Add(); wb.SaveAs(path + fileName); wb.Close(0); } //Create an Excel workbook instance and open it from the predefined location Workbook excelWorkBook = excelApp.Workbooks.Open(path + fileName); Worksheet excelWorkSheet = excelWorkBook.Sheets.Add(); try { if (!Directory.Exists(path + "Imported")) { System.IO.Directory.CreateDirectory(path + "Imported"); } if (File.Exists(path + fileName)) { var newPath = Path.Combine(path + fileName, path + "Imported"); var processedFileName = Path.Combine(path + "Imported", $"_Imported{fileName}{Path.GetExtension(path)}"); if (File.Exists(processedFileName)) { File.Delete(processedFileName); } } var hotelRates = new List <ExpandoObject>(); foreach (JObject content in values.Children <JObject>()) { var x = new ExpandoObject() as IDictionary <string, Object>; foreach (JProperty prop in content.Properties()) { if (prop.Value.Type == JTokenType.Object) { var childObject = (JObject)prop.Value; foreach (JProperty cprop in childObject.Properties()) { x.Add(cprop.Name, cprop.Value); } Console.WriteLine(prop.Name); } if (prop.Value.Type == JTokenType.Array) { var childArray = (JArray)prop.Value; foreach (var child in childArray) { var cprop = (JObject)child; foreach (JProperty c in cprop.Properties()) { if (c.Value.Type == JTokenType.Boolean) { var val = (bool)c.Value == true ? "1" : "0"; x.Add(c.Name, val); } else { x.Add(c.Name, c.Value); } } } } if (prop.Value.Type != JTokenType.Array && prop.Value.Type != JTokenType.Object) { if (prop.Value.Type == JTokenType.Date) { x.Add(prop.Name, Convert.ToDateTime(prop.Value).ToString("dd'.'MM'.'yyyy", CultureInfo.InvariantCulture)); } else { x.Add(prop.Name, prop.Value); } } } x.TryGetValue("targetDay", out object value); var testt = value; x.Add("ARRIVAL_DATE", testt); hotelRates.Add(x as ExpandoObject); } var dt = ListConvertorManager.ToDataTable <dynamic>(hotelRates); dt.Columns.Remove("numericFloat"); dt.Columns.Remove("rateId"); dt.Columns.Remove("rateDescription"); dt.Columns.Remove("name"); dt.Columns.Remove("los"); dt.Columns["targetDay"].SetOrdinal(0); dt.Columns["ARRIVAL_DATE"].SetOrdinal(1); dt.Columns["numericInteger"].SetOrdinal(2); dt.Columns["currency"].SetOrdinal(3); dt.Columns["ratename"].SetOrdinal(4); dt.Columns["adults"].SetOrdinal(5); dt.Columns["shape"].SetOrdinal(6); dt.Columns["targetDay"].ColumnName = "DEPARTURE_DATE"; dt.Columns["numericInteger"].ColumnName = "PRICE"; dt.Columns["currency"].ColumnName.ToUpper(); dt.Columns["ratename"].ColumnName.ToUpper(); dt.Columns["adults"].ColumnName.ToUpper(); dt.Columns["shape"].ColumnName = "BREAKFAST_INCLUDED"; Range SourceRange = (Range)excelWorkSheet.get_Range("A1:G" + dt.Rows.Count + 1); // or whatever range you want here FormatAsTable(SourceRange, "Table1", "TableStyleLight20"); for (int i = 1; i < dt.Columns.Count + 1; i++) { excelWorkSheet.Cells[1, i] = dt.Columns[i - 1].ColumnName.ToUpper(); excelWorkSheet.Cells[1, i].Font.Color = Color.Blue; } for (int j = 0; j < dt.Rows.Count; j++) { for (int k = 0; k < dt.Columns.Count; k++) { excelWorkSheet.Cells[j + 2, k + 1] = dt.Rows[j].ItemArray[k].ToString(); } } if (isCallFromAutomation) { MemoryStream obj_stream = new MemoryStream(); var tempFile = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid() + ".xls"); excelWorkBook.SaveAs(tempFile); excelWorkBook.Close(0); excelApp.Quit(); obj_stream = new MemoryStream(File.ReadAllBytes(tempFile)); var attachment = new Attachment(obj_stream, DateTime.Now.ToString("dd-MMM-yyyy") + fileName); UnityManager.GetCommand <SendEmail>().Run(request, "smtp.gmail.com", 465, "", "", "", "", "HotelRatesReport", "", "Please see attached", new List <Attachment>() { attachment }, false); } else { excelWorkBook.Save(); excelWorkBook.Close(0); excelApp.Quit(); } var response = new CommandResponse(); response.Headers.Add("location", "report saved at " + path + fileName); // var cr = new CommandResponse("File Saved at " + path + fileName, "application/json"); return(response); //return true; } catch (Exception e) { excelWorkBook.Close(0); throw new Exception(e.Message); } }
public Result Run(RouteRequest request) { UnityManager.GetCommand <GetHotelRatesReport>().Run(request, true); return(Result.Success()); }