예제 #1
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            var container = DIService.ConfigureContainer(services);

            return(new AutofacServiceProvider(container));
        }
예제 #2
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            IServiceCollection newServices     = new ServiceCollection();
            IServiceProvider   serviceProvider = null;

            foreach (var service in services)
            {
                newServices.Add(service);
            }
            newServices.AddMvc(option =>
            {
                //全局引用Filter
                option.Filters.Add(typeof(TestResourceFilter));
                option.Filters.Add(typeof(TestActionFilter));
                option.Filters.Add(typeof(TestExceptionFilter));
                option.Filters.Add(typeof(TestResultFilter));
            });
            ////"http://192.168.10.125:3000", "http://localhost:3000","http://localhost:8080"
            newServices.AddScoped <MyActionServiceFilter>();
            newServices.AddCors(options => options.AddPolicy("defaultCors",
                                                             p => p.WithOrigins("*")
                                                             .AllowAnyMethod()
                                                             .AllowAnyHeader()
                                                             .AllowCredentials()
                                                             ));
            //  newServices.AddAuthorization();
            DIService.AddDataService(newServices);
            serviceProvider = newServices.BuildServiceProvider();
            DIService.SetServiceProvider(serviceProvider);
            return(serviceProvider);
        }
예제 #3
0
 static void Main()
 {
     DIService.Wire(new ApplicationModule());
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(DIService.Resolve <LauchPad>());
 }
예제 #4
0
        private void EditLabelsButton_OnClick(object sender, RoutedEventArgs e)
        {
            var selectedOrderId = (int)ComboOrder.SelectedValue;
            var form            = DIService.Resolve <EditLabelsWindow>(new ConstructorArgument("orderId", selectedOrderId, false));

            form.Owner = this;
            form.ShowDialog();
            Refresh();
        }
예제 #5
0
        public App(string dbPath)
        {
            _dbPath = dbPath;
            InitializeComponent();
            Debug.WriteLine($"Database located at: {dbPath}");
            DIService.RegisterDIService(_dbPath);
            var pn = new PageNavigator();

            MainPage = pn.MainPage();
        }
예제 #6
0
        //large Response test
        // private const int _chunkSize = 4096;
        // private const int _defaultNumChunks = 16;
        // private static byte[] _chunk = Encoding.UTF8.GetBytes(new string('a', _chunkSize));
        // private static Task _emptyTask = Task.FromResult<object>(null);

        public Startup(IHostingEnvironment env, ILoggerFactory logger)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                          .AddEnvironmentVariables();

            DIService.GetDbConfig();
        }
예제 #7
0
 public IActionResult DeleteReport([FromBody] RequestMessage <ReportViewModel> reqMsg)
 {
     if (ModelState.IsValid)
     {
         using (IReportService rptSrv = DIService.GetService <IReportService>())
         {
             var result = rptSrv.DeleteReport(reqMsg);
             return(Json(result, JsonService.SelfLoopJsonSettings));
         }
     }
     return(BadRequest());
 }
예제 #8
0
 public IActionResult DeleteBomNode([FromBody] RequestMessage <BomNodeViewModel> reqMsg)
 {
     if (ModelState.IsValid)
     {
         using (IBomManagerService bomSrv = DIService.GetService <IBomManagerService>())
         {
             var result = bomSrv.DeleteBomNode(reqMsg);
             return(Json(result, JsonService.SelfLoopJsonSettings));
         }
     }
     return(BadRequest());
 }
예제 #9
0
 public IActionResult CreateOrUpdateRootReport([FromBody] RequestMessage <ReportViewModel> reqMsg)
 {
     if (ModelState.IsValid)
     {
         using (IReportService rptSrv = DIService.GetService <IReportService>())
         {
             var rpt    = reqMsg.Playload.FirstOrDefault();
             var result = rptSrv.CreateOrUpdateRootReport(reqMsg);
             return(Json(result, JsonService.SelfLoopJsonSettings));
         }
     }
     return(BadRequest());
 }
예제 #10
0
 public IActionResult UpsertRootBomNode([FromBody] RequestMessage <BomNodeViewModel> reqMsg)
 {
     if (ModelState.IsValid)
     {
         using (IBomManagerService bomSrv = DIService.GetService <IBomManagerService>())
         {
             var rpt    = reqMsg.Playload.FirstOrDefault();
             var result = bomSrv.UpsertRootBomNode(reqMsg);
             return(Json(result, JsonService.SelfLoopJsonSettings));
         }
     }
     return(BadRequest());
 }
예제 #11
0
 protected override void OnStartup(StartupEventArgs e)
 {
     try
     {
         var currentDomain = AppDomain.CurrentDomain;
         currentDomain.UnhandledException += OnUnhandledException;
         DIService.Wire(new ApplicationModule());
         base.OnStartup(e);
         var wnd = DIService.Resolve <LabelManagerWindow>();
         wnd.Show();
     }
     catch (Exception exc)
     {
         Logger.Error("Global catch; ", exc);
     }
 }
예제 #12
0
        public static async Task Main(string[] args)
        {
            var configuration = new AppConfigService().Configuration;

            DIService.RegisterService(configuration);
            using (var scope = DIService.ServiceProvider.CreateScope())
            {
                try
                {
                    await scope.ServiceProvider.GetRequiredService <DbClientConsoleWindowService>().RunDbAndClientCommunication();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message + ex.StackTrace);
                }
            }
        }
예제 #13
0
        public IActionResult Post([FromBody] RequestMessage <BlogViewModel> reqMsg)
        {
            if (ModelState.IsValid)
            {
                using (IBlogService blogService = DIService.GetService <IBlogService>())
                {
                    var blogVM = reqMsg.Playload.FirstOrDefault();
                    var result = blogService.CreateOrUpdateBlog2(reqMsg);
                    return(Json(result));
                }
            }
            return(BadRequest());

            //CreatedAtAction("Get", new { id = 123 }, new User() { Id = new Random().Next(1, 10), Name = "myad", Sex = "男" });
            // user.Id = new Random().Next(1, 10);
            // return CreatedAtAction("Get", new { id = user.Id }, user);
        }
예제 #14
0
        private void CustomCustomerEditBox(object sender, EventArgs e)
        {
            var coldWeightDetail = _coldWeightEntryRepository.GetByOrderId(_viewModel.SelectedCustomerLocation.OrderId)
                                   .ColdWeightEntryDetails.Single(c => c.Id == _viewModel.SelectedCustomerLocation.ColdWeightDetailId);
            IList <LabelEditItem> labelsToEdit = new List <LabelEditItem>();
            var sides = _coldWeightEntryDetailRepository.GetSideWeigths(coldWeightDetail.Id);

            foreach (var side in sides)
            {
                if (!side.Value.HasValue)
                {
                    continue;
                }

                var orderDetailsForSide =
                    coldWeightDetail.AnimalOrderDetails.Where(a => a.ColdWeightDetailId == coldWeightDetail.Id)
                    .Select(a => a.OrderDetail)
                    .ToList().FindAll(x => x.SideTypeId == side.Key).ToList();

                if (!orderDetailsForSide.Any())
                {
                    continue;
                }

                var items = orderDetailsForSide.SelectMany(s => s.Label)
                            .Where(s => s.TypeId == OmsLabelType.Box);
                foreach (var label in items)
                {
                    labelsToEdit.Add(new LabelEditItem()
                    {
                        LabelId      = label.Id,
                        LabelType    = label.TypeId,
                        LocationName = label.OrderDetail.CustomerLocation.Name,
                        PoundWeight  = LabelCreateService.GetGrossPoundWeight(label.PoundWeight, label.TypeId, label.OrderDetail),
                        PrintedDate  = label.CreatedDate,
                        ProductName  = ProductService.GetFormattedProductName(label.OrderDetail.Product)
                    });
                }
            }
            var selectedOrderId = (int)ComboOrder.SelectedValue;
            var form            = DIService.Resolve <EditLabelsWindow>(new ConstructorArgument("orderId", selectedOrderId, false), new ConstructorArgument("labels", labelsToEdit, false));

            form.Owner = this;
            form.ShowDialog();
            Refresh();
        }
예제 #15
0
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            var kernel = new StandardKernel();

            try
            {
                kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();
                //kernel.Bind<IManageCaseService>().To<ManageCaseService>();
                DIService.RegisterServicesWeb(kernel);
                return(kernel);
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }
예제 #16
0
        //  [TypeFilter(typeof(MyActionTypeFilter), Arguments = new object[] { "typefilter", "MyTypeFilterAction" })]
        public IActionResult Get(int id)
        {
            // _logger.LogInformation("This is Information Log!");
            // _logger.LogWarning("This is a Warning Log!");
            // _logger.LogError("This is a Error log!");
            try
            {
                //DIService.GetService<IBlogService>()
                // Console.WriteLine(this.HttpContext.RequestServices.GetService(typeof(IBlogService)));
                var user = new User()
                {
                    Id = id, Name = "Name:" + id, Sex = "Male"
                };
                // this._logger.LogInformation(Json(user).ToString());

                using (IBlogService blogService = DIService.GetService <IBlogService>())
                {
                    Blog blog1 = new Blog
                    {
                        BlogName = "我的个人博客II",
                        Url      = "http://www.xyzsoft.com"
                    };
                    Post post = new Post
                    {
                        Title   = "如何使用EFCore-xyzsoft",
                        Content = "要想正确使用EFCORE,必须先看文档,了解有哪些东西,然后配合实践,不明白的再看文档"
                    };
                    blog1.Posts.Add(post);
                    blogService.InsertBlog(blog1);
                    var count = blogService.AcceptAllChanges();
                    ResponseMessage <PostQueryViewModel> posts = blogService.GetAllPosts();
                    return(new ObjectResult(JsonService.SerializeObject(posts)));
                }
            }
            catch (System.Exception ex)
            {
                throw new Exception(ex.Message);
                // return new ObjectResult(ex.Message);
            }
            //  Console.WriteLine(ex.Message);
            //                // this._logger.LogError(ex.InnerException.Message);
            //                 // var jsonstr = "{ message22:" + ex.InnerException.Message + " }";
            //                 // Console.WriteLine(jsonstr);
        }
예제 #17
0
 public IActionResult GetBlog([FromBody] RequestMessage <BlogViewModel> reqModel)
 {
     try
     {
         if (ModelState.IsValid)
         {
             using (IBlogService blogService = DIService.GetService <IBlogService>())
             {
                 var blogvm = blogService.GetBlog(reqModel);
                 return(Json(blogvm));  //new ObjectResult(JsonService.SerializeObject(blogvm));
             }
         }
         return(new ObjectResult("{ message:" + "对象不合法" + " }"));
     }
     catch (System.Exception ex)
     {
         this._logger.LogError(ex.InnerException.Message);
         var jsonstr = "{ message:" + ex.InnerException.Message + " }";
         return(new ObjectResult(jsonstr));
     }
 }
예제 #18
0
        private DIService initializer()
        {
            var init = new DIService(ref sendEvent, ref sendQueue);

            return(init);
        }
예제 #19
0
        public static void Main(string[] args)
        {
            DIService.RegisterService();

            var dbconfig = DIService.ServiceProvider.GetService <IOptions <DatabaseConfig> >();

            // var abc = DIService.services.BuildServiceProvider();
            AppConfig.MasterDatabaseInfo = dbconfig.Value;
            //  new DataService.Infrastructure.DatabaseConfig()
            // {
            //     Name = "cx",
            //     StoreType = StoreType.MySql,
            //     ConnectionString = @"server=localhost;userid=root;pwd=99b3ad6e;port=3306;database=blogdb;sslmode=none;"
            // };
            using (IBlogService blogService = DIService.GetService <IBlogService>())
            {
                Blog blog1 = new Blog();
                blog1.BlogName = "我的个人博客II";
                blog1.Url      = "http://www.xyzsoft.com";
                Post post = new Post();
                post.Title   = "如何使用EFCore-xyzsoft";
                post.Content = "要想正确使用EFCORE,必须先看文档,了解有哪些东西,然后配合实践,不明白的再看文档";
                blog1.Posts.Add(post);
                blogService.InsertBlog(blog1);

                //blogService.InsertBlog(new Blog() { Url = "http://blogs.msdn.com/adonet", BlogName = "我的博客" });

                var count = blogService.AcceptAllChanges();
                Console.WriteLine("{0} records saved to database", count);
                // Console.WriteLine("All blogs in database:");
                // foreach (var blog in blogService.GetAllBlogs().Where(b => b.BlogId > 0))
                // {
                //     Console.WriteLine(" - {0} - {1}", blog.Url, blog.SiteName);
                // }
            }

            var options = new DbContextOptionsBuilder <DbContextBase>()
                          .UseMySql(new MySqlConnection(AppConfig.MasterDatabaseInfo.ConnectionString))
                          .Options;

            using (var context1 = new MySqlContext(options))
            {
                using (var transaction = context1.Database.BeginTransaction())
                {
                    context1.CommittableTransaction = transaction;
                    try
                    {
                        var blog2 = new Blog {
                            Url = "http://blogs.msdn.com/visualstudio", BlogName = "新增的博客"
                        };
                        // var post = context1.Set<Post>().Last();
                        var post = new Post();
                        post.Title   = "学习EF CORE";
                        post.Content = "学习EF CORE,必须了解的细节";
                        blog2.Posts.Add(post);
                        // post.BlogId = blog2.BlogId;
                        context1.Add(blog2);
                        //  context1.Set<Blog>().Add(new Blog { BlogName = "单独实例上下文56", Url = "http://blogs.msdn.com/dotnet598" });
                        context1.SaveChanges();

                        using (var context2 = new MySqlContext(options))
                        {
                            // context2.Database.UseTransaction(context1.GetDbTransaction());
                            context2.UseTransaction(context1);
                            var lastblog = context2.Set <Blog>().Last();
                            // context2.Set<Blog>().Remove(lastblog);
                            context2.SaveChanges();

                            var blogs = context2
                                        .Set <Blog>()
                                        .FromSql("select * from Blog")
                                        .Include(b => b.Posts)
                                        .Select(blog => new { blog.BlogId, blog.Url, blog.BlogName, blog.Posts })
                                        .OrderBy(b => b.Url)
                                        .ToList();
                            foreach (var blog in blogs)
                            {
                                Console.WriteLine(" - {0} - {1} - {2}", blog.Url, blog.BlogName, blog.Posts.Count());
                            }
                            // Commit transaction if all commands succeed, transaction will auto-rollback
                            // when disposed if either commands fails
                            transaction.Commit();
                        }
                    }
                    catch (Exception)
                    {
                        // TODO: Handle failure
                    }
                }
            }
            Console.ReadKey();
        }