public IFileInfo GetFileInfo(string sPath) { sPath = PreparePath(sPath); AzureCloudFile file = _provider.Get(sPath, false); var info = new AzureFileInfo((AzureCloudFile)file, _provider); return(info); }
static void AzureStorageRemoveAction(string key, object value, CacheItemRemovedReason reason) { AzureFileInfo azureFile = value as AzureFileInfo; if (azureFile != null) { AzureFileSystemProvider provider = new AzureFileSystemProvider(""); provider.AccountName = azureFile.AccountName; provider.ContainerName = azureFile.ContainerName; FileManagerFile file = new FileManagerFile(provider, azureFile.FileKeyName); provider.DeleteFile(file); } }
/// <summary> /// Tries to add AzureFileInfo record to DB. Creates a link that can be sent to the recipient. /// If a file recipient is specified, the user of the link will be required to enter their email address as authentication. /// </summary> /// <param name="cloudFile">The cloud file.</param> /// <param name="directory">The directory.</param> /// <param name="fileName">Name of the file.</param> /// <param name="fileSize">Size of the file.</param> /// <param name="fileRecipient">The file recipient.</param> /// <returns></returns> internal static bool TryAddAzureFileInfo(CloudFile cloudFile, string directory, string fileName, long fileSize, string fileRecipient) { try { // Add FileInfo to Database using (var db = new AzureFileInfoContext()) { var azureFileInfo = new AzureFileInfo() { AzureUri = cloudFile.Uri.ToString(), AzureDirectory = directory, FileName = fileName, FileSize = fileSize, UploadDate = DateTime.Now, Recipient = !String.IsNullOrWhiteSpace(fileRecipient) ? fileRecipient : null }; // Generate the azureFileInfo field and save to DB. db.AzureFileInfos.Add(azureFileInfo); db.SaveChanges(); // The newly generated Id value will be used to create the Link that the user will click on: Download\[Id] azureFileInfo.GenerateLink(); // Commit additional updates to the FileInfo record. db.SaveChanges(); return(true); } } catch (SqlException se) { Console.WriteLine(se.Message); return(false); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } }
public static void RemoveFileFromAzureWithDelay(string fileKeyName, string accountName, string accessKey, string containerName, int delay) { AzureFileInfo azureFile = new AzureFileInfo(fileKeyName, accountName, accessKey, containerName); RemoveFileWithDelayInternal(fileKeyName, azureFile, delay, AzureStorageRemoveAction); }
private static Tuple <Dictionary <string, AzureFileInfo>, Dictionary <string, AzureFileInfo> > GenerateAzureFileInfo(string repositoryRoot, List <AzureTransformArguments> azureTransformArgumentsList, string azureDocumentUriPrefix) { var azureMarkdownFileInfoMapping = new ConcurrentDictionary <string, AzureFileInfo>(); var azureResourceFileInfoMapping = new ConcurrentDictionary <string, AzureFileInfo>(); var files = Directory.GetFiles(repositoryRoot, "*", SearchOption.AllDirectories); Parallel.ForEach( files, new ParallelOptions { MaxDegreeOfParallelism = 4 }, file => { var relativePath = PathUtility.MakeRelativePath(repositoryRoot, file); var isMarkdownFile = Path.GetExtension(relativePath).Equals(MarkdownExtension, StringComparison.OrdinalIgnoreCase); if (IsIgnoreFile(relativePath)) { return; } bool isSucceed = true; var azureTransformArguments = azureTransformArgumentsList.FirstOrDefault(a => PathUtility.IsPathUnderSpecificFolder(file, a.SourceDir)); var fileName = Path.GetFileName(file); if (azureTransformArguments == null) { var azureFileInfo = new AzureFileInfo { FileName = fileName, FilePath = PathUtility.NormalizePath(file), NeedTransformToAzureExternalLink = true, UriPrefix = azureDocumentUriPrefix }; if (isMarkdownFile) { isSucceed = azureMarkdownFileInfoMapping.TryAdd(fileName, azureFileInfo); } else { isSucceed = azureResourceFileInfoMapping.TryAdd(fileName, azureFileInfo); } } else { var azureFileInfo = new AzureFileInfo { FileName = fileName, FilePath = PathUtility.NormalizePath(file), NeedTransformToAzureExternalLink = false, UriPrefix = azureTransformArguments.DocsHostUriPrefix, }; if (isMarkdownFile) { isSucceed = azureMarkdownFileInfoMapping.TryAdd(fileName, azureFileInfo); } else { isSucceed = azureResourceFileInfoMapping.TryAdd(fileName, azureFileInfo); } } if (!isSucceed) { Console.WriteLine($"GenerateAzureFileInfo failed: can't insert file with external prefix {file}"); } }); return(Tuple.Create(azureMarkdownFileInfoMapping.ToDictionary(m => m.Key, m => m.Value), azureResourceFileInfoMapping.ToDictionary(m => m.Key, m => m.Value))); }
private static bool GenerateAzureFileInfoForMigration( string repositoryRoot, RewriterToolArguments rewriterToolArguments, string azureDocumentUriPrefix, AzureFileInformationCollection azureFileInformationCollection) { var azureMarkdownFileInfoMapping = new ConcurrentDictionary <string, AzureFileInfo>(); var azureResourceFileInfoMapping = new ConcurrentDictionary <string, AzureFileInfo>(); var azureIncludeMarkdownFileInfoMapping = new ConcurrentDictionary <string, AzureFileInfo>(); var azureIncludeResourceFileInfoMapping = new ConcurrentDictionary <string, AzureFileInfo>(); bool hasDupliateMdFileName = false; var files = Directory.GetFiles(repositoryRoot, "*", SearchOption.AllDirectories); Parallel.ForEach( files, new ParallelOptions { MaxDegreeOfParallelism = 8 }, file => { var relativePath = PathUtility.MakeRelativePath(repositoryRoot, file); if (IsIgnoreFile(relativePath, rewriterToolArguments.IsMigration)) { return; } var filePath = PathUtility.NormalizePath(file); var fileName = Path.GetFileName(file); var azureFileInfo = new AzureFileInfo { FileName = fileName, FilePath = PathUtility.NormalizePath(file), NeedTransformToAzureExternalLink = false, UriPrefix = string.Empty }; var isIncludeFile = filePath.Split(new[] { Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries) .Any(folder => folder.Equals("includes", StringComparison.OrdinalIgnoreCase)); var isMarkdownFile = Path.GetExtension(relativePath).Equals(MarkdownExtension, StringComparison.OrdinalIgnoreCase); AzureFileInfo conflictFile = null; var isSucceed = true; if (!isIncludeFile && isMarkdownFile) { isSucceed = azureMarkdownFileInfoMapping.TryAdd(fileName, azureFileInfo); azureMarkdownFileInfoMapping.TryGetValue(fileName, out conflictFile); } else if (!isIncludeFile && !isMarkdownFile) { // For resource file, even if has conflicts, we regards that as succeed azureResourceFileInfoMapping.TryAdd(fileName, azureFileInfo); } else if (isIncludeFile && isMarkdownFile) { isSucceed = azureIncludeMarkdownFileInfoMapping.TryAdd(fileName, azureFileInfo); azureIncludeMarkdownFileInfoMapping.TryGetValue(fileName, out conflictFile); } else { // For resource file, even if has conflicts, we regards that as succeed azureIncludeResourceFileInfoMapping.TryAdd(fileName, azureFileInfo); } if (!isSucceed) { hasDupliateMdFileName = true; Logger.LogError($"Error: GenerateAzureFileInfo failed. File: {file} name confilicts with: {conflictFile?.FilePath}"); } }); azureFileInformationCollection.AzureMarkdownFileInfoMapping = azureMarkdownFileInfoMapping.ToDictionary(m => m.Key, m => m.Value); azureFileInformationCollection.AzureResourceFileInfoMapping = azureResourceFileInfoMapping.ToDictionary(m => m.Key, m => m.Value); azureFileInformationCollection.AzureIncludeMarkdownFileInfoMapping = azureIncludeMarkdownFileInfoMapping.ToDictionary(m => m.Key, m => m.Value); azureFileInformationCollection.AzureIncludeResourceFileInfoMapping = azureIncludeResourceFileInfoMapping.ToDictionary(m => m.Key, m => m.Value); return(!hasDupliateMdFileName); }
private static bool GenerateAzureFileInfo( string repositoryRoot, RewriterToolArguments rewriterToolArguments, string azureDocumentUriPrefix, AzureFileInformationCollection azureFileInformationCollection) { var azureMarkdownFileInfoMapping = new ConcurrentDictionary <string, AzureFileInfo>(); var azureResourceFileInfoMapping = new ConcurrentDictionary <string, AzureFileInfo>(); var files = Directory.GetFiles(repositoryRoot, "*", SearchOption.AllDirectories); Parallel.ForEach( files, new ParallelOptions { MaxDegreeOfParallelism = 8 }, file => { var relativePath = PathUtility.MakeRelativePath(repositoryRoot, file); if (IsIgnoreFile(relativePath, rewriterToolArguments.IsMigration)) { return; } var isSucceed = true; var azureTransformArguments = rewriterToolArguments.AzureTransformArgumentsList.FirstOrDefault(a => PathUtility.IsPathUnderSpecificFolder(file, a.SourceDir)); // By default, all the link should be transformed to external link with azure uri prefix // However, if we find that the file is under one of the folder that need to be transformed. Then the prefix uri should be docs but not auzre var needTransformToAzureExternalLink = true; var uriPrefix = azureDocumentUriPrefix; if (azureTransformArguments != null) { needTransformToAzureExternalLink = false; uriPrefix = azureTransformArguments.DocsHostUriPrefix; } var fileName = Path.GetFileName(file); var azureFileInfo = new AzureFileInfo { FileName = fileName, FilePath = PathUtility.NormalizePath(file), NeedTransformToAzureExternalLink = needTransformToAzureExternalLink, UriPrefix = uriPrefix }; AzureFileInfo conflictFile; var isMarkdownFile = Path.GetExtension(relativePath).Equals(MarkdownExtension, StringComparison.OrdinalIgnoreCase); if (isMarkdownFile) { isSucceed = azureMarkdownFileInfoMapping.TryAdd(fileName, azureFileInfo); azureMarkdownFileInfoMapping.TryGetValue(fileName, out conflictFile); } else { isSucceed = azureResourceFileInfoMapping.TryAdd(fileName, azureFileInfo); azureResourceFileInfoMapping.TryGetValue(fileName, out conflictFile); } if (!isSucceed) { Console.WriteLine($"GenerateAzureFileInfo warning: can't insert file: {file}, confilicts with: {conflictFile?.FilePath}"); } }); azureFileInformationCollection.AzureMarkdownFileInfoMapping = azureMarkdownFileInfoMapping.ToDictionary(m => m.Key, m => m.Value); azureFileInformationCollection.AzureResourceFileInfoMapping = azureResourceFileInfoMapping.ToDictionary(m => m.Key, m => m.Value); return(true); }
public static void RemoveFileFromAzureWithDelay(string fileKeyName, string accountName, string accessKey, string containerName, int delay) { AzureFileInfo azureFile = new AzureFileInfo(fileKeyName, accountName, accessKey, containerName); RemoveFileWithDelayInternal(fileKeyName, azureFile, delay, AzureStorageRemoveAction); }