示例#1
0
        public override bool Execute()
        {
            Log.LogMessage(MessageImportance.High, "Modeling Text Document(s)");
            WarnIfUneven(Tuple.Create("Downloads", Downloads), Tuple.Create("Documents", Documents), Tuple.Create("Uris", Uris), Tuple.Create("Models", Models));
            foreach (var tuple in Zip(Downloads, Documents, Uris, Models))
            {
                ITaskItem downloadInput = tuple.Item1;
                ITaskItem documentInput = tuple.Item2;
                ITaskItem uri           = tuple.Item3;
                ITaskItem modelOutput   = tuple.Item4;

                Log.LogMessage(MessageImportance.Normal, modelOutput.ItemSpec);
                modelOutput.RequireParentDirectory(Log);

                modelOutput.LoadCustomMetadataFrom(documentInput);

                Uri    u  = new Uri(uri.ItemSpec.Replace('\\', '/'));
                string us = u.ToString();

                modelOutput.SetMetadata("Uri", us);
                modelOutput.SetMetadata(FolderUriAlias ?? "FolderUri", us.Substring(0, us.Length - u.Segments.Last().Length));

                XslTransforms.Google.Documents.Text.ToModel(htmlPath: downloadInput.ItemSpec, modelPath: modelOutput.ItemSpec, metadata: modelOutput.GetAllMetadata());

                DateTime modified = downloadInput.GetTimestamp();
                File.SetLastWriteTime(modelOutput.ItemSpec, modified);
            }
            return(true);
        }
示例#2
0
        public static void Save(this ITaskItem taskItem, TaskLoggingHelper log, DateTime?lastWriteTime = null)
        {
            XNamespace xm       = "http://code.google.com/p/exult/model";
            XElement   document = new XElement(xm + "Document",
                                               new XAttribute(XNamespace.Xmlns + "xm", "http://code.google.com/p/exult/model"));

            document.Add(
                taskItem
                .MetadataNames
                .OfType <string>()
                .Distinct()
                .OrderBy(item => item)
                .Select(item => new XAttribute(item, taskItem.GetMetadata(item)))
                .ToArray());

            taskItem.RequireParentDirectory(log);

            XmlWriterSettings settings = new XmlWriterSettings()
            {
                Indent = true, NewLineOnAttributes = true
            };

            using (XmlWriter writer = XmlWriter.Create(taskItem.ItemSpec, settings))
            {
                document.Save(writer);
            }
            if (lastWriteTime != null)
            {
                taskItem.Touch(lastWriteTime.Value);
            }
        }
示例#3
0
        public override bool Execute()
        {
            WarnIfUneven(Tuple.Create("LocalItems", LocalItems), Tuple.Create("S3ObjectTimestamps", S3ObjectTimestamps), Tuple.Create("Receipts", Receipts), Tuple.Create("S3Puts", S3Puts));
            foreach (var tuple in Zip(LocalItems, S3ObjectTimestamps, Receipts, S3Puts))
            {
                ITaskItem publish        = tuple.Item1;
                ITaskItem published      = tuple.Item2;
                ITaskItem receipt        = tuple.Item3;
                ITaskItem put            = tuple.Item4;
                DateTime  publishUpdated = publish.GetTimestamp();

                bool newPublish = !File.Exists(published.ItemSpec);

                if (newPublish ||                              //If this is a new publish
                    publishUpdated > published.GetTimestamp()) //Or there is an update
                {
                    put.RequireParentDirectory(Log);

                    File.Copy(publish.ItemSpec, put.ItemSpec, true);
                    put.Touch(publishUpdated);
                }

                //Add a publish receipt for building the RSS feed
                if (newPublish)
                {
                    receipt.Save(Log, publishUpdated);
                }
            }
            return(true);
        }
示例#4
0
        public override bool Execute()
        {
            List <string> selectorNames =
                (Selectors ?? string.Empty)
                .Split(';')
                .Select(item => item.Trim())
                .DefaultIfEmpty("*")
                .ToList();
            bool removeAll = false;

            if (selectorNames.Any(item => item == "*"))
            {
                removeAll = true;
            }

            List <SelectorInfo> selectors = selectorNames.Select(item => new SelectorInfo(Log, item)).ToList();

            WarnIfUneven(Tuple.Create("Inputs", Inputs), Tuple.Create("Outputs", Outputs));
            foreach (var tuple in Zip(Inputs, Outputs))
            {
                ITaskItem input  = tuple.Item1;
                ITaskItem output = tuple.Item2;

                Log.LogMessage(MessageImportance.High, input.ItemSpec);
                bool         updatedItem = false;
                HtmlDocument document    = new HtmlDocument();
                document.Load(input.ItemSpec);

                if (removeAll)
                {
                    Log.LogMessage(MessageImportance.Normal, "Removing all <style/> tags");
                    updatedItem = RemoveAll(document);
                }
                else
                {
                    Log.LogMessage(MessageImportance.Normal, "Removing {0}", Selectors);
                    updatedItem = RemoveSelectors(Log, document, selectors);
                }

                output.RequireParentDirectory(Log);

                if (updatedItem)
                {
                    document.Save(output.ItemSpec);
                }
                else
                {
                    File.Copy(input.ItemSpec, output.ItemSpec, true);
                }
                input.CopyMetadataTo(output);
            }
            return(true);
        }
示例#5
0
文件: Bind.cs 项目: HimmaTong/exult
        public override bool Execute()
        {
            DateTime viewModelTimestamp = ViewModel.GetTimestamp();

            Log.LogMessage(MessageImportance.High, "Bind:");
            Log.LogMessage(MessageImportance.Normal, "ViewModel: {0}", ViewModel.ItemSpec);

            WarnIfUneven(Tuple.Create("Models", Models), Tuple.Create("Views", Views));
            foreach (var tuple in Zip(Models, Views))
            {
                ITaskItem model = tuple.Item1;
                ITaskItem view  = tuple.Item2;

                Log.LogMessage(MessageImportance.Normal, "Model: {0}", model.ItemSpec);
                Log.LogMessage(MessageImportance.Normal, "View: {0}", view.ItemSpec);

                DateTime modelTimestamp = model.GetTimestamp();

                view.RequireParentDirectory(Log);

                if (!XslTransforms.Bind(Log, modelPath: model.ItemSpec, viewModelPath: ViewModel.ItemSpec, viewPath: view.ItemSpec))
                {
                    return(false);
                }

                HtmlDocument doc = new HtmlDocument();
                doc.Load(view.ItemSpec);
                HtmlNode html = doc.DocumentNode.SelectSingleNode("//html");
                if (html != null)
                {
                    HtmlAttribute xvm = html.Attributes.FirstOrDefault(item => item.Name == "xmlns:xvm");
                    if (xvm != null)
                    {
                        xvm.Remove();
                        doc.Save(view.ItemSpec);
                    }
                }

                if (viewModelTimestamp > modelTimestamp)
                {
                    view.Touch(viewModelTimestamp);
                }
                else
                {
                    view.Touch(modelTimestamp);
                }
            }
            return(true);
        }
示例#6
0
        private void DoDownload(Request documentsRequest, ITaskItem document, ITaskItem download)
        {
            string sourceFile      = document.ItemSpec;
            string targetFile      = download.ItemSpec;
            string targetDirectory = Path.GetDirectoryName(targetFile);

            Log.LogMessage(MessageImportance.High, "Downloading \"{0}\"", document.RequireTitle());
            Log.LogMessage(MessageImportance.Normal, "To \"{0}\"", targetDirectory);
            download.RequireParentDirectory(Log);

            if (!File.Exists(sourceFile))
            {
                throw new FileNotFoundException("Cannot find", sourceFile);
            }

            ResourceType resourceType = document.RequireResourceType();

            switch (resourceType)
            {
            case ResourceType.file:
                DoFileDownload(documentsRequest, document, targetFile);
                break;

            case ResourceType.document:
                DoDocumentDownload(documentsRequest, document, targetFile);
                break;

            default:
                throw new NotImplementedException(string.Format("Resource Type '{0}' is unsupported", resourceType));
            }

            DateTime updated = document.GetTimestamp();

            File.SetLastWriteTime(download.ItemSpec, updated);
            document.CopyMetadataTo(download);
        }
示例#7
0
        private void DoDownload(Request documentsRequest, ITaskItem document, ITaskItem download)
        {
            string sourceFile = document.ItemSpec;
            string targetFile = download.ItemSpec;
            string targetDirectory = Path.GetDirectoryName(targetFile);
            Log.LogMessage(MessageImportance.High,"Downloading \"{0}\"", document.RequireTitle());
            Log.LogMessage(MessageImportance.Normal, "To \"{0}\"", targetDirectory);
            download.RequireParentDirectory(Log);

            if (!File.Exists(sourceFile))
            {
                throw new FileNotFoundException("Cannot find", sourceFile);
            }

            ResourceType resourceType = document.RequireResourceType();
            switch (resourceType)
            {
                case ResourceType.file:
                    DoFileDownload(documentsRequest, document, targetFile);
                    break;
                case ResourceType.document:
                    DoDocumentDownload(documentsRequest, document, targetFile);
                    break;
                default:
                    throw new NotImplementedException(string.Format("Resource Type '{0}' is unsupported", resourceType));
            }

            DateTime updated = document.GetTimestamp();
            File.SetLastWriteTime(download.ItemSpec, updated);
            document.CopyMetadataTo(download);
        }