Esempio n. 1
0
        public static Google.Apis.Drive.v3.DriveService GetService_v3()
        {
            UserCredential credential;
            var            auth_filename = AppConfiguration.GetAppConfig("CredentialPath");

            using (var stream = new FileStream(auth_filename, FileMode.Open, FileAccess.Read))
            {
                //String FolderPath = @"D:\";
                //String FilePath = Path.Combine(FolderPath, "DriveServiceCredentials.json");

                var authPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\Authentication\\";

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(authPath, true)).Result;
            }

            //Create Drive API service.
            Google.Apis.Drive.v3.DriveService service = new Google.Apis.Drive.v3.DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = "SuchPropsUploader",
            });

            return(service);
        }
Esempio n. 2
0
        private Error runFileMode(BackgroundWorker worker, string name)
        {
            var isSourceDelete    = Convert.ToBoolean(AppConfiguration.GetAppConfig("SourceDelete"));
            var nameOnGoogleDrive = AppConfiguration.GetAppConfig("NameOnGoogleDrive");
            var destPath          = AppConfiguration.GetAppConfig("LocalPath");
            var credentialPath    = AppConfiguration.GetAppConfig("CredentialPath");

            var target = destPath + "\\" + Path.GetFileName(name);

            Program.AddLog("Start copy to " + target);

            //Create a tast to run copy file
            target = FileInfoExtension.getFilepathCheckExist(target);

            File.Copy(name, target);
            worker.ReportProgress(30, "Start security " + name);

            /// 인터넷 체크
            Program.AddLog("Internet connection check.. ");
            if (!GoogleDriveApi.CheckForInternetConnection())
            {
                Program.AddLog("Failed.");
                return(Error.FAILED_INTERNET_CONNECTION);
            }

            /// root id 가져오기
            var id = GoogleDriveApi.getBackupFolderId(nameOnGoogleDrive);

            if (String.IsNullOrEmpty(id))
            {
                id = GoogleDriveApi.CreateFolder(nameOnGoogleDrive);
            }

            Program.AddLog("Start google drive upload.. " + id);

            //Google upload
            worker.ReportProgress(80, "Start security " + target);
            Program.AddLog("Compression success.. ");
            if (GoogleDriveApi.FileUploadInFolder(id, target))
            {
                Program.AddLog("Upload success.");
                if (isSourceDelete)
                {
                    FileInfoExtension.DeleteFolder(name);
                }
            }
            else
            {
                return(Error.FAILED_UPLOAD);
            }

            return(Error.SUCCESS);
        }
Esempio n. 3
0
 static void Main(string[] args)
 {
     log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo("App.config"));
     log = LogManager.GetLogger("Logger");
     if (Convert.ToBoolean(AppConfiguration.GetAppConfig("DevMode")))
     {
         AllocConsole();
         IntPtr         stdHandle      = GetStdHandle(STD_OUTPUT_HANDLE);
         SafeFileHandle safeFileHandle = new SafeFileHandle(stdHandle, true);
         FileStream     fileStream     = new FileStream(safeFileHandle, FileAccess.Write);
         StreamWriter   standardOutput = new StreamWriter(fileStream, System.Text.Encoding.Unicode);
         standardOutput.AutoFlush = true;
         Console.SetOut(standardOutput);
     }
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(new MainFrame(args));
 }
Esempio n. 4
0
        public MainFrame(string[] args)
        {
            InitializeComponent();
            InitializeBackgroundWorker();

            if (!Convert.ToBoolean(AppConfiguration.GetAppConfig("DevMode")) && args.Length == 0)
            {
                showMessageBox("선택한 파일이 없으므로 프로그램을 종료합니다.");
                Program.AddLog("파일 또는 폴더 입력이 없습니다.");
                System.Environment.Exit(0);
                return;
            }

            sourceFolderDeleteAfterCopy.Checked = Convert.ToBoolean(AppConfiguration.GetAppConfig("SourceDelete"));
            googleDriveTextBox.Text             = AppConfiguration.GetAppConfig("NameOnGoogleDrive");
            localFolderTextBox.Text             = AppConfiguration.GetAppConfig("LocalPath");
            credentialTextBox.Text = AppConfiguration.GetAppConfig("CredentialPath");

            connectEvent();
            devMode();
            if (!Convert.ToBoolean(AppConfiguration.GetAppConfig("DevMode")))
            {
                m_selectedFile = new List <string>(args);

                if (String.IsNullOrEmpty(localFolderTextBox.Text) ||
                    String.IsNullOrEmpty(googleDriveTextBox.Text) ||
                    String.IsNullOrEmpty(credentialTextBox.Text) ||
                    !new FileInfo(credentialTextBox.Text).Exists)
                {
                    return;
                }

                uploadMode();
                backgroundWorker1.RunWorkerAsync();
            }
            else
            {
                Program.AddLog("==================================================");
                Program.AddLog("==================   DevMode   ===================");
                Program.AddLog("==================================================");
            }
        }
Esempio n. 5
0
        // This event handler is where the actual,
        // potentially time-consuming work is done.
        private void backgroundWorker1_DoWork(object sender,
                                              DoWorkEventArgs e)
        {
            // Get the BackgroundWorker that raised this event.
            BackgroundWorker worker = sender as BackgroundWorker;

            e.Result = Error.SUCCESS;
            var isSourceDelete    = Convert.ToBoolean(AppConfiguration.GetAppConfig("SourceDelete"));
            var nameOnGoogleDrive = AppConfiguration.GetAppConfig("NameOnGoogleDrive");
            var destPath          = AppConfiguration.GetAppConfig("LocalPath");
            var credentialPath    = AppConfiguration.GetAppConfig("CredentialPath");

            if (String.IsNullOrEmpty(destPath) ||
                String.IsNullOrEmpty(nameOnGoogleDrive) ||
                String.IsNullOrEmpty(credentialPath) ||
                !new FileInfo(credentialPath).Exists)
            {
                e.Result = Error.NOT_READY;
                return;
            }
            worker.ReportProgress(0, "Start security (0/3)");
            /// 파일 링크 주소
            foreach (string input in m_selectedFile)
            {
                var info = new FileInfo(input);
                Program.AddLog("Input file source : " + input);
                if (!FileInfoExtension.isDirectory(input))
                {
                    runFileMode(worker, input);
                }
                else
                {
                    runDirectoryMode(worker, input);
                }
            }
            worker.ReportProgress(100, "Start bong's security (3/3)");
        }