Example #1
0
        /// <summary>
        ///     Parse permissions from plugin.yml
        /// </summary>
        /// <param name="map"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        private List <PluginPermission> ParsePermissions(Mapping map)
        {
            try
            {
                List <PluginPermission> l = new List <PluginPermission>();

                Scalar sc          = new Scalar();
                Type   typeScalar  = sc.GetType();
                Type   typeMapping = map.GetType();
                if (map.GetType() != typeMapping)
                {
                    return(l);
                }
                foreach (MappingEntry entry in map.Enties)
                {
                    PluginPermission pp = new PluginPermission {
                        Name = ((Scalar)entry.Key).Text
                    };
                    if (entry.Value.GetType() != typeMapping)
                    {
                        continue;
                    }
                    foreach (MappingEntry secondlevel in ((Mapping)entry.Value).Enties)
                    {
                        if (secondlevel.Key.GetType() != typeScalar)
                        {
                            continue;
                        }
                        switch (((Scalar)secondlevel.Key).Text)
                        {
                        case "description":
                            pp.Description = ((Scalar)secondlevel.Value).Text;
                            break;

                        case "default":

                            break;

                        case "children":
                            pp.Children = new List <PluginPermissionChild>();
                            foreach (MappingEntry thirdlevel in ((Mapping)secondlevel.Value).Enties)
                            {
                                PluginPermissionChild ppc = new PluginPermissionChild
                                {
                                    Name = ((Scalar)thirdlevel.Key).Text
                                };
                                pp.Children.Add(ppc);
                            }

                            break;
                        }
                    }
                    l.Add(pp);
                }
                return(l);
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Warning, "InstalledPlugin",
                           "An exception occured when trying to load plugin permissions", ex.Message);
                return(new List <PluginPermission>());
            }
        }
        /// <summary>
        ///     Parse permissions from plugin.yml
        /// </summary>
        /// <param name="map"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        private List<PluginPermission> ParsePermissions(Mapping map)
        {
            try
            {
                List<PluginPermission> l = new List<PluginPermission>();

                Scalar sc = new Scalar();
                Type typeScalar = sc.GetType();
                Type typeMapping = map.GetType();
                if (map.GetType() != typeMapping) return l;
                foreach (MappingEntry entry in map.Enties)
                {
                    PluginPermission pp = new PluginPermission {Name = ((Scalar) entry.Key).Text};
                    if (entry.Value.GetType() != typeMapping) continue;
                    foreach (MappingEntry secondlevel in ((Mapping) entry.Value).Enties)
                    {
                        if (secondlevel.Key.GetType() != typeScalar) continue;
                        switch (((Scalar) secondlevel.Key).Text)
                        {
                            case "description":
                                pp.Description = ((Scalar) secondlevel.Value).Text;
                                break;
                            case "default":

                                break;
                            case "children":
                                pp.Children = new List<PluginPermissionChild>();
                                foreach (MappingEntry thirdlevel in ((Mapping) secondlevel.Value).Enties)
                                {
                                    PluginPermissionChild ppc = new PluginPermissionChild
                                    {
                                        Name = ((Scalar) thirdlevel.Key).Text
                                    };
                                    pp.Children.Add(ppc);
                                }

                                break;
                        }
                    }
                    l.Add(pp);
                }
                return l;
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Warning, "InstalledPlugin",
                    "An exception occured when trying to load plugin permissions", ex.Message);
                return new List<PluginPermission>();
            }
        }