private void enrollmentControl_OnDelete(object control, int fingerNbr, ref EventHandlerStatus eventHandlerStatus) { if (eventHandlerStatus == EventHandlerStatus.Failure) { MessageBox.Show("Finger deletion failed.", "Deletion Failure", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var fingerIndex = DpfpFingerNbrToFingerIndex[fingerNbr]; var ctx = RemoteDatabase.GetDbContext(); { var fingerprint = ctx.Fingerprints.FirstOrDefault( fp => fp.Index == (int)fingerIndex && fp.GrantedUserId == _currentUser.GrantedUserId); if (fingerprint == null) { return; } ctx.Fingerprints.Remove(fingerprint); ctx.SaveChanges(); ctx.Database.Connection.Close(); ctx.Dispose(); } }
public RemoteDatabaseViewModel() { SyncCommand = new RelayCommand(OnConnect, CanConnect); _remoteDatabase = new RemoteDatabase(); _remoteDatabaseService = new RemoteDatabaseService(); _localDatabaseViewModel = new LocalDatabaseViewModel(); }
async void PopulateDevice() { try { var ctx = await RemoteDatabase.GetDbContextAsync(); var lstDev = ctx.Devices.ToList(); EditedDevice = new Device(); DataDevice.Clear(); foreach (var dv in lstDev) { DataDevice.Add(dv); } ctx.Database.Connection.Close(); ctx.Dispose(); } catch (Exception error) { await mainview0.Dispatcher.BeginInvoke(new System.Action(() => { ExceptionMessageBox exp = new ExceptionMessageBox(error, "Error in Populate Device"); exp.ShowDialog(); })); } }
public static async Task <SmartDrawerDatabase.DAL.Device> GetDeviceEntityAsync() { if (_deviceEntity != null) { return(_deviceEntity); } if ((Device == null) || string.IsNullOrWhiteSpace(Device.SerialNumber)) { return(null); } try { var ctx = await RemoteDatabase.GetDbContextAsync(); _deviceEntity = ctx.Devices .Where(d => d.RfidSerial == Device.SerialNumber) .Include(d => d.DeviceType) .FirstOrDefault(); ctx.Database.Connection.Close(); ctx.Dispose(); return(_deviceEntity); } catch (Exception error) { ///Trace.TraceError("{0} Unable to get data from local DB [Device].", DateTime.Now.ToString("g")); //return null; ExceptionMessageBox exp = new ExceptionMessageBox(error, "GetDeviceEntityAsync"); exp.ShowDialog(); return(null); } }
private void ThisAddIn_Startup(object sender, System.EventArgs e) => AsyncContext.Run(async() => { var configuration = new Configuration(); var httpClientHandler = new HttpClientHandler { UseDefaultCredentials = true }; var httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(configuration.AllorsDatabaseAddress), }; var serviceProvider = new ServiceCollection() // TODO: use DI logging //.AddLogging() .AddSingleton <IMessageService, MessageService>() .AddSingleton <IErrorService, ErrorService>() .BuildServiceProvider(); this.database = new RemoteDatabase(httpClient); var objectFactory = new ObjectFactory(MetaPopulation.Instance, typeof(User)); var workspace = new Workspace(objectFactory); this.Client = new Client(this.database, workspace); var program = new Program(serviceProvider, this.Client); var office = new Office(); this.AddIn = new AddIn(this.Application, program, office); this.Ribbon.AddIn = this.AddIn; this.Ribbon.Authentication = new Authentication(this.Ribbon, database, this.Client, configuration); await program.OnStart(this.AddIn); });
private void enrollmentControl_OnEnroll(object control, int fingerNbr, DPFP.Template template, ref EventHandlerStatus eventHandlerStatus) { if (eventHandlerStatus == EventHandlerStatus.Failure) { MessageBox.Show("Finger enrollment failed.", "Enrollment Failure", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var fingerIndex = DpfpFingerNbrToFingerIndex[fingerNbr]; string base64EncodedTemplate = FingerprintReader.EncodeBase64Template(template); var ctx = RemoteDatabase.GetDbContext(); { ctx.Fingerprints.Add(new SmartDrawerDatabase.DAL.Fingerprint { Index = (int)fingerIndex, GrantedUserId = _currentUser.GrantedUserId, Template = base64EncodedTemplate }); ctx.SaveChanges(); ctx.Database.Connection.Close(); ctx.Dispose(); } }
public async static void Reload() { if (_deviceEntity == null) { _deviceEntity = DevicesHandler.GetDeviceEntity(); if (_deviceEntity == null) { return; } } try { var ctx = await RemoteDatabase.GetDbContextAsync(); // Get all users who have accesses on this device, and Administrators. Include Fingerprints to the request, as they're needed by FPReaderHandle. //Cache = ctx.GrantedUsers.Where(gu => gu.GrantedAccesses.Any(ga => ga.DeviceId == _deviceEntity.DeviceId) || gu.UserRank.Rank == UserRank.Administrator).Include(gu => gu.Fingerprints).ToList(); Cache = ctx.GrantedUsers.Include(gu => gu.Fingerprints).ToList(); ctx.Database.Connection.Close(); ctx.Dispose(); } catch (Exception error) { ExceptionMessageBox exp = new ExceptionMessageBox(error, "Unable to get data from local DB [Users Cache]"); exp.ShowDialog(); } }
public void ConfigureServices(IServiceCollection services) { services.AddSingleton <RemoteDatabase>((serviceProvider) => { var http = serviceProvider.GetRequiredService <HttpClient>(); http.BaseAddress = new Uri(ServerUrl); var database = new RemoteDatabase(http); return(database); }); services.AddSingleton <IDatabase>(provider => provider.GetRequiredService <RemoteDatabase>()); services.AddSingleton <Workspace>((serviceProvider) => { var objectFactory = new Allors.Workspace.ObjectFactory(MetaPopulation.Instance, typeof(User)); var workspace = new Workspace(objectFactory); return(workspace); }); var implementationInstance = new AllorsAuthenticationStateProviderConfig { AuthenticationUrl = "/TestAuthentication/Token", }; services.AddSingleton(implementationInstance); services.AddScoped <AllorsAuthenticationStateProvider>(); services.AddScoped <AuthenticationStateProvider>(provider => provider.GetRequiredService <AllorsAuthenticationStateProvider>()); services.AddAuthorizationCore(); services.AddBootstrapCSS(); }
public RegisterWindow() : base(Gtk.WindowType.Toplevel) { this.Build(); this._remoteDatabase = new RemoteDatabase(); }
public Authentication(Program program, RemoteDatabase database, Client client, AppConfig configuration) { this.Program = program; this.Database = database; this.Client = client; this.Configuration = configuration; }
public static SmartDrawerDatabase.DAL.Device GetDeviceEntity() { if (_deviceEntity != null) { return(_deviceEntity); } if ((Device == null) || string.IsNullOrWhiteSpace(Device.SerialNumber)) { return(null); } try { var ctx = RemoteDatabase.GetDbContext(); _deviceEntity = ctx.Devices .Where(d => d.RfidSerial == Device.SerialNumber) .Include(d => d.DeviceType) .FirstOrDefault(); ctx.Database.Connection.Close(); ctx.Dispose(); return(_deviceEntity); } catch (Exception error) { ExceptionMessageBox msg = new ExceptionMessageBox(error, "Error GetDeviceEntity"); msg.ShowDialog(); return(null); } }
public override string GetCustomUI(string _) { try { SynchronizationContext windowsFormsSynchronizationContext = new WindowsFormsSynchronizationContext(); SynchronizationContext.SetSynchronizationContext(windowsFormsSynchronizationContext); this.AppConfig = new AppConfig(); var restClient = new RestClient(this.AppConfig.AllorsDatabaseAddress).UseNewtonsoftJson(); this.database = new RemoteDatabase(() => restClient); var objectFactory = new ObjectFactory(MetaPopulation.Instance, typeof(User)); var workspace = new Workspace(objectFactory); this.Client = new Client(this.database, workspace); this.Program = new Program(new ServiceLocator(), this.Client); this.AddIn = new AddIn((InteropApplication)ExcelDnaUtil.Application, this.Program, this); this.Authentication = new Authentication(this.Program, this.database, this.Client, this.AppConfig); return(RibbonResources.Ribbon); } catch (Exception e) { e.Handle(); throw; } }
public Authentication(Ribbon ribbon, RemoteDatabase database, Client client, Configuration configuration) { this.Ribbon = ribbon; this.Database = database; this.Client = client; this.Configuration = configuration; }
private async void RemoveGrantDevice() { if ((SelectedDeviceGranted != null) && (SelectedGrantedUser != null)) { try { var ctx = await RemoteDatabase.GetDbContextAsync(); var user = ctx.GrantedUsers.Find(SelectedGrantedUser.Id); if (user != null) { ctx.GrantedAccesses.RemoveAccess(user, SelectedDeviceGranted); await ctx.SaveChangesAsync(); ctx.Database.Connection.Close(); ctx.Dispose(); } } catch (Exception error) { await mainview0.Dispatcher.BeginInvoke(new System.Action(() => { ExceptionMessageBox exp = new ExceptionMessageBox(error, "Error in remove access"); })); } } PopulateDeviceGranted(); }
public async Task <string> PullItem(Stream streamdata) { try { StreamReader reader = new StreamReader(streamdata); string res = reader.ReadToEnd(); reader.Close(); reader.Dispose(); JsonItemToPull jitp = JsonConvert.DeserializeObject <JsonItemToPull>(res); if (jitp != null) { var ctx = await RemoteDatabase.GetDbContextAsync(); var currentpullItem = ctx.PullItems.GetByServerId(jitp.ServerPullItemId); if (currentpullItem != null) { ctx.PullItems.Remove(currentpullItem); await ctx.SaveChangesAsync(); } var user = ctx.GrantedUsers.GetByServerId(jitp.userId); var pullItemToAdd = new SmartDrawerDatabase.DAL.PullItem { ServerPullItemId = jitp.ServerPullItemId, PullItemDate = jitp.pullItemDate, Description = string.IsNullOrEmpty(jitp.description) ? " " : jitp.description, GrantedUser = user, TotalToPull = jitp.listOfTagToPull.Length, }; ctx.PullItems.Add(pullItemToAdd); foreach (string uid in jitp.listOfTagToPull) { RfidTag tag = ctx.RfidTags.AddIfNotExisting(uid); ctx.PullItemsDetails.Add(new PullItemDetail { PullItem = pullItemToAdd, RfidTag = tag, }); } await ctx.SaveChangesAsync(); ctx.Database.Connection.Close(); ctx.Dispose(); if (MyHostEvent != null) { MyHostEvent(this, new MyHostEventArgs("PullItemsRequest", null)); } return("Success : " + pullItemToAdd.ServerPullItemId); } return("Error : Bad Parameters"); } catch (Exception exp) { return("Exception : " + exp.InnerException + "-" + exp.Message); } }
static void Main(string[] args) { var rd = new RemoteDatabase(); // Overloaded(1, rd.GetCommand); // this is a compile error, ambigous Overloaded(1, () => rd.GetCommand()); // this compiles and works Console.ReadLine(); }
public MainViewModel(RemoteDatabase remoteDatabase, ILocalDatabaseService localDatabaseService, IRemoteDatabaseService remoteDatabaseService) { ConnectCmd = new RelayCommand(OnConnect, CanConnect); SyncCmd = new RelayCommand(OnSync, CanSync); _remoteDatabase = remoteDatabase; _localDatabaseService = localDatabaseService; _remoteDatabaseService = remoteDatabaseService; }
private void Awake() { if (instance == null) { instance = this; } if (instance != this) { Destroy(this); } }
private async void SaveDevice() { if (EditedDevice != null) { var ctx = await RemoteDatabase.GetDbContextAsync(); if (SelectedDevice != null) //Update existing { if (string.IsNullOrEmpty(EditedDevice.DeviceName) || string.IsNullOrEmpty(EditedDevice.DeviceSerial)) { await mainview0.ShowMessageAsync("INFORMATION", "Please Fill device Name and RFID Serial before saving"); return; } else { var original = ctx.Devices.Find(SelectedDevice.DeviceId); if (original != null) { original.DeviceName = EditedDevice.DeviceName; original.DeviceSerial = EditedDevice.DeviceSerial; original.RfidSerial = EditedDevice.RfidSerial; original.IpAddress = EditedDevice.IpAddress; ctx.Entry(original).State = EntityState.Modified; ctx.SaveChanges(); } } } else //save new { if (string.IsNullOrEmpty(EditedDevice.DeviceName) || string.IsNullOrEmpty(EditedDevice.RfidSerial)) { await mainview0.ShowMessageAsync("INFORMATION", "Please Fill device Name and RFID Serial before saving"); return; } else { ctx.Devices.Add(new Device { DeviceTypeId = 15, DeviceName = EditedDevice.DeviceName, DeviceSerial = EditedDevice.DeviceSerial, RfidSerial = EditedDevice.RfidSerial, IpAddress = EditedDevice.IpAddress }); ctx.SaveChanges(); } } ctx.Database.Connection.Close(); ctx.Dispose(); PopulateDevice(); } }
public static async Task <bool> UpdateUserAsync(string login) { try { string serverIP = Properties.Settings.Default.ServerIp; int serverPort = Properties.Settings.Default.ServerPort; string urlServer = "http://" + serverIP + ":" + serverPort; var client = new RestClient(urlServer); client.Authenticator = new HttpBasicAuthenticator(publicApiLogin, publicApiMdp); var request = new RestRequest("users/" + login, Method.GET); var response = await client.ExecuteTaskAsync(request); if (response.IsSuccessful) { var User = JsonUserList.DeserializedJsonAlone(response.Content); if (User != null) { var request2 = new RestRequest("users/" + login, Method.PUT); var ctx = await RemoteDatabase.GetDbContextAsync(); var dbUser = ctx.GrantedUsers.GetByServerId(User.user_id); if (dbUser != null) { request2.AddParameter("login", dbUser.Login); request2.AddParameter("password", dbUser.Password); request2.AddParameter("lname", dbUser.LastName); request2.AddParameter("fname", dbUser.FirstName); request2.AddParameter("badge_num", dbUser.BadgeNumber); var dbFingers = ctx.Fingerprints.Where(fp => fp.GrantedUserId == dbUser.GrantedUserId).ToList(); if (dbFingers != null) { foreach (SmartDrawerDatabase.DAL.Fingerprint fp in dbFingers) { request2.AddParameter("finger_index", fp.Index.ToString()); request2.AddParameter("ftemplate", fp.Template); } } var response2 = await client.ExecuteTaskAsync(request2); return(response2.IsSuccessful); } } return(false); } } catch (Exception error) { ExceptionMessageBox exp = new ExceptionMessageBox(error, "Error update user"); exp.ShowDialog(); } return(false); }
public async Task <string> AddOrUpdateUserFingerprint(Stream streamdata) { try { StreamReader reader = new StreamReader(streamdata); string res = reader.ReadToEnd(); reader.Close(); reader.Dispose(); JsonUserFingerprint juf = JsonConvert.DeserializeObject <JsonUserFingerprint>(res); if (juf != null) { var ctx = await RemoteDatabase.GetDbContextAsync(); var user = ctx.GrantedUsers.GetByServerId(juf.GrantedUserId); if (user != null) //user Exist { var fingerprint = ctx.Fingerprints.FirstOrDefault(fp => fp.Index == juf.Index && fp.GrantedUserId == user.GrantedUserId); if (fingerprint != null) { ctx.Fingerprints.Remove(fingerprint); } ctx.Fingerprints.Add(new SmartDrawerDatabase.DAL.Fingerprint { Index = juf.Index, GrantedUserId = user.GrantedUserId, Template = juf.Template }); await ctx.SaveChangesAsync(); ctx.Database.Connection.Close(); ctx.Dispose(); MyHostEvent(this, new MyHostEventArgs("UpdateUserInfoList", null)); return("Success : " + user.GrantedUserId); } else //create { return("Failed : " + juf.GrantedUserId); } } return("Error : Bad Parameters"); } catch (Exception exp) { return("Exception : " + exp.InnerException + "-" + exp.Message); } }
public RemoteTest() { var client = new HttpClient() { BaseAddress = new Uri(Url), }; this.Database = new RemoteDatabase(client); var objectFactory = new ObjectFactory(MetaPopulation.Instance, typeof(User)); this.Workspace = new Workspace(objectFactory); this.Init(); }
private async void DeleteUser() { if (SelectedUser != null) //Update existing { var ctx = await RemoteDatabase.GetDbContextAsync(); var original = ctx.GrantedUsers.Find(SelectedUser.Id); if (original != null) { ctx.GrantedUsers.Remove(original); } ctx.SaveChanges(); ctx.Database.Connection.Close(); ctx.Dispose(); PopulateUser(); } }
private async Task Login(RemoteDatabase database) { try { if (!this.Client.IsLoggedIn) { var autoLogin = this.Configuration.AutoLogin; var authenticationTokenUrl = this.Configuration.AllorsAuthenticationTokenUrl; if (!string.IsNullOrWhiteSpace(autoLogin)) { var user = this.Configuration.AutoLogin; var uri = new Uri(authenticationTokenUrl, UriKind.Relative); this.Client.IsLoggedIn = await database.Login(uri, user, null); if (this.Client.IsLoggedIn) { this.Client.UserName = user; } } else { if (!this.Client.IsLoggedIn) { using var loginForm = new LoginForm { Database = database, Uri = new Uri(authenticationTokenUrl, UriKind.Relative) }; var result = loginForm.ShowDialog(); if (result == DialogResult.OK) { this.Client.UserName = loginForm.UserName; this.Client.IsLoggedIn = true; } } } } } catch (Exception e) { e.Handle(); } }
public static DatasetBase CreateDataset(RemoteDatabase rd) { switch (rd.ProviderName) { case Schema.SqlServer.Constants.SqlServerProviderName: return(CreateSqlServerDataset(rd)); case Schema.MySql.Constants.MySqlProviderName: return(CreateMySqlDataset(rd)); case Schema.PostgreSql.Constants.PostgreSqlProviderName: return(CreatePostgreSqlDataset(rd)); default: throw new NotImplementedException(); } }
private static Schema.MySql.MySqlDataset CreateMySqlDataset(RemoteDatabase rd) { var ds = new Schema.MySql.MySqlDataset() { Name = rd.Name, IsCacheable = true, }; ds.ConnectionString = ds.GetSpecializedConnectionString( rd.ConnectionString, rd.IntegratedSecurity, rd.Username, rd.Password, false); return(ds); }
public string StockOutProduct(Stream streamdata) { try { StreamReader reader = new StreamReader(streamdata); string res = reader.ReadToEnd(); reader.Close(); reader.Dispose(); JsonProductToStockOut ListOfTags = JsonConvert.DeserializeObject <JsonProductToStockOut>(res); if (ListOfTags != null) { var ctx = RemoteDatabase.GetDbContext(); int nbSuccess = 0; for (int loop = 0; loop < ListOfTags.listOfTagId.Length; loop++) { Product p = ctx.Products.GetByTagUid(ListOfTags.listOfTagId[loop]); if (p != null) { ctx.Products.Remove(p); } nbSuccess++; } ctx.SaveChanges(); ctx.Database.Connection.Close(); ctx.Dispose(); if (MyHostEvent != null) { MyHostEvent(this, new MyHostEventArgs("StockOutProduct", nbSuccess + " Product(s) Stocked out")); } return("Success"); } else { return("Failed : List of tags is null or empty"); } } catch (Exception exp) { return("failed : " + exp.InnerException); } }
private void GetServerSettings(schema::DatasetBase ds, out string connectionString, out DbProviderFactory dbf) { EntityFactory ef = new EntityFactory(RegistryContext); Entity db = ef.LoadEntity(EntityType.Unknown, Jhu.Graywulf.Registry.AppSettings.FederationName, ds.Name); if (StringComparer.InvariantCultureIgnoreCase.Compare(ds.Name, MyDBDatabaseDefinition.Name) == 0) { // In case of myDB connectionString = ((schema::SqlServer.SqlServerDataset)SchemaManager.Datasets[MyDBDatabaseDefinition.Name]).ConnectionString; dbf = DbProviderFactories.GetFactory(ds.ProviderName); } else if (db is DatabaseDefinition) { // In case of a Graywulf database definition DatabaseDefinition dd = (DatabaseDefinition)db; dd.LoadDatabaseVersions(false); DatabaseVersion rs = dd.DatabaseVersions.Values.First(r => r.Name == "HOT"); // ***** TODO: this should come from the job settings... dd.LoadDatabaseInstances(false); List <DatabaseInstance> dis = new List <DatabaseInstance>(dd.DatabaseInstances.Values.Where(dii => dii.DatabaseVersionReference.Guid == rs.Guid)); // Pick a random server Random rnd = new Random(); DatabaseInstance di = dis[rnd.Next(dis.Count)]; connectionString = di.GetConnectionString().ConnectionString; dbf = System.Data.SqlClient.SqlClientFactory.Instance; } else if (db is RemoteDatabase) { RemoteDatabase rd = (RemoteDatabase)db; connectionString = ds.GetSpecializedConnectionString(rd.ConnectionString, rd.IntegratedSecurity, rd.Username, rd.Password, false); dbf = DbProviderFactories.GetFactory(ds.ProviderName); } else { throw new InvalidOperationException(); } }
public async Task <string> RemoveUser(Stream streamdata) { try { StreamReader reader = new StreamReader(streamdata); string res = reader.ReadToEnd(); int IdToRemove; reader.Close(); reader.Dispose(); if (int.TryParse(res, out IdToRemove)) { var ctx = await RemoteDatabase.GetDbContextAsync(); var user = ctx.GrantedUsers.GetByServerId(IdToRemove); if (user != null) { ctx.GrantedUsers.Remove(user); await ctx.SaveChangesAsync(); ctx.Database.Connection.Close(); ctx.Dispose(); if (MyHostEvent != null) { MyHostEvent(this, new MyHostEventArgs("UpdateUserInfoList", null)); } return("Success : " + IdToRemove); } else { ctx.Database.Connection.Close(); ctx.Dispose(); return("Failed : " + IdToRemove); } } return("Error : Bad Parameters"); } catch (Exception exp) { return("Exception : " + exp.InnerException + "-" + exp.Message); } }
private async void PopulateDeviceGranted() { try { DataDeviceAvailable.Clear(); DataDeviceGranted.Clear(); if (SelectedGrantedUser != null) { var ctx = await RemoteDatabase.GetDbContextAsync(); var user = ctx.GrantedUsers.Find(SelectedGrantedUser.Id); if (user != null) { var lstDev = ctx.GrantedAccesses.GetByUser(user); foreach (var dv in lstDev) { DataDeviceGranted.Add(dv.Device); } foreach (var dv in DataDevice) { if (DataDeviceGranted.Where(d => d.DeviceId == dv.DeviceId).FirstOrDefault() == null) { DataDeviceAvailable.Add(dv); } } } ctx.Database.Connection.Close(); ctx.Dispose(); } } catch (Exception error) { await mainview0.Dispatcher.BeginInvoke(new System.Action(() => { ExceptionMessageBox exp = new ExceptionMessageBox(error, "Error in Populate Device"); exp.ShowDialog(); })); } }