Invoke() 개인적인 메소드

private Invoke ( string methodName, string>.IDictionary parameters, bool skipAuthorization = false ) : string
methodName string
parameters string>.IDictionary
skipAuthorization bool
리턴 string
예제 #1
0
        public MusicLoader(string syncDir, string token, long userId)
        {
            DependencyUtility.BuildUp(this);

            syncDirectory = syncDir;
            this.userId = userId;

            api = new VkApi();
            api.Authorize(token, userId);
            api.Invoke("stats.trackVisitor", new Dictionary<string, string>(), true); // статистика посещаемости приложения

            remoteAudioSizeHelper = new RemoteAudioSizeHelper(Path.Combine(AppPaths.SettingsPath, "sizes.dat"));

            tracks = new ConcurrentSortedList<int, Track>();

            int key = 0;
            foreach (var track in TrackRepository.GetTracks())
                tracks.Add(key++, track);
        }
예제 #2
0
파일: Account.cs 프로젝트: Se11eR/Puckevich
        private long GetUserIdFromString(VkApi api, string id)
        {
            long longId;
            if (id.StartsWith("id"))
            {
                id = id.Substring(2);
                if (Int64.TryParse(id, out longId))
                    return longId;
            }
            
            var dict = new Dictionary<string, string>();
            dict.Add("user_ids", id);
            try
            {
                var res = api.Invoke("users.get", dict, true);

                var serializer = new JsonSerializer();
                dynamic resDict =
                    serializer.Deserialize(new JsonTextReader(new StringReader(res)));

                id = resDict["response"][0]["uid"];
                if (!Int64.TryParse(id, out longId))
                    throw new AuthIDException("Invalid id!");
                return longId;
            }
            catch
            {
                throw new AuthIDException("Invalid id!");
            }
        }
예제 #3
0
        public string GenerateUnitTest(string categoryName, string accessToken)
        {
            // 1. read assembly
            // 2. find methods in particular category
            // 3. find methods with not input parameters (it's the most simple case)
            // 4. invoke a method
            // 5. construct unit-test
            // 6. return it

            Assembly dll = Assembly.LoadFrom("VkNet.dll");

            // todo refactor it later
            List<Type> classes = dll.GetTypes().Where(t => t.Name.Contains("Category") && t.Name.Contains(categoryName)).ToList();

            Type category = classes.FirstOrDefault();

            MethodInfo[] methods = category.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);

            var genMethods = new List<VkMethodGenInfo>();
            foreach (var methodInfo in methods)
            {
                var genInfo = GetMethodData(methodInfo);

                if (string.IsNullOrEmpty(genInfo.ApiMethod)) continue;

                Debug.WriteLine(genInfo.ToString());

                genMethods.Add(genInfo);

            }

            // invoke and get json and url
            var api = new VkApi();

            api.Authorize(accessToken);
            // TODO must be authorized

            var unittests = new List<UnitTestInfo>();

            var testCategory = new StringBuilder();
            foreach (var m in genMethods)
            {
                if (m.Skip) continue;

                var test = new UnitTestInfo
                {
                    Name = string.Format("{0}_", m.Name),
                    Url = Utilities.PreetyPrintApiUrl(api.GetApiUrl(m.ApiMethod, m.Params))
                };

                // TODO refactor this shit
                int index = test.Url.IndexOf("access_token", StringComparison.InvariantCulture);
                if (index != -1)
                {
                    test.Url = test.Url.Substring(0, index) + "access_token=token\";";
                }

                test.Json = Utilities.PreetyPrintJson(api.Invoke(m.ApiMethod, m.Params));

                unittests.Add(test);

                testCategory.Append(test);
            }

            File.WriteAllText(@"d:\vk.txt", testCategory.ToString());

            return string.Empty;

            //throw new NotImplementedException();
        }