public AppsResult UpsertEmployee([FromBody] Employee employee)
        {
            var result = new AppsResult();

            try
            {
                //using (var dblocal = new LiteDatabase(dbPath))
                //{

                //    var objs = dblocal.GetCollection<Employee>("Employees");
                //    objs.Upsert(employee);

                //    result.Data = objs.FindAll().ToList();
                //    result.Success = true;
                //}

                using (var db = new Data())
                {
                    db.Employees.Add(employee);
                    db.SaveChanges();
                    result.Success = true;
                }
            }
            catch (Exception ex)
            {
                result.FailMessages.Add("Exception saving employee.");
                AppsLog.LogStep <Business.Flows.Employee.Exception>(ex.ToString());
            }

            return(result);
        }
        public AppsResult GetEmployeeById(int id)
        {
            var result = new AppsResult();

            try
            {
                //using (var db = new LiteDatabase(dbPath))
                //{
                //    var objs = db.GetCollection<Employee>("Employees");

                //    result.Data = objs.FindAll().Where(e => e.ID == id).ToList();
                //    result.Success = true;
                //}

                using (var db = new Data())
                {
                    result.Data    = db.Employees.Where(e => e.ID == id).ToList();
                    result.Success = true;
                }
            }
            catch (Exception ex)
            {
                result.FailMessages.Add("Exception getting employee by ID.");
                AppsLog.LogStep <Business.Flows.Employee.Exception>(ex.ToString());
            }

            return(result);
        }
        public AppsResult UnitTests()
        {
            var result = new AppsResult();

            try
            {
                using (var db = new LiteDatabase(dbPath))
                {
                    //get model
                    result = GetEmployeeModel();

                    //bind model
                    //get employees
                    //get single employee
                    //create employee
                }
            }
            catch (Exception ex)
            {
                result.FailMessages.Add("Exception getting employee by ID.");
                AppsLog.LogStep <Business.Flows.Employee.Exception>(ex.ToString());
            }

            return(result);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //services.AddDbContext<AppsContext>(options =>
            //options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
            //Selenium Driver
            //Action<OpenQA.Selenium.Chrome.ChromeDriver> chromeDriver = (cd => { 

            //});

            //services.addeaddeAddEntityFrameworkSqlite().AddDbContext<DatabaseContext>();
            
            services.AddSingleton<OpenQA.Selenium.Chrome.ChromeDriver>(new OpenQA.Selenium.Chrome.ChromeDriver(Environment.CurrentDirectory + "\\Libraries"));

            //Main db
            Action<AppsData> liteDBOptions = (opt =>
            {
                opt.AppsDBPath = System.Environment.CurrentDirectory + "\\Business\\Data\\Apps.db";
                opt.AppsDB = new LiteDB.LiteDatabase(opt.AppsDBPath);
            });

            //Main ef context
            Action<AppsContext> contextOptions = (opt => { opt = new AppsContext(); });
            services.AddSingleton(resolver => resolver.GetRequiredService<IOptions<AppsContext>>().Value);

            ////Flows db
            //Action<FlowsData> flowDBOptions = (opt =>
            //{
            //    opt.FlowsDBPath = System.Environment.CurrentDirectory + "\\Flows.db";
            //    opt.FlowsDB = new LiteDB.LiteDatabase(opt.FlowsDBPath);
            //});

            services.Configure(liteDBOptions);
            services.AddSingleton(resolver => resolver.GetRequiredService<IOptions<AppsData>>().Value);


            //services.Configure(flowDBOptions);
            //services.AddSingleton(resolver => resolver.GetRequiredService<IOptions<FlowsData>>().Value);

            //services.AddCors(options =>
            //{
            //    options.AddPolicy(MyAllowSpecificOrigins,
            //    builder =>
            //    {
            //        builder.WithOrigins("http://localhost:52780");
            //    });
            //});
            services.AddSignalR();
            services.AddControllers();
            services.AddMvcCore().AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
                options.SerializerSettings.ContractResolver = new DefaultContractResolver();
            });
            //services.AddOcelot();

            //var builder = services.AddIdentityServer()
            //    .AddDeveloperSigningCredential()        //This is for dev only scenarios when you don’t have a certificate to use.
            //    .AddInMemoryApiScopes(IdentityServerTest.Config.ApiScopes)
            //    .AddInMemoryClients(IdentityServerTest.Config.Clients);

            //// this comes from Ocelot.Tracing.Butterfly package
            //services.AddButterfly(option =>
            //{
            //    //this is the url that the butterfly collector server is running on...
            //    option.CollectorUrl = "https://localhost:9618";
            //    option.Service = "Ocelot";
            //});
            //services.AddIdentityServer()
            //    .AddDeveloperSigningCredential()
            //    //.AddInMemoryApiResources(new[] { new ApiResource("socialnetwork", "Social Network") })
            //    .AddInMemoryClients(new[] { new Client{
            //         ClientId = "socialnetwork",
            //         ClientSecrets = new [] { new Secret("secret".Sha256())},
            //         AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,
            //         AllowedScopes = new[] {"socialnetwork"}
            //        } 
            //    }).AddInMemoryApiScopes(new[] { new ApiScope("socialnetwork", "My API") });
            //.AddTestUsers(new List<IdentityServer4.Test.TestUser> { 
            //    new IdentityServer4.Test.TestUser
            //    {
            //        SubjectId = "1",
            //        Username = "******",
            //        Password = "******"
            //    }

            //services.AddAuthentication("Bearer").AddJwtBearer("Bearer", options =>
            //{
            //    options.Authority = "https://localhost:54321";
            //    options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
            //    {
            //        ValidateAudience = false
            //    };
            //});

            //// Add Hangfire services.
            //services.AddHangfire(configuration => configuration
            //    .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
            //    .UseSimpleAssemblyNameTypeSerializer()
            //    .UseRecommendedSerializerSettings()
            //    .UseMemoryStorage());

            //// Add the processing server as IHostedService
            //services.AddHangfireServer();
            //var flowsDb = new LiteDB.LiteDatabase(System.Environment.CurrentDirectory + "\\Flows.db");
            //FlowsData.FlowTable = flowsDb.GetCollection<AppFlowEvent>("Flows");

            //var clientConfig = new AppsClientConfig();
            //clientConfig.Load("Brooksoft.Apps", Environment.MachineName, Environment.CurrentDirectory, new System.Version(0, 0, 1), new List<string>(), new List<AppsCustomConfigItem>(), true, true, new AppFlow());

            AppsLog.LogInfo("Finished configure services.");
            //var perms = new Brooksoft.Apps.Business.Publish.Permissions();
            //perms.ReadEffectivePermissions();
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, AppsData appsdb)
        {
            //app.UseCors(MyAllowSpecificOrigins);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseDefaultFiles(new DefaultFilesOptions { DefaultFileNames = new List<string> { "index.html" } });

            app.UseStaticFiles();

            //app.UseHangfireDashboard();
            
            app.UseHttpsRedirection();

            app.UseRouting();

            //app.UseAuthentication();

            //app.UseAuthorization();

            //app.addj.AddJsonOptions(options =>
            // {
            //     options.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
            //     options.SerializerSettings.ContractResolver = new DefaultContractResolver();
            // });
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapHub<AppsHub>("/appsHub");
            });

            //app.UseIdentityServer();
            //app.UseOcelot().Wait(); //Must go after id server

            AppsLog.Load("Apps"); //already done with config registration
            var hub = new AppsHub(appsdb);
            hub.Load();
            FlowsData.Load();

            //AppsHub.TestProgress("hiya");
            //var aTimer = new System.Timers.Timer(5000);
            //// Hook up the Elapsed event for the timer. 
            //aTimer.Elapsed += ATimer_Elapsed; ;
            //aTimer.AutoReset = true;
            //aTimer.Enabled = true;

            //AppsDB = appsdb.AppsDB;
            //FlowsDB = flowsdb.FlowsDB;
            //var solutionDirectory = @"D:\Work\Brooksoft\AppsJS\AppsJSDemo\AppsJSDemo\AppsJSDemo.sln";
            //var projectFilePath = @"D:\Work\Brooksoft\AppsJS\AppsJSDemo\AppsJSDemo\AppsJSDemo.csproj";

            //var globalProperties = new Dictionary<string, string> {
            //    { "DesignTimeBuild", "true" },
            //    { "BuildProjectReferences", "false" },
            //    { "_ResolveReferenceDependencies", "false" },
            //    { "SolutionDir", solutionDirectory + System.IO.Path.DirectorySeparatorChar }
            //};

            //var collection = new Microsoft.Build.Evaluation.ProjectCollection();
            //Microsoft.Build.Evaluation.Project project = collection.LoadProject(projectFilePath);

            //Run();

            //hangfireJobs.Enqueue(() => Console.WriteLine("Hello world from Hangfire!"));
            AppsLog.LogInfo("Finished configure.");
        }
Example #6
0
        void HandleAndroidException(object sender, RaiseThrowableEventArgs e)
        {
//			#if !DEBUG
            string methodShow = null;
            string exClass    = null;

            if (e.Exception.TargetSite != null)
            {
                methodShow = e.Exception.TargetSite.Name;
                exClass    = e.Exception.TargetSite.DeclaringType.FullName;
            }
            string userInfo = null;

            if (User.Singleton != null)
            {
                userInfo = "userID = " + User.Singleton.Id + ";\r\nmail=" + User.Singleton.Email + ";\r\nkey=" + User.Singleton.HashKey;
            }

            var activityManager = GetSystemService(Activity.ActivityService) as ActivityManager;

            ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
            activityManager.GetMemoryInfo(memoryInfo);

            double totalUsed = memoryInfo.AvailMem / (1024 * 1024);
            double totalRam  = memoryInfo.TotalMem / (1024 * 1024);

            e.Handled = true;

            //AppsLog.SendLog(new AppsLog {
            //	SystemName = Device.OS.ToString(),
            //	DeviceModel = Android.OS.Build.Model,
            //	SystemVersion = Android.OS.Build.VERSION.Sdk,
            //	ExceptionType = e.Exception.GetType().ToString(),
            //	StackTrace = e.Exception.StackTrace,
            //	Message = e.Exception.Message,
            //	AdditionalData = "",

            //	AppVersion = appVersion,
            //	AppFunction = exClass + "." + methodShow,
            //	SizeMemory = totalUsed.ToString("f2") + "/" + totalRam.ToString("f2"),
            //	TypeError = "TypeApplication",
            //	UserId = User.Singleton == null ? 0 : User.Singleton.Id,
            //	UseKey = User.Singleton?.HashKey,
            //	UrlApp = "",
            //	UrlData = "",
            //	UrlMethod = "",
            //}
            //);
            string pageHistory;

            if (OnePage.redirectApp != null)
            {
                pageHistory = OnePage.redirectApp.GetHistoryToJson();
            }
            else
            {
                pageHistory = "нету";
            }
            AppsLog.SendLog(new Dictionary <string, string> ()
            {
                { "system_name", Device.OS.ToString() },
                { "device_model", Android.OS.Build.Model },
                { "system_version", Android.OS.Build.VERSION.Sdk },
                { "exception_type", e.Exception.GetType().ToString() },
                { "stack_trace", e.Exception.StackTrace },
                { "message", e.Exception.Message },
                { "additional_data", @""" """ },
                { "page_history", pageHistory },

                { "app_version", App.Version },
                { "app_function", exClass + "." + methodShow },
                { "size_memory", totalUsed.ToString("f2") + "/" + totalRam.ToString("f2") },
                { "type_error", "TypeApplication" },
                { "user_id", User.Singleton == null ? "0" : User.Singleton.Id.ToString() },
                { "user_key", User.Singleton?.HashKey },
                { "url", "" },
                { "url_data", "" },
                { "url_method", "" },
            });
        }
Example #7
0
        // This is the main entry point of the application.
        static void Main(string[] args)
        {
            // if you want to use a different Application Delegate class from "AppDelegate"
            // you can specify it here.
            try {
                UIApplication.Main(args, null, "AppDelegate");
            }
            catch (Exception ex)
            {
//				#if !DEBUG
                string methodShow = null;
                string exClass    = null;
                if (ex.TargetSite != null)
                {
                    methodShow = ex.TargetSite.Name;
                    exClass    = ex.TargetSite.DeclaringType.FullName;
                }
                string userInfo = null;
                if (User.Singleton != null)
                {
                    userInfo = "userID = " + User.Singleton.Id + ";\r\nmail=" + User.Singleton.Email + ";\r\nkey=" + User.Singleton.HashKey;
                }
                string pageHistory;
                if (OnePage.redirectApp != null)
                {
                    pageHistory = OnePage.redirectApp.GetHistoryToJson();
                }
                else
                {
                    pageHistory = "нету";
                }
                double totalRam = NSProcessInfo.ProcessInfo.PhysicalMemory / (1024 * 1024);

                AppsLog.SendLog(new Dictionary <string, string>()
                {
                    { "system_name", Device.OS.ToString() },
                    { "device_model", UIDevice.CurrentDevice.Name },
                    { "system_version", UIDevice.CurrentDevice.SystemVersion },
                    { "exception_type", ex.GetType().ToString() },
                    { "stack_trace", ex.StackTrace },
                    { "message", ex.Message },
                    { "additional_data", "''" },
                    { "page_history", pageHistory },

                    { "app_version", App.Version },
                    { "app_function", exClass + "." + methodShow },
                    { "size_memory", totalRam.ToString("f2") },
                    { "type_error", "TypeApplication" },
                    { "user_id", User.Singleton == null ? "0" : User.Singleton.Id.ToString() },
                    { "user_key", User.Singleton?.HashKey },
                    { "url", "" },
                    { "url_data", "" },
                    { "url_method", "" },
                });

                //AppsLog.SendLog (new AppsLog {
                //	SystemName = Device.OS.ToString(),
                //	DeviceModel =  UIDevice.CurrentDevice.Name,
                //	SystemVersion = UIDevice.CurrentDevice.SystemVersion,
                //	ExceptionType = ex.GetType ().ToString (),
                //	StackTrace = ex.StackTrace,
                //	Message = ex.Message,
                //	//AdditionalData = "appVersion = " + appVersion + "; " + userInfo + ";\r\nmethod=" + exClass + "." + methodShow,
                //	AppVersion = appVersion.ToString(),
                //	AppFunction = exClass + "." + methodShow,
                //	SizeMemory = totalRam.ToString("f2"),
                //	TypeError = "TypeApplication",
                //	UserId = User.Singleton == null ? 0 : User.Singleton.Id,
                //	UseKey = User.Singleton?.HashKey,
                //	UrlApp = "",
                //	UrlData = "",
                //	UrlMethod = "",
                //}
                //);
//				#endif
            }
        }