Esempio n. 1
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);
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
0
            public Stream Download(ITaskItem input, Document.DownloadType type, string baseDomain = null, int sheetNumber = 0)
            {
                input.LoadCustomMetadata();
                Document.DocumentType documentType = input.RequireDocumentType();

                Service s        = this.Service;
                string  queryUri = this.BuildDocumentPartialExportUrl(input.RequireExportUri());

                switch (documentType)
                {
                case Document.DocumentType.Spreadsheet:
                    s = this.Service;
                    switch (type)
                    {
                    case Document.DownloadType.xls:
                        queryUri += "xls";
                        break;

                    case Document.DownloadType.csv:
                        queryUri += "csv&gid=" + sheetNumber.ToString();
                        break;

                    case Document.DownloadType.pdf:
                        queryUri += "pdf";
                        break;

                    case Document.DownloadType.ods:
                        queryUri += "ods";
                        break;

                    case Document.DownloadType.tsv:
                        queryUri += "tsv&gid=" + sheetNumber.ToString();;
                        break;

                    case Document.DownloadType.html:
                        queryUri += "html";
                        break;

                    default:
                        throw new ArgumentException("type is invalid for a spreadsheet");
                    }
                    break;

                case Document.DocumentType.Presentation:
                    switch (type)
                    {
                    case Document.DownloadType.swf:
                        queryUri += "swf";
                        break;

                    case Document.DownloadType.pdf:
                        queryUri += "pdf";
                        break;

                    case Document.DownloadType.ppt:
                        queryUri += "ppt";
                        break;

                    default:
                        throw new ArgumentException("type is invalid for a presentation");
                    }
                    break;

                case Document.DocumentType.Unknown:
                    break;

                default:
                    queryUri += type.ToString();
                    break;
                }

                Uri target = new Uri(queryUri);

                return(s.Query(target));
            }
Esempio n. 4
0
            public Stream Download(ITaskItem input, Document.DownloadType type, string baseDomain = null, int sheetNumber = 0)
            {
                input.LoadCustomMetadata();
                Document.DocumentType documentType = input.RequireDocumentType();

                Service s = this.Service;
                string queryUri = this.BuildDocumentPartialExportUrl(input.RequireExportUri());

                switch (documentType)
                {
                    case Document.DocumentType.Spreadsheet:
                        s = this.Service;
                        switch (type)
                        {
                            case Document.DownloadType.xls:
                                queryUri += "xls";
                                break;
                            case Document.DownloadType.csv:
                                queryUri += "csv&gid=" + sheetNumber.ToString();
                                break;
                            case Document.DownloadType.pdf:
                                queryUri += "pdf";
                                break;
                            case Document.DownloadType.ods:
                                queryUri += "ods";
                                break;
                            case Document.DownloadType.tsv:
                                queryUri += "tsv&gid=" + sheetNumber.ToString(); ;
                                break;
                            case Document.DownloadType.html:
                                queryUri += "html";
                                break;
                            default:
                                throw new ArgumentException("type is invalid for a spreadsheet");
                        }
                        break;

                    case Document.DocumentType.Presentation:
                        switch (type)
                        {
                            case Document.DownloadType.swf:
                                queryUri += "swf";
                                break;
                            case Document.DownloadType.pdf:
                                queryUri += "pdf";
                                break;
                            case Document.DownloadType.ppt:
                                queryUri += "ppt";
                                break;
                            default:
                                throw new ArgumentException("type is invalid for a presentation");
                        }
                        break;

                    case Document.DocumentType.Unknown:
                        break;

                    default:
                        queryUri += type.ToString();
                        break;
                }

                Uri target = new Uri(queryUri);
                return s.Query(target);
            }