Ejemplo n.º 1
0
 public FrmLogin(Profile profile, DesktopClientSettings settings, string fileName)
     : this()
 {
     this.profile = profile;
     this.fileName = fileName;
     this.settings = settings;
 }
Ejemplo n.º 2
0
        public static ClientCredential Login(Action cancelCallback, DesktopClientSettings settings,
            bool alwaysShowDialog = false)
        {
            var crypto = Crypto.CreateDefaultCrypto();
            Profile profile;
            var profileFile = Directories.GetFullName(Constants.ProfileFileName);
            var profileDirectory = Path.GetDirectoryName(profileFile);
            if (string.IsNullOrEmpty(profileDirectory))
                throw new InvalidOperationException("The directory name is invalid (empty).");
            if (!Directory.Exists(profileDirectory))
            {
                Directory.CreateDirectory(profileDirectory);
                profile = new Profile();
            }
            else
            {
                if (File.Exists(profileFile))
                {
                    try
                    {
                        profile = Profile.Load(profileFile);
                    }
                    catch
                    {
                        profile = new Profile();
                    }
                }
                else
                {
                    profile = new Profile();
                }
            }

            ClientCredential credential = null;
            var selectedUserProfile = profile.UserProfiles.FirstOrDefault(p => p.IsSelected);
            var selectedServerProfile = profile.ServerProfiles.FirstOrDefault(p => p.IsSelected);
            if (alwaysShowDialog || selectedUserProfile == null || !selectedUserProfile.AutoLogin)
            {
                var loginForm = new FrmLogin(profile, settings, profileFile);
                var dialogResult = loginForm.ShowDialog();
                if (dialogResult == DialogResult.OK)
                {
                    credential = loginForm.Credential;
                }
                else
                {
                    cancelCallback();
                }
            }
            else
            {
                credential = new ClientCredential
                {
                    Password = crypto.Decrypt(selectedUserProfile.Password),
                    ServerUri = selectedServerProfile == null ? string.Empty : selectedServerProfile.Uri,
                    UserName = selectedUserProfile.UserName
                };
            }
            return credential;
        }
Ejemplo n.º 3
0
 public static void Save(string fileName, Profile profile)
 {
     using (var stream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
     {
         var xmlSerializer = new XmlSerializer(typeof (Profile));
         xmlSerializer.Serialize(stream, profile);
     }
 }