Example #1
0
        public string DirForImages(DirSwitcher switcher)
        {
            string tmpCurrent;
            string path;
            //TODO make location crossplatform
            var tmpTodayFolder = location.Replace("//", "/").Split('/').Last();

            switch (switcher)
            {
            case DirSwitcher.Auto:
                tmpCurrent = LastDir(Path.Combine(location, automatic)).Replace("//", "/").Split('/').Last();
                path       = Path.Combine(automatic, tmpCurrent);
                break;

            case DirSwitcher.Manual:
                tmpCurrent = LastDir(Path.Combine(location, manual)).Replace("//", "/").Split('/').Last();
                path       = Path.Combine(manual, tmpCurrent);
                break;

            case DirSwitcher.Instant:
                tmpCurrent = LastDir(Path.Combine(location, instant)).Replace("//", "/").Split('/').Last();
                path       = Path.Combine(instant, tmpCurrent);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(switcher), switcher, null);
            }

            return(Path.Combine(tmpTodayFolder, path));
        }
Example #2
0
        public string GenerateForecastFolder(string assetId, int period, DirSwitcher switcher, DateTime?context = null)
        {
            var    timeNow   = DateTime.Now.ToString("HH:mm:ss").Replace(':', '.');
            var    newFolder = $"{timeNow}_{assetId}_{period}";
            string newLocation;

            switch (switcher)
            {
            case DirSwitcher.Auto:
                var subFolderForAuto = context?.ToString("HH:mm:ss").Replace(':', '-');
                newLocation = Path.Combine(_location, _automatic, subFolderForAuto, newFolder);
                break;

            case DirSwitcher.BotForecast:
                var subFolderForBotForecast = context?.ToString("HH:mm:ss").Replace(':', '-');
                newLocation = Path.Combine(_location, _botForecast, subFolderForBotForecast, newFolder);
                break;

            case DirSwitcher.Manual:
                newLocation = Path.Combine(_location, _manual, newFolder);
                break;

            case DirSwitcher.Instant:
                newLocation = Path.Combine(_location, _instant, newFolder);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(switcher), switcher, null);
            }
            try
            {
                var exist = Directory.Exists(newLocation);
                if (exist)
                {
                    return(newLocation);
                }
                lock (_locker)
                {
                    Directory.CreateDirectory(newLocation);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Couldn't generate the Forecast Folder");
            }

            return(newLocation);
        }
Example #3
0
        public string GetLastFolder(DirSwitcher switcher)
        {
            var parts = _location.Split(Path.DirectorySeparatorChar);

            Array.Resize(ref parts, parts.Length - 1);
            var locStr = new StringBuilder();

            foreach (var part in parts)
            {
                locStr.Append(part); //, Path.DirectorySeparatorChar.ToString());
                locStr.Append(Path.DirectorySeparatorChar.ToString());
            }

            var loc = locStr.ToString();

            switch (switcher)
            {
            case DirSwitcher.Auto:
                loc = Path.Combine(LastDirAuto(loc), _automatic);
                break;

            case DirSwitcher.Manual:
                loc = Path.Combine(LastDir(loc), _manual);
                break;

            case DirSwitcher.Instant:
                loc = Path.Combine(LastDir(loc), _instant);
                break;

            case DirSwitcher.BotForecast:
                loc = Path.Combine(LastDirAuto(loc), _botForecast);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(switcher), switcher, null);
            }
            return(LastDir(loc));
        }
Example #4
0
        public string GetLastFolder(DirSwitcher switcher)
        {
            string loc;

            switch (switcher)
            {
            case DirSwitcher.Auto:
                loc = Path.Combine(location, automatic);
                break;

            case DirSwitcher.Manual:
                loc = Path.Combine(location, manual);
                break;

            case DirSwitcher.Instant:
                loc = Path.Combine(location, instant);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(switcher), switcher, null);
            }
            return(LastDir(loc));
        }
Example #5
0
        public ImagesPath ImagePath(DirSwitcher switcher, Indicator?indicator = null, string subFolder = null, string fullPath = null)
        {
            string tmpCurrent;
            string path;
            var    images = new ImagesPath();

            switch (switcher)
            {
            case DirSwitcher.Auto:
                var parts = _location.Split(Path.DirectorySeparatorChar);
                Array.Resize(ref parts, parts.Length - 1);
                var locStr = new StringBuilder();
                foreach (var part in parts)
                {
                    locStr.Append(part);     //, Path.DirectorySeparatorChar.ToString());
                    locStr.Append(Path.DirectorySeparatorChar.ToString());
                }

                var loc  = locStr.ToString();
                var time = fullPath.Split(Path.DirectorySeparatorChar);
                tmpCurrent           = LastDirAuto(Path.Combine(loc)).Split(Path.DirectorySeparatorChar).Last();
                path                 = Path.Combine(tmpCurrent, _automatic);
                images.ForecastImage = Path.Combine(Path.DirectorySeparatorChar.ToString(),
                                                    _settings.ForecastDir,
                                                    path,
                                                    time.Last(),
                                                    indicator.ToString(),
                                                    subFolder,
                                                    Static.ForecastFile);
                images.ComponentsImage = Path.Combine(Path.DirectorySeparatorChar.ToString(),
                                                      _settings.ForecastDir,
                                                      path,
                                                      time.Last(),
                                                      indicator.ToString(),
                                                      subFolder,
                                                      Static.ComponentsFile);
                break;

            case DirSwitcher.Manual:
                tmpCurrent           = LastDir(Path.Combine(_location, _manual)).Split(Path.DirectorySeparatorChar).Last();
                path                 = Path.Combine(_manual, tmpCurrent);
                images.ForecastImage = Path.Combine(Path.DirectorySeparatorChar.ToString(),
                                                    _settings.ForecastDir,
                                                    _todayDate,
                                                    path,
                                                    Static.ForecastFile);
                images.ComponentsImage = Path.Combine(Path.DirectorySeparatorChar.ToString(),
                                                      _settings.ForecastDir,
                                                      _todayDate,
                                                      path,
                                                      Static.ComponentsFile);
                break;

            case DirSwitcher.Instant:
                tmpCurrent           = LastDir(Path.Combine(_location, _instant)).Split(Path.DirectorySeparatorChar).Last();
                path                 = Path.Combine(_instant, tmpCurrent);
                images.ForecastImage = Path.Combine(Path.DirectorySeparatorChar.ToString(),
                                                    _settings.ForecastDir,
                                                    _todayDate,
                                                    path,
                                                    Static.ForecastFile);
                images.ComponentsImage = Path.Combine(Path.DirectorySeparatorChar.ToString(),
                                                      _settings.ForecastDir,
                                                      _todayDate,
                                                      path,
                                                      Static.ComponentsFile);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(switcher), switcher, null);
            }

            return(images);
        }
        private static bool Build(string url, string key, ref List <List <AssetModel> > modelSet, DirSwitcher switcher)
        {
            var response            = StaticUtility.GenerateRestUrl(url, key);
            List <AssetModel> model = null;

            switch (switcher)
            {
            case DirSwitcher.Auto:
                if (response.StatusDescription == "OK")
                {
                    model = JsonConvert.DeserializeObject <List <AssetModel> >(response.Content);
                    if (model.Any())
                    {
                        modelSet.Add(model);
                    }
                }
                else
                {
                    return(false);
                }
                break;

            case DirSwitcher.Manual:
                if (response.StatusDescription != "OK")
                {
                    throw new Exception(response.Content);
                }
                model = JsonConvert.DeserializeObject <List <AssetModel> >(response.Content);
                if (model.Any())
                {
                    modelSet.Add(model);
                    return(true);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(switcher), switcher, null);
            }

            return(true);
        }
        public bool FillMissingData(int period, DateTime startDate, string apiKey, ref List <List <AssetModel> > model, DirSwitcher switcher)
        {
            if (CountArrElements(model) > period)
            {
                RemoveExcess(period, ref model);
                return(true);
            }
            if (CountArrElements(model) < period)
            {
                return(FillGaps(period, startDate, apiKey, ref model, switcher));
            }

            return(false);
        }
        public bool FillModel(string url, DateTime dtMin, DateTime dtMax, string apiKey, ref List <List <AssetModel> > modelSet, DirSwitcher switcher)
        {
            var counter = 0;

            while (dtMin < dtMax.AddDays(4))
            {
                var dateStartStr = dtMin.ToString("s");
                var dateEndStr   = dtMin.AddDays(4).ToString("s");
                var coinUrl      = BuildCoinUrl(url, coinName, dateStartStr, dateEndStr);
                switch (switcher)
                {
                case DirSwitcher.Auto:
                    if (!Build(coinUrl, apiKey, ref modelSet, switcher))
                    {
                        return(false);
                    }
                    break;

                case DirSwitcher.Manual:
                    Build(coinUrl, apiKey, ref modelSet, switcher);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(switcher), switcher, null);
                }


                dtMin = dtMin.AddDays(4);
                counter++;
            }

            StaticUtility.AddRequestCount(counter);
            return(true);
            //manager.UpdateRequests(counter);
        }
        private bool FillGaps(int period, DateTime dateStart, string apiKey, ref List <List <AssetModel> > model, DirSwitcher switcher)
        {
            var difference    = period - CountArrElements(model);
            var requestsCount = Convert.ToInt32(difference / 100) + 1;
            var tmpDate       = dateStart;
            var tmpModelSet   = new List <List <AssetModel> >();
            var counter       = 0;

            while (requestsCount != 0)
            {
                counter++;
                var firstItemInModel = StaticUtility.TimeConverter(model.First().First().TimeClose);
                var dtMax            = tmpDate;

                if (firstItemInModel.Subtract(tmpDate).TotalMinutes > 60)
                {
                    dtMax = dtMax.AddHours(1);
                }
                var dtMin = dtMax.AddDays(-4);

                var url = BuildCoinUrl(apiUrl, coinName, dtMin.ToString("s"), dtMax.ToString("s"));
                switch (switcher)
                {
                case DirSwitcher.Auto:
                    if (!Build(url, apiKey, ref tmpModelSet, switcher))
                    {
                        return(false);
                    }
                    break;

                case DirSwitcher.Manual:
                    Build(url, apiKey, ref tmpModelSet, switcher);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(switcher), switcher, null);
                }
                tmpDate = tmpDate.AddDays(-4);
                requestsCount--;
            }



            StaticUtility.AddRequestCount(counter);
            //manager.UpdateRequests(counter);

            if (!tmpModelSet.Any())
            {
                return(false);
            }

            var tmpCounterfForModel = CountArrElements(tmpModelSet);

            if (tmpCounterfForModel <= difference)
            {
                return(false);
            }
            model.Insert(0, (RemoveExcessFromEnd(period, tmpModelSet, model)));
            return(true);
        }