private bool CreateUploaderForWinFabFolder(
            string source,
            string destination,
            string workFolder,
            out FileShareUploader uploader)
        {
            uploader = null;

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

                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(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        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);
        }