/// <summary> /// Called when [exeption occured]. /// </summary> private static void OnExceptionOccured(object sender, ClientException e) { MessageBox.Show(e.DisplayText + "\r\n\r\n" + ExceptionPrinter.Print(e), e.Message, MessageBoxButton.OK, MessageBoxImage.Error); Execute.BeginOnUIThread(() => Application.Current.Shutdown(2)); }
/// <summary> /// Removes the service from the windows service registry /// </summary> private static RuntimeErrorCode UninstallService() { if (!IsPrivileged()) { return(RuntimeErrorCode.Error); } try { var si = new ServiceInstaller(); var spi = new ServiceProcessInstaller(); si.Parent = spi; si.ServiceName = Platform.Current.ProductName; // Install context si.Context = new InstallContext(UninstallLogPath, null); // Uninstall service si.Uninstall(null); return(RuntimeErrorCode.NoError); } catch (Exception e) { Console.WriteLine(ExceptionPrinter.Print(e)); return(RuntimeErrorCode.Error); } }
/// <summary> /// Prints a module notification to the console /// </summary> private static void PrintNotification(IModuleNotification notification) { var dashes = Enumerable.Repeat("-", Console.WindowWidth); var line = dashes.Aggregate((sum, next) => sum + next); Console.WriteLine(line); Console.WriteLine("Timestamp: " + notification.Timestamp); Console.Write("Severity: "); if (notification.Severity == Severity.Warning) { Console.ForegroundColor = ConsoleColor.Yellow; } if (notification.Severity >= Severity.Error) { Console.ForegroundColor = ConsoleColor.Red; } Console.WriteLine(notification.Severity); Console.ResetColor(); Console.WriteLine("Message: " + notification.Message); Console.Write("Exception: "); if (notification.Exception != null) { Console.WriteLine(Environment.NewLine + ExceptionPrinter.Print(notification.Exception)); } }
private SqlCommand ConfigSqlCommandSearch(SqlConnection connection, Filtro filter) { try { SqlCommand cmd = new SqlCommand { CommandText = "PR_OBTENER_CONTACTOS", CommandType = CommandType.StoredProcedure, Connection = connection }; cmd.Parameters.AddRange(new SqlParameter[] { new SqlParameter() { ParameterName = "@apellidoNombre", Value = filter.apellido_nombre, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@idPais", Value = filter.id_pais, SqlDbType = SqlDbType.Int }, new SqlParameter() { ParameterName = "@localidad", Value = filter.localidad, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@fechaIngDesde", Value = filter.F_ingresoD, SqlDbType = SqlDbType.DateTime }, new SqlParameter() { ParameterName = "@fechaIngHasta", Value = filter.F_ingresoH, SqlDbType = SqlDbType.DateTime }, new SqlParameter() { ParameterName = "@idContInterno", Value = filter.id_cont_int, SqlDbType = SqlDbType.Int }, new SqlParameter() { ParameterName = "@organizacion", Value = filter.organizacion, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@idArea", Value = filter.id_area, SqlDbType = SqlDbType.Int }, new SqlParameter() { ParameterName = "@idActicvo", Value = filter.id_activo, SqlDbType = SqlDbType.Int }, }); return(cmd); } catch (Exception e) { ExceptionPrinter.Print(e); return(null); } }
/// <summary> /// Installs the service in the windows service registry /// </summary> private RuntimeErrorCode InstallService() { if (!IsPrivileged()) { return(RuntimeErrorCode.Error); } try { var spi = new ServiceProcessInstaller(); var si = new ServiceInstaller(); //# Service Account Information spi.Username = Options.User; spi.Password = Options.Password; spi.Account = Options.Account; //# Service Information si.Parent = spi; si.StartType = ServiceStartMode.Automatic; si.ServicesDependedOn = Options.Dependencies.ToArray(); si.Description = Platform.Current.ProductDescription; //# This must be identical to the MoryxService.ServiceBase name //# set in the constructor of MoryxService.cs si.ServiceName = Platform.Current.ProductName; // Install context si.Context = new InstallContext(InstallLogPath, null); // Execution path with parameters var exec = Assembly.GetEntryAssembly(); var cmdOptions = Parser.Default.FormatCommandLine(new WinServiceOptions { ConfigDir = Options.ConfigDir }); // ReSharper disable once PossibleNullReferenceException var serviceExecution = AppendPathParameter(exec.Location, cmdOptions); // ReSharper disable once StringLiteralTypo si.Context.Parameters["assemblypath"] = serviceExecution; // Install service IDictionary stateSaver = new Hashtable(); si.Install(stateSaver); return(RuntimeErrorCode.NoError); } catch (Exception e) { Console.WriteLine(ExceptionPrinter.Print(e)); return(RuntimeErrorCode.Error); } }
public SqlConnection AbrirConexion() { try { connection.Open(); Console.WriteLine("Se creo la conexión exitosamente"); return(connection); } catch (Exception e) { ExceptionPrinter.Print(e); return(null); } }
private void ExecuteInitializer(IResourceInitializer initializer, Action <string> outputStream) { try { outputStream($"Executing initializer '{initializer.Name}' ..."); ResourceManager.ExecuteInitializer(initializer); outputStream("Successful! Restart the module to load the changes!"); outputStream(string.Empty); } catch (Exception e) { outputStream(ExceptionPrinter.Print(e)); outputStream("... initialization failed!"); } }
/// <summary> /// Perform all internal formatting operations /// </summary> internal void Format() { // Format message try { Message = string.Format(_message, _parameters); } catch { // Someone failed to write a working format string Message = _message + " - Format failed!"; } // Concat exception to message if (IsException) { Message += $"\nException: {ExceptionPrinter.Print(Exception)}"; } }
//Consulta por filtro/////////////////////////////////////////////////////////// public DataSet ConsultarContactosFilter(SqlConnection connection, Filtro filter) { try { using (SqlDataAdapter adapter = new SqlDataAdapter()) { adapter.SelectCommand = ConfigSqlCommandSearch(connection, filter); DataSet ds = new DataSet(); adapter.Fill(ds); return(ds); } } catch (Exception e) { ExceptionPrinter.Print(e); return(null); } }
/// <summary> /// Convert object instance using custom strategy /// </summary> public static Entry EncodeObject(object instance, ICustomSerialization customSerialization) { var instanceType = instance.GetType(); var isValueType = ValueOrStringType(instanceType); var converted = CreateFromType(instanceType, customSerialization); // Value or string are easily value encoded if (isValueType) { converted.Value.Current = ConvertToString(instance, customSerialization.FormatProvider); return(converted); } // Collections are encoded as a root entry with subentries if (converted.Value.Type == EntryValueType.Collection) { var possibleElementValues = customSerialization.PossibleElementValues(instanceType, instanceType); var strategy = CreateStrategy(instance, instance, instanceType, customSerialization); foreach (var entry in strategy.Serialize()) { entry.Value.Possible = possibleElementValues; converted.SubEntries.Add(entry); } return(converted); } // Classes are encoded per-property recursively var filtered = customSerialization.GetProperties(instance.GetType()); foreach (var property in filtered) { var convertedProperty = EncodeProperty(property, customSerialization); object value; try { value = property.GetValue(instance); } catch (Exception ex) { value = ex; // Change type in case of exception convertedProperty.Value.Type = EntryValueType.Exception; } switch (convertedProperty.Value.Type) { case EntryValueType.Collection: // Get collection and iterate if it has entries if (value == null) { break; } var possibleElementValues = customSerialization.PossibleElementValues(property.PropertyType, property); var strategy = CreateStrategy(value, value, property.PropertyType, customSerialization); foreach (var entry in strategy.Serialize()) { entry.Value.Possible = possibleElementValues; convertedProperty.SubEntries.Add(entry); } break; case EntryValueType.Class: var subEntry = value == null ? EncodeClass(property.PropertyType, customSerialization) : EncodeObject(value, customSerialization); convertedProperty.Value.Current = ConvertToString(subEntry.Value.Current, customSerialization.FormatProvider); convertedProperty.SubEntries = subEntry.SubEntries; break; case EntryValueType.Exception: convertedProperty.Value.Current = ExceptionPrinter.Print((Exception)value); break; case EntryValueType.Stream: var stream = value as Stream; if (stream != null) { if (stream.CanSeek) { stream.Seek(0, SeekOrigin.Begin); } convertedProperty.Value.Current = ConvertToBase64(stream); } break; default: convertedProperty.Value.Current = ConvertToString(value, customSerialization.FormatProvider); break; } converted.SubEntries.Add(convertedProperty); } return(converted); }
/// <summary> /// Default constructor with a unsuccessful result based on an exception /// </summary> public InvocationResponse(Exception e) { Success = false; ExceptionType = e.GetType().ToString(); ErrorMessage = ExceptionPrinter.Print(e); }
private SqlCommand ConfigParametersUpdateInsert(SqlCommand cmd, Contacto cont) { try { cmd.Parameters.AddRange(new SqlParameter[] { new SqlParameter() { ParameterName = "@apellidoNombre", Value = cont.apellido_nombre, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@id_genero", Value = cont.id_genero, SqlDbType = SqlDbType.Int }, new SqlParameter() { ParameterName = "@idPais", Value = cont.id_pais, SqlDbType = SqlDbType.Int }, new SqlParameter() { ParameterName = "@localidad", Value = cont.localidad, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@idContInterno", Value = cont.id_cont_int, SqlDbType = SqlDbType.Int }, new SqlParameter() { ParameterName = "@organizacion", Value = cont.organizacion, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@idArea", Value = cont.id_area, SqlDbType = SqlDbType.Int }, new SqlParameter() { ParameterName = "@idActicvo", Value = cont.id_activo, SqlDbType = SqlDbType.Int }, new SqlParameter() { ParameterName = "@direccion", Value = cont.direccion, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@tel_fijo", Value = cont.tel_fijo, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@tel_cel", Value = cont.tel_cel, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@email", Value = cont.e_mail, SqlDbType = SqlDbType.VarChar }, new SqlParameter() { ParameterName = "@skype", Value = cont.skype, SqlDbType = SqlDbType.VarChar } }); return(cmd); } catch (Exception e) { ExceptionPrinter.Print(e); return(null); } }
private void OnModuleStateChanged(object sender, ModuleStateChangedEventArgs stateChanged) { // Reset NoChangeStep _noChangeTimer.Stop(); _noChangeTimer.Start(); // Ignore temporary states if (stateChanged.NewState.HasFlag(ServerModuleState.Initializing)) { return; } // Output state change if (stateChanged.NewState == ServerModuleState.Failure) { var module = (IServerModule)sender; Console.WriteLine("Module {0} failed with Exception:\n", module.Name); Console.WriteLine(ExceptionPrinter.Print(module.Notifications.OrderBy(n => n.Timestamp).Last(n => n.Severity == Severity.Error).Exception)); _failed = true; _awaitStep.Set(); } lock (ModuleManager) { // If we allready failed skip output if (_failed | _timedOut) { return; } var stepDone = false; switch (_currentStep) { case TestStep.StartAll: // Check if all auto start modules are on their feet var autoPlugin = ModuleManager.AllModules.Where(item => ModuleManager.BehaviourAccess <ModuleStartBehaviour>(item).Behaviour == ModuleStartBehaviour.Auto).ToArray(); var running = autoPlugin.Count(item => item.State == ServerModuleState.Running); var allAuto = autoPlugin.Length; if (running == allAuto) { stepDone = true; } Console.WriteLine("{0} of {1} auto started modules are running", running.ToString("D").PadLeft(_digits), allAuto); break; case TestStep.StartManuals: case TestStep.ReincarnateSingle: // Check if target service is back running running = ModuleManager.AllModules.Count(item => item.State == ServerModuleState.Running); if (running == _modulesCount) { stepDone = true; } Console.WriteLine("{0} of {1} modules are running", running.ToString("D").PadLeft(_digits), _modulesCount); break; case TestStep.StopAll: // Check if all auto start modules are stopped var stopped = ModuleManager.AllModules.Count(item => item.State == ServerModuleState.Stopped); if (stopped == _modulesCount) { stepDone = true; } Console.WriteLine("{0} of {1} modules stopped", stopped.ToString("D").PadLeft(_digits), _modulesCount); break; default: throw new ArgumentOutOfRangeException(); } if (stepDone) { _awaitStep.Set(); } } }