示例#1
0
        public override TaskExecutionDetails Execute(string Value)
        {
            TaskExecutionDetails d = new TaskExecutionDetails();


            HtmlDocument doc = new HtmlDocument();

            doc.Load(IOHelper.MapPath(SystemDirectories.Masterpages) + "/" + TargetFile);

            //if (doc.DocumentNode.SelectSingleNode(string.Format("//link [@href = '{0}']", Value)) == null)
            //{

            HtmlNode target = doc.DocumentNode.SelectSingleNode(string.IsNullOrEmpty(TargetSelector) ? "//head" : TargetSelector.ToLower());

            if (target != null)
            {
                HtmlNode s = doc.CreateElement("link");
                //s.Name = "link";
                s.Attributes.Append("rel", "stylesheet");
                s.Attributes.Append("type", "text/css");


                s.Attributes.Append("href", Value);


                if (!string.IsNullOrEmpty(Media))
                {
                    s.Attributes.Append("media", Media);
                }

                target.AppendChild(s);

                doc.Save(IOHelper.MapPath(SystemDirectories.Masterpages) + "/" + TargetFile);

                d.TaskExecutionStatus = TaskExecutionStatus.Completed;
                d.NewValue            = Value;
            }
            else
            {
                d.TaskExecutionStatus = TaskExecutionStatus.Cancelled;
            }
            //}
            //else
            //    d.TaskExecutionStatus = TaskExecutionStatus.Cancelled;

            return(d);
        }