Example #1
0
        public PathMapping(PathMapping parentMapping, ITaskItem model)
        {
            if (parentMapping != null)
            {
                if (parentMapping.DocumentType != Document.DocumentType.Folder)
                {
                    throw new ArgumentException("Path should have 'Folder' Document Type", "folderPath");
                }
                ParentMapping = parentMapping;
            }

            ResourceType = GetResourceType(model.RequireResourceId());

            Title = model.RequireTitle();

            switch (ResourceType)
            {
            case ResourceType.file:
                MappedFilename  = SanitizeTitle(Path.GetFileNameWithoutExtension(Title));
                MappedExtension = String.Concat(".", ResourceType.ToString(), "_", SanitizeTitle(Path.GetExtension(Title).TrimStart('.')));
                break;

            case ResourceType.folder:
                MappedFilename  = SanitizeTitle(Title);
                MappedExtension = null;
                break;

            default:
                MappedFilename  = SanitizeTitle(Title);
                MappedExtension = string.Concat(".", ResourceType.ToString());
                break;
            }
        }
Example #2
0
        public PathMapping(PathMapping parentMapping, ITaskItem model)
        {
            if (parentMapping != null)
            {
                if (parentMapping.DocumentType != Document.DocumentType.Folder)
                {
                    throw new ArgumentException("Path should have 'Folder' Document Type", "folderPath");
                }
                ParentMapping = parentMapping;
            }

            ResourceType = GetResourceType(model.RequireResourceId());

            Title = model.RequireTitle();

            switch (ResourceType)
            {
                case ResourceType.file:
                    MappedFilename = SanitizeTitle(Path.GetFileNameWithoutExtension(Title));
                    MappedExtension = String.Concat(".", ResourceType.ToString(), "_", SanitizeTitle(Path.GetExtension(Title).TrimStart('.')));
                    break;
                case ResourceType.folder:
                    MappedFilename = SanitizeTitle(Title);
                    MappedExtension = null;
                    break;
                default:
                    MappedFilename = SanitizeTitle(Title);
                    MappedExtension = string.Concat(".",ResourceType.ToString());
                    break;
            }
        }
Example #3
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);
        }