EddiCompanionAppService.CompanionAppCredentials.FromFile C# (CSharp) Method

FromFile() public static method

Obtain credentials from a file. If the file name is not supplied the the default path of Constants.Data_DIR\credentials.json is used
public static FromFile ( string filename = null ) : CompanionAppCredentials
filename string
return CompanionAppCredentials
        public static CompanionAppCredentials FromFile(string filename=null)
        {
            if (filename == null)
            {
                filename = Constants.DATA_DIR + @"\credentials.json";
            }

            CompanionAppCredentials credentials = new CompanionAppCredentials();
            try
            {
                string credentialsData = File.ReadAllText(filename);
                credentials = JsonConvert.DeserializeObject<CompanionAppCredentials>(credentialsData);
            }
            catch {}

            credentials.dataPath = filename;
            return credentials;
        }

Usage Example

コード例 #1
0
        private CompanionAppService()
        {
            Credentials = CompanionAppCredentials.FromFile();

            // Need to work out our current state.

            //If we're missing username and password then we need to log in again
            if (string.IsNullOrEmpty(Credentials.email) || string.IsNullOrEmpty(Credentials.password))
            {
                CurrentState = State.NEEDS_LOGIN;
            }
            else if (string.IsNullOrEmpty(Credentials.machineId) || string.IsNullOrEmpty(Credentials.machineToken))
            {
                CurrentState = State.NEEDS_LOGIN;
            }
            else
            {
                // Looks like we're ready but test it to find out
                CurrentState = State.READY;
                try
                {
                    Profile();
                }
                catch (EliteDangerousCompanionAppException ex)
                {
                    Logging.Warn("Failed to obtain profile: " + ex.ToString());
                }
            }
        }
All Usage Examples Of EddiCompanionAppService.CompanionAppCredentials::FromFile
CompanionAppCredentials