Exemplo n.º 1
0
        private void ApplyToken(OAuthToken token)
        {
            if (token != null && token.Equals(State.Token))
            {
                return;
            }
            ;
            State.Token = token;
            var fileInfo = new FileInfo(OAUTHTOKEN_FILENAME);

            try
            {
                if (State.Token is null)
                {
                    _loginStateEvent.Publish(new AppMessages.LoginState(false));
                    File.Delete(fileInfo.FullName);
                }
                else
                {
                    _loginStateEvent.Publish(new AppMessages.LoginState(true));
                    var encrypted = ProtectedData.Protect(Encoding.UTF8.GetBytes(token.ToJson()), null, DataProtectionScope.CurrentUser);
                    File.WriteAllBytes(fileInfo.FullName, encrypted);
                }
            } catch (Exception e)
            {
                _logger.LogError(e, "Error saving OAuthToken to File");
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            s_oauthToken = ConsoleAuthentication.GetOAuthTokenFromFileProvider();
            Debug.Assert(!s_oauthToken.Equals(OAuthToken.Invalid));

            ApiAnalyzer buf  = new ApiAnalyzer(s_oauthToken);
            var         list = new Dictionary <string, string>();

            list = buf.GetBaseUris(Constants.Addresses.SmugMug, "/api/v2");

            for (int i = 0; i < args.Length; i++)
            {
                list.Add("arg" + i, args[i]);
            }

            Dictionary <string, string> uris = new Dictionary <string, string>();

            foreach (var item in list)
            {
                uris.Add(item.Key, Constants.Addresses.SmugMug + item.Value + Constants.RequestModifiers);
            }

            var types = buf.AnalyzeAPIs(uris, Constants.Addresses.SmugMugApi);

            var missingTypes = buf.GetMissingTypes();

            // make sure that we have all the types?
            foreach (var item in missingTypes)
            {
                if (!types.ContainsKey(item))
                {
                    ConsolePrinter.Write(ConsoleColor.Red, "Could not find type {0}", item);
                }
            }

            var jsonSerSettings = new JsonSerializerSettings();

            jsonSerSettings.TypeNameHandling = TypeNameHandling.All;
            jsonSerSettings.Formatting       = Formatting.Indented;
            var jsonSer = Newtonsoft.Json.JsonSerializer.CreateDefault(jsonSerSettings);

            using (StreamWriter sw = new StreamWriter("metadata.json"))
            {
                jsonSer.Serialize(sw, types);
            }

#if DEBUG
            Console.WriteLine("Complete");
            Console.ReadKey();
#endif
        }