public static DateTime GetTimestamp(this ITaskItem taskItem) { if (!taskItem.Exists()) { throw new FileNotFoundException("Cannot get last write time", taskItem.ItemSpec); } return(File.GetLastWriteTime(taskItem.ItemSpec)); }
public override bool Execute() { RequireSecretKey(); AmazonS3 s3Client = AWSClientFactory.CreateAmazonS3Client(AccessKey, SecretKey); string bucketName = Bucket.ItemSpec; Log.LogMessage(MessageImportance.High, "Connecting to \"{0}\"", bucketName); WarnIfUneven(Tuple.Create("Puts", Puts), Tuple.Create("Keys", Keys)); foreach (var tuple in Zip(Puts, Keys)) { ITaskItem put = tuple.Item1; ITaskItem keyItem = tuple.Item2; string key = keyItem.ItemSpec.Replace('\\', '/').TrimStart('/'); if (!put.Exists()) { Log.LogMessage(MessageImportance.Normal, "Skipping {0} because it does not exist", key); continue; } if (_Cancel) { return(false); } var putObjectRequest = new PutObjectRequest { BucketName = bucketName, FilePath = put.ItemSpec, Key = key, Timeout = -1, ReadWriteTimeout = 300000 // 5 minutes in milliseconds }; S3CannedACL cannedACL; if (Enum.TryParse <S3CannedACL>(put.GetMetadata("CannedACL") ?? "", out cannedACL)) { Log.LogMessage(MessageImportance.Normal, "Applying CannedACL: {0}", cannedACL); putObjectRequest.CannedACL = cannedACL; } string contentType = put.GetMetadata("ContentType"); if (!string.IsNullOrWhiteSpace(contentType)) { Log.LogMessage(MessageImportance.Normal, "Applying ContentType: {0}", contentType); putObjectRequest.ContentType = contentType; } Log.LogMessage(MessageImportance.High, "Putting \"{0}\"", key); using (var upload = s3Client.PutObject(putObjectRequest)) { } } return(true); }
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); } }