Ejemplo n.º 1
0
        /// <summary>
        /// set a group setting
        /// </summary>
        public void SetSettingGroup(SettingGroup group)
        {
            string id = group.Id;

            if (GroupsDictionary.ContainsKey(id))
            {
                GroupsDictionary[id] = group;
            }
            else
            {
                GroupsDictionary.Add(id, group);
            }
            bool oldAutoSave = AutoSave;

            AutoSave = false;
            foreach (var item in group.Settings)
            {
                SetSetting(id + "." + item.Key, item.Value);
            }
            AutoSave = oldAutoSave;
            if (AutoSave)
            {
                SaveSettings();
            }
        }
Ejemplo n.º 2
0
        private static CategoriesDictionary GetSortedProperties(PropertyList list)
        {
            CategoriesDictionary sortedProperies = new CategoriesDictionary();

            Dictionary <string, List <string> > Categories = GetCategoriesAndGroups(list);

            foreach (var category in Categories)
            {
                GroupsDictionary groups = new GroupsDictionary();
                foreach (var group in category.Value)
                {
                    PropertyList propertyList = new PropertyList();
                    foreach (var property in list)
                    {
                        if (property.Attributes.Count != 0 &&
                            (property.Attributes.First(a => a.Key == "CategoryAttribute").Value.ToString() == category.Key &&
                             property.Attributes.First(a => a.Key == "GroupName").Value.ToString() == group))
                        {
                            propertyList.Add(property);
                        }
                    }
                    groups.Add(group, propertyList);
                }

                sortedProperies.Add(category.Key, groups);
            }
            return(sortedProperies);
        }
Ejemplo n.º 3
0
 public Dictionary <IRecord, List <WellRecord> > SetGroupsChildren()
 {
     if (GroupsList != null && GroupsList.Count > 0)
     {
         GroupsList.ForEach(record => GroupsDictionary.Add(record, new List <WellRecord>()));
         AddWellsToGroups();
     }
     return(GroupsDictionary);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// set a setting value for a group
 /// </summary>
 public void SetGroupSetting(string groupId, string name, object value)
 {
     if (!string.IsNullOrEmpty(groupId))
     {
         SettingGroup group;
         if (!GroupsDictionary.TryGetValue(groupId, out group))
         {
             group = new SettingGroup {
                 Id = groupId
             };
             GroupsDictionary.Add(groupId, group);
         }
         group.SetSetting(name, value);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Save the current settings to local file
        /// </summary>
        public bool SaveSettings()
        {
            try
            {
                if (string.IsNullOrEmpty(SettingsFile))
                {
                    return(false);
                }

                using (TextWriter writer = File.CreateText(SettingsFile))
                {
                    foreach (SettingGroup group in GroupsDictionary.Values)
                    {
                        writer.WriteLine("Group={0}", group.Id);
                        foreach (var item in group.Settings)
                        {
                            writer.WriteLine("    {0}={1}", item.Key, item.Value);
                        }
                        writer.WriteLine("EndGroup={0}", group.Id);
                    }
                    foreach (var item in SettingsDictionary)
                    {
                        // skip those "group.key=value" for setting group
                        string   key   = item.Key;
                        string[] parts = key.Split(GroupNameDelimiter);
                        if (parts.Length == 1 || !GroupsDictionary.ContainsKey(parts[0]))
                        {
                            writer.WriteLine("{0}={1}", key, item.Value);
                        }
                    }
                    writer.Close();
                }
                return(true);
            }
            catch (Exception err)
            {
                // todo
            }
            return(false);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// try get a setting group by ID
 /// </summary>
 /// <param name="id">the ID of the setting group</param>
 /// <param name="groupSetting">the out setting group</param>
 /// <returns>returns true if exists</returns>
 public bool TryGetSettingGroup(string id, out SettingGroup settingGroup)
 {
     return(GroupsDictionary.TryGetValue(id, out settingGroup));
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Load the settings from local file
        /// </summary>
        public bool LoadSettings()
        {
            bool oldAutoSave = AutoSave;

            AutoSave = false;
            try
            {
                if (string.IsNullOrEmpty(SettingsFile))
                {
                    return(false);
                }

                using (TextReader reader = File.OpenText(SettingsFile))
                {
                    string       currentGroupId = string.Empty;
                    SettingGroup currentGroup   = null;
                    string       buffer;
                    while ((buffer = reader.ReadLine()) != null)
                    {
                        buffer = buffer.Trim();
                        if (string.IsNullOrEmpty(buffer) || buffer.StartsWith("#"))
                        {
                            continue;
                        }

                        string[] parts = buffer.Split(SettingValueDelimiter);
                        if (parts.Length > 0)
                        {
                            string key   = parts[0].Trim();
                            string value = null;
                            if (parts.Length > 1)
                            {
                                value = parts[1].Trim();
                            }
                            if (string.Equals("group", key, StringComparison.OrdinalIgnoreCase))
                            {
                                // assign a GUID as group ID
                                if (string.IsNullOrEmpty(value))
                                {
                                    value = Guid.NewGuid().ToString();
                                }
                                currentGroupId = value;
                                currentGroup   = new SettingGroup()
                                {
                                    Id = value
                                };
                                GroupsDictionary.Add(value, currentGroup);
                                // adding ID to both dictionaries
                                currentGroup.SetSetting("Id", value);
                                SetSetting(currentGroupId + ".Id", value);
                            }
                            else if (string.Equals("endgroup", key, StringComparison.OrdinalIgnoreCase))
                            {
                                currentGroupId = null;
                                currentGroup   = null;
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(currentGroupId))
                                {
                                    SetSetting(key, value);
                                }
                                else
                                {
                                    string fullName = currentGroupId + "." + key;
                                    SetSetting(fullName, value);
                                    currentGroup.SetSetting(key, value);
                                }
                            }
                        }
                    }
                    reader.Close();
                }
                return(true);
            }
            catch (Exception err)
            {
                // todo
            }
            AutoSave = oldAutoSave;
            return(false);
        }