/// <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>
 ///     Convert a sequence to an array
 /// </summary>
 /// <param name="seq"></param>
 /// <returns></returns>
 /// <remarks></remarks>
 private static string[] ArrayFromSequence(Sequence seq)
 {
     try
     {
         Scalar sc = new Scalar();
         Type typeScalar = sc.GetType();
         string[] arr = new string[seq.Enties.Count];
         for (int i = 0; i <= seq.Enties.Count - 1; i++)
         {
             if (seq.Enties[i].GetType() == typeScalar)
             {
                 arr[i] = (((Scalar) seq.Enties[i]).Text);
             }
         }
         return arr;
     }
     catch (Exception ex)
     {
         Logger.Log(LogLevel.Severe, "InstalledPlugin",
             "An exception occured when trying to convert array to sequence", ex.Message);
         return new string[1];
     }
 }
        /// <summary>
        ///     Parse commands from plugin.yml
        /// </summary>
        /// <param name="map"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        private static List<PluginCommand> ParseCommands(Mapping map)
        {
            try
            {
                List<PluginCommand> l = new List<PluginCommand>();

                Scalar sc = new Scalar();
                Sequence seq = new Sequence();
                Type typeScalar = sc.GetType();
                Type typeSequence = seq.GetType();
                Type typeMapping = map.GetType();
                if (map.GetType() != typeMapping) return l;

                foreach (MappingEntry entry in map.Enties)
                {
                    PluginCommand pc = new PluginCommand {Name = ((Scalar) entry.Key).Text};

                    if (entry.Value.GetType() == typeMapping)
                    {
                        foreach (MappingEntry secondlevel in ((Mapping) entry.Value).Enties)
                        {
                            if (secondlevel.Key.GetType() != typeScalar) continue;
                            switch (((Scalar) secondlevel.Key).Text)
                            {
                                case "description":
                                    pc.Description = ((Scalar) secondlevel.Value).Text;
                                    break;
                                case "usage":
                                    pc.Usage = ((Scalar) secondlevel.Value).Text;
                                    break;
                                case "alias":
                                    if (entry.Value.GetType() == typeSequence)
                                    {
                                        pc.Aliases = ArrayFromSequence((Sequence) secondlevel.Value);
                                    }
                                    else if (entry.Value.GetType() == typeScalar)
                                    {
                                        pc.Aliases = new string[1];
                                        // ReSharper disable once PossibleInvalidCastException
                                        pc.Aliases[0] = ((Scalar) entry.Value).Text;
                                    }
                                    break;
                                case "aliases":
                                    if (entry.Value.GetType() == typeSequence)
                                    {
                                        pc.Aliases = ArrayFromSequence((Sequence) secondlevel.Value);
                                    }
                                    else if (entry.Value.GetType() == typeScalar)
                                    {
                                        pc.Aliases = new string[1];
            // ReSharper disable once PossibleInvalidCastException
                                        pc.Aliases[0] = ((Scalar) entry.Value).Text;
                                    }
                                    break;
                            }
                        }
                    }

                    l.Add(pc);
                }
                return l;
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Warning, "InstalledPlugin",
                    "An exception occured when trying to load plugin commands", ex.Message);
                return new List<PluginCommand>();
            }
        }
        /// <summary>
        ///     Loads the contents of a plugin.yml file
        /// </summary>
        /// <param name="ymltext">the yml formatted text</param>
        /// <returns>The InstalledPlugin (me)</returns>
        /// <remarks></remarks>
        public InstalledPlugin LoadPluginYml(string ymltext)
        {
            try
            {
                Scalar sc = new Scalar();
                Sequence seq = new Sequence();
                Mapping map = new Mapping();

                //References to check file types later on
                Type typeScalar = sc.GetType();
                Type typeSequence = seq.GetType();
                Type typeMapping = map.GetType();

                if (ymltext == null | string.IsNullOrEmpty(ymltext))
                {
                    return null;
                }

                YamlStream yml = YamlParser.Load(ymltext);

                if (yml == null)
                {
                    return null;
                }

                //if mapping start parsing
                if (yml.Documents[0].Root.GetType() == typeMapping)
                {
                    foreach (MappingEntry item in ((Mapping) yml.Documents[0].Root).Enties)
                    {
                        //Check the type, check for possible keys and load the value
                        if (item.Value.GetType() == typeScalar)
                        {
                            switch (((Scalar) item.Key).Text)
                            {
                                case "name":
                                    Name = ((Scalar) item.Value).Text;
                                    break;
                                case "version":
                                    Version = ((Scalar) item.Value).Text;
                                    break;
                                case "description":
                                    Description = ((Scalar) item.Value).Text;
                                    break;
                                case "main":
                                    Mainspace = ((Scalar) item.Value).Text;
                                    break;
                                case "author":
                                    Authors = new string[1];
                                    Authors[0] = ((Scalar) item.Value).Text;
                                    break;
                                case "authors":
                                    Authors = new string[1];
                                    Authors[0] = ((Scalar) item.Value).Text;
                                    break;
                            }
                        }
                        else if (item.Value.GetType() == typeSequence)
                        {
                            switch (((Scalar) item.Key).Text)
                            {
                                case "author":
                                    Authors = ArrayFromSequence((Sequence) item.Value);
                                    break;
                                case "Authors":
                                    Authors = ArrayFromSequence((Sequence) item.Value);
                                    break;
                                case "softdepend":
                                    Softdepend = ArrayFromSequence((Sequence) item.Value);
                                    break;
                            }
                        }
                        else if (item.Value.GetType() == typeMapping)
                        {
                            switch (((Scalar) item.Key).Text)
                            {
                                case "commands":
                                    if (item.Value.GetType() == typeMapping)
                                        Commands = ParseCommands((Mapping) item.Value);
                                    else
                                        Commands = new List<PluginCommand>();
                                    break;
                                case "permissions":
                                    if (item.Value.GetType() == typeMapping)
                                        Permissions = ParsePermissions((Mapping) item.Value);
                                    else
                                        Permissions = new List<PluginPermission>();
                                    break;
                            }
                        }
                    }
                }
                return this;
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Warning, "InstalledPlugin", "An exception occured when trying to parse yml text",
                    ex.Message);
                return null;
            }
        }
示例#5
0
		private DataItem ParseFlowNodeInFlow(out bool success)
		{
			DataItem dataItem = new DataItem();

			dataItem = ParseAliasNode(out success);
			if (success) { ClearError(); return dataItem; }

			dataItem = ParseFlowContentInFlow(out success);
			if (success) { ClearError(); return dataItem; }

			while (true)
			{
				int seq_start_position1 = position;
				NodeProperty property = ParseNodeProperty(out success);
				if (success) { dataItem = new Scalar(); }
				else
				{
					Error("Failed to parse property of FlowNodeInFlow.");
					break;
				}

				while (true)
				{
					int seq_start_position2 = position;
					ParseSeparationLinesInFlow(out success);
					if (!success)
					{
						Error("Failed to parse SeparationLinesInFlow of FlowNodeInFlow.");
						break;
					}

					dataItem = ParseFlowContentInFlow(out success);
					if (!success)
					{
						Error("Failed to parse FlowContentInFlow of FlowNodeInFlow.");
						position = seq_start_position2;
					}
					break;
				}
				if (success) { SetDataItemProperty(dataItem, property); }
				success = true;
				break;
			}
			if (success) { ClearError(); return dataItem; }

			return dataItem;
		}
示例#6
0
		private Scalar ParseBlockKey(out bool success)
		{
			Scalar scalar = new Scalar();

			scalar.Text = ParsePlainTextSingleLine(out success);
			if (success) { ClearError(); return scalar; }

			scalar.Text = ParseDoubleQuotedSingleLine(out success);
			if (success) { ClearError(); return scalar; }

			scalar.Text = ParseSingleQuotedSingleLine(out success);
			if (success) { ClearError(); return scalar; }

			return scalar;
		}
示例#7
0
		private Scalar ParseBlockScalar(out bool success)
		{
			Scalar scalar = new Scalar();

			scalar.Text = ParseLiteralText(out success);
			if (success) { ClearError(); return scalar; }

			scalar.Text = ParseFoldedText(out success);
			if (success) { ClearError(); return scalar; }

			return scalar;
		}
示例#8
0
		private Scalar ParseFlowScalarInFlow(out bool success)
		{
			Scalar scalar = new Scalar();

			scalar.Text = ParsePlainTextInFlow(out success);
			if (success) { ClearError(); return scalar; }

			scalar.Text = ParseSingleQuotedText(out success);
			if (success) { ClearError(); return scalar; }

			scalar.Text = ParseDoubleQuotedText(out success);
			if (success) { ClearError(); return scalar; }

			return scalar;
		}