Esempio n. 1
0
 /// <summary>
 /// Adds the given credentials to the  store or updates the credentials if an entry exists for the username, mandant and system.
 /// </summary>
 /// <param name="newCredentials">The credentials to add</param>
 public void SetCredentials(Credentials newCredentials)
 {
     RemoveCredentials(newCredentials.System, newCredentials.Mandant, newCredentials.Username);
      XMLCredentials.Add(newCredentials);
 }
        public override int Run(string[] remainingArguments)
        {
            var store = CredentialStore.Load();

             if (ClearPassword)
             {
            var removed = store.RemoveCredentials(System, Mandant, Username);
            store.Save();
            if (removed) Log.Instance.Write("Credentials have been removed.");
            return 0;
             }

             var credentials = new Credentials(System, Mandant, Username);
             if (!string.IsNullOrWhiteSpace(Password))
             {
            credentials.Password = Password;
            store.SetCredentials(credentials);
            store.Save();
            return 0;
             }
             var password1 = GetPasswordFromConsole(string.Format("Enter Password for user {0}: ", Username));
             if (string.IsNullOrEmpty(password1))
             {
            Log.Instance.Write("User abort.");
            return 5;
             }
             var password2 = GetPasswordFromConsole("Retype Password: "******"Password mismatch");
            return 2;
             }
             credentials.Password = password1;
             store.SetCredentials(credentials);
             store.Save();
             return 0;
        }
Esempio n. 3
0
        public override int Run(string[] remainingArguments)
        {
            var engine = new Engine(ProjectFolder);
             if (!string.IsNullOrWhiteSpace(AppName)) engine.AppName = AppName;
             if (!string.IsNullOrWhiteSpace(AppDescription)) engine.AppDescription = AppDescription;
             if (!string.IsNullOrWhiteSpace(Package)) engine.Package = Package;
             if (TransportRequest != null) engine.TransportRequest = TransportRequest;
             engine.DeltaMode = DeltaMode;
             engine.TestMode = TestMode;
             engine.Timeout = Timeout;
             engine.IgnoreCertificateErrors = IgnoreCertificateErrors;
             Credentials credentials = null;
             if (!string.IsNullOrWhiteSpace(Username) && !string.IsNullOrWhiteSpace(Password))
             {
            credentials = new Credentials(System, Mandant, Username);
            credentials.Password = Password;
             }
             else if (!string.IsNullOrWhiteSpace(Username))
             {
            var credentialStore = CredentialStore.Load();
            credentials = credentialStore.GetCredentials(System, Mandant, Username);
            if (credentials == null)
            {
               credentials = new Credentials(System, Mandant, Username);
               credentials.Password = SetCredentialsCommand.GetPasswordFromConsole(string.Format("Enter Password for user {0}: ", Username));
               if (string.IsNullOrEmpty(credentials.Password)) {
                  Log.Instance.Write("User abort.");
                  return 5;
               }
               Console.Write("Save Password? [Y/N] ");
               var answer = Console.ReadLine();
               if (answer == null)
               {
                  Log.Instance.Write("Non interactive console. Aborting.");
                  return 6;
               }
               if (answer.Trim().Equals("Y", StringComparison.OrdinalIgnoreCase))
               {
                  credentialStore.SetCredentials(credentials);
                  credentialStore.Save();
               }

            }
             }
             else //SSO
             {
            credentials = new Credentials(System, Mandant, null);
             }
             engine.Credentials = credentials;
             Log.Instance.Write("System: {0}", engine.Credentials.System);
             Log.Instance.Write("Mandant: {0}", engine.Credentials.Mandant);
             Log.Instance.Write("Username: {0}", engine.Credentials.Username ?? "SSO");
             Log.Instance.Write("Project folder: {0}", engine.ProjectDir);
             Log.Instance.Write("App name: {0}", engine.AppName);
             Log.Instance.Write("Package: {0}", engine.Package);
             Log.Instance.Write("Transport: {0}", engine.TransportRequest);
             Log.Instance.Write("Ignore Masks: {0}", string.Join(", ", engine.IgnoreMasks));

             if (!SkipConfirmation)
             {
            Console.WriteLine("Do you want to upload? [Y/N]");
            var answer = Console.ReadLine();
            if (answer == null)
            {
               Log.Instance.Write("Non interactive console. Use -f to disable this prompt.");
               return 6;
            }
            if (!answer.Trim().Equals("Y", StringComparison.OrdinalIgnoreCase))
            {
               Log.Instance.Write("User abort.");
               return 0;
            }
             }
             try
             {
            engine.Upload();
             }
             catch (UploadFailedException)
             {
            return 2;
             }
             catch (NotAuthorizedException)
             {
            var credentialStore = CredentialStore.Load();
            credentials = credentialStore.GetCredentials(System, Mandant, Username);
            if (credentials != null)
            {
               Log.Instance.Write("Removing saved password.");
               credentialStore.RemoveCredentials(System, Mandant, Username);
               credentialStore.Save();
            }
            return 1;

             }
             catch (Exception e)
             {
            Log.Instance.Write(e.ToString());
            return 3;
             }
             return 0;
        }