Esempio n. 1
0
        private void cmdAlbumLoadData_OnClick(object sender, RoutedEventArgs e)
        {
            if (SelectedAlbum == null)
            {
                this.ShowError("Для выполнения этой операции необходимо выбрать хотябы один альбом из списка.");
                return;
            }

            if (!this.ShowQuestion(String.Format("Обновить информацию по альбому '{0}'?", SelectedAlbum.GetCleanTitle()))) return;

            if (m_settings.ExpirationDate.CompareTo(DateTime.Now) < 0)
            {
                var af = new AuthForm(3550451);
                if (af.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    this.ShowError("Для работы нужно авторизоваться в сети!");
                    return;
                }

                m_settings.AccessToken = af.GetAccessToken();
                m_settings.LoggedUserId = af.GetTokenUserId();
                m_settings.SetExpiration(Int32.Parse(af.GetExiprationValue()));
            }

            var bg = new BackgroundWorker { WorkerReportsProgress = true };
            bg.DoWork += UpdatePhotosInAlbumThreadProc;
            bg.ProgressChanged += (o, args) =>
                {
                    if (m_waitingWindow != null)
                    {
                        m_waitingWindow.SetState(args.UserState.ToString());
                    }
                };
            bg.RunWorkerCompleted += (o, args) =>
                {
                    var worker = sender as BackgroundWorker;
                    if (worker != null)
                    {
                        lock (m_workersPool)
                        {
                            m_workersPool.Remove(worker);
                        }
                    }

                    if (m_waitingWindow != null)
                    {
                        m_waitingWindow.Close();
                        m_waitingWindow = null;
                    }

                    if (args.Error != null)
                    {
                        this.ShowError(args.Error.Message);
                        return;
                    }

                    if (m_selectedView == ServiceTreeNodes.AlbumPaymets)
                    {
                        ShowAlbumPaymentsDetails(SelectedAlbum);
                    }
                    else if (m_selectedView == ServiceTreeNodes.AlbumProducts)
                    {
                        ShowAlbumProductsDetails(SelectedAlbum);
                    }
                    else if (m_selectedView == ServiceTreeNodes.AlbumCustomers)
                    {
                        ShowAlbumCutomersDetails(SelectedAlbum);
                    }
                };

            lock (m_workersPool)
            {
                m_workersPool.Add(bg);
            }
            bg.RunWorkerAsync(SelectedAlbum);

            m_waitingWindow =new WaitingWindow(this);
            m_waitingWindow.ShowDialog();
        }
Esempio n. 2
0
        /// <summary>
        /// Загрузка альбомов рабочей группы
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CmdFileLoadAlbums_OnClick(object sender, RoutedEventArgs e)
        {
            if (m_settings.ExpirationDate.CompareTo(DateTime.Now) < 0)
            {
                var af = new AuthForm(3550451);
                if (af.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                m_settings.AccessToken = af.GetAccessToken();
                m_settings.LoggedUserId = af.GetTokenUserId();
                m_settings.SetExpiration(Int32.Parse(af.GetExiprationValue()));
            }

            var bg = new BackgroundWorker {WorkerReportsProgress = true};
            bg.ProgressChanged += (o, args) =>
                {
                    if (m_waitingWindow != null) m_waitingWindow.SetState(args.UserState.ToString());
                };
            bg.DoWork += AlbumsUpdateThreadProc;
            bg.RunWorkerCompleted += (o, args) =>
                {
                    if (m_waitingWindow != null)
                    {
                        m_waitingWindow.Close();
                        m_waitingWindow = null;
                    }

                    if (args.Error != null)
                    {
                        this.ShowError(args.Error.Message);
                    }
                    lock (m_workersPool)
                    {
                        m_workersPool.Remove((BackgroundWorker)o);
                    }

                    // обновить список альбомов на форме
                    FillAlbumsListAsync();
                };
            lock (m_workersPool)
            {
                m_workersPool.Add(bg);
            }

            bg.RunWorkerAsync();
            m_waitingWindow = new WaitingWindow(this);
            m_waitingWindow.ShowDialog();
        }
Esempio n. 3
0
        private static void Main(string[] args)
        {
            Console.CancelKeyPress += ConsoleOnCancelKeyPress;
            Console.CursorVisible = false;
            Console.Title = "VK";

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            log4net.Config.XmlConfigurator.Configure();

            Status("Загрузка...");
            try
            {
                s_db = DbManger.GetInstance();
                ParseArguments(args);
                ReadConfiguration(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.ini"));
            }
            catch (Exception e)
            {
                Error(e.Message);
                return;
            }

            Status("Авторизация...");
            var af = new AuthForm(s_appId);
            if (af.ShowDialog() != DialogResult.OK)
            {
                Error("Для работы нужно авторизоваться в сети!");
                return;
            }

            var usrManager = new UsersManager(af.GetAccessToken());
            try
            {
                var currentuser = usrManager.GetUserById(af.GetTokenUserId());
                Console.Title = String.Format("AppID: {0} - {1}", s_appId, currentuser.GetFullName());
            }
            catch (Exception e)
            {
                Error(e.Message);
                return;
            }

            var offset = 0;
            var random = new Random();
            var query = new VkUsersSearchQuery();
            query.SetParameter(UserSearchParam.HomeTown, "Снежинск");
            query.SetParameter(UserSearchParam.Count, RES_COUNT);
            query.SetParameter(UserSearchParam.Fields,
                               new List<VkProfile.EntryType> {VkProfile.EntryType.Sex, VkProfile.EntryType.Contacts});

            Status("Выполнение...");

            for (int age = 10; age < 60; age++)
            {
                query.SetParameter(UserSearchParam.AgeFrom, age);
                query.SetParameter(UserSearchParam.AgeTo, age);
                offset = 0;
                while (true)
                {
                    query.SetParameter(UserSearchParam.Offset, offset);
                    List<VkUser> result;
                    try
                    {
                        result = usrManager.Search(query);
                    }
                    catch (Exception e)
                    {
                        Error(e.Message);
                        break;
                    }
                    if (result.Count == 0) break;

                    foreach (VkUser user in result)
                    {
                        Status("({0}) {1}... ", user.Id, user.GetFullName());
                        using (var session = s_db.OpenSession())
                        {
                            using (var t = session.BeginTransaction())
                            {
                                try
                                {
                                    session.Save(new User
                                        {
                                            FirstName = user.FirstName,
                                            LastName = user.LastName,
                                            VkId = user.Id,
                                            Sex = user.Sex,
                                            HomePhone = user.HomePhone,
                                            MobilePhone = user.MobilePhone,
                                            BirthYear = user.BirthYear
                                        });
                                }
                                catch (Exception e)
                                {
                                    if (e.InnerException != null &&
                                        e.InnerException is System.Data.SqlClient.SqlException)
                                    {
                                        if (
                                            !(e.InnerException as System.Data.SqlClient.SqlException).Message.Contains(
                                                "Violation of UNIQUE KEY"))
                                        {
                                            Error(e.Message);
                                        }
                                        else
                                        {
                                            Error("({0}) {1}: Уже сохранено!", user.Id, user.GetFullName());
                                        }
                                    }
                                    continue;
                                }
                                t.Commit();
                                Print("({0}) {1}: Сохранено", user.Id, user.GetFullName());
                            }
                        }
                    }
                    offset += result.Count;

                    // sleep 1 - 20 seconds
                    var secs = random.Next(1000, 20000);
                    Status("Ожидание {0} сек.", secs/1000);
                    Thread.Sleep(secs);
                }

                var asecs = random.Next(1000, 20000);
                Status("Ожидание {0} сек.", asecs/1000);
                Thread.Sleep(asecs);
            }

            Status("Готово");
        }