Пример #1
0
        public void WriteProfile(String name, object settings)
        {
            Profiles.RemoveAll(cp => cp.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase));
            ChatProfile profile = new ChatProfile();

            profile.Name = name;


            try
            {
                foreach (SettingsPropertyValue prop in ((Properties.Settings)settings).PropertyValues)
                {
                    if (prop != null && prop.Name != null)
                    {
                        if (ChatProperties.Any(cp => prop.Name.EndsWith(cp, StringComparison.CurrentCultureIgnoreCase)))
                        {
                            profile.Strings.Add(new KeyValuePair <String, String>()
                            {
                                Key = prop.Name, Value = (String)prop.PropertyValue
                            });
                        }
                        else if (prop.Property.PropertyType == typeof(Font))
                        {
                            profile.Fonts.Add(new KeyValuePair <String, String>()
                            {
                                Key = prop.Name, Value = fontConverter.ConvertToString(prop.PropertyValue)
                            });
                        }
                        else if (prop.Property.PropertyType == typeof(Color))
                        {
                            profile.Colors.Add(new KeyValuePair <String, String>()
                            {
                                Key = prop.Name, Value = colorConverter.ConvertToString(prop.PropertyValue)
                            });
                        }
                        else if (prop.Property.PropertyType == typeof(Size))
                        {
                            profile.Sizes.Add(new KeyValuePair <String, String>()
                            {
                                Key = prop.Name, Value = sizeConverter.ConvertToString(prop.PropertyValue)
                            });
                        }
                        else if (prop.Property.PropertyType == typeof(Point))
                        {
                            profile.Locations.Add(new KeyValuePair <String, String>()
                            {
                                Key = prop.Name, Value = locationConverter.ConvertToString(prop.PropertyValue)
                            });
                        }
                    }
                }

                Profiles.Add(profile);
            }
            catch (Exception e)
            {
                Debug.Print("WriteProfile: {0}", e.Message);
            }
        }
Пример #2
0
        public String CreateNew(ChatProfile template)
        {
            int i = 1;

            while (Profiles.Any(p => p.Name.Equals(newProfile + i, StringComparison.CurrentCultureIgnoreCase)))
            {
                i++;
            }
            var tmp = template.GetCopy();

            tmp.Name = newProfile + i;
            Profiles.Add(tmp);
            return(tmp.Name);
        }
Пример #3
0
        public void ReadProfile(String name, ref object settings)
        {
            if (Profiles == null)
            {
                return;
            }

            ChatProfile profile = Profiles.FirstOrDefault(p => p.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase));

            if (profile.Strings == null)
            {
                return;
            }
            try
            {
                foreach (var pair in profile.Strings)
                {
                    ((Properties.Settings)settings)[pair.Key] = pair.Value;
                }
                foreach (var pair in profile.Fonts)
                {
                    ((Properties.Settings)settings)[pair.Key] = (Font)fontConverter.ConvertFromString(pair.Value);
                }
                foreach (var pair in profile.Colors)
                {
                    ((Properties.Settings)settings)[pair.Key] = (Color)colorConverter.ConvertFromString(pair.Value);
                }
                foreach (var pair in profile.Sizes)
                {
                    ((Properties.Settings)settings)[pair.Key] = (Size)sizeConverter.ConvertFromString(pair.Value);
                }
                foreach (var pair in profile.Locations)
                {
                    ((Properties.Settings)settings)[pair.Key] = (Point)locationConverter.ConvertFromString(pair.Value);
                }
            }
            catch (Exception e)
            {
                Debug.Print("ReadProfile: {0}", e.Message);
            }
        }