예제 #1
0
        /// <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>
        /// 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));
        }
예제 #3
0
        /// <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);
     }
 }
예제 #5
0
        /// <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!");
     }
 }
예제 #8
0
        /// <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);
            }
        }
예제 #10
0
        private void UpdateFormSettings()
        {
            Exception exception;
            int       counter = 0;

            try
            {
                while (!SaveFormSettings(Settings, out exception))
                {
                    counter++;
                    if (counter > 4)
                    {
                        throw new Exception("Failed to save to FormSettings.json after 5 tries", exception);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionPrinter.PrintException(ex, "Error saving settings to FormSettings.json");
            }
        }
예제 #11
0
        /// <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);
            }
        }
예제 #14
0
        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();
                }
            }
        }
예제 #15
0
        public ProcessInfoForm(int listMax)
        {
            InitializeComponent();

            FormSettingsSaveTimer          = new System.Timers.Timer(600000);
            FormSettingsSaveTimer.Elapsed += (s, e) =>
            {
                UpdateFormSettings();
            };

            ListMax = listMax;

            ContextMenu OverviewCpuCM = new ContextMenu(new MenuItem[]
            {
                new MenuItem("Resize X-Axis", (s, e) =>
                {
                    int value = new IntegerInput((int)OverviewCpuChart.ChartAreas[0].AxisX.Maximum, ListMax).ShowFormDialog();
                    OverviewCpuChart.ChartAreas[0].AxisX.Maximum = value;
                    Settings.OverviewCpuMax = value;
                })
            });

            OverviewCpuChart.ContextMenu = OverviewCpuCM;

            ContextMenu OverviewMemoryCM = new ContextMenu(new MenuItem[]
            {
                new MenuItem("Resize X-Axis", (s, e) =>
                {
                    int value = new IntegerInput((int)OverviewMemChart.ChartAreas[0].AxisX.Maximum, ListMax).ShowFormDialog();
                    OverviewMemChart.ChartAreas[0].AxisX.Maximum = value;
                    Settings.OverviewMemoryMax = value;
                })
            });

            OverviewMemChart.ContextMenu = OverviewMemoryCM;

            ContextMenu OverviewIOCM = new ContextMenu(new MenuItem[]
            {
                new MenuItem("Resize X-Axis", (s, e) =>
                {
                    int value = new IntegerInput((int)OverviewIoChart.ChartAreas[0].AxisX.Maximum, ListMax).ShowFormDialog();
                    OverviewIoChart.ChartAreas[0].AxisX.Maximum = value;
                    Settings.OverviewIoMax = value;
                })
            });

            OverviewIoChart.ContextMenu = OverviewIOCM;

            ContextMenu MemoryWSCM = new ContextMenu(new MenuItem[]
            {
                new MenuItem("Resize X-Axis", (s, e) =>
                {
                    int value = new IntegerInput((int)MemoryWorkingSetChart.ChartAreas[0].AxisX.Maximum, ListMax).ShowFormDialog();
                    MemoryWorkingSetChart.ChartAreas[0].AxisX.Maximum = value;
                    Settings.MemoryWorkingSetMax = value;
                })
            });

            MemoryWorkingSetChart.ContextMenu = MemoryWSCM;

            ContextMenu MemoryPageFileCM = new ContextMenu(new MenuItem[]
            {
                new MenuItem("Resize X-Axis", (s, e) =>
                {
                    int value = new IntegerInput((int)MemoryPageFileChart.ChartAreas[0].AxisX.Maximum, ListMax).ShowFormDialog();
                    MemoryPageFileChart.ChartAreas[0].AxisX.Maximum = value;
                    Settings.MemoryPageFileMax = value;
                })
            });

            MemoryPageFileChart.ContextMenu = MemoryPageFileCM;

            ContextMenu MemoryVirtualCM = new ContextMenu(new MenuItem[]
            {
                new MenuItem("Resize X-Axis", (s, e) =>
                {
                    int value = new IntegerInput((int)MemoryVirtualChart.ChartAreas[0].AxisX.Maximum, ListMax).ShowFormDialog();
                    MemoryVirtualChart.ChartAreas[0].AxisX.Maximum = value;
                    Settings.MemoryVirtualMax = value;
                })
            });

            MemoryVirtualChart.ContextMenu = MemoryVirtualCM;

            ContextMenu MemoryPoolCM = new ContextMenu(new MenuItem[]
            {
                new MenuItem("Resize X-Axis", (s, e) =>
                {
                    int value = new IntegerInput((int)MemoryPoolChart.ChartAreas[0].AxisX.Maximum, ListMax).ShowFormDialog();
                    MemoryPoolChart.ChartAreas[0].AxisX.Maximum = value;
                    Settings.MemoryPoolMax = value;
                })
            });

            MemoryPoolChart.ContextMenu = MemoryPoolCM;

            ContextMenu IOReadWriteCM = new ContextMenu(new MenuItem[]
            {
                new MenuItem("Resize X-Axis", (s, e) =>
                {
                    int value = new IntegerInput((int)IOReadWriteChart.ChartAreas[0].AxisX.Maximum, ListMax).ShowFormDialog();
                    IOReadWriteChart.ChartAreas[0].AxisX.Maximum = value;
                    Settings.IoReadWriteMax = value;
                })
            });

            IOReadWriteChart.ContextMenu = IOReadWriteCM;

            ContextMenu IODataOtherCM = new ContextMenu(new MenuItem[]
            {
                new MenuItem("Resize X-Axis", (s, e) =>
                {
                    int value = new IntegerInput((int)IODataOtherChart.ChartAreas[0].AxisX.Maximum, ListMax).ShowFormDialog();
                    IODataOtherChart.ChartAreas[0].AxisX.Maximum = value;
                    Settings.IoDataOtherMax = value;
                })
            });

            IODataOtherChart.ContextMenu = IODataOtherCM;

            XValues = new int[listMax];

            for (int i = 0; i < XValues.Length; i++)
            {
                XValues[i] = i;
            }

            Exception exception;
            int       counter = 0;

            try
            {
                while (!CreateFormSettings(out exception))
                {
                    counter++;
                    if (counter > 4)
                    {
                        throw new Exception("Failed to create FormSettings.json after 5 tries", exception);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionPrinter.PrintException(ex, "Error creating FormSettings.json");
            }

            exception = null;
            counter   = 0;
            try
            {
                while (!LoadFormSettings(out exception))
                {
                    counter++;
                    if (counter > 4)
                    {
                        throw new Exception("Failed to load form settings from FormSettings.json after 5 tries", exception);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionPrinter.PrintException(ex, "Error reading settings from FormSettings.json");
            }
        }