Beispiel #1
0
        private static void SetToken(Dictionary <string, string> args)
        {
            Global.Initialize(false);

            AdapterBase adapter = GetAdapter(args);
            string      file;

            if (!args.TryGetValue("file", out file))
            {
                throw new Exception("/file is required");
            }

            if (adapter.Configuration.AdapterTypeId == OneDriveAdapter.TargetTypeId)
            {
                string        tokenContent = File.ReadAllText(file);
                TokenResponse token        = JsonConvert.DeserializeObject <TokenResponse>(tokenContent);

                // Encrypt the token if not already encrypted
                token.Protect();

                ((OneDriveAdapterConfiguration)adapter.Configuration).CurrentToken = token;

                adapter.SaveConfiguration();
            }
            else
            {
                AdapterRegistration registration =
                    AdapterRegistry.GetRegistrationByTypeId(adapter.Configuration.AdapterTypeId);

                throw new Exception(
                          string.Format("Cannot set token from adapter with type {0} ({1})",
                                        registration.AdapterType.Name, adapter.Configuration.AdapterTypeId));
            }
        }