Exemplo n.º 1
0
        /// <summary>
        /// Save the filename and error count of that specific file
        /// </summary>
        /// <param name="fileName">The file that failed</param>
        /// <param name="fileSetting">File to save the name of the file that failed</param>
        /// <param name="countSetting">File to save the error count of the file that failed</param>
        /// <returns>Number of current errors</returns>
        public static async Task <int> SetFileErrorAsync(string fileName, string fileSetting, string countSetting)
        {
            try
            {
                // Load filename last error
                var lastErrorFileName = await SettingsService.LoadSettingFromFileAsync <string>(fileSetting);

                // Check if it is the same file that has an error again
                if (!string.IsNullOrEmpty(lastErrorFileName) &&
                    lastErrorFileName.Equals(fileName))
                {
                    // If the same file, add to the error count, save and return
                    var count = await SettingsService.LoadSettingFromFileAsync <int>(countSetting);

                    count++;
                    await SettingsService.SaveSettingToFileAsync(countSetting, count);

                    return(count);
                }

                // New file error. Save the name and set the error count to one.
                await SettingsService.SaveSettingToFileAsync(fileSetting, fileName);

                await SettingsService.SaveSettingToFileAsync(countSetting, 1);

                return(1);
            }
            catch (Exception)
            {
                // Do not let the error process cause the main service to generate a fault
                return(0);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get available files for upload depending on the Last Upload Date setting
        /// </summary>
        /// <param name="folders">StorageFolders to check for available files</param>
        /// <param name="dateSetting">Name of the date setting to load from settings</param>
        /// <returns>Available files for upload</returns>
        public static async Task <IList <StorageFile> > GetAvailableUploadAsync(string dateSetting, params StorageFolder[] folders)
        {
            try
            {
                var lastUploadDate = await SettingsService.LoadSettingFromFileAsync <DateTime>(dateSetting);

                var upload = new List <StorageFile>();
                foreach (var folder in folders)
                {
                    var files = (await folder.GetFilesAsync(CommonFileQuery.OrderByDate)).ToList();

                    // Reorder because order by date query uses different ordering values and descending
                    files = files.OrderBy(file => file.DateCreated).ToList();

                    // >= to get all files that have the same creation date
                    upload.AddRange(files.Where(file => file.DateCreated.DateTime >= lastUploadDate));
                }

                return(upload);
            }
            catch (Exception e)
            {
                LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Error getting the available files for upload", e);
                return(new List <StorageFile>());
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Check if need to skip the file because of to many errors
        /// </summary>
        /// <param name="fileName">The file to check for errors</param>
        /// <param name="fileSetting">File to load the name of the file that failed</param>
        /// <param name="countSetting">File to load the error count of the file that failed</param>
        /// <returns></returns>
        public static async Task <bool> SkipFileAsync(string fileName, string fileSetting, string countSetting)
        {
            var lastErrorFileName = await SettingsService.LoadSettingFromFileAsync <string>(fileSetting);

            if (string.IsNullOrEmpty(lastErrorFileName) || !lastErrorFileName.Equals(fileName))
            {
                return(false);
            }

            var count = await SettingsService.LoadSettingFromFileAsync <int>(countSetting);

            return(count >= (MaxFileUploadErrors - 1));
        }