コード例 #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);
            }
        }
コード例 #2
0
        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
                });
            }
        }
コード例 #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);
        }
コード例 #4
0
        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());
        }
コード例 #5
0
 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
         });
     }
 }
コード例 #6
0
        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);
        }