Beispiel #1
0
        public static string WebToStringParse(string value)
        {
            var Result = "";

            for (int i = 0; i < value.Length; i++)
            {
                if (value[i].ToString() == "+")
                {
                    Result += " ";
                }
                else if (value[i].ToString() == "%")
                {
                    var Buffer = new byte[0];
                    while (value[i].ToString() == "%")
                    {
                        ArrayExtentions.Insert(ref Buffer,
                                               (byte)HexToDecimal(value.Substring(i + 1, 2)));
                        i += 3;
                        if (!(i < value.Length))
                        {
                            break;
                        }
                    }
                    Result += System.Text.Encoding.UTF8.GetString(Buffer);
                }
                else
                {
                    Result += value[i].ToString();
                }
            }
            return(Result);
        }
Beispiel #2
0
        public static WebData[] GetData(string Data)
        {
            var WebDatas = new WebData[0];

            if (Data.Length > 0)
            {
                var IndexEqual = Data.IndexOf("=");
                var IndexAnd   = Data.IndexOf("&");
                while (IndexAnd > 0)
                {
                    ArrayExtentions.Insert(ref WebDatas,
                                           new WebData(
                                               Data.Substring(0, IndexEqual),
                                               WebToStringParse(Data.Substring(IndexEqual + 1, (IndexAnd - IndexEqual) - 1))));
                    Data       = Data.Substring(IndexAnd + 1);
                    IndexEqual = Data.IndexOf("=");
                    IndexAnd   = Data.IndexOf("&");
                }
                ArrayExtentions.Insert(ref WebDatas,
                                       new WebData(
                                           Data.Substring(0, IndexEqual),
                                           WebToStringParse(Data.Substring(IndexEqual + 1))));
            }
            return(WebDatas);
        }
        public Responsor AddService(
            string ServiceName,
            Action Service)
        {
            var Response = new ResponsorData()
            {
                RequestName = ServiceName,
                Responsor   = new Responsor(null, Service)
            };

            ArrayExtentions.BinaryInsert(ref Childs, Response);
            return(Response.Responsor);
        }
        public Responsor <DataType> AddService <DataType>(
            string ServiceName,
            Func <DataType> Way,
            Action <DataType> Service)
        {
            var Response = new ResponsorData()
            {
                RequestName = ServiceName,
                Responsor   = new Responsor(
                    () => Responsor <DataType> .Data = Way(),
                    () => Service(Responsor <DataType> .Data))
            };

            ArrayExtentions.BinaryInsert(ref Childs, Response);
            return(new Responsor <DataType>(Response.Responsor));
        }
        public static byte[] SerializationDelegate(this Delegate obj)
        {
            var Result = new byte[0];

            var Method = obj.Method.Serialization();

            ArrayExtentions.Insert(ref Result,
                                   System.BitConverter.GetBytes(Method.Length));

            ArrayExtentions.Insert(ref Result, Method);

            var STarger = obj.Target.DynamicSerialization();

            ArrayExtentions.Insert(ref Result,
                                   System.BitConverter.GetBytes(STarger.Length));

            ArrayExtentions.Insert(ref Result, STarger);

            return(Result);
        }
        public static byte[] DynamicSerialization <t>(this t obj)
            where t : new()
        {
            var Result = new byte[0];
            var Type   = obj.GetType();
            var Filds  = Type.GetFields();

            ArrayExtentions.Insert(ref Result, System.BitConverter.GetBytes(Type.Assembly.FullName.Length * 2));
            ArrayExtentions.Insert(ref Result, Encoding.Unicode.GetBytes(Type.Assembly.FullName));

            ArrayExtentions.Insert(ref Result, System.BitConverter.GetBytes(Type.FullName.Length * 2));
            ArrayExtentions.Insert(ref Result, Encoding.Unicode.GetBytes(Type.FullName));

            for (int i = 0; i < Filds.Length; i++)
            {
                var Sfield = Filds[i].GetValue(obj).Serialization();
                ArrayExtentions.Insert(ref Result, System.BitConverter.GetBytes(Sfield.Length));
                ArrayExtentions.Insert(ref Result, Sfield);
            }

            return(Result);
        }
        public static HTMLTag[] Parse(string HTMLDocument)
        {
            return(HTMLDocument.ToStructrure <char, HTMLTag[]>(
                       (c) =>
            {
                var Documents = new HTMLTag[0];

                while (true)
                {
                    c.Data = new string(c.Data.ToArray()).Trim();

                    if (c.Data.Count() == 0)
                    {
                        return Documents;
                    }
                    else if (new string(c.Data.Take(2).ToArray()) == "</")
                    {
                        c.Data = c.Data.Skip(2);
                        return Documents;
                    }

                    if (c.Data.First().ToString() != "<")
                    {
                        throw new FormatException("Invalid Format");
                    }

                    ArrayExtentions.Insert(ref Documents, new HTMLTag());
                    var Document = Documents[Documents.Length - 1];


                    c.Data = c.Data.Skip(1);

                    Document.Name =
                        new string(c.Data.
                                   TakeWhile((q) => q.ToString() != " " &
                                             q.ToString() != ">" &
                                             q.ToString() != "/").ToArray());
                    c.Data = c.Data.Skip(Document.Name.Length);
                    c.Data = new string(c.Data.ToArray()).Trim();

                    if (c.Data.First().ToString() == "/")
                    {
                        c.Data = c.Data.Skip(2);
                    }
                    else if (c.Data.First().ToString() == ">")
                    {
                        c.Data = c.Data.Skip(1);
                        Document.InnerTags.AddRange(c.Repliy());

                        var EndName = new string(c.Data.TakeWhile((q) => q.ToString() != ">").ToArray());

                        if (EndName != Document.Name)
                        {
                            return Documents;
                        }
                        c.Data = c.Data.Skip(EndName.Length);
                    }
                    else
                    {
                        while (c.Data.First().ToString() != ">" &
                               c.Data.First().ToString() != "/")
                        {
                            var OptionName =
                                new string(c.Data.TakeWhile((q) => q.ToString() != "=").ToArray());
                            c.Data = c.Data.Skip(OptionName.Length + 2);

                            var OptionValue = new string(c.Data.TakeWhile((q) => q.ToString() != "\"").ToArray());

                            Document.Options.Add(OptionName, OptionValue);

                            c.Data = c.Data.Skip(OptionValue.Length + 1);
                            c.Data = new string(c.Data.ToArray()).Trim();
                        }

                        if (c.Data.First().ToString() == ">")
                        {
                            c.Data = c.Data.Skip(1);
                            Document.InnerTags.AddRange(c.Repliy());

                            var EndName = new string(c.Data.TakeWhile((q) => q.ToString() != ">").ToArray());

                            if (EndName != Document.Name)
                            {
                                return Documents;
                            }
                            c.Data = c.Data.Skip(EndName.Length);
                        }
                        else
                        {
                            c.Data = c.Data.Skip(2);
                        }
                    }
                }
            }));
        }