Пример #1
0
        public CacheCredentials Load()
        {
            CacheCredentials creds = null;

            string fileName = GetFileName();

            if (File.Exists(fileName))
            {
                FileStream stream = File.OpenRead(fileName);
                if (stream != null)
                {
                    StreamReader sr = new StreamReader(stream);
                    using (JsonTextReader jr = new JsonTextReader(sr))  //this will dispose the wrapped StreamReader and stream.
                    {
                        creds = _js.Deserialize <CacheCredentials>(jr);
                    }
                }
            }

            if (creds == null)
            {
                return(new CacheCredentials());
            }
            return(creds);
        }
Пример #2
0
        public void Save(CacheCredentials credentials)
        {
            Directory.CreateDirectory(GetFolderPath());

            FileStream   stream = File.OpenWrite(GetFileName());
            StreamWriter sw     = new StreamWriter(stream);

            using (JsonTextWriter jw = new JsonTextWriter(sw)) //this will dispose the wrapped StreamWriter and stream.
            {
                _js.Serialize(jw, credentials);
            }
        }
Пример #3
0
        public CacheCredentials Copy()
        {
            CacheCredentials credentials = new CacheCredentials();

            credentials.SelectedCredentialIndex = this.SelectedCredentialIndex;
            foreach (CacheCredential cred in this.Credentials)
            {
                credentials.Credentials.Add(cred.Copy());
            }

            return(credentials);
        }