Example #1
0
        private string CommandByNick(string Nick)
        {
            string sRaw = FileRead("Launcher.bat");

            string[] asRaw = sRaw.Replace("\r", "").Split('\n');
            foreach (string Raw in asRaw)
            {
                if (Raw.Contains("/user " + Nick + " /"))
                {
                    return(Raw);
                }
            }
            return("");
        }
Example #2
0
        /// <summary>
        /// Parse raw data.
        /// </summary>
        private void ParseRaw()
        {
            var queryParameters = new Dictionary <string, string>();

            string[] fragments = null;

            // fragment encoded
            if (Raw.Contains("#"))
            {
                fragments    = Raw.Split('#');
                ResponseType = ResponseTypes.Token;
            }
            // query string encoded
            else if (Raw.Contains("?"))
            {
                fragments    = Raw.Split('?');
                ResponseType = ResponseTypes.AuthorizationCode;
            }
            // form encoded
            else
            {
                fragments    = new string[] { "", Raw };
                ResponseType = ResponseTypes.FormPost;
            }

            if (Raw.Contains(OAuth2Constants.Error))
            {
                ResponseType = ResponseTypes.Error;
            }

            var qparams = fragments[1].Split('&');

            foreach (var param in qparams)
            {
                var parts = param.Split('=');

                if (parts.Length == 2)
                {
                    Values.Add(parts[0], parts[1]);
                }
                else
                {
                    throw new InvalidOperationException("Malformed callback URL.");
                }
            }
        }
Example #3
0
        private void ParseRaw()
        {
            string[] fragments;

            // query string encoded
            if (Raw.Contains("?"))
            {
                fragments = Raw.Split('?');

                var additionalHashFragment = fragments[1].IndexOf('#');
                if (additionalHashFragment >= 0)
                {
                    fragments[1] = fragments[1].Substring(0, additionalHashFragment);
                }
            }
            // fragment encoded
            else if (Raw.Contains("#"))
            {
                fragments = Raw.Split('#');
            }
            // form encoded
            else
            {
                fragments = new[] { "", Raw };
            }

            var qparams = fragments[1].Split('&');

            foreach (var param in qparams)
            {
                var parts = param.Split('=');

                if (parts.Length == 2)
                {
                    Values.Add(parts[0], parts[1]);
                }
                else if (parts.Length == 3)
                {
                    Values.Add(parts[0], parts[1] + '=' + parts[2]);
                }
                else
                {
                    throw new InvalidOperationException("Malformed callback URL.");
                }
            }
        }
 public bool HasValidData()
 {
     return(Raw.Contains("NO DATA"));
 }
Example #5
0
        public async Task <HtmlCollection> DocumentElement()
        {
            IDocument container;

            if (!string.IsNullOrWhiteSpace(Raw))
            {
                var parser = new HtmlParser();
                container = parser.Parse(Raw);
            }
            else if (!string.IsNullOrWhiteSpace(Url))
            {
                container = await BrowsingContext.New(Configuration.Default.WithDefaultLoader()).OpenAsync(Url);
            }
            else
            {
                throw new Exception("no source");
            }

            if (Actions != null)
            {
                foreach (var action in Actions)
                {
                    var subjects = container.QuerySelectorAll(action.At);
                    if (action.Type == "insert")
                    {
                        var sources = await action.Source.DocumentElement();

                        subjects.ForEach(subject => sources.ForEach(source => subject.AppendChild(source.Clone(deep: true))));
                    }
                    else if (action.Type == "replace")
                    {
                        var sources = await action.Source.DocumentElement();

                        subjects.ForEach(subject => subject.Replace(sources.Clone().ToArray()));
                    }
                    else if (action.Type == "remove")
                    {
                        subjects.ForEach(subject => subject.Remove());
                    }
                    else if (action.Type == "insert-after")
                    {
                        var sources = await action.Source.DocumentElement();

                        subjects.ForEach(subject => subject.Insert(AdjacentPosition.AfterEnd, sources.ToHtml()));
                    }
                    else if (action.Type == "insert-before")
                    {
                        var sources = await action.Source.DocumentElement();

                        subjects.ForEach(subject => subject.Insert(AdjacentPosition.BeforeBegin, sources.ToHtml()));
                    }
                    else if (action.Type == "wrap")
                    {
                        var sources = await action.Source.DocumentElement();

                        if (sources.Count > 1)
                        {
                            throw new Exception("Wrap can only support a single element in the source");
                        }
                        subjects.ForEach(subject => {
                            var contextSource = sources.First().Clone();
                            subject.Replace(contextSource);
                            contextSource.AppendChild(subject);
                        });
                    }
                }
            }

            var elements = new HtmlCollection();

            if (!string.IsNullOrWhiteSpace(Raw))
            {
                if (Raw.Contains("<html>"))
                {
                    elements.Add(container.DocumentElement);
                }
                else
                {
                    if (container.Body.Children.Any())
                    {
                        elements.AddRange(container.Body.Children);
                    }
                    else if (container.Head.Children.Any())
                    {
                        elements.AddRange(container.Head.Children);
                    }
                    else
                    {
                        throw new Exception("Could not find created element");
                    }
                }

                if (!string.IsNullOrWhiteSpace(Select))
                {
                    elements = elements.QuerySelectorAll(Select);
                }
            }
            else if (!string.IsNullOrWhiteSpace(Url))
            {
                if (!string.IsNullOrWhiteSpace(Select))
                {
                    elements.AddRange(container.QuerySelectorAll(Select));
                }
                else
                {
                    elements.Add(container.DocumentElement);
                }
            }
            else
            {
                throw new Exception("no source");
            }


            return(elements);
        }