コード例 #1
0
        private UserInputLookup Load(IUserInputLookupOwner owner, string lookupName)
        {
            var    filename = GetUserInputLookupFileName(lookupName);
            var    lookup   = new UserInputLookup(owner, lookupName);
            string json;

            try
            {
                json = File.ReadAllText(filename);
            }
            catch (FileNotFoundException)
            {
                return(lookup);
            }
            try
            {
                lookup = JsonConvert
                         .DeserializeObject <UserInputLookup>(json);
                lookup.Owner = owner;
            }
            catch (JsonSerializationException ex)
            {
                lookup.SelectedItem = ex.Message;
                return(lookup);
            }
            lookup.Name = lookupName;
            foreach (var value in lookup)
            {
                lookup.Add(value);
            }
            return(lookup);
        }
コード例 #2
0
        private void UpdateRegistry(UserInputLookup lookup)
        {
            if (lookup == null)
            {
                return;
            }

            if (_registry.ContainsKey(lookup.Name))
            {
                _registry[lookup.Name] = lookup;
            }
            else
            {
                _registry.Add(lookup.Name, lookup);
            }
        }
コード例 #3
0
        private void Update(UserInputLookup lookup)
        {
            if (lookup == null || lookup == UserInputLookup.Empty)
            {
                return;
            }
            string lookupName;

            if (lookup is UserInputLookup userInputLookup)
            {
                lookupName = userInputLookup.Name;
                var    filename = GetUserInputLookupFileName(lookupName);
                string json     = JsonConvert.SerializeObject(userInputLookup);
                File.WriteAllText(filename, json);
                UpdateRegistry(userInputLookup);
            }
        }