Ejemplo n.º 1
0
    public bool ValidateCache(IEnumerable <string> guids)
    {
        var loadFromCache = false;

        if (_cachedPositions == null)
        {
//            Debug.Log( "no cache found" );
            _cachedPositions = new PositionDictionary();
        }
        else
        {
            var allNodes = guids.ToList();
            if (allNodes.Any(guid => !_cachedPositions.ContainsKey(guid)))
            {
//                Debug.Log( "invalid cache found" );
                _cachedPositions = new PositionDictionary();
            }
            else
            {
                loadFromCache = true;
                var toRemove = _cachedPositions.Keys.Except(allNodes).ToArray();
                foreach (var guid in toRemove)
                {
                    _cachedPositions.Remove(guid);
                }
            }
        }

        return(loadFromCache);
    }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            const string       source      = "Sber";
            Settings           appSettings = SettingsHandler.GetSettings("develop");
            PositionDictionary dict        = new PositionDictionary(appSettings, source);

            List <string> namesOfPosition = new List <string>()
            {
                "vtb",
                "aeroflot",
                "gazprom",
                "nornickel-gmk",
                "lukoil"
            };

            // Проверка, есть ли позиции, которые перечислены в списке позиций, в словаре для конкретного источника данных
            foreach (string name in namesOfPosition)
            {
                if (!dict.Contains(name))
                {
                    Console.WriteLine($"Для словаря {source} отсутствует ключ {name}");
                    Console.WriteLine($"Для продолжения осуществите ввод значения, которое соответствует ключe {name} для словаря {source}");
                    string value = Console.ReadLine();
                    if (dict.Validate(value))
                    {
                        dict[name] = value;
                    }
                    else
                    {
                        Console.WriteLine($"Введенное значение '{value}' не прошло валидацию и не будет добавлено в справочник");
                    }
                }
            }

            // Если в словарь были применены изменения - провести сохранение данных изменений
            if (dict.IsChanged)
            {
                dict.SaveData();
            }


            foreach (string name in namesOfPosition)
            {
                FinamPosition test = new FinamPosition(name);
                Console.WriteLine(test);
            }
        }
Ejemplo n.º 3
0
        public ActionResult AddPositionDictionaryValue(PositionDictionaryValueViewModel model)
        {
            var result = new { Success = "true", Message = "Success" };

            if (ModelState.IsValid)
            {
                try
                {
                    if (model.PositionDictionaryId > 0)
                    {
                        var positionValue = Mapper.Map <PositionDictionaryValue>(model);

                        _positionDictionaryService.CreateDictionaryValue(positionValue);
                    }
                    else
                    {
                        PositionDictionary dictionary = new PositionDictionary()
                        {
                            UserCompanyId = model.UserCompanyId,
                            CreatedDate   = DateTime.Now,
                            UpdatedDate   = DateTime.Now
                        };

                        int dictionaryId = _positionDictionaryService.Create(dictionary);

                        var positionValue = Mapper.Map <PositionDictionaryValue>(model);
                        positionValue.PositionDictionaryId = dictionaryId;

                        _positionDictionaryService.CreateDictionaryValue(positionValue);
                    }
                }
                catch (Exception e)
                {
                    logger.Error(e, e.Message);
                    result = new { Success = "false", Message = WebResources.ErrorMessage };
                }
            }
            else
            {
                var error = ModelState.Values.SelectMany(v => v.Errors).FirstOrDefault().ErrorMessage;

                result = new { Success = "false", Message = error };
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 4
0
 public void Update(PositionDictionary entity)
 {
     _positionDictionaryRepository.Update(entity);
 }
Ejemplo n.º 5
0
 public void Delete(PositionDictionary entity)
 {
     entity.IsDeleted = true;
     _positionDictionaryRepository.Update(entity);
 }
Ejemplo n.º 6
0
        public int Create(PositionDictionary entity)
        {
            _positionDictionaryRepository.Insert(entity);

            return(entity.Id);
        }
Ejemplo n.º 7
0
 public void InvalidateCache()
 {
     _cachedPositions = new PositionDictionary();
 }