Пример #1
0
        private async Task Application_StartupAsync()
        {
            // This frees up the Ctrl-I input binding for italics
            AvalonEditCommands.IndentSelection.InputGestures.Clear();

            AppPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            Local = new SQLiteStorage();
            await Local.Initialize();

            string username = Local.GetUsername().Result;

            Cloud = new GoogleDriveStorage(username);

            if (String.IsNullOrWhiteSpace(username))
            {
                App.Current.Dispatcher.Invoke(() => ShowLoginDialog(true));
            }
            else
            {
                if (!Cloud.IsInternetConnected() || await Cloud.Connect())
                {
                    App.Current.Dispatcher.Invoke(() => ShowMainWindow());
                }
                else
                {
                    App.Current.Dispatcher.Invoke(() => ShowLoginDialog(false, "Timeout attempting to login. Please try again."));
                }
            }
        }
Пример #2
0
        public GoogleDriveStream(GoogleDriveStorage storage, Google.Apis.Drive.v2.Data.File file)
        {
            this.storage = storage;
            this.file = file;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(file.DownloadUrl));
            request.Headers.Add("Authorization", storage.Credential.Token.TokenType + " " + storage.Credential.Token.AccessToken);
            
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            if (response.StatusCode != HttpStatusCode.OK)
                throw new Exception("Could not retrieve file stream");

            using (Stream responseStream = response.GetResponseStream())
                responseStream.CopyTo(dataStream);

            dataStream.Seek(0, SeekOrigin.Begin);
        }
Пример #3
0
        static void Main(string[] args)
        {
            try
            {
                // create dropbox client
                string apiKey;
                string redirectUrl = @"http://*****:*****@"D:\Test Dir\CloudStorages\dbkey.txt");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Cannot read api key: " + ex.Message);
                    throw ex;
                }

                ICloudStorageClient dropBoxClient = new DropBoxStorage(apiKey, redirectUrl);

                Task.Run(() => Test(dropBoxClient)).Wait();
                Console.Write("Finish testing dropbox.\n\n");

                // create google drive client
                string appName = "Test App";
                string apiSecret;
                try
                {
                    apiKey    = File.ReadAllText(@"D:\Test Dir\CloudStorages\gdkey.txt");
                    apiSecret = File.ReadAllText(@"D:\Test Dir\CloudStorages\gdsecret.txt");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Cannot read api key/secret: " + ex.Message);
                    throw ex;
                }

                ICloudStorageClient googleClient = new GoogleDriveStorage(apiKey, apiSecret, appName);

                Task.Run(() => Test(googleClient)).Wait();
                Console.Write("Finish testing google drive.\n\n");

                // create onedrive client
                try
                {
                    apiKey = File.ReadAllText(@"D:\Test Dir\CloudStorages\odkey.txt");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Cannot read api key: " + ex.Message);
                    throw ex;
                }
                ICloudStorageClient onedriveClient = new OneDriveStorage(apiKey);

                Task.Run(() => Test(onedriveClient)).Wait();
                Console.Write("Finish testing onedrive.\n\n");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine("Press any key to end.");
            Console.ReadKey();
        }
Пример #4
0
 public GoogleDriveFile(GoogleDriveStorage storage, GoogleDriveDirectory parent, Google.Apis.Drive.v2.Data.File file)
 {
     this.storage = storage;
     this.parent = parent;
     this.file = file;
 }