Пример #1
0
        public TestUploadClient()
        {
            IRestClient         restClient      = RestClientMockFactory.Get(_expectedDtoReturned);
            TestServiceProvider serviceProvider = new TestServiceProvider(restClient);

            _uploadClient = serviceProvider.Get <UploadClient>();
        }
Пример #2
0
        public void UploadFile(bool isResent)
        {
            byte[] dataToSend;

            if (isResent)
            {
                dataToSend = LastFilePackage.GetCompletePackage();
            }
            else
            {
                byte[] filePackageData = GetDataArray(FileStream);
                LastFilePackage = new FilePackage(filePackageData);
                dataToSend      = LastFilePackage.GetCompletePackage();
            }

            string uploadAddress = UploadAddress + "&hash=" + LastFilePackage.SHA1CheckSumSize;

            uploadAddress += "&site=" + HttpUtility.UrlEncode(App.Params.SiteUrl);
            uploadAddress += "&fileUploadLibrary=" + HttpUtility.UrlEncode(App.Params.FileUploadLibrary);

            if (FileStream.Position >= (FileStream.Length - 1))
            {
                uploadAddress += "&position=last";
            }

            Uri uploadAddressUri = new Uri(uploadAddress);

            UploadClient.OpenWriteAsync(uploadAddressUri, null, dataToSend);
        }
Пример #3
0
 public UploadCommand(ManageClient client, ApiClient apiClient, UploadClient uploader, ILogger <UploadCommand> logger)
 {
     _manager   = client;
     _apiClient = apiClient;
     _uploader  = uploader;
     _logger    = logger;
 }
Пример #4
0
 public static bool UploadFile(string targetPath, string fileName, byte[] data)
 {
     using (var client = new UploadClient(CurrentSession.System.ShopWebSiteId))
     {
         return(client.UploadFile(targetPath, fileName, data));
     }
 }
Пример #5
0
        /// <summary>
        /// Upload files to SharePoint. For now, assumes directory structure already exists.
        /// </summary>
        /// <param name="hostname">Hostname for your SharePoint site.</param>
        /// <param name="team">SharePoint team.</param>
        /// <param name="root">Directory to search for files to upload.</param>
        /// <param name="glob">Pattern to search inside filePath.</param>
        /// <param name="target">Target directory inside the SharePoint site.</param>
        /// <param name="token">
        /// (Optional) AAD access token for auth.
        /// You may obtain this by visiting: https://developer.microsoft.com/en-us/graph/graph-explorer .
        /// </param>
        /// <param name="numFragments">Multiple of 320 KiB to include in each file fragment.</param>
        async static Task Main(
            string hostname,
            string team,
            string root,
            string glob      = "**",
            string target    = "/",
            string token     = "",
            int numFragments = 10)
        {
            // https://github.com/dotnet/runtime/issues/34742
            using var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
            var logger = loggerFactory.CreateLogger <Program>();

            var filesClient = new FilesystemClient(root, glob);
            var files       = filesClient.Search();

            var builder     = new GraphClientBuilder(logger);
            var graphClient = await builder.BuildAsync(token);

            var uploadClient = new UploadClient(hostname, team, target, numFragments, graphClient, loggerFactory);

            foreach (var file in files)
            {
                await uploadClient.UploadAsync(file);
            }

            logger.LogInformation("Done uploading files.");
        }
Пример #6
0
 public CheckCommand(ApiClient apiClient, ILogger <CheckCommand> logger, UploadClient uploadClient, ModConfiguration config, ManageClient manager)
 {
     _apiClient    = apiClient;
     _logger       = logger;
     _uploadClient = uploadClient;
     _config       = config;
     _manager      = manager;
 }
Пример #7
0
 public UpgradeClient(string url)
 {
     this.url          = url;
     this.clientUpload = new UploadClient(url + "/upload", url + "/merge");
     this.clientUpload.UploadProgressChanged += (s, e) =>
     {
         currentProgress += e.Read;
         this.OnUpgradeProgressChanged(new ProgressChangedArgs(e.Read, currentProgress, totalProgress));
     };
 }
Пример #8
0
        public async Task <bool> CreateFeedContainer()
        {
            ValidateContainerName(ContainerName);
            string url = $"{FeedContainerUrl}?restype=container";

            using (HttpClient client = new HttpClient())
            {
                List <Tuple <string, string> > additionalHeaders = null;
                if (IsPublic)
                {
                    Tuple <string, string> headerBlobType = new Tuple <string, string>("x-ms-blob-public-access", "blob");
                    additionalHeaders = new List <Tuple <string, string> >()
                    {
                        headerBlobType
                    };
                }
                var createRequest = AzureHelper.RequestMessage("PUT", url, AccountName, AccountKey, additionalHeaders);

                using (HttpResponseMessage response = await AzureHelper.RequestWithRetry(Log, client, createRequest))
                {
                    try
                    {
                        Log.LogMessage(
                            MessageImportance.Low,
                            "Received response to create Container {0}: Status Code: {1} {2}",
                            ContainerName, response.StatusCode, response.Content.ToString());
                    }
                    catch (Exception e)
                    {
                        Log.LogErrorFromException(e, true);
                    }
                }
            }
            string item       = GenerateRootServiceIndex(RelativePath);
            string uploadPath = CalculateBlobPath(item, RelativePath);

            Log.LogMessage($"Uploading root index.json to {uploadPath}.");
            try
            {
                UploadClient uploadClient = new UploadClient(Log);
                await
                uploadClient.UploadBlockBlobAsync(
                    CancellationToken,
                    AccountName,
                    AccountKey,
                    ContainerName,
                    item,
                    uploadPath);
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e);
            }
            return(!Log.HasLoggedErrors);
        }
        private static void UploadFile(string localFilePath, UploadMode mode)
        {
            if (_currentFolder == null)
            {
                return;
            }

            Console.WriteLine();

            if (!System.IO.File.Exists(localFilePath))
            {
                Console.WriteLine($"Unable to find local file {localFilePath}.  Content APIs will not be able to continue.");
                throw new ConfigurationErrorsException("Cannot find the file defined as the value of \"uploadFile\" configuration");
            }

            Console.WriteLine("Start File Uploading...");

            try
            {
                var uploadClient = new UploadClient(_currentFolder, localFilePath, UploadCallBack);
                switch (mode)
                {
                case UploadMode.Chunked:
                    uploadClient.UploadFileUsingChunks();
                    break;

                case UploadMode.Simple:
                default:
                    uploadClient.UploadFileWithoutChunking();
                    break;
                }

                UploadFinished.WaitOne();
            }
            catch (Exception e)
            {
                Console.WriteLine();
                Console.WriteLine("Uploading file failed.");
                Console.WriteLine("Exception caught:");
                Console.WriteLine(e);
                UploadFinished.Set();
                throw;
            }

            Console.WriteLine();

            if (_lastException != null)
            {
                Console.WriteLine("Uploading file failed.");
                throw new InvalidOperationException("Uploading file failed", _lastException);
            }

            Console.WriteLine($"File {localFilePath} uploaded successfully to folder {_currentFolder.Name}.");
        }
Пример #10
0
        public PluginHandler()
        {
            System.Diagnostics.Trace.TraceInformation("Plugin ChummerHub.Client importing (Constructor).");
            MyUploadClient = new UploadClient();
            if (Properties.Settings.Default.UploadClientId == Guid.Empty)
            {
                Properties.Settings.Default.UploadClientId = Guid.NewGuid();
                Properties.Settings.Default.Save();
            }

            MyUploadClient.Id = Properties.Settings.Default.UploadClientId;
        }
Пример #11
0
        public async Task UploadAssets(ITaskItem item, SemaphoreSlim clientThrottle, bool allowOverwrite = false)
        {
            string relativeBlobPath = item.GetMetadata("RelativeBlobPath");

            if (string.IsNullOrEmpty(relativeBlobPath))
            {
                string fileName     = Path.GetFileName(item.ItemSpec);
                string recursiveDir = item.GetMetadata("RecursiveDir");
                relativeBlobPath = $"{feed.RelativePath}{recursiveDir}{fileName}";
            }

            relativeBlobPath = relativeBlobPath.Replace("\\", "/");

            Log.LogMessage($"Uploading {relativeBlobPath}");

            await clientThrottle.WaitAsync();

            try
            {
                bool blobExists = false;

                if (!allowOverwrite)
                {
                    blobExists = await feed.CheckIfBlobExists(relativeBlobPath);
                }

                if (allowOverwrite || !blobExists)
                {
                    Log.LogMessage($"Uploading {item} to {relativeBlobPath}.");
                    UploadClient uploadClient = new UploadClient(Log);
                    await uploadClient.UploadBlockBlobAsync(
                        CancellationToken,
                        feed.AccountName,
                        feed.AccountKey,
                        feed.ContainerName,
                        item.ItemSpec,
                        relativeBlobPath);
                }
                else
                {
                    Log.LogError($"Item '{item}' already exists in {relativeBlobPath}.");
                }
            }
            catch (Exception exc)
            {
                Log.LogError($"Unable to upload to {relativeBlobPath} due to {exc}.");
                throw;
            }
            finally
            {
                clientThrottle.Release();
            }
        }
Пример #12
0
 protected override void OnStop()
 {
     try
     {
         TraceLog.TraceInfo("Stopping Capture Service");
         CollectorClient.Stop();
         UploadClient.Stop();
     }
     catch (Exception ex)
     {
         TraceLog.TraceException("OnStop: Caught exception", ex);
         throw ex;
     }
 }
Пример #13
0
        private async Task UploadAsync(CancellationToken ct, string item, string uploadPath, SemaphoreSlim clientThrottle, bool isLeaseRequired)
        {
            if (!File.Exists(item))
            {
                throw new Exception(string.Format("The file '{0}' does not exist.", item));
            }

            await clientThrottle.WaitAsync();

            string         leaseId   = string.Empty;
            AzureBlobLease blobLease = new AzureBlobLease(feed.AccountName, feed.AccountKey, string.Empty, feed.ContainerName, uploadPath, Log, "60", "10");

            if (isLeaseRequired)
            {
                try
                {
                    leaseId = blobLease.Acquire();
                }
                catch (Exception)
                {
                    Log.LogError($"Unable to obtain lease on {uploadPath}");
                }
            }
            try
            {
                Log.LogMessage($"Uploading {item} to {uploadPath}.");
                UploadClient uploadClient = new UploadClient(Log);
                await
                uploadClient.UploadBlockBlobAsync(
                    ct,
                    feed.AccountName,
                    feed.AccountKey,
                    feed.ContainerName,
                    item,
                    uploadPath,
                    leaseId);
            }
            catch (Exception)
            {
                Log.LogError($"Unable to upload to {uploadPath}");
            }
            finally
            {
                if (isLeaseRequired)
                {
                    blobLease.Release();
                }
                clientThrottle.Release();
            }
        }
Пример #14
0
        static void Main(string[] args)
        {
            TraceLog.TraceDestination = TraceLog.Destination.Console;
            CollectorClient.Start();
            UploadClient.Start();

            Console.WriteLine("Press any key to stop collection");
            Console.ReadLine();

            CollectorClient.Stop();
            UploadClient.Stop();

            Console.WriteLine("Press any key to exit");
            Console.ReadLine();
        }
Пример #15
0
        static async Task Main(string[] args)
        {
            var baseUrl = "http://localhost:5000";
            var client  = new HttpClient();
            var upload  = new UploadClient(baseUrl, client);

            var bytes  = File.ReadAllBytes("README.md");
            var stream = new MemoryStream(bytes);

            var file = new FileParameter(stream, "README.md", "plain/text");

            var meta = new Metadata {
                F1 = "F1",
                F2 = "F2",
                F3 = "F3"
            };

            var json = JsonConvert.SerializeObject(meta);
            var rs   = await upload.UploadWithMetadataAsync(file, json);
        }
Пример #16
0
        protected override void OnStart(string[] args)
        {
            try
            {
                // set the current directory to the service directory (default is SYSTEM32)
                System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);

                // set the trace destination
                TraceLog.TraceDestination = TraceLog.Destination.File;
                TraceFile.TraceName       = @"CaptureService";

                TraceLog.TraceInfo("Starting Capture Service");
                CollectorClient.Start();
                UploadClient.Start();
            }
            catch (Exception ex)
            {
                TraceLog.TraceException("OnStart: Caught exception, Start aborted", ex);
                throw ex;
            }
        }
Пример #17
0
        static void Main()
        {
            byte[] binaryData = new byte[1000];
            MemoryStream stream = new MemoryStream(binaryData);

            // Upload a stream of 1000 bytes
            UploadClient client = new UploadClient();
            Console.WriteLine(client.Upload(stream));
            Console.WriteLine();
            stream.Close();

            // Compare the wire representations of messages with different payloads
            CompareMessageSize(100);
            CompareMessageSize(1000);
            CompareMessageSize(10000);
            CompareMessageSize(100000);
            CompareMessageSize(1000000);

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
Пример #18
0
 protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
 {
     TraceLog.TraceInfo("Power event: " + powerStatus.ToString());
     switch (powerStatus)
     {
     case PowerBroadcastStatus.ResumeAutomatic:
     case PowerBroadcastStatus.ResumeCritical:
     case PowerBroadcastStatus.ResumeSuspend:
         try
         {
             TraceLog.TraceInfo("Resuming: power state " + powerStatus.ToString());
             CollectorClient.Start();
             UploadClient.Start();
         }
         catch (Exception ex)
         {
             TraceLog.TraceException("OnPowerEvent: Caught exception, Resume processing aborted", ex);
             throw;
         }
         break;
     }
     return(base.OnPowerEvent(powerStatus));
 }
Пример #19
0
        static void Main()
        {
            byte[]       binaryData = new byte[1000];
            MemoryStream stream     = new MemoryStream(binaryData);

            // Upload a stream of 1000 bytes
            UploadClient client = new UploadClient();

            Console.WriteLine(client.Upload(stream));
            Console.WriteLine();
            stream.Close();

            // Compare the wire representations of messages with different payloads
            CompareMessageSize(100);
            CompareMessageSize(1000);
            CompareMessageSize(10000);
            CompareMessageSize(100000);
            CompareMessageSize(1000000);

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
Пример #20
0
        public async Task UploadAssetAsync(
            ITaskItem item,
            SemaphoreSlim clientThrottle,
            int uploadTimeout,
            PushOptions options)
        {
            string relativeBlobPath = item.GetMetadata("RelativeBlobPath");

            if (string.IsNullOrEmpty(relativeBlobPath))
            {
                string fileName     = Path.GetFileName(item.ItemSpec);
                string recursiveDir = item.GetMetadata("RecursiveDir");
                relativeBlobPath = $"{recursiveDir}{fileName}";
            }

            string contentType = item.GetMetadata("ContentType");

            relativeBlobPath = $"{feed.RelativePath}{relativeBlobPath}".Replace("\\", "/");

            if (relativeBlobPath.Contains("//"))
            {
                Log.LogError(
                    $"Item '{item.ItemSpec}' RelativeBlobPath contains virtual directory " +
                    $"without name (double forward slash): '{relativeBlobPath}'");
                return;
            }

            Log.LogMessage($"Uploading {relativeBlobPath}");

            await clientThrottle.WaitAsync();

            try
            {
                UploadClient uploadClient = new UploadClient(Log);

                if (!options.AllowOverwrite && await feed.CheckIfBlobExistsAsync(relativeBlobPath))
                {
                    if (options.PassIfExistingItemIdentical)
                    {
                        if (!await uploadClient.FileEqualsExistingBlobAsync(
                                feed.AccountName,
                                feed.AccountKey,
                                feed.ContainerName,
                                item.ItemSpec,
                                relativeBlobPath,
                                uploadTimeout))
                        {
                            Log.LogError(
                                $"Item '{item}' already exists with different contents " +
                                $"at '{relativeBlobPath}'");
                        }
                    }
                    else
                    {
                        Log.LogError($"Item '{item}' already exists at '{relativeBlobPath}'");
                    }
                }
                else
                {
                    Log.LogMessage($"Uploading {item} to {relativeBlobPath}.");
                    await uploadClient.UploadBlockBlobAsync(
                        CancellationToken,
                        feed.AccountName,
                        feed.AccountKey,
                        feed.ContainerName,
                        item.ItemSpec,
                        relativeBlobPath,
                        contentType,
                        uploadTimeout);
                }
            }
            catch (Exception exc)
            {
                Log.LogError($"Unable to upload to {relativeBlobPath} due to {exc}.");
                throw;
            }
            finally
            {
                clientThrottle.Release();
            }
        }
Пример #21
0
 public UploadTcxController(UploadClient uploadClient)
 {
     _uploadClient = uploadClient;
 }