public DivRes Post([FromBody] DivReq value)
        {
            DivRes result = new DivRes();

            try
            {
                /*  Realiza la division entre el Dividend y el Divisor obtenidos de la peticion,
                 *  cuando el encabezado no contiene el identificador "X-Evi-Tracking-Id"
                 */
                if (String.IsNullOrEmpty(Request.Headers["X-Evi-Tracking-Id"]))
                {
                    result.Quotient  = value.Dividend / value.Divisor;
                    result.Remainder = value.Dividend % value.Divisor;
                }

                /* Si el encabezado contiene el "X-Evi-Tracking-Id" se efectua la operacion
                 * y se crea un archivo con el nombre del id del usuario y los datos de la
                 * operacion realizada
                 */
                else
                {
                    result.Quotient  = value.Dividend / value.Divisor;
                    result.Remainder = value.Dividend % value.Divisor;
                    LogJournal logJournal = new LogJournal(Request.Headers["X-Evi-Tracking-Id"]);
                    logJournal.Add("{" + "\"" + "Operation" + "\"" + ": " + "\"" + "Div" + "\"" + ", " + "\"" + "Calculation" + "\"" + ": " + "\"" + value.Dividend + " / " + value.Divisor + " result: Quotient = " + result.Quotient + " Remainder = " + result.Remainder + "\"" + ", " + "\"" + "Date" + "\"" + ": " + "\"" + DateTime.Now.ToString("u") + "\"" + "}");
                }
            }
            catch (Exception ex)
            {
                Log log = new Log();
                log.Add("Error en SubController.cs " + ex.Message);
            }

            return(result);
        }
Exemplo n.º 2
0
        internal static void StopService()
        {
            try
            {
                if (ms_ServiceHost != null)
                {
                    if (ms_ServiceHost.State != CommunicationState.Opened)
                    {
                        ms_ServiceHost.Abort();
                    }
                    else
                    {
                        ms_ServiceHost.Close();
                    }

                    ms_ServiceHost = null;
                }
            }
            catch (Exception ex)
            {
                Journal.AppendLog("SystemHost", LogJournalMessageType.Warning,
                                  String.Format("SCME Network printing service can not be stopped properly: {0}", ex.Message));
            }

            if (Journal != null)
            {
                Journal.AppendLog("SystemHost", LogJournalMessageType.Info, "SCME Network printing service stopped");
                Journal.Close();
                Journal = null;
            }
        }
        public SqrtRes Post([FromBody] SqrtReq value)
        {
            SqrtRes result = new SqrtRes();

            try
            {
                /*  Obtiene la raiz cuadrada del numero dentro de la peticion,
                 *  cuando el encabezado no contiene el identificador "X-Evi-Tracking-Id"
                 */
                if (String.IsNullOrEmpty(Request.Headers["X-Evi-Tracking-Id"]))
                {
                    result.Square = Math.Sqrt(value.Number);
                }

                /* Si el encabezado contiene el "X-Evi-Tracking-Id" se efectua la operacion
                 * y se crea un archivo con el nombre del id del usuario y los datos de la
                 * operacion realizada
                 */
                else
                {
                    result.Square = Math.Sqrt(value.Number);
                    LogJournal logJournal = new LogJournal(Request.Headers["X-Evi-Tracking-Id"]);
                    logJournal.Add("{" + "\"" + "Operation" + "\"" + ": " + "\"" + "Sqrt" + "\"" + ", " + "\"" + "Calculation" + "\"" + ": " + "\"" + value.Number + " root  = " + result.Square + "\"" + ", " + "\"" + "Date" + "\"" + ": " + "\"" + DateTime.Now.ToString("u") + "\"" + "}");
                }
            }
            catch (Exception ex)
            {
                Log log = new Log();
                log.Add("Error en SubController.cs " + ex.Message);
            }

            return(result);
        }
Exemplo n.º 4
0
        public AddRes Post([FromBody] AddReq value)
        {
            //Retorna BadRequest si la cantidad de operandos es menor a 2
            if (value.Addends.Length < 1)
            {
                //throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            AddRes result = new AddRes();

            result.Sum = 0;
            try
            {
                AddReq numbers = value;

                /*  Realiza la suma para cada uno de los numeros dentro de la peticion,
                 *  cuando el encabezado no contiene el identificador "X-Evi-Tracking-Id"
                 */
                if (String.IsNullOrEmpty(Request.Headers["X-Evi-Tracking-Id"]))
                {
                    foreach (float number in numbers.Addends)
                    {
                        result.Sum += number;
                    }
                }

                /* Si el encabezado contiene el "X-Evi-Tracking-Id" se efectua la operacion
                 * y se crea un archivo con el nombre del id del usuario y los datos de la
                 * operacion realizada
                 */
                else
                {
                    string operation = "";
                    foreach (float number in numbers.Addends)
                    {
                        result.Sum += number;
                        operation  += number + " + ";
                    }
                    LogJournal logJournal = new LogJournal(Request.Headers["X-Evi-Tracking-Id"]);
                    logJournal.Add("{" + "\"" + "Operation" + "\"" + ": " + "\"" + "Sum" + "\"" + ", " + "\"" + "Calculation" + "\"" + ": " + "\"" + operation.Substring(0, operation.Length - 3) + " = " + result.Sum + "\"" + ", " + "\"" + "Date" + "\"" + ": " + "\"" + DateTime.Now.ToString("u") + "\"" + "}");
                }
            }
            catch (Exception ex) {
                Log log = new Log();
                log.Add("Error en AddController.cs " + ex.Message);
            }

            return(result);
        }
Exemplo n.º 5
0
        internal static void StopService()
        {
            try
            {
                if (ms_ServiceHost != null)
                {
                    if (ms_ServiceHost.State != CommunicationState.Opened)
                    {
                        ms_ServiceHost.Abort();
                    }
                    else
                    {
                        ms_ServiceHost.Close();
                    }

                    ms_ServiceHost = null;
                }

                if (_databaseServiceHost != null)
                {
                    if (_databaseServiceHost.State != CommunicationState.Opened)
                    {
                        _databaseServiceHost.Abort();
                    }
                    else
                    {
                        _databaseServiceHost.Close();
                    }

                    _databaseServiceHost = null;
                }
            }
            catch (Exception ex)
            {
                Journal.AppendLog("SystemHost", LogJournalMessageType.Warning,
                                  $"SCME database service can not be stopped properly: {ex.Message}");
            }

            if (Journal != null)
            {
                Journal.AppendLog("SystemHost", LogJournalMessageType.Info, "SCME database service stopped");
                Journal.Close();
                Journal = null;
            }
        }
Exemplo n.º 6
0
        public MultRes Post([FromBody] MultReq value)
        {
            MultRes result = new MultRes();

            result.Product = 1;
            try
            {
                MultReq numbers = value;

                /*  Realiza la multiplicacion cada uno de los numeros dentro de la peticion,
                 *  cuando el encabezado no contiene el identificador "X-Evi-Tracking-Id"
                 */
                if (String.IsNullOrEmpty(Request.Headers["X-Evi-Tracking-Id"]))
                {
                    foreach (float number in numbers.Factors)
                    {
                        result.Product *= number;
                    }
                }

                /* Si el encabezado contiene el "X-Evi-Tracking-Id" se efectua la operacion
                 * y se crea un archivo con el nombre del id del usuario y los datos de la
                 * operacion realizada
                 */
                else
                {
                    string operation = "";
                    foreach (float number in numbers.Factors)
                    {
                        result.Product *= number;
                        operation      += number + " x ";
                    }
                    LogJournal logJournal = new LogJournal(Request.Headers["X-Evi-Tracking-Id"]);
                    logJournal.Add("{" + "\"" + "Operation" + "\"" + ": " + "\"" + "Mult" + "\"" + ", " + "\"" + "Calculation" + "\"" + ": " + "\"" + operation.Substring(0, operation.Length - 3) + " = " + result.Product + "\"" + ", " + "\"" + "Date" + "\"" + ": " + "\"" + DateTime.Now.ToString("u") + "\"" + "}");
                }
            }
            catch (Exception ex)
            {
                Log log = new Log();
                log.Add("Error en AddController.cs " + ex.Message);
            }

            return(result);
        }
        public OperationRes Post([FromBody] OperationReq value)
        {
            OperationRes result = new OperationRes();
            try
            {
                /*  Lee el archivo que pertenece al usuario que hace la peticion
                 *  y obtiene un objeto List Journal Con las operaciones efectuadas por el usuario
                 */
                LogJournal logJournal = new LogJournal(value.Id);
                result.Operations = logJournal.Read(value.Id);
                
            }
            catch (Exception ex)
            {
                Log log = new Log();
                log.Add("Error en AddController.cs " + ex.Message);
            }
            return result;


        }
Exemplo n.º 8
0
        internal static void StartService()
        {
            Journal = new LogJournal();

            try
            {
                var path = String.Format(Settings.Default.LogPathTemplate,
                                         DateTime.Now.ToString(CultureInfo.CurrentCulture).Replace('/', '_').Replace(':', '_'));

                if (!Path.IsPathRooted(path))
                {
                    path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path);
                }

                Journal.Open(path, true, true);
            }
            catch (Exception ex)
            {
                LogCriticalErrorMessage(ex);
                return;
            }

            try
            {
                ms_ServiceHost = new ServiceHost(typeof(PrintingServer));
                ms_ServiceHost.Open();
            }
            catch (Exception ex)
            {
                Journal.AppendLog("SystemHost", LogJournalMessageType.Error,
                                  String.Format("Error starting network printing service: {0}", ex.Message));
                return;
            }

            Journal.AppendLog("SystemHost", LogJournalMessageType.Info,
                              String.Format("SCME Network printing service started on {0}",
                                            ms_ServiceHost.BaseAddresses.FirstOrDefault()));
        }
Exemplo n.º 9
0
        internal static void StartService()
        {
            Journal = new LogJournal();

            try
            {
                var path = String.Format(Settings.Default.LogPathTemplate,
                                         DateTime.Now.ToString(CultureInfo.CurrentCulture).Replace('/', '_').Replace(':', '_'));

                if (!Path.IsPathRooted(path))
                {
                    path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path);
                }

                Journal.Open(path, true, true);
            }
            catch (Exception ex)
            {
                LogCriticalErrorMessage(ex);
                return;
            }

//            try
//            {
//                SQLDatabaseService dbForMigration = new SQLDatabaseService(SQLCentralDatabaseService.GetConnectionStringFromSettings(Settings.Default));
//                dbForMigration.Open();
//                dbForMigration.Migrate();
//                dbForMigration.Close();
//            }
//            catch (Exception ex)
//            {
//                Journal.AppendLog("Central DB SQL SERVER migration", LogJournalMessageType.Error, String.Format("Migrate database error: {0}", ex.Message));
//                return;
//            }

            try
            {
                var service = new SQLCentralDatabaseService(Settings.Default);
                ms_ServiceHost = new ServiceHost(service);
                var behaviour = ms_ServiceHost.Description.Behaviors.Find <ServiceBehaviorAttribute>();
                behaviour.InstanceContextMode = InstanceContextMode.Single;
                ms_ServiceHost.Open();
            }
            catch (Exception ex)
            {
                Journal.AppendLog("SystemHost", LogJournalMessageType.Error,
                                  $"Error starting database service: {ex.Message}");
                return;
            }

            try
            {
                MSSQLDbService mssqlDbService;
                _databaseServiceHost = new ServiceHost(mssqlDbService = new MSSQLDbService(new  SqlConnection(new SqlConnectionStringBuilder()
                {
                    DataSource         = Settings.Default.DbPath,
                    InitialCatalog     = Settings.Default.DBName,
                    IntegratedSecurity = Settings.Default.DBIntegratedSecurity,
                    UserID             = Settings.Default.DBUser,
                    Password           = Settings.Default.DBPassword,
                    ConnectTimeout     = 5
                }.ToString()), false));
                var behaviour = _databaseServiceHost.Description.Behaviors.Find <ServiceBehaviorAttribute>();
                behaviour.InstanceContextMode = InstanceContextMode.Single;
                mssqlDbService.Migrate();
                _databaseServiceHost.Open();
            }
            catch (Exception ex)
            {
                Journal.AppendLog("SystemHost", LogJournalMessageType.Error,
                                  $"Error starting database service: {ex?.InnerException?.ToString() ?? ex.ToString()}");
                return;
            }

            Journal.AppendLog("SystemHost", LogJournalMessageType.Info,
                              $"SCME database service started on {_databaseServiceHost.BaseAddresses.FirstOrDefault()}");
        }