public Capture(RazorPage page, ResourcePosition position, Action <ResourceCollection> onRegisted)
 {
     this._page = page;
     _position  = position;
     this._page.StartTagHelperWritingScope(page.HtmlEncoder);
     _onRegisted = onRegisted;
 }
Пример #2
0
        private IHtmlContent GetResource(bool includeRequired, ResourceType type, ResourcePosition position)
        {
            var builder = new HtmlContentBuilder();

            switch (type)
            {
            case ResourceType.Script:
            {
                if (includeRequired)
                {
                    ResourceManager.ScriptSource.Where(m => m.Value.Required && m.Value.Position == position)
                    .Each(m => m.Value.Each(r => builder.AppendHtml(r.ToSource(this))));
                }

                _requiredScripts.Where(m => m.Position == position).Each(m => m.Each(r => builder.AppendHtml(r.ToSource(this))));
                break;
            }

            case ResourceType.Style:
            {
                if (includeRequired)
                {
                    ResourceManager.StyleSource.Where(m => m.Value.Required && m.Value.Position == position)
                    .Each(m => m.Value.Each(r => builder.AppendHtml(r.ToSource(this))));
                }

                _requiredStyles.Where(m => m.Position == position).Each(m => m.Each(r => builder.AppendHtml(r.ToSource(this))));
                break;
            }
            }
            return(builder);
        }
Пример #3
0
 public Capture(WebPageBase page, Action <ResourceCollection, string> callBack, ResourcePosition position, string key)
 {
     _key       = key;
     this._page = page;
     _position  = position;
     _callBack  = callBack;
 }
Пример #4
0
 public Capture(WebPageBase page, Action<ResourceCollection, string> callBack, ResourcePosition position, string key)
 {
     _key = key;
     this._page = page;
     _position = position;
     _callBack = callBack;
 }
Пример #5
0
        private IHtmlString GetResource(string key, ResourcePosition position, bool includeRequired)
        {
            var writer = new HtmlStringWriter();

            if (includeRequired)
            {
                switch (key)
                {
                case PartScriptKey:
                    ResourceManager.ScriptSource.Where(m => m.Value.Required && m.Value.Position == position)
                    .Each(m => m.Value.Each(r => writer.WriteLine(r.ToSource(this, this.Context)))); break;

                case PartStyleKey:
                    ResourceManager.StyleSource.Where(m => m.Value.Required && m.Value.Position == position)
                    .Each(m => m.Value.Each(r => writer.WriteLine(r.ToSource(this, this.Context)))); break;
                }
            }

            if (TempData.ContainsKey(key))
            {
                var source = TempData[key] as Dictionary <string, ResourceCollection>;
                if (source != null)
                {
                    source.Each(m => m.Value.Where(n => n.Position == position).Each(l => writer.WriteLine(l.ToSource(this, this.Context))));
                }
            }
            return(writer);
        }
Пример #6
0
        private IHtmlContent GetResource(bool includeRequired, ResourceType type, ResourcePosition position)
        {
            var                  builder            = new HtmlContentBuilder();
            IUrlHelper           urlHelper          = Context.RequestServices.GetService <IUrlHelperFactory>().GetUrlHelper(ViewContext);
            IWebHostEnvironment  hostingEnvironment = Context.RequestServices.GetService <IWebHostEnvironment>();
            IOptions <CDNOption> options            = Context.RequestServices.GetService <IOptions <CDNOption> >();

            switch (type)
            {
            case ResourceType.Script:
            {
                if (includeRequired)
                {
                    ResourceHelper.ScriptSource.Where(m => m.Value.Required && m.Value.Position == position)
                    .Each(m => m.Value.Each(r =>
                        {
                            builder.AppendHtml(r.ToSource(urlHelper, hostingEnvironment, options));
                        }));
                }

                _requiredScripts.Where(m => m.Position == position).Each(m => m.Each(r =>
                                                                                     builder.AppendHtml(r.ToSource(urlHelper, hostingEnvironment, options))));
                break;
            }

            case ResourceType.Style:
            {
                if (includeRequired)
                {
                    ResourceHelper.StyleSource.Where(m => m.Value.Required && m.Value.Position == position)
                    .Each(m => m.Value.Each(r =>
                        {
                            builder.AppendHtml(r.ToSource(urlHelper, hostingEnvironment, options));
                        }));
                }

                _requiredStyles.Where(m => m.Position == position).Each(m => m.Each(r =>
                    {
                        builder.AppendHtml(r.ToSource(urlHelper, hostingEnvironment, options));
                    }));
                break;
            }
            }
            return(builder);
        }
        void IconMouseEvents()
        {
            //Mouse position relatiuve to the window
            MousePosition = Event.current.mousePosition;

            //If the Mouse is inside the scroll window
            if (MousePosition.y > 54 && MousePosition.y < (WindowHeight-26) )
            {
                //check what we are over
                resourceOver = lstResPositions.FirstOrDefault(x => x.resourceRect.Contains(MousePosition + ScrollPosition - new Vector2(8, 54)));
                if (resourceOver != null)
                {
                    resourceOverUpper = ((MousePosition + ScrollPosition - new Vector2(8, 54)).y - resourceOver.resourceRect.y) < resourceOver.resourceRect.height / 2;
                    resourceInsertIndex = lstResPositions.FindIndex(x => x.id == resourceOver.id);
                    if (!resourceOverUpper) resourceInsertIndex += 1;
                }
                else
                    resourceInsertIndex = -1;
                iconOver = lstResPositions.FirstOrDefault(x => x.iconRect.Contains(MousePosition + ScrollPosition + -new Vector2(8, 54)));

                //Will the drop actually change the list
                DropWillReorderList = (resourceInsertIndex != resourceDragIndex) && (resourceInsertIndex != resourceDragIndex + 1);
            }
            else { resourceOver = null; iconOver = null; }

            //did we click on an Icon with mouse button 0
            if (Event.current.type == EventType.mouseDown &&
                Event.current.button==0 && iconOver!=null)
            {
                LogFormatted_DebugOnly("Drag Start");
                resourceDrag = iconOver;
                resourceDragIndex = lstResPositions.FindIndex(x=>x.id==resourceDrag.id);
                DraggingResource = true;
                DropWillReorderList = false;
            }
            //did we release the mouse
            if (Event.current.type == EventType.mouseUp &&
                Event.current.button == 0)
            {
                if (resourceOver != null)
                {
                    //And dropped on a resource - cater to the above below code in this new one
                    //LogFormatted_DebugOnly("Drag Stop:{0}-{1}-{2}", resourceOver == null ? "None" : resourceDragIndex.ToString(), resourceOver == null ? "" : (resourceInsertIndex< lstResPositions.Count ? settings.Resources[lstResPositions[resourceInsertIndex].id].name:"Last"), resourceDrag.name);
                    MoveResource(resourceDragIndex, resourceInsertIndex);

                    //LogFormatted_DebugOnly("Drag Stop:{0}-{1}-{2}", resourceOver == null ? "None" : lstResPositions.FindIndex(x => x.id == resourceOver.id).ToString(), resourceOver == null ? "" : settings.Resources[resourceOver.id].name, resourceDrag.name);
                    //MoveResource(lstResPositions.FindIndex(x => x.id == resourceDrag.id), lstResPositions.FindIndex(x => x.id == resourceOver.id));
                }
                //disable dragging flag
                DraggingResource = false;
                resourceDrag = null;
            }

            //If we are dragging and in the bottom or top area then scrtoll the list
            if(DraggingResource && rectScrollBottom.Contains(MousePosition))
                ScrollPosition.y += (Time.deltaTime * 40);
            if(DraggingResource && rectScrollTop.Contains(MousePosition))
                ScrollPosition.y -= (Time.deltaTime * 40);
        }
        //Outside the window draw routine so it acts anywhere on the screen
        internal override void OnGUIEvery()
        {
            base.OnGUIEvery();

            //disable resource dragging if we mouseup outside the window
            if (Event.current.type == EventType.mouseUp &&
                Event.current.button == 0 &&
                !this.WindowRect.Contains(new Vector2(Input.mousePosition.x,Screen.height-Input.mousePosition.y)))
            {
                DraggingResource = false;
                resourceDrag = null;
                resourceDragIndex = -1;
            }

            //If we are dragging, show what we are dragging
            if (DraggingResource && resourceDrag!=null)
            {
                //set the Style
                GUIStyle styleResMove = SkinsLibrary.CurrentTooltip;
                styleResMove.alignment = TextAnchor.MiddleLeft;

                //set and draw the text like a tooltip
                String Message = "  Moving";
                if (resourceDrag.name == "Separator") Message += " Separator";
                Rect LabelPos = new Rect(Input.mousePosition.x-5,Screen.height-Input.mousePosition.y-9,120,22);
                GUI.Label(LabelPos, Message, SkinsLibrary.CurrentTooltip);

                //If its a resourcethen draw the icon too
                if (resourceDrag.name != "Separator")
                {
                    GUIContent contIcon = Drawing.GetResourceIcon(resourceDrag.name); ;
                    Rect ResPos = new Rect(Input.mousePosition.x + 55, Screen.height - Input.mousePosition.y-6, 32, 16);
                    GUI.Box(ResPos, contIcon, new GUIStyle());
                }
                //On top of everything
                GUI.depth = 0;
            }
        }
Пример #9
0
        /// <summary>
        /// Position a resource first, last or by dependency.
        /// </summary>
        /// <param name="position"></param>
        public ResourceDefinition SetPosition(ResourcePosition position)
        {
            Position = position;

            return(this);
        }