private IAsset ProcessUploadFile(string fileName, string storageAccount = null)
        {
            string safeFileName = Path.GetFileName(fileName);

            if (storageAccount == null)
            {
                storageAccount = MyContext.DefaultStorageAccount.Name;                         // no storage account or null, then let's take the default one
            }
            IAsset asset = null;

            try
            {
                asset = MyContext.Assets.CreateFromFile(
                    fileName,
                    storageAccount,
                    AssetCreationOptions.None,
                    (af, p) =>
                {
                    progressBarUpload.BeginInvoke(new Action(() => progressBarUpload.Value = (int)p.Progress), null);
                }
                    );
                AssetInfo.SetFileAsPrimary(asset, Path.GetFileName(safeFileName));
            }
            catch
            {
                asset = null;
            }
            return(asset);
        }
Esempio n. 2
0
        private void ProcessUploadFile(string fileName, string storageaccount = null)
        {
            string safeFileName = Path.GetFileName(fileName);

            if (storageaccount == null)
            {
                storageaccount = _context.DefaultStorageAccount.Name;                         // no storage account or null, then let's take the default one
            }
            IAsset asset = null;

            try
            {
                asset = _context.Assets.CreateFromFile(
                    fileName as string,
                    storageaccount,
                    Properties.Settings.Default.useStorageEncryption ? AssetCreationOptions.StorageEncrypted : AssetCreationOptions.None,
                    (af, p) =>
                {
                    progressBarUpload.BeginInvoke(new Action(() => progressBarUpload.Value = (int)p.Progress), null);
                }
                    );
                AssetInfo.SetFileAsPrimary(asset, safeFileName);
            }
            catch
            {
            }
        }
        private IAsset ProcessUploadFile(string SafeFileName, string FileName, string storageaccount = null)
        {
            if (storageaccount == null)
            {
                storageaccount = MyContext.DefaultStorageAccount.Name;                         // no storage account or null, then let's take the default one
            }
            IAsset        asset   = null;
            IAccessPolicy policy  = null;
            ILocator      locator = null;

            try
            {
                asset = MyContext.Assets.Create(SafeFileName as string, storageaccount, AssetCreationOptions.None);
                IAssetFile file = asset.AssetFiles.Create(SafeFileName);
                policy = MyContext.AccessPolicies.Create(
                    SafeFileName,
                    TimeSpan.FromDays(30),
                    AccessPermissions.Write | AccessPermissions.List);

                locator = MyContext.Locators.CreateLocator(LocatorType.Sas, asset, policy);
                file.UploadProgressChanged += file_UploadProgressChanged;
                file.Upload(FileName);
                AssetInfo.SetFileAsPrimary(asset, SafeFileName);
            }
            catch
            {
                asset = null;
            }
            finally
            {
                if (locator != null)
                {
                    locator.Delete();
                }
                if (policy != null)
                {
                    policy.Delete();
                }
            }
            return(asset);
        }