Animatroller.MonoExpander.MonoExpanderClient.CheckFile C# (CSharp) Method

CheckFile() private method

private CheckFile ( object triggerMessage, FileTypes fileType, string fileName ) : bool
triggerMessage object
fileType FileTypes
fileName string
return bool
        private bool CheckFile(object triggerMessage, FileTypes fileType, string fileName)
        {
            if (!string.IsNullOrEmpty(Path.GetDirectoryName(fileName)))
                throw new ArgumentException("FileName should be without path");

            string fileTypeFolder = Path.Combine(this.main.FileStoragePath, fileType.ToString());
            Directory.CreateDirectory(fileTypeFolder);

            string filePath = Path.Combine(fileTypeFolder, fileName);
            if (File.Exists(filePath))
                return true;

            CleanUpDownloadInfo();

            this.log.Info("Missing file {0} of type {1}", fileName, fileType);

            string downloadId;

            lock (this.downloadInfos)
            {
                if (this.downloadInfos.Any(x => x.Value.FileType == fileType && x.Value.FileName == fileName))
                {
                    // Already in the process to be downloaded
                    this.log.Info("Already in the process of being downloaded");

                    return false;
                }

                var downloadInfo = new DownloadInfo(this.main.FileStoragePath, fileType)
                {
                    TriggerMessage = triggerMessage,
                    FileName = fileName,
                    FinalFilePath = filePath
                };

                this.downloadInfos.Add(downloadInfo.Id, downloadInfo);

                if (Directory.Exists(downloadInfo.TempFolder))
                    // Empty it
                    Directory.Delete(downloadInfo.TempFolder, true);

                downloadId = downloadInfo.Id;
            }

            // Request the file
            SendMessage(new FileRequest
            {
                DownloadId = downloadId,
                Type = fileType,
                FileName = fileName
            });

            return false;
        }