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);
        }
示例#2
0
        private static Dictionary <Guid, List <Audience> > _parse_audience(ref IDataReader reader)
        {
            Dictionary <Guid, List <Audience> > ret = new Dictionary <Guid, List <Audience> >();

            while (reader.Read())
            {
                try
                {
                    Audience audience = new Audience();

                    if (!string.IsNullOrEmpty(reader["ObjectID"].ToString()))
                    {
                        audience.ObjectID = (Guid)reader["ObjectID"];
                    }
                    if (!string.IsNullOrEmpty(reader["RoleID"].ToString()))
                    {
                        audience.RoleID = (Guid)reader["RoleID"];
                    }

                    PermissionType tp = PermissionType.None;
                    if (!Enum.TryParse <PermissionType>(reader["PermissionType"].ToString(), out tp) ||
                        tp == PermissionType.None)
                    {
                        continue;
                    }
                    audience.PermissionType = tp;

                    if (!string.IsNullOrEmpty(reader["Allow"].ToString()))
                    {
                        audience.Allow = (bool)reader["Allow"];
                    }
                    if (!string.IsNullOrEmpty(reader["ExpirationDate"].ToString()))
                    {
                        audience.ExpirationDate = (DateTime)reader["ExpirationDate"];
                    }
                    if (!string.IsNullOrEmpty(reader["Name"].ToString()))
                    {
                        audience.RoleName = (string)reader["Name"];
                    }
                    if (!string.IsNullOrEmpty(reader["Type"].ToString()))
                    {
                        audience.RoleType = (string)reader["Type"];
                    }
                    if (!string.IsNullOrEmpty(reader["NodeType"].ToString()))
                    {
                        audience.NodeType = (string)reader["NodeType"];
                    }
                    if (!string.IsNullOrEmpty(reader["AdditionalID"].ToString()))
                    {
                        audience.AdditionalID = (string)reader["AdditionalID"];
                    }

                    if (!audience.ObjectID.HasValue)
                    {
                        continue;
                    }

                    if (!ret.ContainsKey(audience.ObjectID.Value))
                    {
                        ret[audience.ObjectID.Value] = new List <Audience>();
                    }

                    ret[audience.ObjectID.Value].Add(audience);
                }
                catch { }
            }

            if (!reader.IsClosed)
            {
                reader.Close();
            }

            return(ret);
        }