Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Account"/> class.
 /// </summary>
 public Account()
 {
     googleDrive = new GoogleDrive();
 }
Ejemplo n.º 2
0
        private bool BackUpFile(
            Google.Apis.Drive.v3.Data.File serverFolder,
            IList <Google.Apis.Drive.v3.Data.File> serverFiles,
            FileInfo file,
            bool retry)
        {
            bool success = false;

            try
            {
                string fileName = GoogleDrive.SanitizeFileName(file.FullName);

                string message = string.Format(
                    CultureInfo.InvariantCulture,
                    "Checking: {0}",
                    fileName);
                Log.Info(CultureInfo.InvariantCulture, m => m(
                             message));

                Google.Apis.Drive.v3.Data.File serverFile =
                    GoogleDrive.GetFileInList(
                        serverFiles, file.Name);

                Upload(serverFolder, file, serverFile, retry);

                success = true;
            }
            catch (AggregateException exception)
            {
                Log.Error(CultureInfo.InvariantCulture, m => m(
                              "AggregateException caught"));
                Log.Error(CultureInfo.InvariantCulture, m => m(
                              exception.ToString()));

                foreach (Exception innerExecption in exception.InnerExceptions)
                {
                    if (innerExecption is TaskCanceledException)
                    {
                        Log.Warn(CultureInfo.InvariantCulture, m => m(
                                     exception.ToString()));

                        retries--;
                    }
                    else if (innerExecption is ArgumentNullException ||
                             innerExecption is DirectoryNotFoundException ||
                             innerExecption is FileNotFoundException ||
                             innerExecption is FormatException ||
                             innerExecption is IOException ||
                             innerExecption is NullReferenceException ||
                             innerExecption is IndexOutOfRangeException ||
                             innerExecption is InvalidOperationException ||
                             innerExecption is UnauthorizedAccessException)
                    {
                        retries = 0;
                    }
                    else
                    {
                        // Rethrow any other exception.
                        throw;
                    }
                }
            }
            catch (Exception exception) when
                (exception is ArgumentNullException ||
                exception is DirectoryNotFoundException ||
                exception is FileNotFoundException ||
                exception is FormatException ||
                exception is IOException ||
                exception is NullReferenceException ||
                exception is IndexOutOfRangeException ||
                exception is InvalidOperationException ||
                exception is UnauthorizedAccessException)
            {
                Log.Error(CultureInfo.InvariantCulture, m => m(
                              exception.ToString()));

                retries = 0;
            }

            return(success);
        }