public static void CheckException(Exception ex, MaterialProgressBar dataLoadProgressBar) { Tuple <Type, string> type = ExceptionData.ExceptionList.Find(e => e.Item1.IsInstanceOfType(ex)); ExceptionMessageBox exceptionMessage = new ExceptionMessageBox(type.Item2); exceptionMessage.ShowDialog(); dataLoadProgressBar.Value = 0; }
private void LoadConEmuDll(string asLibrary) { try { if (m_ConEmuHandle != IntPtr.Zero) { return; } m_ConEmuHandle = LoadLibrary(asLibrary); if (m_ConEmuHandle == IntPtr.Zero) { int error = Marshal.GetLastWin32Error(); ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException("Unable to load the conemu library", "Failure while load the conemu library" + Environment.NewLine + "Library path: " + asLibrary + Environment.NewLine + "Last error code: " + error); box.ShowDialog(); return; } const string fnNameOld = "ConsoleMain3"; IntPtr ptrConsoleMain = GetProcAddress(m_ConEmuHandle, fnNameOld); const string fnNameNew = "GuiMacro"; IntPtr ptrGuiMacro = GetProcAddress(m_ConEmuHandle, fnNameNew); if (ptrConsoleMain == IntPtr.Zero && ptrGuiMacro == IntPtr.Zero) { int error = Marshal.GetLastWin32Error(); ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException("Unable to load the conemu library", "Failure while getting the addresses of the methods in the conemu library" + Environment.NewLine + "Library path: " + asLibrary + Environment.NewLine + "Methods: ConsoleMain3, GuiMacro" + Environment.NewLine + "Last error code: " + error); box.ShowDialog(); UnloadConEmuDll(); return; } m_fnGuiMacro = (FGuiMacro)Marshal.GetDelegateForFunctionPointer(ptrGuiMacro, typeof(FGuiMacro)); m_fnConsoleMain3 = (FConsoleMain3)Marshal.GetDelegateForFunctionPointer(ptrConsoleMain, typeof(FConsoleMain3)); } catch (Exception error) { UnloadConEmuDll(); ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException(error); box.ShowDialog(); } }
public static async Task <bool> UpdateSelectionAsync(int IdSel, List <string> TagToRemove) { 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("selections/" + IdSel, Method.GET); client.Timeout = timeout; client.ReadWriteTimeout = timeout; request.Timeout = timeout; request.ReadWriteTimeout = timeout; var response = await client.ExecuteTaskAsync(request); if (response.IsSuccessful) { var Selection = JsonSelectionList.DeserializedJsonAlone(response.Content); if (Selection != null) { if (Selection.state == "closed") { return(false); } var request2 = new RestRequest("/selections/" + IdSel, Method.PUT); foreach (string uid in TagToRemove) { request2.AddParameter("listOfTagPulled", uid); } var client2 = new RestClient(urlServer); client2.Authenticator = new HttpBasicAuthenticator(privateApiLogin, privateApiMdp); LogToFile.LogMessageToFile("------- Start Update selection --------"); var response2 = await client2.ExecuteTaskAsync(request2); LogToFile.LogMessageToFile(response2.Content); LogToFile.LogMessageToFile("------- End Updateselection --------"); return(response2.IsSuccessful); } return(false); } return(false); } catch (Exception error) { ExceptionMessageBox exp = new ExceptionMessageBox(error, "Error update selection"); exp.ShowDialog(); return(false); } }
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); }
/// <summary> /// Occurs when the script is going to be run. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void EventHandler_Run(object sender, System.EventArgs e) { try { compiler__.ClearCodes(); compiler__.AddCode(syntaxDocument1.Text); int ret = compiler__.Compile(); Output.Clear(); ErrorList.Clear(); if (ret > 0) { foreach (CompilerError error in compiler__.Errors) { ErrorLevel level = error.IsWarning ? ErrorLevel.elWarning : ErrorLevel.elError; ErrorList.Add(level, error.ErrorNumber, error.ErrorText, error.Line); } Output.Add(SunnyChen.Gulu.Win.Properties.Resources.TEXT_ERR_COMPILE); ErrorList.Show(); } else if (ret == 0) { Output.Add(SunnyChen.Gulu.Win.Properties.Resources.TEXT_COMPILE_OK); Output.Show(); try { compiler__.Run("Program", "Main"); } catch (Exception ex) { //ExceptionMessageBox.ShowDialog(ex); Exception param = ex.InnerException == null ? ex : ex.InnerException; ExceptionMessageBox.ShowDialog(param, true); } } else if (ret == -1) { Output.Add(SunnyChen.Gulu.Win.Properties.Resources.TEXT_ERR_NO_CODE); Output.Show(); } else { Output.Add(SunnyChen.Gulu.Win.Properties.Resources.TEXT_ERR_COMPILE_GENERAL); Output.Show(); } } catch { throw; } }
public static async Task <List <Device> > GetCabinets() { 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("cabinets", Method.GET); client.Timeout = timeout; client.ReadWriteTimeout = timeout; request.Timeout = timeout; request.ReadWriteTimeout = timeout; var response = await client.ExecuteTaskAsync(request); if (response.IsSuccessful) { List <Device> lstDevice = new List <Device>(); var devices = JsonDevice.DeserializedJsonList(response.Content); if ((devices != null) && (devices.Count() > 0)) { foreach (JsonDevice jd in devices) { Device newDev = new Device { DeviceName = jd.name, DeviceSerial = jd.serial_num, DeviceLocation = jd.Location, IpAddress = jd.IP_addr, }; lstDevice.Add(newDev); } } return(lstDevice); } else { return(null); } } catch (Exception error) { ExceptionMessageBox exp = new ExceptionMessageBox(error, "Get Cabinet "); exp.ShowDialog(); return(null); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOK_Click(object sender, System.EventArgs e) { using (new LengthyOperation(this)) { try { System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); // Sets preference settings PreferenceConfigHandler preferenceHandler = (PreferenceConfigHandler)config.GetSection("PreferenceConfig"); preferenceHandler.SearchRecursivly = chkSearchRecursivly.Checked; preferenceHandler.FileTreeShowFiles = chkShowFiles.Checked; preferenceHandler.FileTreeShowHidden = chkShowHidden.Checked; preferenceHandler.FileTreeShowSystem = chkShowSystem.Checked; // Sets backup settings BackupConfigHandler backupHandler = (BackupConfigHandler)config.GetSection("BackupConfig"); backupHandler.BackupDirectory = txtBackupDirectory.Text; backupHandler.EnableBackup = chkEnableBackup.Checked; // Sets editor and compiler settings EditorCompilerConfigHandler editorCompilerConfigHandler = (EditorCompilerConfigHandler)config.GetSection("EditorCompilerConfig"); editorCompilerConfigHandler.CompilerTypeName = txtCodeDomCompilerType.Text; if (cbSimpleTemplate.SelectedItem.ToString().Equals(Resources.TEXT_NOT_SPECIFIED) || cbGTemplate.SelectedItem.ToString().Equals(Resources.TEXT_NOT_SPECIFIED) || cbSyntaxFile.SelectedItem.ToString().Equals(Resources.TEXT_NOT_SPECIFIED)) { MessageBox.Show(Resources.TEXT_SCRIPT_MUST_SPECIFY, Resources.TEXT_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error); // forbid closing DialogResult = DialogResult.None; return; } editorCompilerConfigHandler.SimpleTemplate = cbSimpleTemplate.SelectedItem.ToString(); editorCompilerConfigHandler.GTemplate = cbGTemplate.SelectedItem.ToString(); editorCompilerConfigHandler.SyntaxFileName = cbSyntaxFile.SelectedItem.ToString(); config.Save(ConfigurationSaveMode.Full); DialogResult = DialogResult.OK; } catch (Exception ex) { ExceptionMessageBox.ShowDialog(ex, true); } } }
public bool CheckConEmuAndDisplay() { bool result = CheckConEmu(); if (result == false) { var conemu = GetConEmuExecutable(); ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException("Unable to find the ConEmu installation", "Please set the paths of your ConEmu installation in the Visual Studio options pane" + Environment.NewLine + Environment.NewLine + "ConEmu Path: " + conemu + Environment.NewLine); box.ShowDialog(); } return(result); }
private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { e.Handled = true; try { var logger = SimpleIoc.Default.GetInstance <ILogService>().GetLogger <App>(); logger.Fatal("Some crash occurred.", e.Exception); } catch (InvalidOperationException) { } var window = new ExceptionMessageBox(e.Exception, "Im Programm ist ein Fehler aufgetreten.", true); window.ShowDialog(); }
public static async Task <Device> GetCabinet(string serial) { try { Properties.Settings.Default.Reload(); 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("cabinets/" + serial, Method.GET); client.Timeout = timeout; client.ReadWriteTimeout = timeout; request.Timeout = timeout; request.ReadWriteTimeout = timeout; var response = await client.ExecuteTaskAsync(request); if (response.IsSuccessful) { var device = JsonDevice.DeserializedJsonAlone(response.Content); if (device != null) { Device newDev = new Device { DeviceName = device.name, DeviceSerial = device.serial_num, DeviceLocation = device.Location, IpAddress = device.IP_addr, }; return(newDev); } return(null); } else { return(null); } } catch (Exception error) { ExceptionMessageBox exp = new ExceptionMessageBox(error, "Error in Get Cabinet"); exp.ShowDialog(); return(null); } }
protected override void OnStartup(StartupEventArgs args) { Dispatcher.UnhandledException += (sender, e) => { //new Window1().Show(); //var errorMessage = string.Format("An exception occurred: {0}", // e.Exception.Message + Environment.NewLine + e.Exception.StackTrace); //MessageBox.Show(errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error); e.Handled = true; var window = new ExceptionMessageBox(e.Exception, "AN UNHANDLED EXCEPTION HAS OCCURED."); window.ShowDialog(); }; BackgroundRunner.Init(); BackgroundRunner.Run(Repository.Instance.Refresh); BackgroundRunner.Run(Repository.Instance.LoadQueryHierarchy); base.OnStartup(args); }
private void MenuItemCallback(object sender, EventArgs e) { try { var window = (FastFileAccessWindow)this.package.FindToolWindow(typeof(FastFileAccessWindow), 0, true); if ((null == window) || (null == window.Frame)) { throw new NotSupportedException("Cannot create tool window"); } IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show()); } catch (Exception error) { ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException(error); box.ShowDialog(); } }
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(); })); } }
public static async Task <bool> CreateCabinet(Device dev) { 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("cabinets/", Method.POST); client.Timeout = timeout; client.ReadWriteTimeout = timeout; request.Timeout = timeout; request.ReadWriteTimeout = timeout; request.AddParameter("serial_num", dev.DeviceSerial); request.AddParameter("name", dev.DeviceName); request.AddParameter("location", dev.DeviceLocation); // If default parameter is nul get found IP if (string.IsNullOrEmpty(Properties.Settings.Default.NotificationIp)) { request.AddParameter("IP_addr", dev.IpAddress); } else { request.AddParameter("IP_addr", Properties.Settings.Default.NotificationIp); } request.AddParameter("port", Properties.Settings.Default.NotificationPort); var response = await client.ExecuteTaskAsync(request); return(response.IsSuccessful); } catch (Exception error) { ExceptionMessageBox exp = new ExceptionMessageBox(error, "Error Delete Selection"); exp.ShowDialog(); return(false); } }
public static async Task <JsonSku> GetSkuInfo(string skuQueried) { try { Properties.Settings.Default.Reload(); 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(privateApiLogin, privateApiMdp); var request = new RestRequest("sku", Method.GET); client.Timeout = timeout; client.ReadWriteTimeout = timeout; request.Timeout = timeout; request.ReadWriteTimeout = timeout; request.AddParameter("refNumber", skuQueried); var response = await client.ExecuteTaskAsync(request); if (response.IsSuccessful) { var skuInfo = JsonSku.DeserializedJsonAlone(response.Content); if (skuInfo != null) { return(skuInfo); } return(null); } else { return(null); } } catch (Exception error) { ExceptionMessageBox exp = new ExceptionMessageBox(error, "Error in Get sku"); exp.ShowDialog(); return(null); } }
public void Execute(string asWhere, string asMacro) { try { if (m_ConEmuHandle == IntPtr.Zero) { return; } new Thread(() => { Thread.CurrentThread.IsBackground = true; ExecuteHelper(asWhere, asMacro); }).Start(); } catch (Exception error) { ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException(error); box.ShowDialog(); } }
/// <summary> /// Crea el mensaje de error y lo muestra /// </summary> /// <param name="ex"></param> /// <param name="handlingInstanceId"></param> /// <returns></returns> private DialogResult ShowThreadExceptionDialog(Exception exception, Guid handlingInstanceId) { //Capturar las excepciones para las cuales no se quiere mostrar el dialogo de exception, sino un mensaje estandar if (exception is PPPNegocioException) { MessageHelper.MostrarMensajeAlerta(exception.Message); return DialogResult.OK; } //Capturar las excepciones para las cuales se muestra la innerException if (exception.InnerException != null) { if (exception.InnerException is SqlException) { exception = exception.InnerException; } } var form = new ExceptionMessageBox(exception.Message); return form.ShowDialog(); }
public void OpenConEmuToolWindow() { if (this.Package == null || this.Package.Zombied) { return; } try { if (CheckConEmuAndDisplay() == false) { return; } var window = this.Package.FindToolWindow(typeof(ConEmuWindow), 0, true) as ConEmuWindow; if (window?.Frame == null) { throw new NotSupportedException("Cannot create tool window"); } ThreadHelper.ThrowIfNotOnUIThread(); IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; ErrorHandler.ThrowOnFailure(windowFrame.Show()); if (IsConEmuToolWindowVisible(windowFrame) == false) { window.RunConEmu(); } } catch (Exception error) { ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException(error); box.ShowDialog(); } }
public bool RunConEmu() { ThreadHelper.ThrowIfNotOnUIThread(); try { if (ProductEnvironment.Instance.ConEmu == null || m_HasExited) { RunConEmuSession(); } else { DisableMaxMinCloseButtons(); } return(true); } catch (Exception error) { ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException(error); box.ShowDialog(); } return(false); }
private async void PopulateUser() { try { var ctx = await RemoteDatabase.GetDbContextAsync(); var lstDev = ctx.GrantedUsers .Where(u => u.UserRankId > 1).ToList(); EditedUser = new UsersViewModel(); DataUser.Clear(); foreach (var dv in lstDev) { UsersViewModel uvm = new UsersViewModel() { Id = dv.GrantedUserId, Login = dv.Login, FirstName = dv.FirstName, LastName = dv.LastName, BadgeId = dv.BadgeNumber, Fingerprints = dv.Fingerprints.Count }; DataUser.Add(uvm); } 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(); })); } }
private async void myDatagrid_Loaded(object sender, RoutedEventArgs e) { try { var ctx = await RemoteDatabase.GetDbContextAsync(); if (ctx.Columns != null && ctx.Columns.Count() > 0) { foreach (Column col in ctx.Columns) { myDatagrid.Columns[col.ColumnIndex].IsHidden = false; myDatagrid.Columns[col.ColumnIndex].HeaderText = col.ColumnName; } } myDatagrid.Columns["Drawer"].IsHidden = false; ctx.Database.Connection.Close(); ctx.Dispose(); } catch (Exception err) { ExceptionMessageBox exp = new ExceptionMessageBox(err, "Error Datagrid loaded"); exp.ShowDialog(); } }
private void ExecuteHelper(string asWhere, string asMacro) { try { if (m_fnGuiMacro != null) { IntPtr bstrPtr = IntPtr.Zero; int result = m_fnGuiMacro.Invoke(asWhere, asMacro, out bstrPtr); if (result != 133 /*CERR_GUIMACRO_SUCCEEDED*/ || result != 134 /*CERR_GUIMACRO_FAILED*/) { return; // Sucess } ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException("Invoke GuiMacro method failed", "Failure while invoke the GuiMacro of the conemu library" + Environment.NewLine + "Result code: " + result); box.ShowDialog(); if (bstrPtr != IntPtr.Zero) { Marshal.FreeBSTR(bstrPtr); } } else { ExecuteLegacy(asWhere, asMacro); } } catch (Exception error) { ExceptionMessageBox box = new ExceptionMessageBox(); box.SetException(error); box.ShowDialog(); } }
public void OnProjectChanged(string path, string[] filter) { this.treeViewExplorer.BeginUpdate(); this._model = new TreeModel(); BaseNode rootNode = new BaseNode("UDK"); this._model.Nodes.Add(rootNode); try { PopulateTree(path, rootNode, filter); } catch (Exception e) { ExceptionMessageBox msgBox = new ExceptionMessageBox(e); msgBox.ShowDialog(); } this.treeViewExplorer.Model = _model; this.treeViewExplorer.EndUpdate(); foreach (TreeNodeAdv node in this.treeViewExplorer.Root.Children) { node.Expand(); } }
public void EventHandler_Run(object sender, System.EventArgs e) { try { TreeNode node = gscriptTreeView.SelectedNode; if (node != null) { ScriptTreeNodeProperty prop = (ScriptTreeNodeProperty)node.Tag; if (prop != null) { if (prop.Type == ScriptTreeNodeType.G || prop.Type == ScriptTreeNodeType.Simple) { ScriptType type; type = prop.Type == ScriptTreeNodeType.G ? ScriptType.G : ScriptType.Simple; string code = scriptRepository__.GetContent(prop.Name, type); compiler__.ClearCodes(); compiler__.AddCode(code); int ret = compiler__.Compile(); Output.Clear(); ErrorList.Clear(); if (ret > 0) { foreach (CompilerError error in compiler__.Errors) { ErrorLevel level = error.IsWarning ? ErrorLevel.elWarning : ErrorLevel.elError; ErrorList.Add(level, error.ErrorNumber, error.ErrorText, error.Line); } Output.Add(Resources.TEXT_ERR_COMPILE); ErrorList.Show(); } else if (ret == 0) { Output.Add(Resources.TEXT_COMPILE_OK); Output.Show(); try { compiler__.Run("Program", "Main"); } catch (Exception ex) { //ExceptionMessageBox.ShowDialog(ex); Exception param = ex.InnerException == null ? ex : ex.InnerException; ExceptionMessageBox.ShowDialog(param, true); } } else if (ret == -1) { Output.Add(Resources.TEXT_ERR_NO_CODE); Output.Show(); } else { Output.Add(Resources.TEXT_ERR_COMPILE_GENERAL); Output.Show(); } } } } } catch { throw; } }
public static async Task <bool> GetAndStoreSelectionAsync() { 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("selections", Method.GET); client.Timeout = timeout; client.ReadWriteTimeout = timeout; request.Timeout = timeout; request.ReadWriteTimeout = timeout; var response = await client.ExecuteTaskAsync(request); if (response.IsSuccessful) { var ctx = await RemoteDatabase.GetDbContextAsync(); ctx.PullItems.Clear(); await ctx.SaveChangesAsync(); lock (somePublicStaticObject) { var lstSelection = JsonSelectionList.DeserializedJsonList(response.Content); if ((lstSelection != null) && (lstSelection.Length > 0)) { foreach (var sel in lstSelection) { if (sel == null) { LogToFile.LogMessageToFile("------- Start Error in selection --------"); LogToFile.LogMessageToFile(response.Content); LogToFile.LogMessageToFile("------- End Error in selection --------"); break; } } lastSelection = lstSelection; } else { lastSelection = null; } ctx.Database.Connection.Close(); ctx.Dispose(); return(true); } } return(false); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } return(false); } catch (Exception error) { ExceptionMessageBox exp = new ExceptionMessageBox(error, "Error getting selection"); exp.ShowDialog(); return(false); } }
internal void ParseScript(string file) { this.treeViewOutline.BeginUpdate(); this._model = new TreeModel(); this._outline = ScriptOutline.CreateFromScript(file); if (this._outline != null) { BookmarkNode rootNode = new BookmarkNode(this._outline.Class, BookmarkNode.Categories.Class, null); this._model.Nodes.Add(rootNode); try { BookmarkNode replicationNode = new BookmarkNode("Replication", BookmarkNode.Categories.Replication, this._outline.Replication); rootNode.Nodes.Add(replicationNode); BookmarkNode defaultPropertiesNode = new BookmarkNode("Default Properties", BookmarkNode.Categories.DefaultProperties, this._outline.DefaultProperties); rootNode.Nodes.Add(defaultPropertiesNode); BookmarkNode varsNode = new BookmarkNode("Variables", BookmarkNode.Categories.Group, null); rootNode.Nodes.Add(varsNode); foreach (ScriptOutline.VarDesc scriptVar in this._outline.Variables) { BookmarkNode varNode = new BookmarkNode(scriptVar.Identifier, BookmarkNode.Categories.Variable, scriptVar); varsNode.Nodes.Add(varNode); } BookmarkNode stateNode = null; Dictionary<string, BookmarkNode> states = new Dictionary<string, BookmarkNode>(); BookmarkNode functionsNode = new BookmarkNode("Functions", BookmarkNode.Categories.Group, null); rootNode.Nodes.Add(functionsNode); states.Clear(); stateNode = new BookmarkNode("\tGlobal", BookmarkNode.Categories.State, null); states["\tGlobal"] = stateNode; functionsNode.Nodes.Add(stateNode); foreach (ScriptOutline.StateDesc scriptState in this._outline.States) { stateNode = new BookmarkNode(scriptState.Identifier, BookmarkNode.Categories.State, scriptState); states[scriptState.Identifier] = stateNode; functionsNode.Nodes.Add(stateNode); } foreach (ScriptOutline.FunctionDesc scriptFunction in this._outline.Functions) { BookmarkNode functionNode = new BookmarkNode(scriptFunction.Identifier, BookmarkNode.Categories.Function, scriptFunction); if (states.TryGetValue(scriptFunction.State, out stateNode)) { stateNode.Nodes.Add(functionNode); } } BookmarkNode eventsNode = new BookmarkNode("Events", BookmarkNode.Categories.Group, null); rootNode.Nodes.Add(eventsNode); states.Clear(); stateNode = new BookmarkNode("\tGlobal", BookmarkNode.Categories.State, null); states["\tGlobal"] = stateNode; eventsNode.Nodes.Add(stateNode); foreach (ScriptOutline.StateDesc scriptState in this._outline.States) { stateNode = new BookmarkNode(scriptState.Identifier, BookmarkNode.Categories.State, scriptState); states[scriptState.Identifier] = stateNode; eventsNode.Nodes.Add(stateNode); } foreach (ScriptOutline.EventDesc scriptEvent in this._outline.Events) { BookmarkNode eventNode = new BookmarkNode(scriptEvent.Identifier, BookmarkNode.Categories.Event, scriptEvent); if (states.TryGetValue(scriptEvent.State, out stateNode)) { stateNode.Nodes.Add(eventNode); } } } catch (Exception e) { ExceptionMessageBox msgBox = new ExceptionMessageBox(e); msgBox.ShowDialog(); } } this.treeViewOutline.Model = _model; this.treeViewOutline.EndUpdate(); foreach (TreeNodeAdv node in this.treeViewOutline.Root.Children) { node.Expand(); } }
public static async Task <bool> GetAndStoreUserAsync() { try { string serverIP = Properties.Settings.Default.ServerIp; int serverPort = Properties.Settings.Default.ServerPort; //serverIP = "157.230.97.196"; //serverPort = 3000; string urlServer = "http://" + serverIP + ":" + serverPort; var client = new RestClient(urlServer); client.Authenticator = new HttpBasicAuthenticator(publicApiLogin, publicApiMdp); var request = new RestRequest("/users", Method.GET); client.Timeout = timeout; client.ReadWriteTimeout = timeout; request.Timeout = timeout; request.ReadWriteTimeout = timeout; var response = await client.ExecuteTaskAsync(request); if (response.IsSuccessful) { // remove granted standard users var ctx = await RemoteDatabase.GetDbContextAsync(); /* ctx.GrantedAccesses.Clear(); * await ctx.SaveChangesAsync();*/ //get device Device mydev = ctx.Devices.GetBySerialNumber(Properties.Settings.Default.WallSerial); if (mydev == null) { return(false); } var lstUser = JsonUserList.DeserializedJsonList(response.Content); if ((lstUser != null) && (lstUser.Length > 0)) { foreach (JsonUserList jsl in lstUser) { var original = ctx.GrantedUsers.GetByServerId(jsl.user_id); var original2 = ctx.GrantedUsers.GetByLogin(jsl.login); if ((original != null) && (original.Login != "Admin")) { TimeSpan ts = jsl.updated_at - original.UpdateAt; if (Math.Abs(ts.TotalSeconds) > 1) // Not the latest but avoid ms { original.ServerGrantedUserId = jsl.user_id; original.Login = jsl.login; original.Password = jsl.password; original.FirstName = jsl.fname; original.LastName = jsl.lname; original.BadgeNumber = string.IsNullOrEmpty(jsl.badge_num) ? "000000" : jsl.badge_num; original.UserRankId = 3; original.UpdateAt = jsl.updated_at; ctx.Entry(original).State = EntityState.Modified; await ctx.SaveChangesAsync(); //deletefingerprint for this user if exists var fpUser = ctx.Fingerprints.Where(gu => gu.GrantedUserId == original.GrantedUserId).ToList(); if ((fpUser != null) && (fpUser.Count > 0)) { foreach (SmartDrawerDatabase.DAL.Fingerprint fp in fpUser) { ctx.Fingerprints.Remove(fp); } await ctx.SaveChangesAsync(); } if ((jsl.ftemplate != null) & (jsl.ftemplate.Count > 0)) { for (int loop = 0; loop < jsl.ftemplate.Count; loop++) { if (!string.IsNullOrEmpty(jsl.ftemplate[loop]) && !string.IsNullOrEmpty(jsl.finger_index[loop])) { ctx.Fingerprints.Add(new SmartDrawerDatabase.DAL.Fingerprint { GrantedUserId = original.GrantedUserId, Index = Convert.ToInt32(jsl.finger_index[loop]), Template = jsl.ftemplate[loop], }); } } await ctx.SaveChangesAsync(); } ctx.GrantedAccesses.AddOrUpdateAccess(original, mydev, ctx.GrantTypes.All()); await ctx.SaveChangesAsync(); } } else if (original2 != null) { TimeSpan ts = jsl.updated_at - original2.UpdateAt; if (Math.Abs(ts.TotalSeconds) > 1) // Not the latest but avoid ms { original2.ServerGrantedUserId = jsl.user_id; original2.Login = jsl.login; original2.Password = jsl.password; original2.FirstName = jsl.fname; original2.LastName = jsl.lname; original2.BadgeNumber = string.IsNullOrEmpty(jsl.badge_num) ? "000000" : jsl.badge_num; original2.UserRankId = 3; original2.UpdateAt = jsl.updated_at; ctx.Entry(original2).State = EntityState.Modified; await ctx.SaveChangesAsync(); //deletefingerprint for this user if exists var fpUser = ctx.Fingerprints.Where(gu => gu.GrantedUserId == original2.GrantedUserId).ToList(); if ((fpUser != null) && (fpUser.Count > 0)) { foreach (SmartDrawerDatabase.DAL.Fingerprint fp in fpUser) { ctx.Fingerprints.Remove(fp); } await ctx.SaveChangesAsync(); } if ((jsl.ftemplate != null) & (jsl.ftemplate.Count > 0)) { for (int loop = 0; loop < jsl.ftemplate.Count; loop++) { if (!string.IsNullOrEmpty(jsl.ftemplate[loop]) && !string.IsNullOrEmpty(jsl.finger_index[loop])) { ctx.Fingerprints.Add(new SmartDrawerDatabase.DAL.Fingerprint { GrantedUserId = original2.GrantedUserId, Index = Convert.ToInt32(jsl.finger_index[loop]), Template = jsl.ftemplate[loop], }); } } await ctx.SaveChangesAsync(); } ctx.GrantedAccesses.AddOrUpdateAccess(original2, mydev, ctx.GrantTypes.All()); await ctx.SaveChangesAsync(); } } else if ((original == null) && (original2 == null)) { GrantedUser newUser = new GrantedUser() { ServerGrantedUserId = jsl.user_id, Login = jsl.login, Password = jsl.password, FirstName = jsl.fname, LastName = jsl.lname, BadgeNumber = string.IsNullOrEmpty(jsl.badge_num) ? "000000" : jsl.badge_num, UpdateAt = jsl.updated_at, UserRankId = 3, }; ctx.GrantedUsers.Add(newUser); await ctx.SaveChangesAsync(); if ((jsl.ftemplate != null) & (jsl.ftemplate.Count > 0)) { for (int loop = 0; loop < jsl.ftemplate.Count; loop++) { if (!string.IsNullOrEmpty(jsl.ftemplate[loop]) && !string.IsNullOrEmpty(jsl.finger_index[loop])) { ctx.Fingerprints.Add(new SmartDrawerDatabase.DAL.Fingerprint { GrantedUserId = newUser.GrantedUserId, Index = Convert.ToInt32(jsl.finger_index[loop]), Template = jsl.ftemplate[loop], }); } } await ctx.SaveChangesAsync(); } ctx.GrantedAccesses.AddOrUpdateAccess(newUser, mydev, ctx.GrantTypes.All()); await ctx.SaveChangesAsync(); } } ctx.Database.Connection.Close(); ctx.Dispose(); return(true); } return(true); } return(false); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } catch (Exception error) { ExceptionMessageBox exp = new ExceptionMessageBox(error, "Error getting user"); exp.ShowDialog(); return(false); } }
public static bool Execute(ExceptionInfo info) { var f = new ExceptionMessageBox(info.TheException, info.TheException.Message); return(f.ShowDialog() == true); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void frmConfiguration_Load(object sender, System.EventArgs e) { try { cbSimpleTemplate.Items.Clear(); cbGTemplate.Items.Clear(); cbSyntaxFile.Items.Clear(); // Populates values DirectoryInfo directoryInfo = new DirectoryInfo(Directories.ScriptsPath); FileInfo[] simpleTemplates = directoryInfo.GetFiles("*.simpletemplate"); foreach (FileInfo simpleTemplate in simpleTemplates) { cbSimpleTemplate.Items.Add(simpleTemplate.Name); } cbSimpleTemplate.Items.Add(Resources.TEXT_NOT_SPECIFIED); FileInfo[] gTemplates = directoryInfo.GetFiles("*.gtemplate"); foreach (FileInfo gTemplate in gTemplates) { cbGTemplate.Items.Add(gTemplate.Name); } cbGTemplate.Items.Add(Resources.TEXT_NOT_SPECIFIED); DirectoryInfo rootDirectoryInfo = new DirectoryInfo(Directories.ApplicationPath); FileInfo[] syntaxFiles = rootDirectoryInfo.GetFiles("*.syn"); foreach (FileInfo syntaxFile in syntaxFiles) { cbSyntaxFile.Items.Add(syntaxFile.Name); } cbSyntaxFile.Items.Add(Resources.TEXT_NOT_SPECIFIED); cbSimpleTemplate.SelectedIndex = 0; cbGTemplate.SelectedIndex = 0; cbSyntaxFile.SelectedIndex = 0; // Loads configurations System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); // Gets preference settings PreferenceConfigHandler preferenceConfigHandler = (PreferenceConfigHandler)config.GetSection("PreferenceConfig"); chkSearchRecursivly.Checked = preferenceConfigHandler.SearchRecursivly; chkShowFiles.Checked = preferenceConfigHandler.FileTreeShowFiles; chkShowHidden.Checked = preferenceConfigHandler.FileTreeShowHidden; chkShowSystem.Checked = preferenceConfigHandler.FileTreeShowSystem; // Gets backup settings BackupConfigHandler backupConfigHandler = (BackupConfigHandler)config.GetSection("BackupConfig"); chkEnableBackup.Checked = backupConfigHandler.EnableBackup; txtBackupDirectory.Text = backupConfigHandler.BackupDirectory; // Gets editor and compiler settings EditorCompilerConfigHandler editorCompilerConfigHandler = (EditorCompilerConfigHandler)config.GetSection("EditorCompilerConfig"); txtCodeDomCompilerType.Text = editorCompilerConfigHandler.CompilerTypeName; if (!cbSimpleTemplate.Items.Contains(editorCompilerConfigHandler.SimpleTemplate)) { cbSimpleTemplate.SelectedItem = Resources.TEXT_NOT_SPECIFIED; } else { cbSimpleTemplate.SelectedItem = editorCompilerConfigHandler.SimpleTemplate; } if (!cbGTemplate.Items.Contains(editorCompilerConfigHandler.GTemplate)) { cbGTemplate.SelectedItem = Resources.TEXT_NOT_SPECIFIED; } else { cbGTemplate.SelectedItem = editorCompilerConfigHandler.GTemplate; } if (!cbSyntaxFile.Items.Contains(editorCompilerConfigHandler.SyntaxFileName)) { cbSyntaxFile.SelectedItem = Resources.TEXT_NOT_SPECIFIED; } else { cbSyntaxFile.SelectedItem = editorCompilerConfigHandler.SyntaxFileName; } } catch (Exception ex) { ExceptionMessageBox.ShowDialog(ex, true); } }