Example #1
0
        public Task ReceiveAsync(IContext context)
        {
            switch (context.Message)
            {
            case Started _:
                _logger.Warning($"Worker {context.Self} restarting...");
                context.Send(context.Self !, new StartCracking());
                break;

            case Stopping _:
                _logger.Error($"Worker {context.Self} stopping...");
                break;

            case Stopped _:
                _logger.Error($"Worker {context.Self} stopped");
                break;

            case Restarting _:
                _logger.Warning($"Worker {context.Self} restarting...");
                break;

            case StartCracking _:
                StartCrack(context);
                break;

            case RequestNumKeysTried _:
                context.Send(context.Parent !, new ResponseNumKeysTried(NumKeysTried));
                break;
            }
            return(Task.CompletedTask);
        }
Example #2
0
        public List <T> GetJsonSerializedObjsFromFile <T>(string path, string extension = "", SearchOption searchOptions = SearchOption.TopDirectoryOnly)
        {
            var result = new List <T>();

            try
            {
                var letterFiles = Util.GetAllFilesInDir
                                      (path, $"*.{extension}", SearchOption.AllDirectories);

                foreach (var letterFilePath in letterFiles)
                {
                    if (!File.Exists(letterFilePath))
                    {
                        continue;
                    }

                    var letterContent = File.ReadAllText(letterFilePath);

                    if (string.IsNullOrWhiteSpace(letterContent))
                    {
                        continue;
                    }

                    var letter = DeserializeFromJson <T>(letterContent);

                    result.Add(letter);
                }
            }
            catch (Exception ex)
            {
                _logger.Error($"Error encountered deserializing {typeof(T).Name} objects from {path}", ex);
            }

            return(result);
        }
Example #3
0
        public TcpClient Connect()
        {
            var socket = new TcpClient();

            try
            {
                socket = new TcpClient(IQFeedConfiguration.IQFeedHostName, IQFeedConfiguration.IQFeedHistoryPort);
            }
            catch (SocketException ex)
            {
                _logger.Error(ex.Message);
            }

            return(socket);
        }
Example #4
0
        public async Task <T> GetTypeAsync <T>(string resourceUrl)
        {
            T results = default(T);

            try
            {
                var client = CreateHttpClient();
                //var response = await client.GetAsync(resourceUrl);
                var response = client.GetAsync(resourceUrl).Result;

                if (response.IsSuccessStatusCode)
                {
                    var responseText = await response.Content.ReadAsStringAsync();

                    results = JsonConvert.DeserializeObject <T>(responseText);
                }
                else
                {
                    _logger.Error($"Error making call to {resourceUrl}");
                    return(default(T));
                }
            }
            catch (Exception e)
            {
                var eMessage = e.Message;
            }

            return(results);
        }
        public bool SaveLegislatorToFile(string filePath, List <Legislator> legislators)
        {
            try
            {
                var serializedLegislators = JsonConvert.SerializeObject(legislators);

                File.WriteAllText(filePath, serializedLegislators);

                return(true);
            }
            catch (Exception e)
            {
                MyLogger.Error($"Error occurred saving legislator to file {filePath}", e);
                return(false);
            }
        }
        public bool DeleteLetterById(string letterId)
        {
            if (string.IsNullOrWhiteSpace(letterId))
            {
                _logger.Error("Cannot delete letter,  letterId is null or empty.");
                return(true);
            }

            return(_provider.DeleteLetterById(letterId));
        }
        protected async Task <T> GetMemberResults <T>(string legislatorsUri, ApiBase apiSvc, Func <string, string> actionToPerformOnJsonOutput = null) where T : class
        {
            try
            {
                var client = apiSvc.CreateHttpClient();

                //TODO RM (Low Priority): Ensure this is async
                var response = client.GetAsync(legislatorsUri).Result;
                //var response = await client.GetAsync(legislatorsByZipUri); //TODO Find out why this fails
                //http://stackoverflow.com/questions/10343632/httpclient-getasync-never-returns-when-using-await-async


                if (response.IsSuccessStatusCode)
                {
                    //var responseText = await response.Content.ReadAsStringAsync();
                    var responseText = response.Content.ReadAsStringAsync().Result;

                    if (actionToPerformOnJsonOutput != null)
                    {
                        responseText = actionToPerformOnJsonOutput(responseText);
                    }

                    var results = JsonConvert.DeserializeObject <T>(responseText);

                    return(results);
                }
                else
                {
                    _logger.Error($"Error occurred retrieving legislators using URI: {legislatorsUri}");
                }
            }
            catch (Exception e)
            {
                _logger.Error("Error retrieving legislators.", e);
            }

            return(null);
        }
Example #8
0
        public IActionResult PublicAccountCallback([FromQuery] string signature, [FromQuery] string timestamp, [FromQuery] string nonce, [FromQuery] string echostr)
        {
            try
            {
                _logger.Info(echostr, signature, timestamp, nonce);

                CheckSignature checkSignature = new CheckSignature(_weChatSettings.Value.token);

                if (checkSignature.IsValidSignature(timestamp, nonce, signature))
                {
                    return(Ok(echostr));
                }
                else
                {
                    return(Unauthorized());
                }
            }
            catch (Exception e)
            {
                _logger.Error(e.ToString());
                return(StatusCode(500));
            }
        }
        public void SendRequest(string request, NetworkStream network)
        {
            var result = CreateSendRequest(request);

            if (network.CanWrite)
            {
                network.Write(result, 0, result.Length);
                network.Flush();
            }
            else
            {
                _logger.Error("You cannon write in stream");
            }
        }
Example #10
0
        public static bool DeleteFile(string filePath, IMyLogger logger)
        {
            if (!File.Exists(filePath))
            {
                return(true);
            }

            try
            {
                File.Delete(filePath);
                return(true);
            }
            catch (Exception ex)
            {
                logger.Error($"Unable to delete file in path {filePath}.", ex);
                return(false);
            }
        }
        public string CreateQuery(IRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            var dlr = IQFeedConfiguration.Delimiter;
            var trm = IQFeedConfiguration.Terminater;

            var query = string.Empty;

            switch (request.TimeFrame)
            {
            case "Tick Days":
                //HTD,[Symbol],[Days],[MaxDatapoints],[BeginFilterTime],[EndFilterTime],[DataDirection],[RequestID],[DatapointsPerSend]<CR><LF>
                //Retrieves ticks for the previous [Days] days for the specified [Symbol].
                //[Symbol] - Required - Max Length 30 characters.
                //[Days] - Required - The number of calendar days ("1" equals current day) of tick history to be retrieved
                //[MaxDatapoints] - Optional - the maximum number of data points to be retrieved.
                //[BeginFilterTime] - Optional - Format HHmmSS - Allows you to specify the earliest time of day (EST) for which to receive data.
                //[EndFilterTime] - Optional - Format HHmmSS - Allows you to specify the latest time of day (EST) for which to receive data.
                //[DataDirection] - Optional - '0' (default) for "newest to oldest" or '1' for "oldest to newest".
                //[RequestID] - Optional - Will be sent back at the start of each line of data returned for this request.
                //[DatapointsPerSend] - Optional - Specifies the number of data points that IQConnect.exe will queue before attempting to send across the socket to your app.
                query =
                    IQFeedConfiguration.TickDaysHeader + dlr +
                    request.CurrentSymbol + dlr +
                    request.Days + dlr +
                    request.MaxDatapoints + dlr +
                    request.BeginFilterTime + dlr +
                    request.EndFilterTime + dlr + request.DataDirection + dlr +
                    request.DatapointsPerSend + trm;

                _logger.Info(query);
                break;

            case "Tick Interval":
                //HTT,[Symbol],[BeginDate BeginTime],[EndDate EndTime],[MaxDatapoints],[BeginFilterTime],[EndFilterTime],[DataDirection],[RequestID],[DatapointsPerSend]<CR><LF>
                //Retrieves tick data between [BeginDate BeginTime] and [EndDate EndTime] for the specified [Symbol].
                //[Symbol] - Required - Max Length 30 characters.
                //[BeginDate BeginTime] - Required if [EndDate EndTime] not specified - Format CCYYMMDD HHmmSS - Earliest date/time to receive data for.
                //[EndDate EndTime] - Required if [BeginDate BeginTime] not specified - Format CCYYMMDD HHmmSS - Most recent date/time to receive data for.
                //[MaxDatapoints] - Optional - the maximum number of data points to be retrieved.
                //[BeginFilterTime] - Optional - Format HHmmSS - Allows you to specify the earliest time of day (EST) for which to receive data.
                //[EndFilterTime] - Optional - Format HHmmSS - Allows you to specify the latest time of day (EST) for which to receive data.
                //[DataDirection] - Optional - '0' (default) for "newest to oldest" or '1' for "oldest to newest".
                //[RequestID] - Optional - Will be sent back at the start of each line of data returned for this request.
                //[DatapointsPerSend] - Optional - Specifies the number of data points that IQConnect.exe will queue before attempting to send across the socket to your app.
                query =
                    IQFeedConfiguration.TickIntervalHeader + dlr +
                    request.CurrentSymbol + dlr +
                    request.BeginDateTime + dlr +
                    request.EndDateTime + dlr +
                    request.MaxDatapoints + dlr +
                    request.BeginFilterTime + dlr +
                    request.EndFilterTime + dlr +
                    request.DataDirection + dlr +
                    request.DatapointsPerSend + trm;

                _logger.Info(query);
                break;

            case "Intraday Days":
                //HID,[Symbol],[Interval],[Days],[MaxDatapoints],[BeginFilterTime],[EndFilterTime],[DataDirection],[RequestID],[DatapointsPerSend]<CR><LF>
                //Retrieves [Days] days of interval data for the specified [Symbol].
                //[Symbol] - Required - Max Length 30 characters.
                //[Interval] - Required - The interval in seconds.
                //[Days] - Required - The number of calendar days ("1" equals current day) of tick history to be retrieved
                //[MaxDatapoints] - Optional - the maximum number of data points to be retrieved.
                //[BeginFilterTime] - Optional - Format HHmmSS - Allows you to specify the earliest time of day (EST) for which to receive data.
                //[EndFilterTime] - Optional - Format HHmmSS - Allows you to specify the latest time of day (EST) for which to receive data.
                //[DataDirection] - Optional - '0' (default) for "newest to oldest" or '1' for "oldest to newest".
                //[RequestID] - Optional - Will be sent back at the start of each line of data returned for this request.
                //[DatapointsPerSend] - Optional - Specifies the number of data points that IQConnect.exe will queue before attempting to send across the socket to your app.
                query =
                    IQFeedConfiguration.IntradayDaysHeader + dlr +
                    request.CurrentSymbol + dlr +
                    request.Interval + dlr +
                    request.Days + dlr +
                    request.DatapointsPerSend + dlr +
                    request.BeginFilterTime + dlr +
                    request.EndFilterTime + dlr +
                    request.DataDirection + dlr +
                    request.DatapointsPerSend + trm;

                _logger.Info(query);
                break;

            case "Intraday Interval":
                //HIT,[Symbol],[Interval],[BeginDate BeginTime],[EndDate EndTime],[MaxDatapoints],[BeginFilterTime],[EndFilterTime],[DataDirection],[RequestID],[DatapointsPerSend]<CR><LF>
                //Retrieves interval data between [BeginDate BeginTime] and [EndDate EndTime] for the specified [Symbol].
                //[Symbol] - Required - Max Length 30 characters.
                //[Interval] - Required - The interval in seconds.
                //[BeginDate BeginTime] - Required if [EndDate EndTime] not specified - Format CCYYMMDD HHmmSS - Earliest date/time to receive data for.
                //[EndDate EndTime] - Required if [BeginDate BeginTime] not specified - Format CCYYMMDD HHmmSS - Most recent date/time to receive data for.
                //[MaxDatapoints] - Optional - the maximum number of data points to be retrieved.
                //[BeginFilterTime] - Optional - Format HHmmSS - Allows you to specify the earliest time of day (EST) for which to receive data.
                //[EndFilterTime] - Optional - Format HHmmSS - Allows you to specify the latest time of day (EST) for which to receive data.
                //[DataDirection] - Optional - '0' (default) for "newest to oldest" or '1' for "oldest to newest".
                //[RequestID] - Optional - Will be sent back at the start of each line of data returned for this request.
                //[DatapointsPerSend] - Optional - Specifies the number of data points that IQConnect.exe will queue before attempting to send across the socket to your app.
                query =
                    IQFeedConfiguration.IntradayIntervalHeader + dlr +
                    request.CurrentSymbol + dlr +
                    request.Interval + dlr +
                    request.BeginDateTime + dlr +
                    request.EndDateTime + dlr +
                    request.MaxDatapoints + dlr +
                    request.BeginFilterTime +
                    dlr + request.EndFilterTime + dlr +
                    request.DataDirection + dlr +
                    request.DatapointsPerSend + trm;

                _logger.Info(query);
                break;

            case "Daily Days":
                //HDX,[Symbol],[MaxDatapoints],[DataDirection],[RequestID],[DatapointsPerSend]<CR><LF>
                //Retrieves up to [MaxDatapoints] number of End-Of-Day Data for the specified [Symbol].
                //[Symbol] - Required - Max Length 30 characters.
                //[MaxDatapoints] - Required - The maximum number of data points to be retrieved.
                //[DataDirection] - Optional - '0' (default) for "newest to oldest" or '1' for "oldest to newest".
                //[RequestID] - Optional - Will be sent back at the start of each line of data returned for this request.
                //[DatapointsPerSend] - Optional - Specifies the number of data points that IQConnect.exe will queue before attempting to send across the socket to your app.
                query =
                    IQFeedConfiguration.DailyDaysHeader + dlr +
                    request.CurrentSymbol + dlr +
                    request.DatapointsPerSend + dlr +
                    request.DataDirection + dlr +
                    request.DatapointsPerSend + trm;

                _logger.Info(query);
                break;

            case "Daily Interval":
                //HDT,[Symbol],[BeginDate],[EndDate],[MaxDatapoints],[DataDirection],[RequestID],[DatapointsPerSend]<CR><LF>
                //Retrieves Daily data between [BeginDate] and [EndDate] for the specified [Symbol].
                //[Symbol] - Required - Max Length 30 characters.
                //[BeginDate] - Required if [EndDate] not specified - Format CCYYMMDD - Earliest date to receive data for.
                //[EndDate] - Required if [BeginDate] not specified - Format CCYYMMDD - Most recent date to receive data for.
                //[MaxDatapoints] - Optional - the maximum number of data points to be retrieved.
                //[DataDirection] - Optional - '0' (default) for "newest to oldest" or '1' for "oldest to newest".
                //[RequestID] - Optional - Will be sent back at the start of each line of data returned for this request.
                //[DatapointsPerSend] - Optional - Specifies the number of data points that IQConnect.exe will queue before attempting to send across the socket to your app.
                query =
                    IQFeedConfiguration.DailyIntervalHeader + dlr +
                    request.CurrentSymbol + dlr +
                    request.BeginDateTime + dlr +
                    request.EndDateTime + dlr +
                    request.MaxDatapoints + dlr +
                    request.DataDirection + dlr +
                    request.DatapointsPerSend + trm;

                _logger.Info(query);
                break;

            case "Weekly Days":
                //HWX,[Symbol],[MaxDatapoints],[DataDirection],[RequestID],[DatapointsPerSend]<CR><LF>
                //Retrieves up to [MaxDatapoints] data points of composite weekly data points for the specified [Symbol].
                //[Symbol] - Required - Max Length 30 characters.
                //[MaxDatapoints] - Required - The maximum number of data points to be retrieved.
                //[DataDirection] - Optional - '0' (default) for "newest to oldest" or '1' for "oldest to newest".
                //[RequestID] - Optional - Will be sent back at the start of each line of data returned for this request.
                //[DatapointsPerSend] - Optional - Specifies the number of data points that IQConnect.exe will queue before attempting to send across the socket to your app.
                query =
                    IQFeedConfiguration.WeeklyDaysHeader + dlr +
                    request.CurrentSymbol + dlr +
                    request.MaxDatapoints + dlr +
                    request.DataDirection + dlr +
                    request.DatapointsPerSend + trm;

                _logger.Info(query);
                break;

            case "Monthly Days":
                //HMX,[Symbol],[MaxDatapoints],[DataDirection],[RequestID],[DatapointsPerSend]<CR><LF>
                //Retrieves up to [MaxDatapoints] data points of composite monthly data points for the specified [Symbol].
                //[Symbol] - Required - Max Length 30 characters.
                //[MaxDatapoints] - Required - The maximum number of data points to be retrieved.
                //[DataDirection] - Optional - '0' (default) for "newest to oldest" or '1' for "oldest to newest".
                //[RequestID] - Optional - Will be sent back at the start of each line of data returned for this request.
                //[DatapointsPerSend] - Optional - Specifies the number of data points that IQConnect.exe will queue before attempting to send across the socket to your app.
                query =
                    IQFeedConfiguration.MonthlyDaysHeader + dlr +
                    request.CurrentSymbol + dlr +
                    request.MaxDatapoints + dlr +
                    request.DataDirection + dlr +
                    request.DatapointsPerSend + trm;

                _logger.Info(query);
                break;

            default:
                _logger.Error("Request error");
                break;
            }

            return(query);
        }