public static void SetCredientals(string dpUser, string dpPassword) { if (string.IsNullOrEmpty(dpUser) || string.IsNullOrEmpty(dpPassword)) return; _credentials = new DropBoxCredentials(); _credentials.ConsumerKey = ConsumerKey; _credentials.ConsumerSecret = ConsumerSecret; _credentials.UserName = dpUser.Trim(); _credentials.Password = dpPassword.Trim(); }
public void startSave() //thelei douleia afti { if (locations.Count == 0) { onSaveError("Save started with no locations"); return; } LocationCredentialsConfig config; DataTable data = backup_adapter.GetDataByID(locations[0]); if (data.Rows.Count == 0) { onSaveError("Location not found in the database"); return; } long type = (Int64)data.Rows[0]["service_type"]; adapter = new LocationAdapter(); adapter.Progress += onSaveProgressHandler; adapter.SaveComplete += onSaveCompleteHandler; adapter.SaveError += onSaveErrorHandler; adapter.setLocationId(locations[0]); switch (type) //edw gemizei to config apo to database prepei na kanei diaforetiko query gia kathe diaforetiko type kai na gemisei to config prin to settarei ston adapter { case 0: //file system config = new LocationCredentialsConfig(); config.fnamePrefix = fnamePrefix; config.sourcePath = sourcePath; config.locationPath = (string)data.Rows[0]["path"]; adapter.setLocalLocation(config); break; case 1: //FTP config = new FTPCredentialsConfig(); config.fnamePrefix = fnamePrefix; config.sourcePath = sourcePath; config.locationPath = (string)data.Rows[0]["path"] + (string)data.Rows[0]["filename"]; ((FTPCredentialsConfig)config).id = (Int64)data.Rows[0]["id"]; ((FTPCredentialsConfig)config).host = (string)data.Rows[0]["host"]; config.port = unchecked ((int)(Int64)data.Rows[0]["port"]); config.username = (string)data.Rows[0]["username"]; config.password = (string)data.Rows[0]["password"]; Int64 useSFTP = (Int64)data.Rows[0]["usesftp"]; if (useSFTP == 1) { ((FTPCredentialsConfig)config).useSFTP = true; ((FTPCredentialsConfig)config).SshHostKeyFingerprint = (string)data.Rows[0]["ssh_key_fingerprint"]; } string keypath = (string)data.Rows[0]["ssh_key"]; if (!string.IsNullOrEmpty(keypath)) { ((FTPCredentialsConfig)config).usePrivateKey = true; ((FTPCredentialsConfig)config).privateKeyPath = keypath; } adapter.setFtpLocation(config); break; case 2: //Dropbox DropBoxCredentials boxcreds = new DropBoxCredentials(); boxcreds.Path = (string)data.Rows[0]["path"]; boxcreds.Name = (string)data.Rows[0]["name"]; boxcreds.FileName = (string)data.Rows[0]["filename"]; boxcreds.Token = (string)data.Rows[0]["access_token"]; boxcreds.LocalFilePath = sourcePath; //EDW SETUP TO CONFIG adapter.setCloudBoxLocation(boxcreds); break; case 3: //Google drive config = new LocationCredentialsConfig(); config.fnamePrefix = fnamePrefix; //EDW SETUP TO CONFIG adapter.setCloudDriveLocation(config); break; default: onSaveError("Location type unknown"); return; } onInnerSaveInit((string)data.Rows[0]["name"], unchecked ((int)type)); Task managersendtask = new Task(adapter.sendFile); managersendtask.Start(); }
public void setCloudBoxLocation(DropBoxCredentials config) { this.location = new LocationCloudBox(); ((LocationCloudBox)this.location).config = config; ((LocationCloudBox)this.location).Progress += progressHandler; }
public void startImport() { if (isLocal) { if (!File.Exists(path + filename)) { onImportError("File doesnt exist, path: " + path); return; } templocalpath = path; templocalfilename = filename; startDecompression(); } else { //set config locationadapter = new LocationAdapter(); locationadapter.Progress += downloadProgressHandler; locationadapter.SaveComplete += downloadCompleteHandler; locationadapter.SaveError += downloadErrorHandler; LocationCredentialsConfig config; templocalpath = ConfigurationManager.getInstance().mysqlDumpConfigInstance.getSettings().tempSavePath; //calculate local path if (!File.Exists(path + filename)) { templocalfilename = filename; } else { Random rnd = new Random(); string extension = StringUtils.getExtension(filename); templocalfilename = "Temp" + rnd.Next(1000000, 9999999) + extension; Directory.CreateDirectory(templocalpath); //checking if file exists while (File.Exists(templocalpath + templocalfilename)) { templocalfilename = "Temp" + rnd.Next(1000000, 9999999) + extension; } } try { long type = (Int64)locationdata["service_type"]; switch (type) //edw gemizei to config apo to database prepei na kanei diaforetiko query gia kathe diaforetiko type kai na gemisei to config prin to settarei ston adapter { case 0: //file system //De ginete na einai file system kai na erthei edw break; case 1: //FTP config = new FTPCredentialsConfig(); config.sourcePath = path + filename; config.locationPath = templocalpath + templocalfilename; ((FTPCredentialsConfig)config).id = (Int64)locationdata["id"]; ((FTPCredentialsConfig)config).host = (string)locationdata["host"]; config.port = unchecked ((int)(Int64)locationdata["port"]); config.username = (string)locationdata["username"]; config.password = EncryptionUtils.sDecrypt((string)locationdata["password"]); Int64 useSFTP = (Int64)locationdata["usesftp"]; if (useSFTP == 1) { ((FTPCredentialsConfig)config).useSFTP = true; ((FTPCredentialsConfig)config).SshHostKeyFingerprint = (string)locationdata["ssh_key_fingerprint"]; } string keypath = (string)locationdata["ssh_key"]; if (!string.IsNullOrEmpty(keypath)) { ((FTPCredentialsConfig)config).usePrivateKey = true; ((FTPCredentialsConfig)config).privateKeyPath = keypath; } locationadapter.setFtpLocation(config); break; case 2: //Dropbox DropBoxCredentials boxcreds = new DropBoxCredentials(); //EDW SETUP TO CONFIG locationadapter.setCloudBoxLocation(boxcreds); break; case 3: //Google drive config = new LocationCredentialsConfig(); //EDW SETUP TO CONFIG locationadapter.setCloudDriveLocation(config); break; default: onImportError("Location type unknown"); return; } onInnerProccessInit(Convert.ToInt32(type), 100); locationadapter.getFile(); } catch (InvalidCastException ex) { onImportError("Save location data load failed:\n" + ex.Message); } } }