Example #1
0
        private static void GetResponseCallback(IAsyncResult asynchronousResult)
        {
            var exchange = (TransportExchange)asynchronousResult.AsyncState;

            try
            {
                // End the operation
                string responsestring;
                using (var response = (HttpWebResponse)exchange.Request.EndGetResponse(asynchronousResult))
                {
                    using (var streamResponse = response.GetResponseStream())
                    {
                        using (var streamRead = new StreamReader(streamResponse))
                            responsestring = streamRead.ReadToEnd();
                    }

                    if (response.Cookies != null)
                    {
                        foreach (Cookie cookie in response.Cookies)
                        {
                            exchange.AddCookie(cookie);
                        }
                    }
                }
                exchange.Messages = DictionaryMessage.ParseMessages(responsestring);

                exchange.Listener.OnMessages(exchange.Messages);
                exchange.Dispose();
            }
            catch (Exception e)
            {
                exchange.Listener.OnException(e, ObjectConverter.ToListOfIMessage(exchange.Messages));
                exchange.Dispose();
            }
        }
Example #2
0
 public override sealed void LoadMessage()
 {
     DictionaryMessage.Add("msgWarningTitle", "Aviso");
     DictionaryMessage.Add("msgSelectStock", "Selecione um ativo para continuar");
     DictionaryMessage.Add("msgSelectPeriodicity", "Selecione uma periocidade para continuar");
     DictionaryMessage.Add("msgErrLoadStockLocalData", "Ativo não encontrado em nossa base de dados.");
     DictionaryMessage.Add("msgGenerateDataWeekly", "Houve um erro na conversão de dados.");
     DictionaryMessage.Add("msgCandlesMinimum", "Periodicidade solicitada não gerou o número mínimo de candles para exibição.");
     DictionaryMessage.Add("msgIntervalMaximum", "O intervalo para periodicidade intra-diário não pode ser inferior a 1 ou superior a 420 minutos.");
     DictionaryMessage.Add("msgHistoryMaximum", "O intervalo para história intra-diário não pode ser inferior a 2 ou superior a 15000.");
     DictionaryMessage.Add("msgSelectIndicator", "Selecione um indicador para continuar");
     DictionaryMessage.Add("msgPeriodsMinimum", "O período informado tem que ser maior que 0.");
     DictionaryMessage.Add("msgCycleMinimum", "O ciclo informado tem que ser maior que 0.");
     DictionaryMessage.Add("msgPeriodsIsEmpty", "O período informado não pode ser inferior a 0 ou superior a 999.");
     DictionaryMessage.Add("msgThresholdIsEmpty", "O limite deve ser um valor entre 0 e 100.");
     DictionaryMessage.Add("msgCycleIsEmpty", "O ciclo informado não pode ser vazio.");
     DictionaryMessage.Add("msgRemoveIndicatorMock", "Deseja realmente remover o indicator selecionado?");
     DictionaryMessage.Add("msgIndicatorChanged", "Indicador alterado com sucesso!");
     DictionaryMessage.Add("msgIndicatorInserted", "Indicador inserido com sucesso!");
     DictionaryMessage.Add("msgExistingBookmark", "Indicador existente!");
     DictionaryMessage.Add("msgNotRootRemove", "Não é possível remover registros que contém itens.");
     DictionaryMessage.Add("msgTemplateAdded", "Modelo adicionado com sucesso!");
     DictionaryMessage.Add("msgTemplateDeleted", "Modelo removido com sucesso!");
     DictionaryMessage.Add("msgTemplateExists", "Existe informações com essa descrição.");
     DictionaryMessage.Add("msgWorkspaceExists", "Existe informações com essa descrição.");
     DictionaryMessage.Add("msgTemplateChanged", "Modelo alterado com sucesso!");
     DictionaryMessage.Add("msgTemplateEmpty", "Insira um valor no campo modelo!");
     DictionaryMessage.Add("msgWorkspaceEmpty", "Insira um valor no campo workspace!");
     DictionaryMessage.Add("msgTemplateMainNotRemoved", "Modelo principal não pode ser removido.");
     DictionaryMessage.Add("msgWorkspaceMainNotRemoved", "Workspace principal não pode ser removido.");
     DictionaryMessage.Add("msgRemoveWorkspace", "Deseja realmente remover a área de trabalho selecionada?");
     DictionaryMessage.Add("msgRemoveNodeTemplate", "Deseja realmente remover o Template selecionado?");
     DictionaryMessage.Add("msgRemoveAllDrawings", "Deseja remover todos os estudos/desenhos?");
     DictionaryMessage.Add("msgInvalidPeriodicity", "Não há dados para esta periodicidade em ");
 }
        public void EqualsFieldsTest()
        {
            var val1 = new DictionaryMessage()
            {
                Id = Guid.NewGuid(), Value = "NOME DA RUA", Type = "TYPE TESTE"
            };
            var val2 = new DictionaryMessage()
            {
                Id = Guid.NewGuid(), Value = "NOME DA RUA", Type = "TYPE TESTE"
            };

            Assert.Equal(val1, val2);
        }
        public void EqualsIdTest()
        {
            var id   = Guid.NewGuid();
            var val1 = new DictionaryMessage()
            {
                Id = id
            };
            var val2 = new DictionaryMessage()
            {
                Id = id
            };

            Assert.Equal(val1, val2);
        }
        private static void GetResponseCallback(IAsyncResult asynchronousResult)
        {
            var exchange = (TransportExchange)asynchronousResult.AsyncState;

            try
            {
                // End the operation
                string responsestring;
                using (var response = (HttpWebResponse)exchange.Request.EndGetResponse(asynchronousResult))
                {
                    using (var streamResponse = response.GetResponseStream())
                    {
                        using var streamRead = new StreamReader(streamResponse);
                        responsestring       = streamRead.ReadToEnd();
                    }

                    _logger?.LogDebug("Received message(s).");

                    if (response.Cookies != null)
                    {
                        foreach (Cookie cookie in response.Cookies)
                        {
                            exchange.AddCookie(cookie);
                        }
                    }

                    response.Close();
                }

                try
                {
                    exchange.Messages = DictionaryMessage.ParseMessages(responsestring);
                }
                catch (Exception e)
                {
                    _logger?.LogError($"Failed to parse the messages json: {e}");
                }

                exchange.Listener.OnMessages(exchange.Messages);
                exchange.Dispose();
            }
            catch (Exception e)
            {
                exchange.Listener.OnException(e, ObjectConverter.ToListOfIMessage(exchange.Messages));
                exchange.Dispose();
            }
        }
Example #6
0
        public DictionaryMessage LoadModuleAssemblyProperties(string assemblyFullPath)
        {
            var result = new DictionaryMessage();

            if (new FileInfo(assemblyFullPath).Exists)
            {
                var moduleAssemblyFileVersionInfo = FileVersionInfo.GetVersionInfo(assemblyFullPath);
                foreach (var property in moduleAssemblyFileVersionInfo.GetType().GetProperties())
                {
                    result.Properties.Add(property.Name, property.GetValue(moduleAssemblyFileVersionInfo, null).ToString());
                }
            }
            else
            {
                result.Properties["FileVersion"] = "0.0.0.0";
            }

            return(result);
        }
        private static void GetResponseCallback(IAsyncResult asynchronousResult)
        {
            TransportExchange exchange = (TransportExchange)asynchronousResult.AsyncState;

            try
            {
                // End the operation
                string responseString;

                using (HttpWebResponse response = (HttpWebResponse)exchange.request.EndGetResponse(asynchronousResult))
                {
                    using (Stream streamResponse = response.GetResponseStream())
                    {
                        using (StreamReader streamRead = new StreamReader(streamResponse))
                            responseString = streamRead.ReadToEnd();
                    }

                    if (response.Cookies != null)
                    {
                        foreach (Cookie cookie in response.Cookies)
                        {
                            exchange.AddCookie(cookie);
                        }
                    }

                    response.Close();
                }
                exchange.messages = DictionaryMessage.parseMessages(responseString);

                exchange.listener.onMessages(exchange.messages);
                exchange.Dispose();
            }
            catch (Exception e)
            {
                if (!e.Message.Contains("operation has timed out")) // Supress timeout messages due to inactivity
                {
                    exchange.listener.onException(e, ObjectConverter.ToListOfIMessage(exchange.messages));
                }
                exchange.Dispose();
            }
        }
        private static void GetResponseCallback(IAsyncResult asynchronousResult)
        {
            TransportExchange exchange = (TransportExchange)asynchronousResult.AsyncState;

            try
            {
                // End the operation
                string responseString;
                using (HttpWebResponse response = (HttpWebResponse)exchange.request.EndGetResponse(asynchronousResult))
                {
                    using (Stream streamResponse = response.GetResponseStream())
                    {
                        using (StreamReader streamRead = new StreamReader(streamResponse))
                            responseString = streamRead.ReadToEnd();
                    }
                    //Console.WriteLine("Received message(s): {0}", responseString);

#if !SILVERLIGHT
                    if (response.Cookies != null)
                    {
                        foreach (Cookie cookie in response.Cookies)
                        {
                            exchange.AddCookie(cookie);
                        }
                    }
#endif
                    response.Close();
                }
                exchange.messages = DictionaryMessage.parseMessages(responseString);

                exchange.listener.onMessages(exchange.messages);
                exchange.Dispose();
            }
            catch (Exception e)
            {
                exchange.listener.onException(e, ObjectConverter.ToListOfIMessage(exchange.messages));
                exchange.Dispose();
            }
        }
Example #9
0
 public override sealed void LoadMessage()
 {
     DictionaryMessage.Add("msgWarningTitle", "Warning");
     DictionaryMessage.Add("msgSelectStock", "Select an stock to continue");
     DictionaryMessage.Add("msgSelectPeriodicity", "Select a periodicity to continue");
     DictionaryMessage.Add("msgErrLoadStockLocalData", "Active not found in our database");
     DictionaryMessage.Add("msgGenerateDataWeekly", "There was an error in data conversion.");
     DictionaryMessage.Add("msgCandlesMinimum", "Recurrence has not generated the required minimum number of candles for display.");
     DictionaryMessage.Add("msgIntervalMaximum", "The range for intra-day periodicity can not be less than 1 or exceeds 420 minutes.");
     DictionaryMessage.Add("msgHistoryMaximum", "The range for intra-day history can not be less than 2 or exceeds 15000.");
     DictionaryMessage.Add("msgSelectIndicator", "Select a indicator to continue");
     DictionaryMessage.Add("msgPeriodsMinimum", "The reporting period must be greater than 0.");
     DictionaryMessage.Add("msgCycleMinimum", "The cycle is reported to be greater than 0.");
     DictionaryMessage.Add("msgPeriodsIsEmpty", "The reporting period can not be empty.");
     DictionaryMessage.Add("msgThresholdIsEmpty", "The reporting threshold can not be empty.");
     DictionaryMessage.Add("msgCycleIsEmpty", "The cycle entered can not be empty");
     DictionaryMessage.Add("msgRemoveIndicatorMock", "Really remove the indicator selected?");
     DictionaryMessage.Add("msgIndicatorChanged", "Indicator successfully changed!");
     DictionaryMessage.Add("msgIndicatorInserted", "Indicator inserted successfully!");
     DictionaryMessage.Add("msgExistingBookmark", "Existing Bookmark!");
     DictionaryMessage.Add("msgNotRootRemove", "Can not remove records that contain items.");
     DictionaryMessage.Add("msgTemplateAdded", "Template successfully added!");
     DictionaryMessage.Add("msgTemplateDeleted", "Template successfully deleted!");
     DictionaryMessage.Add("msgTemplateExists", "There is information in this description.");
     DictionaryMessage.Add("msgWorkspaceExists", "There is information in this description.");
     DictionaryMessage.Add("msgTemplateChanged", "Template changed successfully!");
     DictionaryMessage.Add("msgTemplateEmpty", "Enter a value in the template!");
     DictionaryMessage.Add("msgWorkspaceEmpty", "Enter a value in the workspace!");
     DictionaryMessage.Add("msgTemplateMainNotRemoved", "Template main not can removed.");
     DictionaryMessage.Add("msgWorkspaceMainNotRemoved", "Workspace main not can removed.");
     DictionaryMessage.Add("msgRemoveStudy", "Really remove the study selected?");
     DictionaryMessage.Add("msgRemoveWorkspace", "Really remove the selected workspace?");
     DictionaryMessage.Add("msgRemoveNodeTemplate", "Really remove the selected template?");
     DictionaryMessage.Add("msgRemoveAllDrawings", "Remove all studies/drawings?");
     DictionaryMessage.Add("msgInvalidPeriodicity", "Invalid periodicity for ");
 }
Example #10
0
        private static void GetResponseCallback(IAsyncResult asyncResult)
        {
            LongPollingRequest exchange = asyncResult.AsyncState as LongPollingRequest;

            try
            {
                string         responseString;
                HttpStatusCode responseStatus;

                // End the operation
                HttpWebResponse response;
                Exception       error = null;
                try
                {
                    response = exchange._request.EndGetResponse(asyncResult) as HttpWebResponse;
                }
                catch (WebException wex)
                {
                    if (wex.Status == WebExceptionStatus.RequestCanceled)
                    {
                        throw;
                    }

                    response = wex.Response as HttpWebResponse;
                    if (null == response)
                    {
                        throw;
                    }

                    error = wex;
                }

                using (response)
                {
                    responseStatus = response.StatusCode;

                    using (StreamReader streamRead = new StreamReader(response.GetResponseStream(), Encoding.UTF8, true))
                    {
                        responseString = streamRead.ReadToEnd();
                        // DEBUG
                        if (logger.IsDebugEnabled)
                        {
                            logger.DebugFormat(CultureInfo.InvariantCulture, "Received message(s): {0}", responseString);
                        }
                    }

                    // Stores the transport Cookies to use for next requests
                    if (response.Cookies != null && response.Cookies.Count > 0)
                    {
                        foreach (Cookie cookie in response.Cookies)
                        {
                            if (null != cookie && (!cookie.Discard || !cookie.Expired))
                            {
                                exchange._transport.SetCookie(cookie);
                            }
                        }
                    }
                }

                if (responseStatus != HttpStatusCode.OK)                // TODO: error != null
                {
                    if (null != exchange._listener)
                    {
                        exchange._listener.OnProtocolError(String.Format(CultureInfo.InvariantCulture,
                                                                         "Unexpected response {0}: {1}", (int)responseStatus, responseString), error, exchange._messages);
                    }
                    else
                    {
                        // DEBUG
                        logger.Error(String.Format(CultureInfo.InvariantCulture,
                                                   "Unexpected response {0}: {1}", (int)responseStatus, responseString), error);
                    }
                }
                else if (responseString != null && (responseString = responseString.Trim()).Length > 0)
                {
                    // TODO: responseString.Replace('"', '\'')
                    IList <IMutableMessage> messages = DictionaryMessage.ParseMessages(responseString);

                    // Backups the transport Timeout value (in milliseconds) to use for next requests
                    foreach (IMutableMessage message in messages)
                    {
                        if (message != null &&
                            message.IsSuccessful &&
                            Channel.MetaConnect.Equals(message.Channel, StringComparison.OrdinalIgnoreCase))
                        {
                            IDictionary <string, object> advice = message.Advice;
                            object timeout;
                            if (advice != null &&
                                advice.TryGetValue(Message.TimeoutField, out timeout) &&
                                timeout != null && timeout.ToString().Trim().Length > 0)
                            {
                                exchange._transport.Advice = advice;
                            }
                        }
                    }

                    if (null != exchange._listener)
                    {
                        // Fixes the received messages before processing
                        string requestChannel = null;
                        string requestUrl, baseUrl;
                        foreach (IMutableMessage msg in messages)
                        {
                            if (String.IsNullOrEmpty(msg.Channel))
                            {
                                if (null == requestChannel)
                                {
                                    requestUrl = exchange._request.RequestUri.ToString();                                    // Absolute request URI

                                    baseUrl = exchange._transport.Url;
                                    baseUrl = (null == baseUrl) ? String.Empty : baseUrl.Trim();

                                    if (requestUrl.StartsWith(baseUrl, StringComparison.OrdinalIgnoreCase))
                                    {
                                        requestChannel = requestUrl.Substring(baseUrl.Length).Trim('\\', '/');
                                        requestChannel = Channel.Meta.TrimEnd('\\', '/') + "/" + requestChannel;
                                    }
                                    else
                                    {
                                        requestChannel = String.Empty;
                                    }
                                }

                                if (!String.IsNullOrEmpty(requestChannel))
                                {
                                    msg.Channel = requestChannel;
                                }
                            }
                        }

                        exchange._listener.OnMessages(messages);
                    }
                }
                else
                {
                    if (null != exchange._listener)
                    {
                        exchange._listener.OnProtocolError(String.Format(CultureInfo.InvariantCulture,
                                                                         "Empty response (204) from URL: {0}", exchange._request.RequestUri), null, exchange._messages);
                    }
                    else
                    {
                        // DEBUG
                        logger.ErrorFormat(CultureInfo.InvariantCulture, "Empty response (204) from URL: {0}", exchange._request.RequestUri);
                    }
                }
            }
            catch (Exception ex)
            {
                if (null != exchange._listener && !exchange._aborted)
                {
                    exchange._listener.OnException(ex, exchange._messages);
                }
                else
                {
                    logger.Error(ex);                    // DEBUG
                }
            }
            finally
            {
                exchange._isSending = false;
                exchange._transport.RemoveRequest(exchange);
            }
        }
        public void EqualsInstanceTest()
        {
            var val1 = new DictionaryMessage();

            Assert.Equal(val1, val1);
        }
        public void EmpityFiedTest()
        {
            var validators = new DictionaryMessage().Validate();

            Assert.True(validators.Count(c => c.MessageType.Equals(nameof(FieldValueException))) == 6);
        }