Exemplo n.º 1
0
        public static void logMessage(string message, Category category, Priority priority)
        {
            switch (category)
            {
            case Category.Debug:
                logger.Debug(message);
                break;

            case Category.Warn:
                logger.Warn(message);
                break;

            case Category.Exception:
                logger.Error(message);
                break;

            case Category.Info:
                logger.Info(message);
                break;
            }
            if (priority == Priority.High)
            {
                HubFunctions.SendMessage(message);
            }
        }
        public async Task <IHttpActionResult> ImportKtp()
        {
            _logger.Info("Start import ktp ");
            HubFunctions.SendMessage("Start import ktp ");
            HubFunctions.WaitProcess("Import Ktp");
            HttpResponseMessage response = new HttpResponseMessage();
            var httpRequest = HttpContext.Current.Request;

            try
            {
                int i = 0;
                if (httpRequest.Files.Count > 0)
                {
                    foreach (string file in httpRequest.Files)
                    {
                        i++;
                        var hedgeimport = new HedgeImport();
                        var postedFile  = httpRequest.Files[file];
                        //var filePath = HttpContext.Current.Server.MapPath("~/UploadFile/" + postedFile.FileName);
                        var filePath = System.Configuration.ConfigurationManager.AppSettings["ShareFolderPath"] + @"\" + postedFile.FileName;
                        postedFile.SaveAs(filePath);
                        //CALLING A FUNCTION THAT CALCULATES PERCENTAGE AND SENDS THE DATA TO THE CLIENT
                        HubFunctions.SendMessage("file uploded successfully : " + postedFile.FileName);

                        //byte[] buffer = new byte[postedFile.InputStream.Length];
                        //postedFile.InputStream.Seek(0, SeekOrigin.Begin);
                        //postedFile.InputStream.Read(buffer, 0, Convert.ToInt32(postedFile.InputStream.Length));
                        //MemoryStream stream2 = new MemoryStream(buffer);

                        hedgeimport.ImportKtp(filePath);
                        HubFunctions.SendRefreshData("All");
                    }
                }
                _logger.Info("End import ktp ");
                HubFunctions.SendMessage("End import ktp ");
                HubFunctions.EndProcess("Import Ktp");


                //for (int j = 0; j <= 10; j++)
                //{
                //    //SIMULATING SOME TASK
                //    Thread.Sleep(500);

                //    //CALLING A FUNCTION THAT CALCULATES PERCENTAGE AND SENDS THE DATA TO THE CLIENT
                //    Functions.SendProgress("Process in progress...", j, 10);
                //}
                return(Ok());
            }
            catch (Exception exp)
            {
                HubFunctions.EndProcess("ImportKTp");
                HubFunctions.SendMessage("Error in ktp import : " + exp.Message);
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = new StringContent(exp.Message),
                    ReasonPhrase = "Critical Exception : " + exp.Message
                });
            }
        }
Exemplo n.º 3
0
        private void LogAndAddWarningtoData(string warn, ref IDataOutputResult <ExecutionFX> data)
        {
            IWarnings warning = new WarningMessage(warn);

            data.WarningMessage.Add(warning);
            logger.Warn(warn);
            HubFunctions.SendMessage(warn);
        }
Exemplo n.º 4
0
        public async Task <Result> MouseMove([FromBody] MouseEvent evt)
        {
            logger.LogInformation("({0}, {1})", evt.ClientX, evt.ClientY);
            await HubFunctions.FireMouseMove(hub.Clients, evt);

            return(new Result {
                Success = true
            });
        }
Exemplo n.º 5
0
        public async Task <Result> KeyPress([FromBody] KeyPressEvent evt)
        {
            logger.LogInformation("{0} {1}", evt.Key, evt.KeyCode);

            Cached.Add((char)evt.KeyCode);
            await HubFunctions.FireKeyPress(hub.Clients, evt);

            await HubFunctions.FireSummary(hub.Clients, Cached.Dict);

            return(new Result {
                Success = true
            });
        }
        public async Task <IHttpActionResult> LongRunningProcess()
        {
            //THIS COULD BE SOME LIST OF DATA
            int itemsCount = 100;

            for (int i = 0; i <= itemsCount; i++)
            {
                //SIMULATING SOME TASK
                Thread.Sleep(100);

                //CALLING A FUNCTION THAT CALCULATES PERCENTAGE AND SENDS THE DATA TO THE CLIENT
                HubFunctions.SendProgress("Process in progress...", i, itemsCount);
            }
            return(Ok());
        }
Exemplo n.º 7
0
        public JsonResult LongRunningProcess()
        {
            //THIS COULD BE SOME LIST OF DATA
            int itemsCount = 100;

            for (int i = 0; i <= itemsCount; i++)
            {
                //SIMULATING SOME TASK
                Thread.Sleep(100);

                //CALLING A FUNCTION THAT CALCULATES PERCENTAGE AND SENDS THE DATA TO THE CLIENT
                HubFunctions.SendProgress("Process in progress...", i, itemsCount);
            }

            return(Json("", JsonRequestBehavior.AllowGet));
        }
        private string SaveOperations(GetListOperationsOutput operationOutput, string program, DateTime startDate, DateTime endDate, ref Dictionary <int, string> errorMessage)
        {
            var outMessages = new StringBuilder();

            if (operationOutput != null && operationOutput.returnCodes != null && operationOutput.returnCodes.Length > 0)
            {
                errorMessage.Add(operationOutput.returnCodes[0].code, operationOutput.returnCodes[0].message);
            }
            else if (operationOutput != null && operationOutput.listOperations != null && operationOutput.listOperations.Length > 0)
            {
                List <ListOperations> lstOperationOutput = operationOutput.listOperations.Where(o => string.Equals(o.codeAbattement, "0")).ToList();
                try
                {
                    //System.Diagnostics.Stopwatch sw2 = new System.Diagnostics.Stopwatch();
                    //sw2.Start();
                    using (operationBusiness = new OperationBusiness())
                    {
                        HubFunctions.SendMessage($"start Save Operations...");
                        var outmsg = operationBusiness.SaveOperations(lstOperationOutput, program, startDate, endDate, out isSommeErrorsInOperations);
                        outMessages.AppendLine(outmsg);
                        HubFunctions.SendMessage($"End Save Operations...");
                        //calcul de l'exposure sur chaque opeartion par procedure stoqué
                        HubFunctions.SendMessage($"start compute exposure by operation ...");
                        _dataContext.ExecuteStoreCommand("[compute]", new object[] { });
                        HubFunctions.SendMessage($"end compute exposure by operation ...");
                    }
                    //sw2.Stop();
                    //Console.WriteLine("Temps traitement Operations." + (sw2.ElapsedMilliseconds / 1000).ToString() + "s" + "    " + sw2.ElapsedMilliseconds.ToString() + "ms");
                    outMessages.AppendLine("mise à jour operations + contrats réussi");
                }
                catch (Exception exp)
                {
                    throw exp;
                }
                finally
                {
                    if (operationBusiness != null)
                    {
                        ((IDisposable)operationBusiness).Dispose();
                    }
                }
            }

            return(outMessages.ToString());
        }
 public async Task <IHttpActionResult> ImportSignal(string programCode, DateTime startDate, DateTime endDate, string operationsInternes = "")
 {
     try
     {
         string authToken = string.Empty;
         if (Request.Headers.Contains("Authorization"))
         {
             authToken = Request.Headers.GetValues("Authorization").First();
             //check authentification
             _logger.Info("Authorization infos sended from client " + authToken);
         }
         string message = "Start Import Signal " + authToken;
         _logger.Info(message);
         HubFunctions.SendMessage(message);
         HubFunctions.WaitProcess("ImportSignal");
         HttpResponseMessage response = new HttpResponseMessage();
         var httpRequest = HttpContext.Current.Request;
         if (string.IsNullOrEmpty(operationsInternes))
         {
             operationsInternes = "NON";
         }
         var outmessage = await new SignalService().GetOperations("REFERENCE", startDate, endDate, operationsInternes);
         HubFunctions.SendRefreshData("All");
         message = "End import Signal " + authToken;
         _logger.Info(message);
         HubFunctions.SendMessage(message);
         HubFunctions.SendMessage(outmessage);
         HubFunctions.EndProcess("ImportSignal");
         HubFunctions.SendRefreshData("All");
         return(Ok(outmessage));
     }
     catch (Exception exp)
     {
         HubFunctions.EndProcess("ImportSignal");
         HubFunctions.SendMessage("Error in signal import : " + exp.Message);
         throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
         {
             Content      = new StringContent(exp.Message),
             ReasonPhrase = "Critical Exception : " + exp.Message
         });
     }
 }
        public async Task <string> GetOperations(string programCode, DateTime startDate, DateTime endDate, string operationsInternes)
        {
            GetListOperationsOutput operationOutput = null;
            string error      = "";
            var    retryCount = 0;
            var    canRetry   = retryCount < 3;
            Dictionary <int, string> errorMessage = new Dictionary <int, string>();
            var outMessages = string.Empty;

            try
            {
                GetListOperationsInput ReservationsInput = new GetListOperationsInput()
                {
                    principal          = System.Configuration.ConfigurationManager.AppSettings["SignalUser"],
                    subject            = System.Configuration.ConfigurationManager.AppSettings["SignalPassword"],
                    codeProgramme      = programCode,
                    codeNavire         = null,
                    operationsInternes = operationsInternes,
                    dateDebut          = startDate,
                    dateFin            = endDate,
                };

                _logger.Debug($"Calling Signal WS: {_proxy.Endpoint.ListenUri.AbsoluteUri}.");
                //_logger.Debug($"Start importing Signal operations. Criteria: {JsonConvert.SerializeObject(ReservationsInput)}.");
                HubFunctions.SendMessage($"start Calling Signal WS: {_proxy.Endpoint.ListenUri.AbsoluteUri}.");
                _logger.Debug($"Start importing Signal operations. Criteria: {JsonConvert.SerializeObject(ReservationsInput)}.");
                while (canRetry)
                {
                    try
                    {
                        operationOutput = await GetOperations(ReservationsInput);

                        HubFunctions.SendMessage($"end Calling Signal WS");
                        canRetry = false;
                    }
                    catch (Exception ex)
                    {
                        retryCount++;
                        canRetry = retryCount < 3;
                        if (!canRetry)
                        {
                            error = $"An error occurred while calling Signal ExtractionOperationsWS service: {ex.Message}\n";
                            HubFunctions.SendMessage(error);
                            _logger.Error(error);
                            throw;
                        }
                        else
                        {
                            //_logger.Debug($"An error occurred while calling Signal ExtractionOperationsWS service. Waiting for retry..");
                            HubFunctions.SendMessage($"An error occurred while calling Signal ExtractionOperationsWS service. Waiting for retry..");
                            _logger.Error($"An error occurred while calling Signal ExtractionOperationsWS service. Waiting for retry..");
                            await Task.Delay(5000 *retryCount);
                        }
                    }
                }

                if (operationOutput != null && operationOutput.listOperations != null && operationOutput.listOperations.Any())
                {
                    if (operationOutput.returnCodes != null && operationOutput.returnCodes.Length > 0)
                    {
                        // errorMessage.Add(operationOutput.returnCodes[0].code, operationOutput.returnCodes[0].message);
                        outMessages = "ErrorCode: " + operationOutput.returnCodes[0].code + "\n Error message: " + operationOutput.returnCodes[0].message;
                        return(outMessages);
                    }
                    //var listOpe = operations.listOperations.Where(e => e.idPositionCtrm > 0).ToList();
                    outMessages = SaveOperations(operationOutput, programCode, startDate, endDate, ref errorMessage);
                    //calcul de l'exposure sur chaque opeartion par procedure stoqué
                    //_dataContext..ExecuteStoreCommand("[compute]", new object[] { });
                }
            }
            finally
            {
                //CheckProcessCanContinue(_currentProcess, error);
            }

            return(outMessages);
        }