Example #1
0
 /// <summary>
 /// Initializes api query builder
 /// </summary>
 /// <param name="apiId">Your desktop api id</param>
 /// <param name="si">Session info, provided by SessionManager</param>
 public ApiQueryBuilder(int apiId, SessionInfo si)
 {
     this.paramData = new Dictionary<string, string>();
     this.apiId = apiId;
     this.session = si;
     this.Add("api_id", this.apiId.ToString());
 }
Example #2
0
        private void LoginBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            if (e.Url.ToString().Contains("#"))
            {
                Regex r = new Regex(@"\{(.*)\}");
                string[] json = r.Match(e.Url.ToString()).Value.Replace("{", "").Replace("}", "").Replace("\"", "").Split(',');
                Hashtable h = new Hashtable();
                foreach (string str in json)
                {
                    string[] kv = str.Split(':');
                    h[kv[0]] = kv[1];
                }

                this.si = new SessionInfo();
                this.si.AppId = this.AppId;
                this.si.Permissions = this.Permissions;
                this.si.MemberId = (string)h["mid"];
                this.si.SessionId = (string)h["sid"];
                this.si.Expire = Convert.ToInt32(h["expire"]);
                this.si.Secret = (string)h["secret"];
                this.si.Signature = (string)h["sig"];

                this.LoginInfoReceived = true;
                this.Close();
            }
        }
 /// <summary>
 /// Initializes api query builder
 /// </summary>
 /// <param name="apiId">Your desktop api id</param>
 /// <param name="si">Session info, provided by SessionManager</param>
 public ApiQueryBuilder(int apiId, SessionInfo si)
 {
     this.paramData = new Dictionary<string, string>();
     this.apiId = apiId;
     // If si is instance of VKSessionInfo(old auth method)
     if (si is VKSessionInfo)
     {
         this.session = new VKSessionInfo();
         this.builderFunc = new BuildApiQuery(this.VKBuildQuery);
     }
     else
     {
         this.session = new OAuthSessionInfo();
         this.builderFunc = new BuildApiQuery(this.OAuthBuildQuery);
     }
     this.session = si;
     this.Add("api_id", this.apiId.ToString());
 }
Example #4
0
 /// <summary>
 /// Initializes api query builder
 /// </summary>
 /// <param name="apiId">Your desktop api id</param>
 /// <param name="si">Session info, provided by SessionManager</param>
 public ApiQueryBuilder(int apiId, SessionInfo si)
 {
     this.paramData = new Dictionary<string, string>();
     this.apiId = apiId;
     this.session = si;
 }
Example #5
0
        private void Reauth()
        {
            if (!this.isLoggedIn)
            {
                SessionManager sm = new SessionManager(1928531, Convert.ToInt32(ApiPerms.Audio | ApiPerms.ExtendedMessages | ApiPerms.ExtendedWall | ApiPerms.Friends | ApiPerms.Offers | ApiPerms.Photos | ApiPerms.Questions | ApiPerms.SendNotify | ApiPerms.SidebarLink | ApiPerms.UserNotes | ApiPerms.UserStatus | ApiPerms.Video | ApiPerms.WallPublisher | ApiPerms.Wiki));
                //sm.Log += new SessionManagerLogHandler(sm_Log);
                this.sessionInfo = sm.GetSession();
                if (this.sessionInfo != null)
                {
                    this.isLoggedIn = true;
                }
            }

            if (this.isLoggedIn)
            {
                manager = new ApiManager(this.sessionInfo);
                //manager.Log += new ApiManagerLogHandler(manager_Log);
                //manager.DebugMode = true;
                manager.Timeout = 10000;
                this.FriendList.Enabled = true;
                this.Text = this.appTitle + ": Authorization success!";

                this.friendFactory = new FriendsFactory(this.manager);
                this.photoFactory = new PhotosFactory(this.manager);
                this.photoList = new List<PhotoEntryFull>();
                this.albumList = new List<AlbumEntry>();
                this.userIdCheck = new Regex("([\\d])+$");
                this.GetFriendList();
            }
        }
Example #6
0
 /// <summary>
 /// Set new session info
 /// </summary>
 /// <param name="session">New session info</param>
 protected void UseSession(SessionInfo session)
 {
     this.session = session;
 }
Example #7
0
 /// <summary>
 /// Init new API manager
 /// </summary>
 /// <param name="apiId">Registered desktop application id</param>
 /// <param name="si">Session information</param>
 public ApiManager(SessionInfo si)
 {
     this.appId = si.AppId;
     this.session = si;
     this.OnCapthaRequired += new ApiManagerCapthaRequired(ApiManager_CapthaRequired);
 }
Example #8
0
 /// <summary>
 /// Init new API manager
 /// </summary>
 /// <param name="apiId">Registered desktop application id</param>
 /// <param name="si">Session information</param>
 public ApiManager(SessionInfo si)
 {
     this.appId = si.AppId;
     this.session = si;
 }
Example #9
0
 private void reauthToolStripMenuItem_Click(object sender, EventArgs e)
 {
     var sm = new SessionManager(2369574, "status,wall,photos,audio");
     _sessionInfo = sm.ReLogin();
     _isLoggedIn = false;
     Reauth();
 }
Example #10
0
        private void Reauth()
        {
            try
            {
                if (!_isLoggedIn)
                {
                    // Соединяемся с VK API, передаем ему ключ приложения и необходимые нам разрешения
                    var sm = new SessionManager(2369574, "status,wall,photos,audio");
                    _sessionInfo = sm.GetOAuthSession();
                    if (_sessionInfo != null)
                    {
                        _isLoggedIn = true;
                    }
                    Reauth();
                }

                // Выполняется если пользователь залогинен
                else
                {
                    _manager = new ApiManager(_sessionInfo) { Timeout = 10000 };
                    Text = AppTitle + ": Авторизован!";

                    CheckiTunes();
                    GetStatus();
                    GetFriends();
                }
            }
            catch (Exception e)
            {
                AddLineToConsole(e.Message);
            }
        }
Example #11
0
        private void Reauth()
        {
            // если пользователь не авторизован
            if (!this.isLoggedIn)
            {
                // создаем новый менеджер сессий
                SessionManager sm = new SessionManager(1928531, "audio");
                // подключаем обработчик события на получение сообщений из лога
                //sm.Log += new SessionManagerLogHandler(sm_Log);
                // Авторизуемся через OAuth и получаем сессию
                this.sessionInfo = sm.GetOAuthSession();
                // если сессия получена, отмечаем пользователя как залогинившегося
                if (this.sessionInfo != null)
                {
                    this.isLoggedIn = true;
                }
            }

            // если пользователь залогинился
            if (this.isLoggedIn)
            {
                // создаем менеджера api. через этот объект происходит взаимодействие всех фрапперов api
                manager = new ApiManager(this.sessionInfo);
                //manager.Log += new ApiManagerLogHandler(manager_Log);
                //manager.DebugMode = true;
                // устанавливаем таймаут для запросов к pi
                manager.Timeout = 10000;
                // косметические изменения
                this.Text = this.appTitle + ": Authorization success!";
                // создаем фабрику аудиозаписей
                this.audioFactory = new AudioFactory(this.manager);

            }
        }
Example #12
0
        // Функция «Перелогиниться»
        private void Reauth()
        {
            // Выполняется если пользователь незалогинен
            if (!_isLoggedIn)
            {
                // Соединяемся с VK API, передаем ему ключ приложения и необходимые нам разрешения
                SessionManager sm = new SessionManager(2369574, Convert.ToInt32(ApiPerms.UserStatus | ApiPerms.WallPublisher));
                _sessionInfo = sm.GetSession();
                if (_sessionInfo != null)
                {
                    _isLoggedIn = true;
                }
                Reauth();
            }

            // Выполняется если пользователь залогинен
            if (_isLoggedIn)
            {
                _manager = new ApiManager(_sessionInfo) {Timeout = 10000};
                Text = AppTitle + ": Авторизован!";
                templateForStatus.Text = _templatestatus;

                checkiTunes();
                GetStatus();
            }
        }
Example #13
0
        public void Auth()
        {
            //чтобы форма с авторизацией не фризила поток, а продолжала свою работу сразу после эвента
            //https://stackoverflow.com/questions/1916095/how-do-i-make-an-eventhandler-run-asynchronously
            //Task.Factory.FromAsync(
            //    (asyncCallback, @object) =>
            //    {
            //        var onConnecting = this.Connecting;
            //        return onConnecting != null ? onConnecting.BeginInvoke(this, GetNetworkName(), asyncCallback, @object) : null;
            //    },
            //    this.Connecting.EndInvoke, null);

            OnConnecting();
            ShareDestionation = ShareDestinations.Messages;
             _sessionManager = new SessionManager(2369574, "status,wall,photos,audio,messages");
            if (_needRelogin)
            {
                _sessionManager.ReLogin();
                _isLogged = false;
                _needRelogin = false;
            }
            if (!_isLogged)
            {

                // Соединяемся с VK API, передаем ему ключ приложения и необходимые нам разрешения

                _sessionInfo = _sessionManager.GetOAuthSession();

                if (_sessionInfo != null)
                {
                    _isLogged = true;
                }
                Auth();
            }

            // Выполняется если пользователь залогинен
            else
            {
                _manager = new ApiManager(_sessionInfo) { Timeout = 10000 };
                _statusFactory = new StatusFactory(_manager);
                _friendsFactory = new FriendsFactory(_manager);
                _audioFactory = new AudioFactory(_manager);
                _messagesFactory = new MessagesFactory(_manager);
                _photosFactory = new PhotosFactory(_manager);
                _wallFactory = new WallFactory(_manager);
                OnConnected(_sessionInfo.UserId.ToString());
            }
        }