private static CloudBlob GetCloudBlob(string containerName, string blobName, BlobType blobType)
        {
            CloudBlobClient client = GetCloudBlobClient();
            CloudBlobContainer container = client.GetContainerReference(containerName);
            container.CreateIfNotExists();

            CloudBlob cloudBlob;

            switch (blobType)
            {
                case BlobType.AppendBlob:
                    cloudBlob = container.GetAppendBlobReference(blobName);
                    break;
                case BlobType.BlockBlob:
                    cloudBlob = container.GetBlockBlobReference(blobName);
                    break;
                case BlobType.PageBlob:
                    cloudBlob = container.GetPageBlobReference(blobName);
                    break;
                case BlobType.Unspecified:
                default:
                    throw new ArgumentException(string.Format("Invalid blob type {0}", blobType.ToString()), "blobType");
            }

            return cloudBlob;
        }
Esempio n. 2
0
        public static async Task <CloudBlob> getCloudBlobAsync(string containerName, string blobName, BlobType blobType)
        {
            var client    = getCloudBlobClient();
            var container = client.GetContainerReference(containerName);
            await container.CreateIfNotExistsAsync();

            CloudBlob cloudBlob;

            switch (blobType)
            {
            case BlobType.AppendBlob:
                cloudBlob = container.GetAppendBlobReference(blobName);
                break;

            case BlobType.BlockBlob:
                cloudBlob = container.GetBlockBlobReference(blobName);
                break;

            case BlobType.PageBlob:
                cloudBlob = container.GetPageBlobReference(blobName);
                break;

            case BlobType.Unspecified:
            default:
                throw new ArgumentException(string.Format("Invalid blob type {0}", blobType.ToString()), "blobType");
            }

            return(cloudBlob);
        }
Esempio n. 3
0
        public async Task <Response <long> > SaveBlob(string basePath, byte[] blob, BlobType type)
        {
            if (!Directory.Exists(basePath))
            {
                Directory.CreateDirectory(basePath);
            }

            var name = Guid.NewGuid() + "." + type.ToString();

            var filepath = basePath + name;

            File.WriteAllBytes(filepath, blob);

            var model = new BLOB()
            {
                ACTIVE    = true,
                PATH      = filepath,
                NAME      = name,
                BLOB_TYPE = type,
                CREATED   = DateTime.Now,
                MODIFIED  = DateTime.Now
            };

            return(await _insertBlob.UploadBlobAsync(model));
        }
Esempio n. 4
0
 public static string GetBlobName(Guid id, BlobType type, string blobName) =>
 Path.Combine(
     id.ToString("N"),
     type.ToString(),
     Path.GetFileName(blobName))
 .Replace(
     Path.DirectorySeparatorChar,
     Path.AltDirectorySeparatorChar);
Esempio n. 5
0
    public static Sprite GetTypeSprite(BlobType type)
    {
        switch (type)
        {
        case BlobType.Conductor:
            return(instance.conductorSprite);

        case BlobType.Rock:
            return(instance.rockSprite);

        default:
            Debug.LogWarning("Trying to access unknown blob type sprite of type " + type.ToString());
            return(null);
        }
    }
Esempio n. 6
0
    public static BlobBase GetBlobPrefab(BlobType type)
    {
        switch (type)
        {
        case BlobType.Conductor:
            return(instance.conductorBlobPrefab);

        case BlobType.Rock:
            return(instance.rockBlobPrefab);

        default:
            Debug.LogWarning("Trying to access unknown blob prefab of type " + type.ToString());
            return(null);
        }
    }
Esempio n. 7
0
        public async Task <CloudBlob> GetorCreateCloudBlobAsync(string containerName, string blobName, BlobType blobType, DateTimeOffset?snapshotTime = null)
        {
            using (Operation azOp = L.Begin("Get Azure Storage blob {0}/{1}", containerName, blobName))
            {
                try
                {
                    GetCloudBlobClient();
                    CloudBlobContainer Container = BlobClient.GetContainerReference(containerName);
                    await Container.CreateIfNotExistsAsync();

                    CloudBlob cloudBlob;
                    switch (blobType)
                    {
                    case BlobType.AppendBlob:
                        cloudBlob = Container.GetAppendBlobReference(blobName, snapshotTime);
                        break;

                    case BlobType.BlockBlob:
                        cloudBlob = Container.GetBlockBlobReference(blobName, snapshotTime);
                        break;

                    case BlobType.PageBlob:
                        cloudBlob = Container.GetPageBlobReference(blobName, snapshotTime);
                        break;

                    case BlobType.Unspecified:
                    default:
                        throw new ArgumentException(string.Format("Invalid blob type {0}", blobType.ToString()), "blobType");
                    }
                    azOp.Complete();
                    return(cloudBlob);
                }
                catch (StorageException se)
                {
                    if (RethrowExceptions)
                    {
                        throw se;
                    }
                    else
                    {
                        L.Error(se, "A storage error occurred getting Azure Storage blob {bn} in container {cn}.", blobName, containerName);
                        return(null);
                    }
                }
                catch (Exception e)
                {
                    if (RethrowExceptions)
                    {
                        throw e;
                    }
                    else
                    {
                        L.Error(e, "An error occurred getting Azure Storage blob {bn} from container {cn}.", blobName, containerName);
                        return(null);
                    }
                }
            }
        }
Esempio n. 8
0
 public ProcessArgumentBuilder BuildWindowsArguments(ProcessArgumentBuilder args)
 {
     //var args = new ProcessArgumentBuilder();
     args.Append("/Y");
     if (Pattern.IsDefined())
     {
         args.AppendSwitchQuoted("/Pattern", ":", Pattern);
     }
     if (DestinationKey.IsDefined())
     {
         args.AppendSwitchQuotedSecret("/DestKey", ":", DestinationKey);
     }
     if (DestinationSAS.IsDefined())
     {
         args.AppendSwitchQuotedSecret("/DestSAS", ":", DestinationSAS);
     }
     if (SourceKey.IsDefined())
     {
         args.AppendSwitchQuotedSecret("/SourceKey", ":", SourceKey);
     }
     if (SourceSAS.IsDefined())
     {
         args.AppendSwitchQuotedSecret("/SourceSAS", ":", SourceSAS);
     }
     if (Recursive)
     {
         args.Append("/S");
     }
     if (BlobType != null)
     {
         args.AppendSwitchQuoted("/BlobType", ":", BlobType.ToString());
     }
     if (UseChecksum)
     {
         args.Append("/CheckMD5");
     }
     if (LogFile != null)
     {
         args.AppendSwitchQuoted("/V", ":", LogFile.FullPath);
     }
     if (ParameterFiles.Any())
     {
         foreach (var file in ParameterFiles)
         {
             args.AppendSwitchQuoted("@", ":", file.FullPath);
         }
     }
     if (FileHandlingBehaviour != null)
     {
         if (FileHandlingBehaviour.Value.HasFlag(FileHandling.ArchiveOnly))
         {
             args.Append("/A");
         }
         if (FileHandlingBehaviour.Value.HasFlag(FileHandling.ExcludeNewerSource))
         {
             args.Append("/XN");
         }
         if (FileHandlingBehaviour.Value.HasFlag(FileHandling.ExcludeOlderSource))
         {
             args.Append("/XO");
         }
         if (FileHandlingBehaviour.Value.HasFlag(FileHandling.UpdateLastModified))
         {
             args.Append("/MT");
         }
     }
     if (Delimiter != null)
     {
         args.AppendSwitchQuoted("/Delimiter", ":", Delimiter.ToString());
     }
     if (ConcurrentOperations != 0)
     {
         args.AppendSwitchQuoted("/NC", ":", ConcurrentOperations.ToString());
     }
     if (TargetContentType.IsDefined())
     {
         args.AppendSwitchQuoted("/SetContentType", ":", TargetContentType);
     }
     if (PayloadFormat != PayloadFormat.Default)
     {
         args.AppendSwitchQuoted("/PayloadFormat", ":", PayloadFormat.ToString());
     }
     return(args);
 }
Esempio n. 9
0
 public ProcessArgumentBuilder BuildLinuxArguments(ProcessArgumentBuilder args)
 {
     args.Append("--quiet"); // equivalent to /Y for some reason
     if (Pattern.IsDefined())
     {
         args.AppendSwitchQuoted("--include", Pattern);
     }
     if (DestinationKey.IsDefined())
     {
         args.AppendSwitchQuotedSecret("--dest-key", DestinationKey);
     }
     if (DestinationSAS.IsDefined())
     {
         args.AppendSwitchQuotedSecret("--dest-sas", DestinationSAS);
     }
     if (SourceKey.IsDefined())
     {
         args.AppendSwitchQuotedSecret("--source-key", SourceKey);
     }
     if (SourceSAS.IsDefined())
     {
         args.AppendSwitchQuotedSecret("--source-sas", SourceSAS);
     }
     if (Recursive)
     {
         args.Append("--recursive");
     }
     if (BlobType != null)
     {
         args.AppendSwitch("--blob-type", BlobType.ToString().ToLower());
     }
     if (UseChecksum)
     {
         args.Append("--check-md5");
     }
     if (ParameterFiles.Any())
     {
         foreach (var file in ParameterFiles)
         {
             args.AppendSwitchQuoted("--config-file", file.FullPath);
         }
     }
     if (FileHandlingBehaviour != null)
     {
         if (FileHandlingBehaviour.Value.HasFlag(FileHandling.ExcludeNewerSource))
         {
             args.Append("--exclude-newer");
         }
         if (FileHandlingBehaviour.Value.HasFlag(FileHandling.ExcludeOlderSource))
         {
             args.Append("--exclude-older");
         }
         if (FileHandlingBehaviour.Value.HasFlag(FileHandling.UpdateLastModified))
         {
             args.Append("--preserve-last-modified-time");
         }
     }
     if (Delimiter != null)
     {
         args.AppendSwitchQuoted("--delimiter", Delimiter.ToString());
     }
     if (ConcurrentOperations != 0)
     {
         args.AppendSwitchQuoted("--parallel-level", ConcurrentOperations.ToString());
     }
     if (TargetContentType.IsDefined())
     {
         args.AppendSwitchQuoted("--set-content-type", TargetContentType);
     }
     return(args);
 }
Esempio n. 10
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="blobId"></param>
		/// <param name="blobType"></param>
		/// <returns></returns>
		private static async Task<StorageFile> GetStoryFile(string blobId, BlobType blobType)
		{
			var blobFolder =
				await ApplicationData.Current.LocalFolder.CreateFolderAsync("BlobStorage", CreationCollisionOption.OpenIfExists);

			var mediaFolder =
				await blobFolder.CreateFolderAsync(blobType.ToString(), CreationCollisionOption.OpenIfExists);

			return await mediaFolder.CreateFileAsync(blobId + ".blob", CreationCollisionOption.OpenIfExists);
		}
Esempio n. 11
0
 public ProcessArgumentBuilder BuildWindowsArguments(ProcessArgumentBuilder args)
 {
     //var args = new ProcessArgumentBuilder();
     args.Append("/Y");
     if (Pattern.IsDefined())
     {
         args.AppendSwitchQuoted("/Pattern", ":", Pattern);
     }
     if (DestinationKey.IsDefined())
     {
         args.AppendSwitchQuotedSecret("/DestKey", ":", DestinationKey);
     }
     if (DestinationSAS.IsDefined())
     {
         args.AppendSwitchQuotedSecret("/DestSAS", ":", DestinationSAS);
     }
     if (SourceKey.IsDefined())
     {
         args.AppendSwitchQuotedSecret("/SourceKey", ":", SourceKey);
     }
     if (SourceSAS.IsDefined())
     {
         args.AppendSwitchQuotedSecret("/SourceSAS", ":", SourceSAS);
     }
     if (Recursive)
     {
         args.Append("/S");
     }
     if (BlobType != null)
     {
         args.AppendSwitchQuoted("/BlobType", ":", BlobType.ToString());
     }
     if (UseChecksum)
     {
         args.Append("/CheckMD5");
     }
     if (LogFile != null)
     {
         args.AppendSwitchQuoted("/V", ":", LogFile.FullPath);
     }
     if (ParameterFiles.Any())
     {
         foreach (var file in ParameterFiles)
         {
             args.AppendSwitchQuoted("@", ":", file.FullPath);
         }
     }
     if (FileHandlingBehaviour != null)
     {
         if (FileHandlingBehaviour.Value.HasFlag(FileHandling.ArchiveOnly))
         {
             args.Append("/A");
         }
         if (FileHandlingBehaviour.Value.HasFlag(FileHandling.ExcludeNewerSource))
         {
             args.Append("/XN");
         }
         if (FileHandlingBehaviour.Value.HasFlag(FileHandling.ExcludeOlderSource))
         {
             args.Append("/XO");
         }
         if (FileHandlingBehaviour.Value.HasFlag(FileHandling.UpdateLastModified))
         {
             args.Append("/MT");
         }
     }
     if (Delimiter != null)
     {
         args.AppendSwitchQuoted("/Delimiter", ":", Delimiter.ToString());
     }
     if (ConcurrentOperations != 0)
     {
         args.AppendSwitchQuoted("/NC", ":", ConcurrentOperations.ToString());
     }
     if (TargetContentType != null)
     {
         // Could be present but empty
         if (TargetContentType.Equals(String.Empty))
         {
             // If you specify this option without a value, then AzCopy sets each blob or file's content type according to its file extension.
             // https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azcopy#setcontenttypecontent-type
             args.AppendSwitchQuoted("/SetContentType", String.Empty);
         }
         else
         {
             args.AppendSwitchQuoted("/SetContentType", ":", TargetContentType);
         }
     }
     if (PayloadFormat != PayloadFormat.Default)
     {
         args.AppendSwitchQuoted("/PayloadFormat", ":", PayloadFormat.ToString());
     }
     return(args);
 }
Esempio n. 12
0
        public ProcessArgumentBuilder BuildLinuxArguments(ProcessArgumentBuilder args)
        {
            args.Append("--quiet"); // equivalent to /Y for some reason
            if (Pattern.IsDefined())
            {
                args.AppendSwitchQuoted("--include", Pattern);
            }
            if (DestinationKey.IsDefined())
            {
                args.AppendSwitchQuotedSecret("--dest-key", DestinationKey);
            }
            if (DestinationSAS.IsDefined())
            {
                args.AppendSwitchQuotedSecret("--dest-sas", DestinationSAS);
            }
            if (SourceKey.IsDefined())
            {
                args.AppendSwitchQuotedSecret("--source-key", SourceKey);
            }
            if (SourceSAS.IsDefined())
            {
                args.AppendSwitchQuotedSecret("--source-sas", SourceSAS);
            }
            if (Recursive)
            {
                args.Append("--recursive");
            }
            if (BlobType != null)
            {
                args.AppendSwitch("--blob-type", BlobType.ToString().ToLower());
            }
            if (UseChecksum)
            {
                args.Append("--check-md5");
            }
            if (ParameterFiles.Any())
            {
                foreach (var file in ParameterFiles)
                {
                    args.AppendSwitchQuoted("--config-file", file.FullPath);
                }
            }
            if (FileHandlingBehaviour != null)
            {
                if (FileHandlingBehaviour.Value.HasFlag(FileHandling.ExcludeNewerSource))
                {
                    args.Append("--exclude-newer");
                }
                if (FileHandlingBehaviour.Value.HasFlag(FileHandling.ExcludeOlderSource))
                {
                    args.Append("--exclude-older");
                }
                if (FileHandlingBehaviour.Value.HasFlag(FileHandling.UpdateLastModified))
                {
                    args.Append("--preserve-last-modified-time");
                }
            }
            if (Delimiter != null)
            {
                args.AppendSwitchQuoted("--delimiter", Delimiter.ToString());
            }
            if (ConcurrentOperations != 0)
            {
                args.AppendSwitchQuoted("--parallel-level", ConcurrentOperations.ToString());
            }

            if (TargetContentType != null)
            {
                // Could be present but empty
                if (TargetContentType.Equals(String.Empty))
                {
                    // If you specify this option without a value, then AzCopy sets each blob or file's content type according to its file extension.
                    // https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azcopy#setcontenttypecontent-type
                    args.AppendSwitchQuoted("--set-content-type", String.Empty);
                }
                else
                {
                    args.AppendSwitchQuoted("--set-content-type", TargetContentType);
                }
            }

            return(args);
        }