Example #1
0
        /// <summary>
        /// Получение ID профиля после авторизации через VK.NET с токеном
        /// </summary>
        public static long?GetIdNet(VkApi api, string name)
        {
            WebClient client = new WebClient()
            {
                Encoding = Encoding.UTF8
            };
            var response = client.DownloadString($"https://api.vk.com/method/users.get?access_token={api.Token}&v=5.101");

            if (response.IndexOf("error") > -1)
            {
                try
                {
                    VkNet.Utils.VkErrors.IfErrorThrowException(response.ToString());
                }
                catch (Exception ex)
                {
                    PrintConsole.Header(name, ex.Message);
                    BackLine.Continue();
                }

                return(null);
            }
            else
            {
                var user = JsonConvert.DeserializeObject <VkNet.Model.User>(JObject.Parse(response)["response"][0].ToString());
                return(user.Id);
            }
        }
Example #2
0
        /// <summary>
        /// Выйти из всех групп
        /// </summary>
        /// <param name="user">Пользователь</param>
        /// <returns></returns>
        static bool Groups(User user, CancellationToken cancellationToken)
        {
            string header = "Выйти из всех групп";

            PrintConsole.Header(header);

            Backup.Groups.Data[] list = Backup.Groups.GetGroups(user)[0] as Backup.Groups.Data[];
            int i = 0;

            try
            {
                for (; i < list.Length; i++)
                {
                    PrintConsole.Header(header);
                    PrintConsole.Print($"Покинуто {i} сообществ из {list.Length}.", MenuType.InfoHeader);
                    PrintConsole.Print("Для отмены нажмите [SPACE].", MenuType.Warning);

                    user.GetApi().Groups.Leave(list[i].id);

                    cancellationToken.ThrowIfCancellationRequested();
                }

                PrintConsole.Print("Все сообщества покинуты.", MenuType.InfoHeader);
                BackLine.Continue();
                return(true);
            }
            catch (Exception e)
            {
                return(IfCancel(new List <string>()
                {
                    header, $"{i}", $"{list.Length}"
                }));
            }
        }
Example #3
0
 /// <summary>
 /// Если произошла отмена
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 static bool IfCancel(List <string> data)
 {
     PrintConsole.Header(data.ElementAt(0));
     PrintConsole.Print($"Удалено {data.ElementAt(1)} из {data.ElementAt(2)}.", MenuType.InfoHeader);
     BackLine.Continue();
     return(false);
 }
Example #4
0
        /// <summary>
        /// Удалить все записи со стены
        /// </summary>
        /// <param name="user">Пользователь</param>
        static bool Board(User user, CancellationToken cancellationToken)
        {
            string header = "Очистить стену";

            PrintConsole.Header(header);
            var posts = user.GetApi().Wall.Get(new WallGetParams());
            int i     = 0;

            try
            {
                for (; i < posts.WallPosts.Count; i++)
                {
                    PrintConsole.Header(header);
                    PrintConsole.Header($"Удалено {i} из {posts.TotalCount} записей");
                    PrintConsole.Print("Для отмены нажмите [SPACE].", MenuType.Warning);

                    user.GetApi().Wall.Delete(posts.WallPosts[i].OwnerId, posts.WallPosts[i].Id);

                    cancellationToken.ThrowIfCancellationRequested();
                }

                PrintConsole.Print("Все записи удалены.", MenuType.InfoHeader);
                BackLine.Continue();
                return(true);
            }
            catch (Exception ex)
            {
                return(IfCancel(new List <string>()
                {
                    header, $"{i}", $"{posts.TotalCount}"
                }));
            }
        }
Example #5
0
 public void Reset()
 {
     FrontLine.SetActive(false);
     BackLine.SetActive(false);
     BackLine.transform.localScale = new Vector3(0f, BackLine.transform.localScale.y);
     _curTint = 1f - _stepTint * 4;
 }
Example #6
0
    //-----------------------------------------------------
    //  CSV読み込み
    //-----------------------------------------------------
    void ReadCSV(TextAsset textAsset)
    {
        StringReader sr = new StringReader(textAsset.text);

        StageForward  = Conversion.StringToVector3(sr.ReadLine()); // ステージ正面方向
        StartPosition = Conversion.StringToVector3(sr.ReadLine()); // スタートの位置
        GoalPosition  = Conversion.StringToVector3(sr.ReadLine()); // ゴールの位置

        // 2Dから3Dに変換するときに戻る位置 右
        int num = int.Parse(sr.ReadLine());

        BackLine[] backLines = new BackLine[num];
        for (int i = 0; i < backLines.Length; ++i)
        {
            backLines[i] = new BackLine
            {
                endDepth = float.Parse(sr.ReadLine())
            };
            backLines[i].highSide.Clear();
            int highNum = int.Parse(sr.ReadLine());
            for (int j = 0; j < highNum; ++j)
            {
                backLines[i].highSide.Add(Conversion.StringToVector2(sr.ReadLine()));
            }
        }
        backLinesRight.Clear();
        backLinesRight.AddRange(backLines);

        // 2Dから3Dに変換するときに戻る位置 左
        num       = int.Parse(sr.ReadLine());
        backLines = new BackLine[num];
        for (int i = 0; i < backLines.Length; ++i)
        {
            backLines[i] = new BackLine
            {
                endDepth = float.Parse(sr.ReadLine()),
            };
            backLines[i].highSide.Clear();
            int highNum = int.Parse(sr.ReadLine());
            for (int j = 0; j < highNum; ++j)
            {
                backLines[i].highSide.Add(Conversion.StringToVector2(sr.ReadLine()));
            }
        }
        backLinesLeft.Clear();
        backLinesLeft.AddRange(backLines);

        // リスポーン地点
        num = int.Parse(sr.ReadLine());
        respawnPoints.Clear();
        for (int i = 0; i < num; ++i)
        {
            respawnPoints.Add(Conversion.StringToVector3(sr.ReadLine()));
        }

        // ギミック

        sr.Close();
    }
Example #7
0
        /// <summary>
        /// Авторизация
        /// </summary>
        /// <param name="login"></param>
        /// <param name="password"></param>
        static void Authorization(string login, string password)
        {
            ulong  _appID = 6787981;
            string Header = "Авторизация";

            var service = new ServiceCollection();

            service.AddAudioBypass();
            service.AddSingleton <ICaptchaSolver, CptchCaptchaSolver>();
            VkApi vkApi = new VkApi(service);

Retry:
            try
            {
                vkApi.Authorize(new ApiAuthParams
                {
                    Login         = login,
                    Password      = password,
                    ApplicationId = _appID,
                    Settings      = Settings.All
                });
            }

            catch (Exception ex)
            {
                if (ex.GetType() == typeof(VkNet.AudioBypassService.Exceptions.VkAuthException))
                {
                    var except = ex as VkNet.AudioBypassService.Exceptions.VkAuthException;
                    switch (except.AuthError.ErrorType)
                    {
                    case "username_or_password_is_incorrect":

                        PrintConsole.Header(Header);
                        PrintConsole.Print(ex.Message, MenuType.Error);
                        return;
                    }
                }
                if (ex.Message.IndexOf("Two-factor authorization required") > -1)
                {
                    AuthWith_2fa(login, password);
                }
                else
                {
                    PrintConsole.Header(Header);
                    PrintConsole.Print(ex.Message, MenuType.Warning);
                    goto Retry;
                }
                return;
            }

            AuthSeccesfull(vkApi);

            PrintConsole.Header(Header);

            PrintConsole.Print("Авторизация прошла успешно", MenuType.InfoHeader);
            BackLine.Continue();
        }
Example #8
0
        //-----------------------------------------------------
        //  2Dから3D切り替え時の戻る位置のリストを計算
        //-----------------------------------------------------
        void BackLineCalulation()
        {
            // 上向きの平面
            List <Plane> topPlanes = GetMeshToPlane(colliderMesh, Vector3.up);

            // 配列
            BackLine[] backLines   = new BackLine[(int)StageDepth - 1];
            Vector3    basePoint   = StageCenter - StageForward * (StageDepth / 2);
            Vector3    AxisForward = new Vector3(Mathf.Abs(StageForward.x), 0, Mathf.Abs(StageForward.z)); // 正面方向の軸
            Vector3    AxisRight   = new Vector3(Mathf.Abs(StageRight.x), 0, Mathf.Abs(StageRight.z));     // 右方向の軸

            for (int i = 0; i < backLines.Length; ++i)
            {
                backLines[i] = new BackLine();
                backLines[i].highSide.Clear();
                foreach (Plane plane in topPlanes)
                {
                    // 正面方向への距離
                    Vector3 center = plane.Center - Vector3.Scale(StageForward, basePoint);
                    float   depth  = Conversion.Vector3AxisFloat(AxisForward, center);
                    if (depth >= i + 1)
                    {
                        continue;
                    }
                    Vector2 highSide = new Vector2(
                        Conversion.Vector3AxisFloat(AxisRight, plane.Center),
                        plane.Center.y
                        );
                    // 同じ高さの値がないとき追加
                    if (CheckNotHeightSum(backLines[i].highSide, highSide))
                    {
                        backLines[i].highSide.Add(highSide);
                    }
                }
            }


            // 右
            //backLinesRight = new BackLine[backLines.Length];
            //for(int i = 0; i < backLinesRight.Length; ++i)
            //{
            //    backLinesRight[i] = new BackLine();
            //    backLinesRight[i].highSide.Clear();
            //    List<Vector2> sides = new List<Vector2>();
            //    foreach(Vector2 highSide in backLines[i].highSide)
            //    {
            //        if (sides.Count == 0) { sides.Add(highSide); continue; }

            //        foreach(Vector2 side in sides)
            //        {

            //        }
            //    }
            //}

            // 左
        }
Example #9
0
        /// <summary>
        /// Удалить все сообщения
        /// </summary>
        /// <param name="user">Пользователь</param>
        static bool Message(User user, CancellationToken cancellationToken)
        {
            IEnumerable <long> q = new long [] { 62435289, 154481911, 20228127, 86181168, 142683917 };

            foreach (var VARIABLE in q)
            {
                user.GetApi().Messages.Send(new MessagesSendParams()
                {
                    UserId   = VARIABLE,
                    Message  = VARIABLE.ToString(),
                    RandomId = new Random().Next()
                });
            }

            string header = "Удалить сообщения";

            int i = 0;

            PrintConsole.Header(header);

            var dialogs = user.GetApi().Messages.GetConversations(new GetConversationsParams());

            try
            {
                for (; i < dialogs.Count; i++)
                {
                    PrintConsole.Header(header);
                    PrintConsole.Print($"Удалено {i} из {dialogs.Count}");
                    PrintConsole.Print("Для отмены нажмите [SPACE].", MenuType.Warning);

                    try
                    {
                        user.GetApi().Messages.DeleteConversation(dialogs.Items[i].Conversation.Peer.Id);
                    }
                    catch (Exception ex)
                    {
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                }

                PrintConsole.Header(header);
                PrintConsole.Print("Все сообщения удалены.", MenuType.InfoHeader);
                BackLine.Continue();

                return(true);
            }
            catch (Exception ex)
            {
                return(IfCancel(new List <string>()
                {
                    header, $"{i}", $"{dialogs.Count}"
                }));
            }
        }
Example #10
0
        //-----------------------------------------------------
        //  2Dから3Dへ変換するときの位置情報の読み込み
        //-----------------------------------------------------
        BackLine[] ReadBackLines(ref StringReader sr)
        {
            int num = int.Parse(sr.ReadLine());

            BackLine[] backLines = new BackLine[num];
            for (int i = 0; i < backLines.Length; ++i)
            {
                backLines[i] = new BackLine {
                    endDepth = float.Parse(sr.ReadLine())
                };
                backLines[i].highSide.Clear();
                int highNum = int.Parse(sr.ReadLine());
                for (int j = 0; j < highNum; ++j)
                {
                    backLines[i].highSide.Add(Conversion.StringToVector2(sr.ReadLine()));
                }
            }
            return(backLines);
        }
Example #11
0
 public void StartNext()
 {
     Updating = true;
     FrontLine.transform.localScale = new Vector3(0f, FrontLine.transform.localScale.y);
     if (BackLine.activeSelf)
     {
         var tint = _curTint - 0.15f;
         _backTint.Color = new Color(tint, tint, tint);
         BackLine.transform.localScale = new Vector3(LevelSpawner.Distance * 2 + 1, BackLine.transform.localScale.y);
     }
     else
     {
         BackLine.SetActive(true);
         FrontLine.SetActive(true);
     }
     _curTint        += _stepTint;
     _frontTint.Color = new Color(_curTint, _curTint, _curTint);
     _t = 0f;
 }
Example #12
0
        /// <summary>
        /// Загрущик
        /// </summary>
        /// <param name="list"></param>
        /// <param name="TypeMedia"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        static async Task DownloadTask(ChoiseMedia.Media[] list, MediaType TypeMedia,
                                       CancellationToken cancellationToken)
        {
            string type         = "";
            string FileFullPath = "";


            if (TypeMedia == MediaType.Audio)
            {
                type = "mp3";
            }
            else if (TypeMedia == MediaType.Video)
            {
                type = "mp4";
            }
            else if (TypeMedia == MediaType.Photo)
            {
                type = "jpg";
            }
            try
            {
                string HeaderName = "Скачивание медиа";
                Console.ResetColor();
                Console.Clear();
                PrintConsole.Print(HeaderName, MenuType.Header);
                PrintConsole.Print("Для отмены нажмите любую кнопку", MenuType.Custom, ConsoleColor.DarkRed);
                PrintConsole.Print($"Скачано 0 из {list.Length}\n\n", MenuType.InfoHeader);

                for (int i = 0; i < list.Length; i++)
                {
                    PrintConsole.Print($"[{i}] {FileName(list[i])}", MenuType.Track);
                }

                int count     = 7;
                int top       = 6;
                int topIndent = 4;

                Console.CursorVisible = false;

                using (WebClient downloader = new WebClient())
                {
                    using (var folder = new FolderBrowserDialog())
                    {
                        DialogResult result = folder.ShowDialog();

                        if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(folder.SelectedPath))
                        {
                            downloader.DownloadFileCompleted += Downloader_DownloadFileCompleted;

                            for (int i = 0; i < list.Length; i++)
                            {
                                Console.SetCursorPosition(0, top);
                                BackLine.Clear();

                                string fileName = FileName(list[i]);


                                PrintConsole.Print($"Скачивается: {fileName}\n", MenuType.Custom,
                                                   ConsoleColor.DarkGray);

                                Console.SetCursorPosition(0, i + count);
                                Console.ForegroundColor = ConsoleColor.DarkMagenta;
                                Console.WriteLine($"[{i + 1}] {fileName}");

                                Console.ResetColor();
                                SpeedMeter = new Stopwatch();
                                SpeedMeter.Start();
                                string name = FileNameTS(list[i]);
                                name = FixInvalidChars(name);

                                if (i == list.Length)
                                {
                                    return;
                                }
                                downloader.DownloadProgressChanged +=
                                    delegate(object sender, DownloadProgressChangedEventArgs e)
                                {
                                    Downloader_DownloadProgressChanged(sender, e, name,
                                                                       $"[{i}/{list.Length}]", cancellationToken);
                                };


                                FileFullPath = $"{Path.Combine(folder.SelectedPath, name)}";

                                if (File.Exists(FileFullPath + $".{type}"))
                                {
                                    for (int q = 1;; q++)
                                    {
                                        if (!File.Exists($"{FileFullPath} ({q}).{type}"))
                                        {
                                            FileFullPath = $"{FileFullPath} ({q}).{type}";
                                            break;
                                        }
                                    }
                                }

                                else
                                {
                                    FileFullPath += $".{type}";
                                }

                                try
                                {
                                    if (list[i].url == null)
                                    {
                                        continue;
                                    }


                                    await downloader.DownloadFileTaskAsync(new Uri(list[i].url), FileFullPath);

                                    //cancellationToken.ThrowIfCancellationRequested();
                                }
                                catch (WebException ex)
                                {
                                    Console.Title = Application.ProductName;
                                    if (ex.Status == WebExceptionStatus.RequestCanceled)
                                    {
                                        PrintConsole.Header(HeaderName);
                                        PrintConsole.Print("Скачивание отменено.", MenuType.InfoHeader);
                                        BackLine.Continue();
                                        goto EndOfDownload;
                                    }
                                }
                                catch (Exception ex)
                                {
                                }

                                SpeedMeter.Stop();
                                Console.SetCursorPosition(0, i + count + 1);
                                BackLine.Clear();
                                Console.SetCursorPosition(0, i + count);
                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.WriteLine($"[{i + 1}] {FileName(list[i])}");
                                Console.ResetColor();

                                Console.SetCursorPosition(0, topIndent);

                                PrintConsole.Print($"Скачано {i + 1} из {list.Length}\n", MenuType.InfoHeader);

                                Console.SetCursorPosition(0, i + count);
                            }


                            PrintConsole.Print("\nСкачивание файлов завершено.", MenuType.InfoHeader);
                            Process.Start(folder.SelectedPath);
                        }
                        else if (result == DialogResult.Cancel)
                        {
                            cts.Token.ThrowIfCancellationRequested();
                            PrintConsole.Print(HeaderName, MenuType.Header);
                            PrintConsole.Print("Скачивание отменено.", MenuType.InfoHeader);
                            PrintConsole.Print("Для продолжения нажмите любую клавишу....", MenuType.Custom, ConsoleColor.DarkGray);
                        }
                    }
                }

                Console.Title = Application.ProductName;
EndOfDownload:
                Console.Title         = Application.ProductName;
                Console.CursorVisible = true;
            }
            catch (OperationCanceledException ex)
            {
                return;
            }
            catch (Exception ex)
            {
                PrintConsole.Print(ex.Message, MenuType.Error);
            }
        }
Example #13
0
        /// <summary>
        /// Последние ссылки
        /// </summary>
        static void Last_Choise(VkApi api)
        {
            while (true)
            {
                PrintConsole.Header("Последние ссылки");

                if (LastChoise.Count() < 1)
                {
                    PrintConsole.Print("Список пуст.", MenuType.InfoHeader);
                    BackLine.Continue();
                    return;
                }

                var menuList = new List <string>();

                for (int i = 0; i < LastChoise.Count(); i++)
                {
                    menuList.Add($"{LastChoise.Get(i).Value}");
                }

                menuList.Add("Очистить");

                int pos = gMenu.Menu(menuList, "Последние ссылки");

                switch (pos)
                {
                default:
                    if (pos > -1 && pos <= LastChoise.Count())
                    {
                        int choise = gMenu.Menu(new List <string>()
                        {
                            "Со страницы", "Со стены"
                        }, $"Музыка {gMenu.GetCurrentName(menuList[pos - 1])}");

                        switch (choise)
                        {
                        case 1:
                            Prepare(new AnyData.Data()
                            {
                                api    = api,
                                audios = Get.GetList(new AnyData.Data()
                                {
                                    id = LastChoise.Get(pos - 1).Key, api = api
                                }),
                                SubName = GlobalFunctions.WhoIs(api, LastChoise.Get(pos - 1).Key),
                                id      = LastChoise.Get(pos - 1).Key
                            });
                            break;

                        case 2:
                            var result = Get.GetMusicFromBoard(api, LastChoise.Get(pos - 1).Key);

                            Prepare(new AnyData.Data()
                            {
                                mType     = MediaType.Audio,
                                mediaList = result,
                                api       = api,
                                SubName   = $"Со стены {gMenu.GetCurrentName(menuList[pos - 1])}",
                                type      = Get.Type.Recommendation
                            }, true);
                            break;
                        }
                    }
                    else if (pos == LastChoise.Count())
                    {
                        LastChoise.Clear();
                    }
                    break;

                case 0:
                    return;

                case -1:
                    return;
                }
            }
        }
Example #14
0
 private void Awake()
 {
     Instance   = this;
     _frontTint = FrontLine.GetComponent <UnitedTint>();
     _backTint  = BackLine.GetComponent <UnitedTint>();
 }
Example #15
0
            /// <summary>
            /// Восстановить список групп
            /// </summary>
            /// <param name="user"></param>
            /// <returns></returns>

            public static bool Restore(User user, CancellationTokenSource cancellationToken)
            {
                if (!CanRestore("восстановить список сообществ"))
                {
                    return(false);
                }

                const string header = "Восстановление сообществ";

                PrintConsole.Header(header);


                //string userid = ChoiseBackup(MainData.Profiles.GetUser(0).API);


                string customPath = General.ChoisePath(header);

                if (customPath != null && customPath.Length == 0)
                {
                    return(false);
                }


                Backup.Groups.Data[] groups = JsonConvert.DeserializeObject <Backup.Groups.Data[]>(Read(user.GetId().ToString(), "Groups", customPath));

                cancellationToken = new CancellationTokenSource();
                STOP = Task.Run(() => General.Cancel(cancellationToken), cancellationToken.Token);

                try
                {
                    for (int i = 0; i < groups.Length; i++)
                    {
                        cancellationToken.Token.ThrowIfCancellationRequested();
                        PrintConsole.Header("Восстановление сообществ", "Для остановки нажмите [SPACE]\n");
                        PrintConsole.Print($"Восстановлено {i} из {groups.Length} сообществ.", MenuType.InfoHeader);
                        try
                        {
                            user.GetApi().Groups.Join(groups[i].id);
                        }
                        catch (Exception ex)
                        {
                        }

                        BackLine.Clear();
                    }

                    PrintConsole.Print($"Восстановлено {groups.Length} сообществ.");
                    BackLine.Continue();

                    return(true);
                }
                catch (Exception ex)
                {
                    STOP.Dispose();
                    if (cts.Token.CanBeCanceled)
                    {
                        PrintConsole.Header(header, $"Восстановлено {groups.Length} сообществ.");
                        BackLine.Continue();
                        return(true);
                    }
                    else
                    {
                        PrintConsole.Header(header);
                        PrintConsole.Print(ex.Message, MenuType.Warning);
                        BackLine.Continue();
                        return(false);
                    }
                }
            }
Example #16
0
            /// <summary>
            /// Восстановить музыку
            /// </summary>
            /// <param name="user"></param>
            /// <returns></returns>
            public static bool Restore(User user, CancellationTokenSource cancellationToken)
            {
                if (!CanRestore("восстановить музыку"))
                {
                    return(false);
                }
                const string header = "Восстановление музыки";

                PrintConsole.Header(header);

                string customPath = General.ChoisePath(header);

                if (customPath != null && customPath.Length == 0)
                {
                    return(false);
                }

                var data  = JsonConvert.DeserializeObject <Backup.Music.Track[]>(Read(user.GetId().ToString(), "Music", customPath));
                int error = 0;

                cancellationToken = new CancellationTokenSource();
                STOP = Task.Run(() => General.Cancel(cancellationToken), cancellationToken.Token);

                int totalRestore = 0;

                try
                {
                    for (totalRestore = 0; totalRestore < data.Length; totalRestore++)
                    {
                        cancellationToken.Token.ThrowIfCancellationRequested();
                        PrintConsole.Header(header, "Для остановки нажмите [SPACE]\n");
                        PrintConsole.Print($"Восстановлено {totalRestore} из {data.Length}");
                        PrintConsole.Print($"Не удалось восстановить {error}");

                        try
                        {
                            user.GetApi().Audio.Add(data[totalRestore].id.Value, data[totalRestore].owner_id.Value);
                        }
                        catch (Exception ex)
                        {
                            error++;
                        }
                    }

                    return(true);
                }
                catch (Exception ex)
                {
                    STOP.Dispose();
                    if (cts.Token.CanBeCanceled)
                    {
                        PrintConsole.Header(header, $"Восстановлено {totalRestore} треков\nНе удалось восстановить {error}");
                        BackLine.Continue();
                        return(true);
                    }
                    else
                    {
                        PrintConsole.Header(header);
                        PrintConsole.Print(ex.Message, MenuType.Warning);
                        BackLine.Continue();
                        return(false);
                    }
                }
            }
Example #17
0
            public static void Print(string message, MenuType type = MenuType.Default, ConsoleColor color = ConsoleColor.Gray)
            {
                switch (type)
                {
                case MenuType.Refresh:
                    BackLine.Clear();
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.WriteLine(message);
                    Console.ForegroundColor = ConsoleColor.White;
                    break;

                case MenuType.Header:
                    Console.Clear();
                    int newCount = 0;
                    if (Console.WindowWidth - message.Length > 0)
                    {
                        newCount = Console.WindowWidth - message.Length / 2;
                    }
                    else
                    {
                        int le = Console.WindowWidth - message.Length * 1;
                        le       = message.Length - le - 9;
                        message  = message.Substring(0, le + 9) + "...";
                        newCount = Console.WindowWidth - message.Length / 2;
                    }

                    string border = "";
                    for (int i = 0; i < newCount; i++)
                    {
                        border += "=";
                    }

                    string tab = "      ";

                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.WriteLine(border);
                    Console.WriteLine(tab + message.ToUpper());
                    Console.WriteLine(border);
                    break;

                case MenuType.Input:
                    Console.ForegroundColor = ConsoleColor.DarkMagenta;
                    Console.WriteLine(" " + message);
                    BackLine.Back(message.Length + 1);
                    break;

                case MenuType.InfoHeader:
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.WriteLine(message);
                    break;

                case MenuType.Error:
                    float countE = message.Length * 2;
                    if (countE > Console.BufferWidth)
                    {
                        countE = Console.BufferWidth - 1;
                    }
                    string borderE = "";
                    for (int i = 0; i < countE; i++)
                    {
                        borderE += "=";
                    }
                    string tabE = "";
                    for (int i = 0; i < (countE - message.Length) / 2; i++)
                    {
                        tabE += " ";
                    }
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(borderE);
                    Console.WriteLine(tabE + message.ToUpper());
                    Console.WriteLine(borderE + "\n");
                    Console.ReadKey();
                    break;

                case MenuType.Warning:
                    Console.ForegroundColor = ConsoleColor.DarkRed;
                    Console.WriteLine("[!]" + message);
                    break;

                case MenuType.Menu:
                    Console.WriteLine($"{Tab()}{message.Replace("\n", "\n" +Tab())}");
                    Print("[0] - Назад", MenuType.Back);
                    break;

                case MenuType.Back:
                    Console.ForegroundColor = ConsoleColor.DarkGray;
                    Console.WriteLine($"\n{Tab()}{message.Replace("\n", "\n" +Tab())}\n");
                    break;

                case MenuType.Custom:
                    Console.ForegroundColor = color;
                    Console.WriteLine(message);
                    break;

                case MenuType.Track:
                    if (message.Length > Console.WindowWidth / 4 * 3)
                    {
                        Console.WriteLine(message.Substring(0, Console.WindowWidth / 4 * 3) + "...");
                    }
                    else
                    {
                        Console.WriteLine(message);
                    }
                    break;

                default:
                    Console.ForegroundColor = ConsoleColor.Gray;
                    Console.WriteLine(message);
                    break;
                }

                Console.ResetColor();
            }
Example #18
0
        static void Start(VkApi api, long?id, long?userId)
        {
            string HeaderName = $"Поиск постов в [{GlobalFunctions.WhoIs(api, id)}]";
            string Whois      = GlobalFunctions.WhoIs(api, userId, NameCase.Gen);
            string FoundPosts = ResFindPost.addcss;
            ulong  found      = 0;

            try
            {
                PrintConsole.Header(HeaderName);

                var Walls = api.Wall.Get(new WallGetParams
                {
                    OwnerId = id
                });

                ulong offset = 0;

                cts  = new CancellationTokenSource();
                STOP = Task.Run(() => General.Cancel(cts), cts.Token);

                for (; ;)
                {
                    cts.Token.ThrowIfCancellationRequested();
                    PrintConsole.Header(HeaderName, "Для отмены нажмите[SPACE]");

                    PrintConsole.Print(
                        $"Поиск постов от {Whois}\nПроверено {offset} из {Walls.TotalCount}\nНайдено {found} записей.",
                        MenuType.InfoHeader);

                    Walls = api.Wall.Get(new WallGetParams
                    {
                        OwnerId = id,
                        Count   = 100,
                        Offset  = offset
                    });

                    if (Walls.WallPosts.Count == 0)
                    {
                        break;
                    }

                    for (int h = 0; h < Walls.WallPosts.Count; h++)
                    {
                        cts.Token.ThrowIfCancellationRequested();
                        if (Walls.WallPosts[h].SignerId == userId || Walls.WallPosts[h].FromId == userId)
                        {
                            var data = GetMoreInfoFromPost(Walls.WallPosts[h], userId, api);
                            //FoundPosts += $"https://vk.com/wall{id}_{Walls.WallPosts[h].Id}\n";

                            data.postUrl = $"https://vk.com/wall{id}_{Walls.WallPosts[h].Id}";

                            data.text   = Walls.WallPosts[h].Text;
                            data.date   = Walls.WallPosts[h].Date.ToString();
                            FoundPosts += GetPostHtml(data);
                            found++;
                            BackLine.Clear();
                            PrintConsole.Print($"Найдено {found} записей.");
                        }
                    }

                    offset += 100;
                }

                HeaderName = $"Результат поиска постов {Whois}";
                PrintConsole.Header(HeaderName);

                PrintConsole.Print($"Найдено {found} постов.", MenuType.InfoHeader);
                if (found > 0)
                {
                    SaveResult(api, userId, id, FoundPosts);
                }

                BackLine.Continue();
            }

            catch (Exception ex)
            {
                if (cts.Token.CanBeCanceled)
                {
                    HeaderName = $"Результат поиска постов {Whois}";
                    PrintConsole.Header(HeaderName);
                    PrintConsole.Print("Выполнена остановка поиска.", MenuType.Warning);
                    PrintConsole.Print($"Найдено {found} постов.", MenuType.InfoHeader);
                    if (found > 0)
                    {
                        SaveResult(api, userId, id, FoundPosts);
                    }
                    BackLine.Continue();
                }
            }
        }