public void FlushData()
        {
            var uploaders = this.uploaders;

            if (null == uploaders)
            {
                return;
            }

            foreach (FileShareUploader uploader in uploaders)
            {
                if (this.configReader.IsReadingFromApplicationManifest)
                {
                    lock (AllUploaders)
                    {
                        // Drop the reference count on the uploader object
                        UploaderInfo uploaderInfo = AllUploaders.FirstOrDefault(w => w.Uploader.Equals(uploader));
                        uploaderInfo.Uploader.FlushData();
                    }
                }
                else
                {
                    uploader.FlushData();
                }
            }
        }
Esempio n. 2
0
        public void FlushData()
        {
            var uploaders = this.uploaders;

            if (null == uploaders)
            {
                return;
            }

            foreach (AzureFileUploader uploader in uploaders.Where(u => u != null))
            {
                if (this.configReader.IsReadingFromApplicationManifest)
                {
                    lock (AllUploaders)
                    {
                        UploaderInfo uploaderInfo = AllUploaders.FirstOrDefault(w => w.Uploader.Equals(uploader));
                        if (uploaderInfo != null)
                        {
                            uploaderInfo.Uploader.FlushData();
                        }
                    }
                }
                else
                {
                    uploader.FlushData();
                }
            }
        }
        private void openURLToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (lvUploaders.SelectedItems.Count > 0)
            {
                UploaderInfo uploader = lvUploaders.SelectedItems[0].Tag as UploaderInfo;

                if (uploader != null && uploader.Task != null && uploader.Task.UploadResults.Count > 0 && !string.IsNullOrEmpty(uploader.Task.UploadResults[0].URL))
                {
                    ThreadPool.QueueUserWorkItem(x => Process.Start(uploader.Task.UploadResults[0].URL));
                }
            }
        }
        private void PrepareListItems()
        {
            for (int i = 0; i < lvUploaders.Items.Count; i++)
            {
                ListViewItem lvi = lvUploaders.Items[i];

                while (lvi.SubItems.Count < 3)
                {
                    lvi.SubItems.Add(string.Empty);
                }

                lvi.SubItems[1].Text = "Waiting";
                lvi.BackColor        = Color.LightYellow;

                UploaderInfo uploadInfo = lvi.Tag as UploaderInfo;
                if (uploadInfo != null)
                {
                    uploadInfo.Index = i;
                }
            }
        }
        private void bw_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (!this.IsDisposed)
            {
                UploaderInfo uploader = e.UserState as UploaderInfo;

                if (uploader != null)
                {
                    lvUploaders.Items[uploader.Index].Tag = uploader;

                    switch ((UploadStatus)e.ProgressPercentage)
                    {
                    case UploadStatus.Uploading:
                        lvUploaders.Items[uploader.Index].BackColor        = Color.Gold;
                        lvUploaders.Items[uploader.Index].SubItems[1].Text = "Uploading...";
                        lvUploaders.Items[uploader.Index].SubItems[2].Text = string.Empty;
                        break;

                    case UploadStatus.Uploaded:
                        if (uploader.Task.UploadResults.Count > 0)
                        {
                            if (uploader.Task != null && !string.IsNullOrEmpty(uploader.Task.UploadResults[0].URL))
                            {
                                lvUploaders.Items[uploader.Index].BackColor        = Color.LightGreen;
                                lvUploaders.Items[uploader.Index].SubItems[1].Text = "Success: " + uploader.Task.UploadResults[0].URL;
                            }
                            else
                            {
                                lvUploaders.Items[uploader.Index].BackColor        = Color.LightCoral;
                                lvUploaders.Items[uploader.Index].SubItems[1].Text = "Failed: " + uploader.Task.ToErrorString();
                            }
                        }
                        lvUploaders.Items[uploader.Index].SubItems[2].Text = uploader.Timer.ElapsedMilliseconds + " ms";

                        break;
                    }
                }
            }
        }
Esempio n. 6
0
        private void StopUploaderForApplicationFolder(AzureFileUploader uploader)
        {
            if (null == uploader)
            {
                return;
            }

            lock (AllUploaders)
            {
                // Drop the reference count on the uploader object
                UploaderInfo uploaderInfo = AllUploaders.FirstOrDefault(w => w.Uploader.Equals(uploader));
                uploaderInfo.RefCount--;
                if (0 == uploaderInfo.RefCount)
                {
                    // Tell the uploader object to stop
                    this.traceSource.WriteInfo(
                        this.logSourceId,
                        "Stopping uploader object for application type {0}, source {1} and destination {2} ...",
                        uploaderInfo.Key.ApplicationType,
                        uploaderInfo.Key.SourcePath,
                        uploaderInfo.Key.DestinationPath);

                    uploaderInfo.Uploader.Dispose();
                    AllUploaders.Remove(uploaderInfo);
                }
                else
                {
                    this.traceSource.WriteInfo(
                        this.logSourceId,
                        "Uploader object for application type {0}, source {1}, storage account {2}, container {3} is still in use by other uploaders, so let it continue running",
                        uploaderInfo.Key.ApplicationType,
                        uploaderInfo.Key.SourcePath,
                        this.blobUploadSettings.StorageAccountFactory.Connection.AccountName,
                        this.blobUploadSettings.ContainerName);
                }
            }
        }
Esempio n. 7
0
        private bool CreateUploaderForApplicationFolder(
            string uploaderId,
            string source,
            string workFolder,
            out AzureFileUploader uploader)
        {
            uploader = null;
            bool success = true;
            AzureFileUploader newUploader;

            // Check if we can use an existing uploader object
            UploaderKey key = new UploaderKey()
            {
                SourcePath = source,

                // Destination path is an concatenation of storage account name and container name
                DestinationPath = string.Concat(
                    this.blobUploadSettings.StorageAccountFactory.Connection.UseDevelopmentStorage ?
                    AzureConstants.DevelopmentStorageConnectionString :
                    this.blobUploadSettings.StorageAccountFactory.Connection.AccountName,
                    ";",                   // This separator cannot occur in account name or container name
                    this.blobUploadSettings.ContainerName),
                ApplicationType = this.configReader.GetApplicationType(),
            };

            lock (AllUploaders)
            {
                UploaderInfo uploaderInfo = AllUploaders.FirstOrDefault(w => w.Matches(key));
                if (null != uploaderInfo)
                {
                    // Existing uploader object is available. Increment its reference count
                    this.traceSource.WriteInfo(
                        this.logSourceId,
                        "Existing uploader object for application type {0}, source {1}, storage account {2}, container {3} is available and will be used.",
                        key.ApplicationType,
                        source,
                        this.blobUploadSettings.StorageAccountFactory.Connection.AccountName,
                        this.blobUploadSettings.ContainerName);

                    uploaderInfo.RefCount++;
                    newUploader = uploaderInfo.Uploader;
                    success     = true;
                }
                else
                {
                    // Create a new uploader object
                    this.traceSource.WriteInfo(
                        this.logSourceId,
                        "Creating uploader object for application type {0}, source {1}, storage account {2}, container {3} ...",
                        key.ApplicationType,
                        source,
                        this.blobUploadSettings.StorageAccountFactory.Connection.AccountName,
                        this.blobUploadSettings.ContainerName);

                    // Create and initialize the uploader
                    //
                    // NOTE: We do not make any assumptions about the contents of general
                    // data folders. Hence, as part of old data deletion, we attempt to
                    // delete all files in the corresponding container, without trying to
                    // filter files by Fabric node ID. We do this by specifying 'false'
                    // for the 'filterDeletionByNodeId' parameter.
                    try
                    {
                        var destinationPath = string.Concat(
                            this.blobUploadSettings.StorageAccountFactory.Connection.UseDevelopmentStorage
                                ? AzureConstants.DevelopmentStorageConnectionString
                                : this.blobUploadSettings.StorageAccountFactory.Connection.AccountName,
                            ";", // This separator cannot occur in account name or container name
                            this.blobUploadSettings.ContainerName);
                        newUploader = new AzureFileUploader(
                            this.traceSource,
                            this.logSourceId,
                            source,
                            destinationPath,
                            workFolder,
                            this.blobUploadSettings.StorageAccountFactory,
                            this.blobUploadSettings.ContainerName,
                            this.blobUploadSettings.UploadInterval,
                            this.blobUploadSettings.FileSyncInterval,
                            this.blobUploadSettings.BlobDeletionAge,
                            this.initParam.FabricNodeInstanceName,
                            this.blobUploadSettings.DeploymentId);
                        newUploader.Start();
                        uploaderInfo = new UploaderInfo()
                        {
                            Key      = key,
                            RefCount = 1,
                            Uploader = newUploader
                        };
                        AllUploaders.Add(uploaderInfo);

                        this.traceSource.WriteInfo(
                            this.logSourceId,
                            "Upload to file share is configured. Storage account: {0}, Container: {1}, Local folder path: {2}, Upload interval (minutes): {3}.",
                            this.blobUploadSettings.StorageAccountFactory.Connection.AccountName,
                            this.blobUploadSettings.ContainerName,
                            source,
                            this.blobUploadSettings.UploadInterval);
                        uploader = newUploader;
                    }
                    catch (Exception)
                    {
                        this.traceSource.WriteError(
                            this.logSourceId,
                            "Failed to create uploader object for application type {0}, source {1}, storage account {2}, container {3}.",
                            key.ApplicationType,
                            source,
                            this.blobUploadSettings.StorageAccountFactory.Connection.AccountName,
                            this.blobUploadSettings.ContainerName);
                    }
                }
            }

            return(success);
        }
        public void StartTest(UploaderInfo[] uploaders)
        {
            Testing = true;

            BackgroundWorker bw = new BackgroundWorker();
            bw.WorkerReportsProgress = true;
            bw.DoWork += new DoWorkEventHandler(bw_DoWork);
            bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
            bw.RunWorkerCompleted += (x, x2) => Testing = false;
            bw.RunWorkerAsync(uploaders);
        }
        private bool CreateUploaderForApplicationFolder(
            string uploaderId,
            string source,
            string destination,
            string workFolder,
            out FileShareUploader uploader)
        {
            uploader = null;
            bool success;
            FileShareUploader newUploader = null;

            // Check if we can use an existing uploader object
            UploaderKey key = new UploaderKey()
            {
                SourcePath      = source,
                DestinationPath = destination,
                ApplicationType = this.configReader.GetApplicationType(),
            };

            lock (AllUploaders)
            {
                UploaderInfo uploaderInfo = AllUploaders.FirstOrDefault(w => w.Matches(key));
                if (null != uploaderInfo)
                {
                    // Existing uploader object is available. Increment its reference count
                    this.traceSource.WriteInfo(
                        this.logSourceId,
                        "Existing uploader object for application type {0}, source {1} and destination {2} is available and will be used.",
                        key.ApplicationType,
                        source,
                        destination);

                    uploaderInfo.RefCount++;
                    newUploader = uploaderInfo.Uploader;
                    success     = true;
                }
                else
                {
                    // Create a new uploader object
                    this.traceSource.WriteInfo(
                        this.logSourceId,
                        "Creating uploader object for application type {0}, source {1} and destination {2} ...",
                        key.ApplicationType,
                        source,
                        destination);

                    // Create and initialize the uploader
                    try
                    {
                        newUploader = new FileShareUploader(
                            this.traceSource,
                            uploaderId,
                            true, // runningOnBehalfOfApplication
                            source,
                            destination,
                            this.fileUploadSettings.AccessInfo,
                            workFolder,
                            this.fileUploadSettings.UploadInterval,
                            this.fileUploadSettings.FileSyncInterval,
                            this.fileUploadSettings.FileDeletionAgeMinutes,
                            this.fileUploadSettings.DestinationIsLocalAppFolder,
                            this.initParam.FabricNodeId);
                        newUploader.Start();
                        success = true;
                    }
                    catch (Exception)
                    {
                        success = false;
                    }

                    if (success)
                    {
                        uploaderInfo = new UploaderInfo()
                        {
                            Key      = key,
                            RefCount = 1,
                            Uploader = newUploader
                        };
                        AllUploaders.Add(uploaderInfo);
                    }
                    else
                    {
                        this.traceSource.WriteError(
                            this.logSourceId,
                            "Failed to create uploader object for application type {0}, source {1} and destination {2}.",
                            key.ApplicationType,
                            source,
                            destination);
                    }
                }
            }

            if (success)
            {
                this.traceSource.WriteInfo(
                    this.logSourceId,
                    "Upload to file share is configured.  Destination: {0}, Local folder path: {1}, Upload interval (minutes): {2}.",
                    destination,
                    source,
                    this.fileUploadSettings.UploadInterval);
                uploader = newUploader;
            }

            return(success);
        }