<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Configuration;
using System.Drawing.Imaging;
using Google.GData.Client;
using Google.GData.Photos;
using Google.Picasa;
using System.Net;
using System.Xml;
using System.Net.Sockets;
using NLog;

namespace PicasaWebSync
{
    /// <summary>
    /// A class which interacts with Picasa to provide syncing between local folders and online Picasa Web Albums.
    /// </summary>
    public class PicasaAlbumSynchronizer
    {
        private static Logger s_logger = LogManager.GetLogger("*");

        #region Constructor
        public PicasaAlbumSynchronizer()
        {
            this.ResizePhotos = true;
            this.ResizePhotosMaxSize = DEFAULT_RESIZE_MAX_SIZE;
            this.AlbumAccess = AlbumAccessEnum.Private;
            this.AlbumNameFormat = DEFAULT_ALBUM_NAME_FORMAT;
            this.ExcludeFilesLargerThan = DEFAULT_EXCLUDE_FILES_LARGER_THAN;
        }
        #endregion

        #region Members
        private const string APP_NAME = "PicasaWebSync";
        private const int DEFAULT_RESIZE_MAX_SIZE = 800;
        private const string DEFAULT_ALBUM_NAME_FORMAT = "{0}";
        private const string ENTRY_DELETED_SUMMARY = "[deleted]";
        private const string GDATA_RESPONSE_BADAUTH = "BadAuthentication";
        private const long DEFAULT_EXCLUDE_FILES_LARGER_THAN = 1073741824; //1GB

        private string m_baseDirectoryName;
        private int m_albumCreateCount;
        private int m_albumUpdateCount;
        private int m_albumDeleteCount;
        private int m_folderSkipCount;
        private int m_fileCreateCount;
        private int m_fileDeleteCount;
        private int m_fileSkipCount;
        private int m_errorsCount;
        private DateTime m_startTime;

        public string PicasaUsername { get; set; }
        public string PicasaPassword { get; set; }
        public AlbumAccessEnum AlbumAccess { get; set; }
        public string[] IncludeExtensions { get; set; }
        public string[] ExcludeFileNamesContainingText { get; set; }
        public long ExcludeFilesLargerThan { get; set; }
        public string[] ExcludeFolderNames { get; set; }
        public string ExcludeFoldersContainingFileName { get; set; }
        public bool IncludeSubFolders { get; set; }
        public bool ResizePhotos { get; set; }
        public int ResizePhotosMaxSize { get; set; }
        public bool ResizeVideos { get; set; }
        public string ResizeVideosCommand { get; set; }
        public bool ClearAlbumPhotosFirst { get; set; }
        public string AlbumNameFormat { get; set; }
        public bool IncludeBaseDirectoryInAlbumName { get; set; }
        public string AlbumPublicFileName { get; set; }
        public string[] AlbumPrivateFolderNames { get; set; }
        public string AlbumPrivateFileName { get; set; }
        public bool VerboseOutput { get; set; }
        public bool AddOnly { get; set; }
        #endregion

        #region Methods
        /// <summary>
        /// Syncs a local folder to an online Picasa Web Album location
        /// </summary>
        /// <param name="folderPath">The source folder to sync.</param>
        public void SyncFolder(string folderPath)
        {
            ResetCounters();
            GDataAuthenticator authenticator = new GDataAuthenticator ();
            PicasaService session = new PicasaService("PicasaWebSync");
            session.RequestFactory = authenticator.requestFactory;
            AlbumQuery query = new AlbumQuery(PicasaQuery.CreatePicasaUri(this.PicasaUsername));

            try
            {
                WriteOutput("[Connecting to Picasa web service]");
                //fetch all albums
                PicasaFeed albumFeed = session.Query(query);

                WriteOutput("[Starting sync]");

                folderPath = folderPath.TrimEnd(new char[] { '\\' });
                DirectoryInfo sourceFolder = new DirectoryInfo(folderPath);
                m_baseDirectoryName = sourceFolder.Name;

                SyncFolder(sourceFolder, null, this.AlbumAccess, this.IncludeSubFolders, session, albumFeed);
            }
            catch (GDataRequestException gdrex)
            {
                if (gdrex.ResponseString.Contains(GDATA_RESPONSE_BADAUTH))
                {
                    throw new AuthenticationException("Picasa error - username and/or password is incorrect!  Check the config file values.");
                }
                else
                {
                    throw new Exception(string.Format("Picasa error - {0}", gdrex.ResponseString));
                }
            }<commit_msg>Send the password to the authenticator<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Configuration;
using System.Drawing.Imaging;
using Google.GData.Client;
using Google.GData.Photos;
using Google.Picasa;
using System.Net;
using System.Xml;
using System.Net.Sockets;
using NLog;

namespace PicasaWebSync
{
    /// <summary>
    /// A class which interacts with Picasa to provide syncing between local folders and online Picasa Web Albums.
    /// </summary>
    public class PicasaAlbumSynchronizer
    {
        private static Logger s_logger = LogManager.GetLogger("*");

        #region Constructor
        public PicasaAlbumSynchronizer()
        {
            this.ResizePhotos = true;
            this.ResizePhotosMaxSize = DEFAULT_RESIZE_MAX_SIZE;
            this.AlbumAccess = AlbumAccessEnum.Private;
            this.AlbumNameFormat = DEFAULT_ALBUM_NAME_FORMAT;
            this.ExcludeFilesLargerThan = DEFAULT_EXCLUDE_FILES_LARGER_THAN;
        }
        #endregion

        #region Members
        private const string APP_NAME = "PicasaWebSync";
        private const int DEFAULT_RESIZE_MAX_SIZE = 800;
        private const string DEFAULT_ALBUM_NAME_FORMAT = "{0}";
        private const string ENTRY_DELETED_SUMMARY = "[deleted]";
        private const string GDATA_RESPONSE_BADAUTH = "BadAuthentication";
        private const long DEFAULT_EXCLUDE_FILES_LARGER_THAN = 1073741824; //1GB

        private string m_baseDirectoryName;
        private int m_albumCreateCount;
        private int m_albumUpdateCount;
        private int m_albumDeleteCount;
        private int m_folderSkipCount;
        private int m_fileCreateCount;
        private int m_fileDeleteCount;
        private int m_fileSkipCount;
        private int m_errorsCount;
        private DateTime m_startTime;

        public string PicasaUsername { get; set; }
        public string PicasaPassword { get; set; }
        public AlbumAccessEnum AlbumAccess { get; set; }
        public string[] IncludeExtensions { get; set; }
        public string[] ExcludeFileNamesContainingText { get; set; }
        public long ExcludeFilesLargerThan { get; set; }
        public string[] ExcludeFolderNames { get; set; }
        public string ExcludeFoldersContainingFileName { get; set; }
        public bool IncludeSubFolders { get; set; }
        public bool ResizePhotos { get; set; }
        public int ResizePhotosMaxSize { get; set; }
        public bool ResizeVideos { get; set; }
        public string ResizeVideosCommand { get; set; }
        public bool ClearAlbumPhotosFirst { get; set; }
        public string AlbumNameFormat { get; set; }
        public bool IncludeBaseDirectoryInAlbumName { get; set; }
        public string AlbumPublicFileName { get; set; }
        public string[] AlbumPrivateFolderNames { get; set; }
        public string AlbumPrivateFileName { get; set; }
        public bool VerboseOutput { get; set; }
        public bool AddOnly { get; set; }
        #endregion

        #region Methods
        /// <summary>
        /// Syncs a local folder to an online Picasa Web Album location
        /// </summary>
        /// <param name="folderPath">The source folder to sync.</param>
        public void SyncFolder(string folderPath)
        {
            ResetCounters();
            GDataAuthenticator authenticator = new GDataAuthenticator (this.PicasaPassword);
            PicasaService session = new PicasaService("PicasaWebSync");
            session.RequestFactory = authenticator.requestFactory;
            AlbumQuery query = new AlbumQuery(PicasaQuery.CreatePicasaUri(this.PicasaUsername));

            try
            {
                WriteOutput("[Connecting to Picasa web service]");
                //fetch all albums
                PicasaFeed albumFeed = session.Query(query);

                WriteOutput("[Starting sync]");

                folderPath = folderPath.TrimEnd(new char[] { '\\' });
                DirectoryInfo sourceFolder = new DirectoryInfo(folderPath);
                m_baseDirectoryName = sourceFolder.Name;

                SyncFolder(sourceFolder, null, this.AlbumAccess, this.IncludeSubFolders, session, albumFeed);
            }
            catch (GDataRequestException gdrex)
            {
                if (gdrex.ResponseString.Contains(GDATA_RESPONSE_BADAUTH))
                {
                    throw new AuthenticationException("Picasa error - username and/or password is incorrect!  Check the config file values.");
                }
                else
                {
                    throw new Exception(string.Format("Picasa error - {0}", gdrex.ResponseString));
                }
            }
{'fraction_non_alphanumeric': 0.07538591668428843, 'fraction_numerical': 0.0033833791499259885, 'mean_word_length': 2.372192513368984, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3299142', 'n_tokens_mistral': 2582, 'n_tokens_neox': 2409, 'n_words': 678}