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();
        }
Beispiel #2
0
 public void setCloudDriveLocation(LocationCredentialsConfig config)
 {
     this.location = new LocationCloudDrive();
     ((LocationCloudDrive)this.location).config    = config;
     ((LocationCloudDrive)this.location).Progress += progressHandler;
 }
Beispiel #3
0
 public void setLocalLocation(LocationCredentialsConfig config) //auta na kanoun try catch gia to cast kai na kaloun onError se fail
 {
     this.location = new LocationLocal();
     ((LocationLocal)this.location).config    = config;
     ((LocationLocal)this.location).Progress += progressHandler;
 }
Beispiel #4
0
 public void setFtpLocation(LocationCredentialsConfig config)
 {
     this.location = new LocationFtp();
     ((LocationFtp)this.location).config    = config;
     ((LocationFtp)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);
                }
            }
        }