예제 #1
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();
            }
예제 #2
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);
                    }
                }
            }
예제 #3
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);
            }
        }
예제 #4
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();
                }
            }
        }