Beispiel #1
0
        public static string[] UploadTemplateContent(string[] allFiles, IContainerOwner owner, string targetLocation, bool clearOldTarget,
                                                     Action <BlobStorageContent> preprocessor = null, Predicate <BlobStorageContent> contentFilterer = null, InformationTypeResolver informationTypeResolver = null)
        {
            if (informationTypeResolver == null)
            {
                informationTypeResolver = GetBlobInformationType;
            }
            if (clearOldTarget)
            {
                StorageSupport.DeleteBlobsFromOwnerTarget(owner, targetLocation);
            }
            var processedDict          = allFiles.Where(file => file.EndsWith(".txt")).Where(File.Exists).ToDictionary(file => Path.GetFullPath(file), file => false);
            List <ErrorItem> errorList = new List <ErrorItem>();
            var fixedContent           = allFiles.Where(fileName => fileName.EndsWith(".txt") == false)
                                         .Select(fileName =>
                                                 new BlobStorageContent {
                FileName      = fileName,
                BinaryContent = GetBlobContent(fileName, errorList, processedDict)
            })
                                         .ToArray();

            if (preprocessor != null)
            {
                foreach (var content in fixedContent)
                {
                    preprocessor(content);
                }
            }
            foreach (var content in fixedContent)
            {
                if (contentFilterer != null && contentFilterer(content) == false)
                {
                    // TODO: Properly implement delete above
                    continue;
                }
                string webtemplatePath = Path.Combine(targetLocation, content.FileName).Replace("\\", "/");
                Console.WriteLine("Uploading: " + webtemplatePath);
                string contentInformationType;
                contentInformationType = informationTypeResolver(content);
                StorageSupport.UploadOwnerBlobBinary(owner, webtemplatePath, content.BinaryContent, contentInformationType);
            }
            return(processedDict.Keys.ToArray());
        }