public DigitalDocumentSystemService(DirectoryInfo inputDirectoryInfo, DirectoryInfo outputDirectoryInfo, DriveService driveService) { this.ServiceName = SerivceName; this.CanStop = true; this.inputDirectoryInfo = inputDirectoryInfo; this.outputDirectoryInfo = outputDirectoryInfo; this.driveService = driveService; this.fileWatcher = new FileSystemWatcher(inputDirectoryInfo.FullName) { EnableRaisingEvents = false }; this.fileWatcher.Changed += (s, args) => this.inputChangedEvent.Set(); this.fileWatcher.Created += (s, args) => this.inputChangedEvent.Set(); this.fileWatcher.Renamed += (s, args) => this.inputChangedEvent.Set(); this.worker = new Thread(this.WorkerThread); }
/// <summary> /// The main entry point for the application. /// </summary> static void Main() { var inputDir = new DirectoryInfo(@"E:\Input"); var outputDir = new DirectoryInfo(@"E:\Output"); UserCredential credential; string[] scopes = { DriveService.Scope.Drive }; using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read)) { var credPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart"); credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; Console.WriteLine("Credential file saved to: " + credPath); } var service = new DriveService( new BaseClientService.Initializer { HttpClientInitializer = credential, ApplicationName = DigitalDocumentSystemService.SerivceName }); var servicesToRun = new ServiceBase[] { new DigitalDocumentSystemService(inputDir, outputDir, service) }; ServiceBase.Run(servicesToRun); }