private void PullAcademicData() { try { _consoleInfoData = "Starting Pull of Academic Data"; var settings = RemoteRequest.Get( $"{DatabaseManager.UpdateSpec.RemoteUrl}ApiSettings/PullAcademicData"); if (settings.Result.Status) { DatabaseManager.AcademicSetUpData = Newtonsoft.Json.JsonConvert.DeserializeObject <AcademicSetUpData>( Newtonsoft.Json.JsonConvert.SerializeObject(settings.Result.Data)); _consoleInfoData = $"Pulled Academic Data Successfully"; } else { _consoleInfoData = $"Issue with Synchronization of Academic Data. Please contact the Adminsitrator"; return; } } catch (Exception e) { ErrorHandler.TreatError(e); } }
private void btnStudentRequest_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtStudentMatric.Text.Trim())) { WarnNotify("Warning|Please enter a Matric Number"); return; } new Thread(() => { try { _workingState = true; InfoNotify("Please Wait!|Searching for the Student."); var settings = RemoteRequest.Get( $"{DatabaseManager.UpdateSpec.RemoteUrl}ApiStudentManagement/PullStudentDataByMatricNumber?matricNumber={txtStudentMatric.Text.Trim()}"); if (settings.Result.Status) { _studentData = JsonConvert.DeserializeObject <StudentCompleteData>( JsonConvert.SerializeObject(settings.Result.Data)); if (string.IsNullOrEmpty(_studentData.StudentProfileData.TagId)) { WarnNotify("Awesome!|This is a valid student but it does not have a Tag Yet."); } else { SuccessNotify($"Awesome!|The Tag is Valid. Tag Id is {_tagUID} and Matriculation Number is {_studentData.StudentProfileData.MatricNumber}"); } } else { WarnNotify("Oops!|" + settings.Result.Message); } _workingState = false; } catch (Exception exception) { ErrorHandler.TreatError(exception); } }).Start(); }
private bool RemoteTagClean() { try { var settings = RemoteRequest.Get( $"{DatabaseManager.UpdateSpec.RemoteUrl}ApiStudentManagement/UnTagStudent?tagId={_tagUID}"); MessageBox.Show(settings.Result.Message); return(true); } catch (Exception e) { ErrorHandler.TreatError(e); MessageBox.Show(@"Can not Format the Tag at the moment. Cant seem to reach the Server"); return(false); } }
private void btnUpdateSettingsConfirm_Click(object sender, EventArgs e) { try { new Thread(() => { _workingState = true; var settings = RemoteRequest.Get($"{txtUrl.Text.Trim()}apisettings/PullSettings"); if (settings.Result.Status) { var settingData = Newtonsoft.Json.JsonConvert.DeserializeObject <List <System_Setting> >(settings.Result.Data.ToString()); var localEntities = new LocalEntities(); if (!settingData.Any()) { MessageBox.Show(@"No Settings were found on the server"); _workingState = false; return; } DatabaseManager.ExecuteScripts("truncate table dbo.SystemSetting"); localEntities.System_Setting.AddRange(settingData.Select(sd => new System_Setting() { IsDeleted = false, SettingDate = DateTime.Now, SettingKey = sd.SettingKey, SettingValue = sd.SettingValue })); localEntities.SaveChanges(); DatabaseManager.UpdateSpec = new UpdateSpec() { DatabaseFiles = DatabaseManager.UpdateSpec.DatabaseFiles, DatabaseSchema = DatabaseManager.UpdateSpec.DatabaseSchema, RemoteUrl = settingData.FirstOrDefault(x => x.SettingKey == (int)SettingKey.RemoteApi) ?.SettingValue ?? "" }; } else { MessageBox.Show(@"The server cannot be reached at the moment. Please try again later!"); } settings = RemoteRequest.Get($"{txtUrl.Text.Trim()}ApiUserManagement/Pullusers"); if (settings.Result.Status) { DatabaseManager.LocalAuthData = Newtonsoft.Json.JsonConvert.DeserializeObject <List <AuthModel> >( Newtonsoft.Json.JsonConvert.SerializeObject(settings.Result.Data)); var x = DatabaseManager.LocalAuthData; } else { MessageBox.Show(@"The server cannot be reached at the moment. Please try again later!"); } _workingState = false; }).Start(); } catch (Exception exception) { ErrorHandler.TreatError(exception); } }
private void btnAttach_Click(object sender, EventArgs e) { try { if (txtStudentMatric.Text.Trim() != _studentData.StudentProfileData.MatricNumber) { MessageBox.Show( @"Please request for the Student you wish to Tag. Some modifications have been made to the information retrieved."); return; } if (_tag == null) { MessageBox.Show( @"Lets start over. Close this message and Place a blank Tag"); return; } if (!CheckTagValidity()) { var dialogResult = MessageBox.Show( @"The Current Tag has some data on it? This operation will totally overwrite it. Should I proceed?", @"Waiting for Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult != DialogResult.Yes) { return; } } if (!RemoteTagClean()) { return; } var settings = RemoteRequest.Get( $"{DatabaseManager.UpdateSpec.RemoteUrl}ApiStudentManagement/TagStudent?matricNumber={txtStudentMatric.Text.Trim()}&tagId={_tagUID}"); if (!settings.Result.Status) { MessageBox.Show( @"Cannot Write Tag at the moment. Why? " + settings.Result.Message); return; } var smartPoster = new RtdSmartPoster(); smartPoster.Title.Add(new RtdText(_studentData.StudentProfileData.MatricNumber, "US")); Ndef ndefData = smartPoster; using (var localEntities = new LocalEntities()) { var recordInDb = localEntities.Student_ProfileData.FirstOrDefault(x => x.MatricNumber == txtStudentMatric.Text.Trim()); if (recordInDb != null) { recordInDb.TagId = _tagUID; localEntities.Entry(recordInDb).State = EntityState.Modified; localEntities.SaveChanges(); } } _tag.Content.Clear(); _tag.Content.Add(ndefData); _cardthread = new Thread(() => { card_write_proc(_tag); }); _cardthread.Start(); } catch (Exception exception) { ErrorHandler.TreatError(exception); } }
public object Invoke(string host, string service, string methodName, object[] parameters, Type[] parametersTypes, Type retType) { var endpoint = this._endpointRegistry.GetEndpoint(host); var serializedArs = this._serializationStrategy.SerializeParameters(parameters, parametersTypes); var serializedPInfo = this._serializationStrategy.SerializeParameterTypes(parametersTypes); var requestMessage = new RequestMessage(service, methodName, serializedArs, serializedPInfo); var request = new RemoteRequest(this._context, endpoint, requestMessage, this._serializationStrategy) { ReqPoll = this._requestPoll }; var watch = System.Diagnostics.Stopwatch.StartNew(); if (Castle.Zmq.LogAdapter.LogEnabled) { Castle.Zmq.LogAdapter.LogDebug( "Castle.Facilities.Zmq.Rpc.RemoteRequestService", "About to send request for " + host + "-" + service + "-" + methodName); } var attempts = 0; const int maxAttempts = 3; ResponseMessage response = null; while (attempts++ < maxAttempts) { // request.Monitor = attempts > 1; response = request.Get(); watch.Stop(); if (Castle.Zmq.LogAdapter.LogEnabled) { Castle.Zmq.LogAdapter.LogDebug( "Castle.Facilities.Zmq.Rpc.RemoteRequestService", "Reply from " + host + "-" + service + "-" + methodName + " took " + watch.ElapsedMilliseconds + "ms (" + watch.Elapsed.TotalSeconds + "s). " + "Exception? " + (response.ExceptionInfo != null)); } if (response.ExceptionInfo != null) { if (response.ExceptionInfo.Typename == RemoteRequest.TimeoutTypename) { // our side (local) set a exception info just to inform us - the caller - about a timeout. // since that's the case, attempt to try again continue; } // otherwise -- it's some other kind of error, and we should just fail fast ThrowWithExceptionInfoData(response); } // all went fine if (retType != typeof(void)) { return _serializationStrategy.DeserializeResponseValue(response, retType); } return null; } if (response.ExceptionInfo != null) { ThrowWithExceptionInfoData(response); } return null; }
public object Invoke(string host, string service, string methodName, object[] parameters, Type[] parametersTypes, Type retType) { var endpoint = this._endpointRegistry.GetEndpoint(host); var serializedArs = this._serializationStrategy.SerializeParameters(parameters, parametersTypes); var serializedPInfo = this._serializationStrategy.SerializeParameterTypes(parametersTypes); var requestMessage = new RequestMessage(service, methodName, serializedArs, serializedPInfo); var request = new RemoteRequest(this._context, endpoint, requestMessage, this._serializationStrategy) { ReqPoll = this._requestPoll }; var watch = System.Diagnostics.Stopwatch.StartNew(); if (Castle.Zmq.LogAdapter.LogEnabled) { Castle.Zmq.LogAdapter.LogDebug( "Castle.Facilities.Zmq.Rpc.RemoteRequestService", "About to send request for " + host + "-" + service + "-" + methodName); } var attempts = 0; const int maxAttempts = 3; ResponseMessage response = null; while (attempts++ < maxAttempts) { // request.Monitor = attempts > 1; response = request.Get(); watch.Stop(); if (Castle.Zmq.LogAdapter.LogEnabled) { Castle.Zmq.LogAdapter.LogDebug( "Castle.Facilities.Zmq.Rpc.RemoteRequestService", "Reply from " + host + "-" + service + "-" + methodName + " took " + watch.ElapsedMilliseconds + "ms (" + watch.Elapsed.TotalSeconds + "s). " + "Exception? " + (response.ExceptionInfo != null)); } if (response.ExceptionInfo != null) { if (response.ExceptionInfo.Typename == RemoteRequest.TimeoutTypename) { // our side (local) set a exception info just to inform us - the caller - about a timeout. // since that's the case, attempt to try again continue; } // otherwise -- it's some other kind of error, and we should just fail fast ThrowWithExceptionInfoData(response); } // all went fine if (retType != typeof(void)) { return(_serializationStrategy.DeserializeResponseValue(response, retType)); } return(null); } if (response.ExceptionInfo != null) { ThrowWithExceptionInfoData(response); } return(null); }
private void PullStudents() { try { var listOfProfileData = new List <List <Data.Student_ProfileData> >(); var listOfAcademicData = new List <List <Student_RegistrationData> >(); var done = 0; _consoleInfoData = "Starting Pull of Student Data"; while (true) { var settings = RemoteRequest.Get( $"{DatabaseManager.UpdateSpec.RemoteUrl}ApiStudentManagement/PullStudentsCompleteData?done={done}"); if (settings.Result.Status) { var batch = Newtonsoft.Json.JsonConvert.DeserializeObject <List <StudentCompleteData> >( Newtonsoft.Json.JsonConvert.SerializeObject(settings.Result.Data)); if (!batch.Any()) { break; } listOfProfileData.Add(batch.Select(x => x.StudentProfileData).ToList()); listOfAcademicData.Add(batch .Select(x => x.StudentData.FirstOrDefault()?.StudentRegistrationData).ToList()); done += batch.Count; _consoleInfoData = $"Pulled Student Batch of {batch.Count}. Total Pulled is {done}"; } else { _consoleInfoData = $"Issue with Synchronization of Student Data. Please contact the Adminsitrator"; return; } } if (listOfProfileData.Any()) { _consoleInfoData = @"Discarding all Previous Records"; DatabaseManager.ExecuteScripts("truncate table dbo.Student_ProfileData"); using (var data = new LocalEntities()) { _consoleInfoData = @" Persisting Student Profile Data"; foreach (var list in listOfProfileData) { _consoleInfoData = @"Processing ..."; data.Student_ProfileData.AddRange(list.Select(innerList => new Student_ProfileData() { MatricNumber = innerList.MatricNumber, TagId = innerList.TagId, IsDeleted = false, Phone = innerList.Phone, FirstName = innerList.FirstName, Email = innerList.Email, LastName = innerList.LastName, Sex = innerList.Sex, Picture = innerList.Picture, BloodGroup = innerList.BloodGroup ?? "", PictureEncoded = string.IsNullOrEmpty(innerList.Picture) ? null : Convert.FromBase64String(innerList.Picture), StudentProfileData = Newtonsoft.Json.JsonConvert.SerializeObject(innerList), RemoteId = innerList.Id })); data.SaveChanges(); } _consoleInfoData = @"Student Profile Data Persistence Successful"; _consoleInfoData = @"Persisting Student Academic Data"; foreach (var acadBatch in listOfAcademicData) { _consoleInfoData = @"Processing ..."; foreach (var acad in acadBatch) { var profile = data.Student_ProfileData.FirstOrDefault(x => x.RemoteId == acad.StudentId); if (profile == null) { continue; } var school = DatabaseManager.AcademicSetUpData.AcademicSetUpDatum.FirstOrDefault(x => x.SchoolSubSchool.Id == acad.SubSchoolId); if (school == null) { continue; } profile.Program = school.SchoolSubSchool.SubSchoolName; profile.Department = school.SchoolSubSchoolDepartment .FirstOrDefault(x => x.Id == acad.SubSchoolDepartmentId)?.SubSchoolDepartmentName; data.Entry(profile).State = EntityState.Modified; } data.SaveChanges(); } _consoleInfoData = @"Student Academic Data Persistence Successful"; } _consoleInfoData = @"Completed Pull of Student Data"; } else { _consoleInfoData = @"No Records found at this time."; } } catch (Exception e) { ErrorHandler.TreatError(e); } }