Exemplo n.º 1
0
        public static DefaultPermission fromJson(Dictionary <string, object> json)
        {
            DefaultPermission dp = new DefaultPermission();

            PermissionType pt = PermissionType.None;

            if (json.ContainsKey("PermissionType") && json["PermissionType"] != null &&
                Enum.TryParse <PermissionType>(json["PermissionType"].ToString(), out pt))
            {
                dp.PermissionType = pt;
            }

            PrivacyType dv = PrivacyType.NotSet;

            if (json.ContainsKey("DefaultValue") && json["DefaultValue"] != null &&
                Enum.TryParse <PrivacyType>(json["DefaultValue"].ToString(), out dv))
            {
                dp.DefaultValue = dv;
            }

            return(dp.PermissionType == PermissionType.None ? null : dp);
        }
Exemplo n.º 2
0
        public static Privacy fromJson(Dictionary <string, object> json)
        {
            Privacy obj = new Privacy();

            obj.CalculateHierarchy = PublicMethods.parse_bool(PublicMethods.get_dic_value(json, "CalculateHierarchy"));

            Dictionary <string, object> conf = PublicMethods.get_dic_value <Dictionary <string, object> >(json, "Confidentiality");

            obj.Confidentiality.ID = PublicMethods.parse_guid(PublicMethods.get_dic_value(conf, "ID"));

            foreach (object a in PublicMethods.get_dic_value <ArrayList>(json, "Audience", defaultValue: new ArrayList()))
            {
                if (a.GetType() != typeof(Dictionary <string, object>))
                {
                    continue;
                }
                Audience o = Modules.Privacy.Audience.fromJson((Dictionary <string, object>)a);
                if (o != null)
                {
                    obj.Audience.Add(o);
                }
            }

            foreach (object d in PublicMethods.get_dic_value <ArrayList>(json, "DefaultPermissions", defaultValue: new ArrayList()))
            {
                if (d.GetType() != typeof(Dictionary <string, object>))
                {
                    continue;
                }
                DefaultPermission o = DefaultPermission.fromJson((Dictionary <string, object>)d);
                if (o != null)
                {
                    obj.DefaultPermissions.Add(o);
                }
            }

            return(obj.CalculateHierarchy.HasValue || obj.Confidentiality.ID.HasValue ||
                   obj.Audience.Count > 0 || obj.DefaultPermissions.Count > 0 ? obj : null);
        }