public UpdateAIP(RosettaSettings rs) { _rs = rs; _inst = String.IsNullOrEmpty(_rs.Institution) ? "INS00" : rs.Institution; _ros = new RosettaRepository(_rs.Host, _rs.Port); _ros.Login(_inst, _rs.ApplicationUser, _rs.ApplicationPassword); log.Info(String.Format("Logged in user {0} and received PDS Handle {1}.", _rs.ApplicationUser, _ros.PdsHandle)); }
static void Main(string[] args) { Action action = Action.Replace; string iepid=""; string flpid=""; string reppid=""; string filename=""; // Parse arguments if (args.Length > 0) { for (int n = 0; n < args.Length; n++) { if (args[n].Substring(0, 1) == "-") { // action switch (args[n].ToLower().Substring(1)) { case "replace": case "r": action = Action.Replace; break; case "delete": case "d": action = Action.Delete; break; case "add": case "a": action = Action.Add; break; case "user": case "u": n++; Settings.Default.user = args[n]; continue; case "pass": case "p": n++; Settings.Default.pass = Util.EncryptString(Util.ToSecureString(args[n])); continue; case "host": case "h": n++; Settings.Default.host = args[n]; continue; case "appuser": case "au": n++; Settings.Default.appUser = args[n]; continue; case "apppass": case "ap": n++; Settings.Default.appPassword = Util.EncryptString(Util.ToSecureString(args[n])); continue; case "port": n++; Settings.Default.port = args[n]; continue; case "remotedir": n++; Settings.Default.remotedir = args[n]; continue; case "inst": n++; Settings.Default.institution = args[n]; continue; default: DisplayError("Invalid action."); break; } continue; } if (args[n].Substring(0, 2) == "IE") { iepid = args[n]; continue; } if (args[n].Substring(0, 2) == "FL") { flpid = args[n]; continue; } if (args[n].Substring(0, 3) == "REP") { reppid = args[n]; continue; } filename = args[n]; } Settings.Default.Save(); log.Info("Settings saved."); } // Validate we have enough data to continue // For replace, we need a file at a minimum if (action == Action.Replace && filename == "") DisplayUsage(); // For add, we need the rep and the file if (action == Action.Add && (reppid == "" || filename =="")) DisplayUsage(); // For delete, we need the filename or the file PID if (action == Action.Delete && (filename == "" && flpid == "")) DisplayUsage(); RosettaSettings rs = new RosettaSettings() { ApplicationUser = Settings.Default.appUser, ApplicationPassword = Util.ToInsecureString(Util.DecryptString(Settings.Default.appPassword)), ServerUser = Settings.Default.user, ServerPassword = Util.ToInsecureString(Util.DecryptString(Settings.Default.pass)), Host = Settings.Default.host, Institution = Settings.Default.institution, RemoteDirectory = Settings.Default.remotedir, Port = Settings.Default.port }; UpdateAIP updateAip = new UpdateAIP(rs); try { if (action == Action.Replace) updateAip.UpdateFile(filename, iepid, reppid, flpid); else if (action == Action.Delete) updateAip.DeleteFile(filename, iepid, flpid); else if (action == Action.Add) updateAip.AddFile(filename, reppid); } catch (Exception ex) { DisplayError(ex.Message); } }