示例#1
0
        /// <summary>
        /// Obtain credentials from a file.  If filepath is not supplied then defaultPath is used
        /// </summary>
        public static CompanionAppCredentials Load(string filepath = null)
        {
            CompanionAppCredentials credentials = null;

            filepath = filepath ?? defaultPath;

            string data = Files.Read(filepath);

            if (data != null)
            {
                try
                {
                    credentials = JsonConvert.DeserializeObject <CompanionAppCredentials>(data);
                }
                catch (Exception ex)
                {
                    Logging.Debug("Failed to read companion app credentials", ex);
                }
            }
            if (credentials == null)
            {
                credentials = new CompanionAppCredentials()
                {
                    dataPath = filepath
                };
                credentials.Save();
            }

            credentials.dataPath = filepath;
            return(credentials);
        }