Ejemplo n.º 1
0
        public override bool Execute()
        {
            WarnIfUneven(Tuple.Create("Prefixes", Prefixes), Tuple.Create("Suffixes", Suffixes), Tuple.Create("Outputs", Outputs));
            foreach (var tuple in Zip(Prefixes, Suffixes, Outputs))
            {
                ITaskItem prefix = tuple.Item1;
                ITaskItem suffix = tuple.Item2;
                ITaskItem output = tuple.Item3;

                DateTime prefixUpdated = prefix.GetTimestamp();
                DateTime suffixUpdated = suffix.GetTimestamp();

                Log.LogMessage(MessageImportance.High, "Appending");
                Log.LogMessage(MessageImportance.Normal, "Prefix: {0}", Path.GetFileName(prefix.ItemSpec));
                Log.LogMessage(MessageImportance.Normal, "Suffix: {0}", Path.GetFileName(suffix.ItemSpec));
                Log.LogMessage(MessageImportance.Normal, "Output: {0}", Path.GetFileName(output.ItemSpec));
                Log.LogMessage(MessageImportance.Normal, "Directory: {0}", Path.GetDirectoryName(prefix.ItemSpec));

                JoinModels.Join(
                    log: Log,
                    models: new[] { tuple.Item1, tuple.Item2 },
                    output: tuple.Item3);

                if (prefixUpdated > suffixUpdated)
                {
                    File.SetLastWriteTime(output.ItemSpec, prefixUpdated);
                }
                else
                {
                    File.SetLastWriteTime(output.ItemSpec, suffixUpdated);
                }
            }

            return(true);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public override bool Execute()
        {
            GDataCredentials credentials = GetDataCredentials();
            RequestSettings  settings    = new RequestSettings("code.google.com/p/exult/", credentials);

            settings.AutoPaging = true;
            settings.PageSize   = 100;

            List <ITaskItem> folderContent = new List <ITaskItem>();

            WarnIfUneven(Tuple.Create("Folders", Folders), Tuple.Create("FolderListings", FolderListings));
            foreach (var tuple in Zip(Folders, FolderListings))
            {
                if (_Cancelled)
                {
                    return(false);
                }

                ITaskItem folder        = tuple.Item1;
                ITaskItem folderListing = tuple.Item2;

                folder.LoadCustomMetadata();
                folder.RequireDocumentType(Document.DocumentType.Folder);

                //yada/hrm.folder -> yada/hrm/
                string folderPath = Path.Combine(Path.GetDirectoryName(folder.ItemSpec), Path.GetFileNameWithoutExtension(folder.ItemSpec));
                RequireDirectory(folderPath);
                PathMapping folderMapping = new PathMapping(folderPath);

                Request request = new Request(settings);

                string resourceId = folder.RequireResourceId();

                Log.LogMessage(MessageImportance.High, "Getting Folder Content \"{0}\"", folder.RequireTitlePath());
                Feed <Document> feed = request.GetFolderContent(resourceId);

                // this takes care of paging the results in
                List <Document> documents = feed.Entries.Where(item => item.Type != Document.DocumentType.Folder).ToList();
                Log.LogMessage(MessageImportance.Normal, "Found {0} Item(s)", documents.Count);

                DateTime folderTimestamp = folder.GetTimestamp();
                DateTime latestTimestamp = folderTimestamp;

                foreach (Document document in documents)
                {
                    if (_Cancelled)
                    {
                        return(false);
                    }

                    if (document.Updated > latestTimestamp)
                    {
                        latestTimestamp = document.Updated;
                    }
                    if (Pattern == null || PatternExpression.IsMatch(document.Title))
                    {
                        Log.LogMessage(MessageImportance.Normal, "Matched \"{0}\"", document.Title);
                        folderContent.Add(BuildContent(folder, document, folderMapping));
                    }
                    else
                    {
                        Log.LogMessage(MessageImportance.Low, "Skipped \"{0}\"", document.Title);
                    }
                }
                folder.CopyMetadataTo(folderListing);
                folderListing.Save(Log, latestTimestamp);
            }
            FolderContent = folderContent.ToArray();
            return(true);
        }
Ejemplo n.º 7
0
        public override void ExecuteItemSequence(string groupByValue, IEnumerable <Tuple <ITaskItem, ITaskItem, ITaskItem> > items)
        {
            var feed = new AtomFeed
            {
                Id        = new AtomId(new Uri(FeedId)),
                Title     = new AtomTextConstruct(FeedTitle ?? ""),
                UpdatedOn = DateTime.Now,
            };

            if (!string.IsNullOrWhiteSpace(FeedRights))
            {
                feed.Rights = new AtomTextConstruct(FeedRights);
            }

            if (!string.IsNullOrWhiteSpace(FeedIcon))
            {
                feed.Icon = new AtomIcon(new Uri(FeedIcon));
            }

            if (!string.IsNullOrWhiteSpace(FeedLogo))
            {
                feed.Logo = new AtomLogo(new Uri(FeedLogo));
            }

            if (!string.IsNullOrWhiteSpace(FeedSubtitle))
            {
                feed.Subtitle = new AtomTextConstruct(FeedSubtitle);
            }


            if (!string.IsNullOrWhiteSpace(FeedAuthors))
            {
                foreach (string author in FeedAuthors.Split(';').Select(item => item.Trim()))
                {
                    feed.Authors.Add(new AtomPersonConstruct(author));
                }
            }

            if (!string.IsNullOrWhiteSpace(FeedContributors))
            {
                foreach (string contributor in FeedContributors.Split(';').Select(item => item.Trim()))
                {
                    feed.Contributors.Add(new AtomPersonConstruct(contributor));
                }
            }

            if (!string.IsNullOrWhiteSpace(FeedCategories))
            {
                foreach (string category in FeedCategories.Split(';').Select(item => item.Trim()))
                {
                    feed.Categories.Add(new AtomCategory(category));
                }
            }

            if (FeedLinkRelationSelf != null)
            {
                var selfLink = new AtomLink
                {
                    Relation = "self",
                    Uri      = new Uri(FeedLinkRelationSelf)
                };
                feed.Links.Add(selfLink);
            }

            foreach (Tuple <ITaskItem, ITaskItem, ITaskItem> tuple in items.OrderByDescending(item => item.Item2.GetTimestamp()))
            {
                ITaskItem modelInput   = tuple.Item1;
                ITaskItem receiptInput = tuple.Item2;
                ITaskItem contentInput = tuple.Item3;

                modelInput.LoadCustomMetadata();

                DateTime receiptModified = receiptInput.GetTimestamp();
                var      entry           = new AtomEntry
                {
                    Id        = new AtomId(new Uri(modelInput.GetMetadata(EntryIdSelector ?? "Uri"))),
                    Title     = new AtomTextConstruct(modelInput.GetMetadata(EntryTitleSelector ?? "Title")),
                    UpdatedOn = receiptModified,
                    Summary   = new AtomTextConstruct(modelInput.GetMetadata(EntrySummarySelector ?? "Summary")),
                };

                if (string.IsNullOrWhiteSpace(entry.Title.Content))
                {
                    entry.Title.Content = tuple.Item1.ItemSpec;
                }
                if (string.IsNullOrWhiteSpace(entry.Summary.Content))
                {
                    entry.Summary.Content = entry.Title.Content;
                }

                if (contentInput.Exists())
                {
                    if (string.IsNullOrWhiteSpace(EntryContentEncoding))
                    {
                        entry.Content = new AtomContent(contentInput.ReadAllText());
                    }
                    else
                    {
                        entry.Content = new AtomContent(contentInput.ReadAllText(), EntryContentEncoding);
                    }

                    if (!string.IsNullOrWhiteSpace(EntryContentType))
                    {
                        entry.Content.ContentType = EntryContentType;
                    }
                }

                var alternateLink = new AtomLink
                {
                    Relation = "alternate",
                    Uri      = new Uri(modelInput.GetMetadata(EntryLinkAlternateSelector ?? "Uri"))
                };
                entry.Links.Add(alternateLink);
                feed.AddEntry(entry);
            }
            using (FileStream stream = File.OpenWrite(Output.ItemSpec))
            {
                SyndicationResourceSaveSettings s = new SyndicationResourceSaveSettings()
                {
                    CharacterEncoding = Encoding.UTF8
                };
                feed.Save(stream, s);
            }
        }
Ejemplo n.º 8
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);
        }