示例#1
0
        public static void Load(GenericPropertyCollection properties, string fileName)
        {
            var contents         = File.ReadAllText(fileName, Encoding.UTF8);
            var jArrayProperties = JArray.Parse(contents);

            GenericPropertySerializer.DeserializePropertiesFromArray(properties, jArrayProperties);
        }
示例#2
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            var jObjectSettings = new JObject();

            foreach (TabPage tabPage in tabControl.TabPages)
            {
                if (tabPage.Tag is HuntingType huntingType)
                {
                    GenericPropertyCollection properties = null;
                    foreach (Control control in tabPage.Controls)
                    {
                        if (control is GenericPropertyListControl propertyControl)
                        {
                            properties = propertyControl.Properties;
                        }
                    }

                    if (properties != null)
                    {
                        jObjectSettings[huntingType.TypeName + Constants.HUNTING_PROPERTIES_POSTFIX] = GenericPropertySerializer.SerializePropertiesToArray(properties);
                    }
                }
            }

            jObjectSettings[Constants.GENERAL_PROPERTIES] = GenericPropertySerializer.SerializePropertiesToArray(genericPropertyListControl.Properties);

            SettingsHelper.SaveSettings(jObjectSettings);

            DialogResult = DialogResult.OK;
        }
        public static GenericPropertyCollection GetGeneralProperties()
        {
            var properties = new GenericPropertyCollection()
            {
                new GenericProperty()
                {
                    Browsable    = true,
                    Name         = SettingName.API_KEY,
                    DisplayName  = "Api Key",
                    DefaultValue = string.Empty,
                    Type         = GenericPropertyType.String
                },
                new GenericProperty()
                {
                    Browsable    = true,
                    Name         = SettingName.SECRET_KEY,
                    DisplayName  = "Secret Key",
                    DefaultValue = string.Empty,
                    Type         = GenericPropertyType.String
                },
                new GenericProperty()
                {
                    Browsable    = true,
                    Name         = SettingName.TRADING_ENABLED,
                    DisplayName  = "Trading Enable",
                    DefaultValue = false,
                    Type         = GenericPropertyType.Boolean
                }
            };

            var jArrayProperties = GetJArrayGeneralProperties();

            if (jArrayProperties != null)
            {
                GenericPropertySerializer.DeserializePropertiesFromArray(properties, jArrayProperties);
            }

            return(properties);
        }
示例#4
0
 public Hunting()
 {
     genericProperties = SettingsHelper.GetGeneralProperties();
 }
 public void Invalidate()
 {
     genericProperties = GetGeneralProperties();
 }
示例#6
0
        public static void Save(string fileName, GenericPropertyCollection properties)
        {
            var jArrayProperties = GenericPropertySerializer.SerializePropertiesToArray(properties);

            File.WriteAllText(fileName, jArrayProperties.ToString(), Encoding.UTF8);
        }
        public static void Deserialize(GenericPropertyCollection propertyCollection, JObject jObject)
        {
            foreach (var property in propertyCollection)
            {
                if (jObject[property.Name] != null)
                {
                    switch (property.Type)
                    {
                    case Enum.GenericPropertyType.String:
                    case Enum.GenericPropertyType.Path:
                        property.Value = JObjectHelper.GetString(jObject, property.Name);
                        break;

                    case Enum.GenericPropertyType.Integer:
                        property.Value = JObjectHelper.GetInt32(jObject, property.Name);
                        break;

                    case Enum.GenericPropertyType.Decimal:
                        property.Value = JObjectHelper.GetDouble(jObject, property.Name);
                        break;

                    case Enum.GenericPropertyType.Boolean:
                        property.Value = JObjectHelper.GetBoolean(jObject, property.Name);
                        break;

                    case Enum.GenericPropertyType.Enumeration:
                        property.Value = JObjectHelper.GetString(jObject, property.Name);
                        break;

                    case Enum.GenericPropertyType.Guid:
                        property.Value = JObjectHelper.GetGuid(jObject, property.Name);
                        break;

                    case Enum.GenericPropertyType.Color:
                        property.Value = JObjectHelper.GetColor(jObject, property.Name);
                        break;

                    case Enum.GenericPropertyType.Point:
                        var x = JObjectHelper.GetInt32(jObject, "x");
                        var y = JObjectHelper.GetInt32(jObject, "y");
                        property.Value = new Point(x, y);
                        break;

                    case Enum.GenericPropertyType.Size:
                        var width  = JObjectHelper.GetInt32(jObject, "width");
                        var height = JObjectHelper.GetInt32(jObject, "height");
                        property.Value = new Size(width, height);
                        break;

                    case Enum.GenericPropertyType.Rectangle:
                        var x_      = JObjectHelper.GetInt32(jObject, "x");
                        var y_      = JObjectHelper.GetInt32(jObject, "y");
                        var width_  = JObjectHelper.GetInt32(jObject, "width");
                        var height_ = JObjectHelper.GetInt32(jObject, "height");
                        property.Value = new Rectangle(x_, y_, width_, height_);
                        break;

                    case Enum.GenericPropertyType.DateTime:
                        var valueStr = JObjectHelper.GetString(jObject, property.Name, DateTime.UtcNow.ToString("o"));
                        property.Value = DateTime.Parse(valueStr);
                        break;

                    case Enum.GenericPropertyType.Version:
                        var versionStr = JObjectHelper.GetString(jObject, property.Name);
                        property.Value = new Version(versionStr);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
        public static JObject SerializeToObject(GenericPropertyCollection propertyCollection)
        {
            var jObject = new JObject();

            foreach (var property in propertyCollection)
            {
                var propertyName = property.Name;

                switch (property.Type)
                {
                case GenericPropertyType.String:
                case GenericPropertyType.Path:
                    jObject[propertyName] = Convert.ToString(property.Value);
                    break;

                case GenericPropertyType.Integer:
                    jObject[propertyName] = Convert.ToInt32(property.Value);
                    break;

                case GenericPropertyType.Decimal:
                    jObject[propertyName] = Convert.ToDouble(property.Value);
                    break;

                case GenericPropertyType.Boolean:
                    jObject[propertyName] = Convert.ToBoolean(property.Value);
                    break;

                case GenericPropertyType.Enumeration:
                    jObject[propertyName] = Convert.ToString(property.Value);
                    break;

                case GenericPropertyType.Guid:
                    jObject[propertyName] = Convert.ToString(property.Value);
                    break;

                case GenericPropertyType.Color:
                    jObject[propertyName] = ColorHelper.ToHtml((Color)property.Value, true);
                    break;

                case GenericPropertyType.Point:
                    var point = (Point)property.Value;
                    jObject[propertyName] = new JObject()
                    {
                        ["x"] = point.X,
                        ["y"] = point.Y
                    };
                    break;

                case Enum.GenericPropertyType.Size:
                    var size = (Size)property.Value;
                    jObject[propertyName] = new JObject()
                    {
                        ["width"]  = size.Width,
                        ["height"] = size.Height
                    };
                    break;

                case Enum.GenericPropertyType.Rectangle:
                    var rectangle = (Rectangle)property.Value;
                    jObject[propertyName] = new JObject()
                    {
                        ["x"]      = rectangle.X,
                        ["y"]      = rectangle.Y,
                        ["width"]  = rectangle.Width,
                        ["height"] = rectangle.Height
                    };
                    break;

                case Enum.GenericPropertyType.DateTime:
                    var dateTime    = (DateTime)property.Value;
                    var dateTimeUtc = dateTime.ToUniversalTime();
                    jObject[propertyName] = dateTimeUtc.ToString("o");
                    break;

                case Enum.GenericPropertyType.Version:
                    var version = (Version)property.Value;
                    jObject[propertyName] = version.ToString(3);
                    break;

                default:
                    break;
                }
            }

            return(jObject);
        }
示例#9
0
        public FormMain()
        {
            InitializeComponent();

            var properties = new GenericPropertyCollection();

            properties.Add(new GenericProperty()
            {
                ScopeName           = "options",
                CategoryName        = "person",
                CategoryDisplayName = "Personal Information",
                Name         = "firstName",
                DisplayName  = "First Name",
                Type         = GenericPropertyType.String,
                DefaultValue = "David"
            });

            properties.Add(new GenericProperty()
            {
                ScopeName           = "options",
                CategoryName        = "person",
                CategoryDisplayName = "Personal Information",
                Name         = "lastName",
                DisplayName  = "Last Name",
                Type         = GenericPropertyType.String,
                DefaultValue = "Brown"
            });

            properties.Add(new GenericProperty()
            {
                ScopeName           = "options",
                CategoryName        = "detailedInformation",
                CategoryDisplayName = "Detailed Information",
                Name         = "age",
                DisplayName  = "Age",
                Type         = GenericPropertyType.Integer,
                DefaultValue = 0
            });

            properties.Add(new GenericProperty()
            {
                ScopeName           = "options",
                CategoryName        = "detailedInformation",
                CategoryDisplayName = "Detailed Information",
                Name         = "gender",
                DisplayName  = "Gender",
                Type         = GenericPropertyType.Enumeration,
                DefaultValue = "male",
                EnumItems    = new List <GenericPropertyEnumItem>()
                {
                    new GenericPropertyEnumItem()
                    {
                        Name  = "Male",
                        Value = "male"
                    },
                    new GenericPropertyEnumItem()
                    {
                        Name  = "Female",
                        Value = "female"
                    }
                }
            });

            properties.Add(new GenericProperty()
            {
                ScopeName           = "options",
                CategoryName        = "detailedInformation",
                CategoryDisplayName = "Detailed Information",
                Name         = "retarded",
                DisplayName  = "Retarded",
                Type         = GenericPropertyType.Boolean,
                DefaultValue = true
            });

            properties.Add(new GenericProperty()
            {
                ScopeName           = "options",
                CategoryName        = "detailedInformation",
                CategoryDisplayName = "Detailed Information",
                Name            = "outputPath",
                DisplayName     = "Output Path",
                PathDescription = "Select path",
                Type            = GenericPropertyType.Path,
                DefaultValue    = "c:\\"
            });

            properties.Add(new GenericProperty()
            {
                ScopeName           = "options",
                CategoryName        = "detailedInformation",
                CategoryDisplayName = "Detailed Information",
                Name         = "eyeColor",
                DisplayName  = "Eye Color",
                Type         = GenericPropertyType.Color,
                DefaultValue = Color.Blue
            });

            genericPropertyListControl1.Properties = properties;
            genericPropertyListControl1.RefreshItems();
        }