Ejemplo n.º 1
0
 internal static async void Upload(Folder folder, HtmlCollection <File> files)
 {
     if (files.Length == 1)
     {
         File     file     = files[0];
         ListItem listItem = null;
         if (await LazyWindow.ShowWaiting(string.Format("{0}: uploading...", file.Name),
                                          async delegate(CancellationToken cancellationToken)
         {
             listItem = await folder.Upload(file, cancellationToken);
         }))
         {
             ListItemEditor.Show(new EditAction()
             {
                 EditMode   = EditMode.Edit,
                 ListItem   = listItem,
                 TargetList = listItem.ParentList
             });
         }
     }
     else
     {
         for (int i = 0; i < files.Length; i++)
         {
             if (!await LazyWindow.ShowWaiting(string.Format("{0}: uploading...", files[i].Name),
                                               delegate(CancellationToken cancellation)
             {
                 return(folder.Upload(files[i], cancellation));
             }))
             {
                 break;
             }
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary> Creates new <sse cref="HtmlDocument"/> instance. </summary>
        internal Document(string namespaceUri, string qualifiedNameStr, DocType docType, IWindow window) : base(null)
        {
            Implementation = new DomImplementation();

            StyleSheets = new StyleSheetsList();
            NodeType    = DOCUMENT_NODE;

            if (docType != null)
            {
                AppendChild(docType);
            }

            var root = CreateElementNs(namespaceUri, qualifiedNameStr);

            AppendChild(root);

            Initialize();

            Scripts = new HtmlCollection(() => GetElementsByTagName(TagsNames.Script));
            Forms   = new HtmlCollection(() => GetElementsByTagName(TagsNames.Form));
            Images  = new HtmlCollection(() => GetElementsByTagName(TagsNames.Img));
            Links   = new HtmlCollection(() =>
                                         GetElementsByTagName(TagsNames.A).Where(x => !string.IsNullOrEmpty(((HtmlAnchorElement)x).Href))
                                         .Concat(GetElementsByTagName(TagsNames.Textarea).Where(x => !string.IsNullOrEmpty(((HtmlAreaElement)x).Href))));
            Embeds = new HtmlCollection(() => GetElementsByTagName(TagsNames.Embed));

            DefaultView = window;

            ReadyState = DocumentReadyStates.Loading;
        }
Ejemplo n.º 3
0
 internal static async void Upload(ListItem listItem, HtmlCollection <File> files)
 {
     for (int i = 0; i < files.Length; i++)
     {
         if (!await LazyWindow.ShowWaiting(string.Format("{0}: uploading...", files[i].Name),
                                           delegate(CancellationToken cancellationToken)
         {
             return(listItem.AddAttachment(UriUtility.GetFileName(files[i].Name), files[i], cancellationToken));
         }))
         {
             break;
         }
     }
 }
Ejemplo n.º 4
0
        public static void Main()
        {
            new WindowBuilder()
            .WithTitle("Plover Demo App")
            .WithSize(600, 400)
            .FromHtml("<html><body><h1 id=\"t1\">Hello world!</h1><button>Useless button</button><button>Useless button 2</button></body></html>")
            .Build()
            .Render((window) =>
            {
                Console.WriteLine(window.JavaScript.Execute <string>("document.body.innerHTML"));
                window.JavaScript.Execute("x = 'does this work?';");
                Console.WriteLine(window.JavaScript.Execute <string>("x"));

                Button b    = window.Document.CreateElement <Button>();
                b.InnerHtml = "Hello!";
                b.Id        = "karel";
                window.Document.Body.AppendChild(b);

                Button b2    = window.Document.CreateElement <Button>();
                b2.InnerHtml = "Hello2!";
                b2.Id        = "karel2";
                window.Document.Body.AppendChild(b2);

                HtmlElement possibleButton = window.Document.GetElementById("karel");
                Console.WriteLine($"Equality of elements: {b == possibleButton}");

                Console.WriteLine(window.Document.GetElementById("t1").InnerHtml);
                int cntr   = 0;
                b.OnClick += (s, e) =>
                {
                    b.InnerHtml = $"[{++cntr}] Alt was pressed: {e.AltKey}";
                };
                b.OnContextMenu += (s, e) => Console.WriteLine("Sorry no context menu :(");

                HtmlCollection <Button> buttons = window.Document.GetElementsByTagName <Button>();

                Console.WriteLine($"Buttons:\n{string.Join("\n", buttons.Select(x => x.InnerHtml))}");

                Console.WriteLine($"Button b: {buttons[b.Id]}");
            });
        }
Ejemplo n.º 5
0
 public HtmlTableSectionElement(Document owner, String name)
     : base(owner, name, NodeFlags.Special | NodeFlags.ImplicitelyClosed | NodeFlags.HtmlTableSectionScoped)
 {
     _rows = new HtmlCollection <IHtmlTableRowElement>(this);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates a new datalist element.
 /// </summary>
 internal HTMLDataListElement()
     : base(Tags.Datalist)
 {
     _options = new HtmlCollection <HTMLOptionElement>(this);
 }
Ejemplo n.º 7
0
 public HtmlTableElement(Document owner)
     : base(owner, Tags.Table, NodeFlags.Special | NodeFlags.Scoped | NodeFlags.HtmlTableScoped | NodeFlags.HtmlTableSectionScoped)
 {
     _rows   = new HtmlCollection <IHtmlTableRowElement>(this);
     _bodies = new HtmlCollection <IHtmlTableSectionElement>(this);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Creates a new datalist element.
 /// </summary>
 public HtmlDataListElement(Document owner)
     : base(owner, Tags.Datalist)
 {
     _options = new HtmlCollection <HtmlOptionElement>(this);
 }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
 internal HTMLTableRowElement()
     : base(Tags.Tr, NodeFlags.Special | NodeFlags.ImplicitelyClosed)
 {
     _cells = new HtmlCollection<HTMLTableCellElement>(this);
 }
Ejemplo n.º 11
0
 public HtmlTableRowElement(Document owner)
     : base(owner, Tags.Tr, NodeFlags.Special | NodeFlags.ImplicitelyClosed)
 {
     _cells = new HtmlCollection <HtmlTableCellElement>(this);
 }
Ejemplo n.º 12
0
 public HTMLTableRowElement()
     : base(Tags.Tr, NodeFlags.Special | NodeFlags.ImplicitelyClosed)
 {
     _cells = new HtmlCollection <HTMLTableCellElement>(this);
 }
Ejemplo n.º 13
0
 internal HTMLTableSectionElement(String name)
     : base(name, NodeFlags.Special | NodeFlags.ImplicitelyClosed | NodeFlags.HtmlTableSectionScoped)
 {
     _rows = new HtmlCollection <IHtmlTableRowElement>(this);
 }
Ejemplo n.º 14
0
 internal HTMLTableElement()
     : base(Tags.Table, NodeFlags.Special | NodeFlags.Scoped | NodeFlags.HtmlTableScoped | NodeFlags.HtmlTableSectionScoped)
 {
     _rows = new HtmlCollection<IHtmlTableRowElement>(this);
     _bodies = new HtmlCollection<IHtmlTableSectionElement>(this);
 }