public ConsoleStatus EditCurrentTaskTitle()
        {
            if (manager.CurrentTaskNotLoaded)
            {
                throw new Exception(ZTaskManager.YouHaveNotLoadedACurrentTask);
            }
            else
            {
                Print("Reset Task Title ...");

                // Gather old info
                string title_old = manager.CurrentTask.Title;

                // Read new Title
                ConsoleStatus status = reader.GetTitle(out string newTitle);
                if (Bad(status))
                {
                    if (IsCancel(status))
                    {
                        Print("Operation cancelled ...");
                    }
                    return(status);
                }

                manager.CurrentTask.Title = newTitle;
                Print($"Task '{title_old}'s Title has been changed to '{newTitle}'");
                return(ConsoleStatus.OK);
            }
        }
        public ConsoleStatus EditCurrentTaskDescription()
        {
            if (manager.CurrentTaskNotLoaded)
            {
                throw new Exception(ZTaskManager.YouHaveNotLoadedACurrentTask);
            }
            else
            {
                Print("Reset Task Description ...");

                // Read new Title
                ConsoleStatus status = reader.GetDescription(out string description_new);
                if (Bad(status))
                {
                    if (IsCancel(status))
                    {
                        Print("Operation cancelled ...");
                    }
                    return(status);
                }

                manager.CurrentTask.Description = description_new;
                Print($"Task '{manager.CurrentTask.Title}'s description has updated ...");
                return(ConsoleStatus.OK);
            }
        }
Example #3
0
        /// <summary>
        /// Tells the music player to play a file
        /// </summary>
        /// <param name="filename">Absolute path of file (Drive Letter must be uppercased. AjaxAMP is very very picky)</param>
        /// <returns></returns>
        public async Task PlayFile(string filename)
        {
            await Post("playfile", new Dictionary <string, string>
            {
                ["filename"] = filename,
                ["title"]    = filename
            });

            float position1 = await GetPosition();

            await Task.Delay(400);

            float position2 = await GetPosition();

            if (position1 == position2)
            {
                throw new ApiError("Failed to play given file.");
            }

            await Task.Delay(1000);

            ConsoleStatus status = await GetStatus();

            Console.WriteLine(status.Title);
            if (status.Filename != filename)
            {
                throw new ApiError($"Failed to play given file. Filename: {status.Title}");
            }
        }
Example #4
0
        /// <summary>
        /// Validates the specified consoles assets.
        /// </summary>
        /// <param name="console">The console.</param>
        /// <returns></returns>
        public ConsoleStatus Validate(HyperValidator.Models.Console console)
        {
            var status = new ConsoleStatus()
            {
                Video    = ValidateVideo(console),
                Theme    = ValidateTheme(console),
                WheelArt = ValidateWheelArt(console)
            };

            return(status);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="commands">the whole command include the main command</param>
        /// <returns></returns>
        public ConsoleStatus AddNewTask(string[] commands)
        {
            // 1. Parse flags
            if (commands.Length > 3)
            {
                throw new BadCommandException(commands);
            }

            bool priority  = false;
            bool scheduled = false;

            for (int i = 1; i < commands.Length; ++i)
            {
                switch (commands[i])
                {
                case ScheduledFlag:
                    scheduled = true;
                    break;

                case PriorityFlag:
                    priority = true;
                    break;

                default:
                    throw new BadCommandException();
                }
            }

            // 2. Add task
            ConsoleStatus status = reader.GetTask(scheduled, priority);

            // 3. Print message and return
            switch (status)
            {
            case ConsoleStatus.Cancel:
                PrintWarning("Task is cancelled");
                break;

            case ConsoleStatus.OK:
                Print("Task is added");
                break;

            default:
                break;
            }
            return(status);
        }
Example #6
0
        private static void WriteLine(string text, ConsoleStatus status = ConsoleStatus.Default)
        {
            switch (status)
            {
            case ConsoleStatus.Warning:
                Console.ForegroundColor = ConsoleColor.Yellow;
                break;

            case ConsoleStatus.Alert:
                Console.ForegroundColor = ConsoleColor.Red;
                break;

            case ConsoleStatus.Success:
                Console.ForegroundColor = ConsoleColor.Green;
                break;
            }

            Console.WriteLine(text);

            Console.ResetColor();
        }
        public ConsoleStatus ResetCurrentTaskBuffer()
        {
            // Setting conditions for buffer-resetting
            if (manager.CurrentTaskNotLoaded)
            {
                throw new Exception(ZTaskManager.YouHaveNotLoadedACurrentTask);
            }
            else
            {
                ZScheduledTask scheduled = manager.CurrentTask as ZScheduledTask;
                if (scheduled == null)
                {
                    throw new Exception($"Task '{manager.CurrentTask.Title}' is not scheduled!");
                }

                // Gather information from the task
                string   title      = scheduled.Title;
                TimeSpan buffer_old = scheduled.ZBuffer;

                // Read new buffer
                ConsoleStatus status = reader.GetTimeSpan(out TimeSpan? newBuffer, "Enter the new buffer (1.hh:mm:ss:00:00): ");
                if (Bad(status))
                {
                    if (status == ConsoleStatus.Cancel)
                    {
                        Print("Operation Cancelled ...");
                    }
                    return(status);
                }

                // Reset Buffer, Print Message and Return OK
                scheduled.ResetBuffer(newBuffer.Value);
                Print($"Task '{title}' has been stretched from {buffer_old.ToString()} to {scheduled.ZBuffer.ToString()}");

                return(ConsoleStatus.OK);
            }
        }
        /// <summary>
        /// Stretches the deadline of the current task.
        /// Message: task '{taskName}' has been stretched from '{originalTime}'
        /// to '{newTime}' ...
        /// </summary>
        /// <param name="commands"></param>
        /// <returns></returns>
        public ConsoleStatus StretchCurrentTaskDeadline()
        {
            // Setting conditions for deadline-stretching
            if (manager.CurrentTaskNotLoaded)
            {
                throw new Exception(ZTaskManager.YouHaveNotLoadedACurrentTask);
            }
            else
            {
                ZScheduledTask scheduled = manager.CurrentTask as ZScheduledTask;
                if (scheduled == null)
                {
                    throw new Exception($"Task '{manager.CurrentTask.Title}' is not scheduled!");
                }

                // Gather information from the task
                string   title        = scheduled.Title;
                DateTime deadline_old = scheduled.Deadline;

                // Get the time from console and check status
                ConsoleStatus status = reader.GetTimeSpan(out TimeSpan? stretch, "Enter the time span that you wish to stretch (dd.hh:mm:ss:00:00): ");
                if (Bad(status))
                {
                    if (status == ConsoleStatus.Cancel)
                    {
                        Print("Operation Cancelled ...");
                    }
                    return(status);
                }

                // Put off current task by the value, print message and return
                scheduled.PutOff(stretch.Value);
                Print($"Task '{title}' has been stretched from {deadline_old.ToString("o")} to {scheduled.Deadline.ToString("o")}");

                return(ConsoleStatus.OK);
            }
        }
        /// <summary>
        /// Resets the deadline of the current task
        /// </summary>
        /// <returns>Console Task</returns>
        public ConsoleStatus ResetCurrentTaskDeadline()
        {
            // Setting conditions for deadline-resetting
            if (manager.CurrentTaskNotLoaded)
            {
                throw new Exception(ZTaskManager.YouHaveNotLoadedACurrentTask);
            }
            else
            {
                ZScheduledTask scheduled = manager.CurrentTask as ZScheduledTask;
                if (scheduled == null)
                {
                    throw new Exception($"Task '{manager.CurrentTask.Title}' is not scheduled!");
                }

                // Gather information from the task
                string   title        = scheduled.Title;
                DateTime deadline_old = scheduled.Deadline;

                // Read new deadline
                ConsoleStatus status = reader.GetDeadline(out DateTime? deadline);
                if (Bad(status))
                {
                    if (status == ConsoleStatus.Cancel)
                    {
                        Print("Operation Cancelled ...");
                    }
                    return(status);
                }

                scheduled.ResetDeadline(deadline.Value);
                Print($"Task '{title}'s Deadline has been reset from {deadline_old.ToString("o")} to {scheduled.Deadline.ToString("o")}");

                return(ConsoleStatus.OK);
            }
        }
 public ConsoleStatusChangedEventArgs(ConsoleStatus status)
 {
     Status = status;
 }
 public static bool IsQuit(ConsoleStatus status)
 {
     return(status == ConsoleStatus.Quit);
 }
Example #12
0
    void Awake()
    {
        if (ConsoleStatus.consoleStatus == null)
        {
            ConsoleStatus.consoleStatus = this;
        }
        else
        {
            // Destroy if it exists already.
            // GameObject.Destroy(this.gameObject);
        }

        firstPanel = new Panel(
            new Control(
                ControlType.Button_A,
                false,
                "Wibbly Button (PLACEHOLDER)"
                ),
            new Control(
                ControlType.Button_B,
                false,
                "WibblyWobbly Button (PLACEHOLDER)"
                ),
            new Control(
                ControlType.Lever,
                false,
                "Wibbly Lever (PLACEHOLDER)"
                )
            );

        secondPanel = new Panel(
            new Control(
                ControlType.Button_A,
                false,
                "Wibbly Button #2 (PLACEHOLDER)"
                ),
            new Control(
                ControlType.Button_B,
                false,
                "WibblyWobbly Button # 2 (PLACEHOLDER)"
                ),
            new Control(
                ControlType.Lever,
                false,
                "Wibbly Lever # 2 (PLACEHOLDER)"
                )
            );

        thirdPanel = new Panel(
            new Control(
                ControlType.Button_A,
                false,
                "Wibbly Button #3 (PLACEHOLDER)"
                ),
            new Control(
                ControlType.Button_B,
                false,
                "WibblyWobbly Button # 3 (PLACEHOLDER)"
                ),
            new Control(
                ControlType.Lever,
                false,
                "Wibbly Lever # 3 (PLACEHOLDER)"
                )
            );
    }
Example #13
0
        public int Run(BaseOptions options)
        {
            var opts = (ImportOptions)options;

            Settings.Load(opts.Config);
            PluginProvider.Instance.Initialize();

            string pluginName = opts.Plugin;
            bool   showHelp   = false;

            if (opts.Plugin.ToLower() == "help")
            {
                if (string.IsNullOrWhiteSpace(opts.Library))
                {
                    Console.WriteLine("Available importers:");
                    PluginProvider.Instance.Importers.ForEach(i =>
                    {
                        Console.WriteLine("  {0}\t\t\t{1}", i.Command, i.Name);
                    });
                    Console.WriteLine();

                    return(0);
                }

                pluginName = opts.Library;
                showHelp   = true;
            }

            var plugin = PluginProvider.Instance.GetBookProvider(pluginName);

            if (plugin == null)
            {
                Console.Error.WriteLine("Import plugin '{0}' not found.", opts.Plugin);
                return(1);
            }

            if (showHelp)
            {
                Console.WriteLine(plugin.Help);
                return(0);
            }

            var library = Util.Normalize(opts.Library);

            if (!Directory.Exists(library))
            {
                Console.Error.WriteLine("Library directory {0} not found.", library);
                return(1);
            }

            var watch  = Stopwatch.StartNew();
            var status = new ConsoleStatus();

            using (var task = new ImportTask())
            {
                task.Start(new ImportTaskArgs
                {
                    Plugin  = plugin,
                    Library = library,
                    Args    = opts.Arguments.ToArray()
                }, (e) =>
                {
                    Console.WriteLine();
                    Console.Error.WriteLine("Error executing import plugin '{0}': {1}", opts.Plugin, e.Message);
                    _logger.Fatal(e);
                    Environment.Exit(1);
                });

                while (task.EntriesProcessed == 0)
                {
                    if (Program.Exit.WaitOne(1))
                    {
                        Environment.Exit(1);
                        return(1);
                    }
                    status.Update("Preparing to import, elapsed {0:hh\\:mm\\:ss}", watch.Elapsed);
                }

                status.Clear();
                Console.WriteLine("Using {0} workers", Environment.ProcessorCount);

                var importStart = watch.Elapsed;
                while (!task.Finished)
                {
                    if (Program.Exit.WaitOne(1))
                    {
                        Environment.Exit(1);
                        return(1);
                    }
                    status.Update("Processed {0} of {1}, {2} book/sec, elapsed {3:hh\\:mm\\:ss}", task.EntriesProcessed, task.EntriesTotal,
                                  Math.Truncate(task.EntriesProcessed / (watch.Elapsed.TotalSeconds - importStart.TotalSeconds)), watch.Elapsed);
                }

                watch.Stop();
                status.Update("Done in {0:hh\\:mm\\:ss} ({1} added/updated, {2} deleted)", watch.Elapsed, task.EntriesProcessed, task.EntriesDeleted);
            }

            return(0);
        }
        /// <summary>
        /// return true if the command is quit;
        /// </summary>
        /// <param name="commands"></param>
        /// <returns></returns>
        public bool ProcessCommand(string[] commands)
        {
            string mainCommand = commands[0];

            ConsoleStatus status = ConsoleStatus.OK;

            try
            {
                switch (mainCommand)
                {
                case Quit:     // Quit the program
                    return(true);

                case Save:
                    manager.Save();
                    Print("Tasks saved to disk ...");
                    break;

                case HelpKey:
                    executor.PrintHelpMenu(commands);
                    break;

                case Add:     // Adding a new task
                    status = executor.AddNewTask(commands);
                    if (IsQuit(status))
                    {
                        return(true);
                    }
                    break;

                case CurTask:
                    executor.PrintCurrentTask();
                    break;

                case PutOffCurrent:
                    executor.PutOffCurrentTask(commands);
                    break;

                case ArchiveCurrent:
                    executor.ArchiveCurrentTask(commands);
                    break;

                case Update:
                    manager.Update();
                    Print("Update Successful ...");
                    break;

                case DeprioritizeCurrent:
                    manager.DeprioritizeCurrentTask();
                    Print($"Current Task '{manager.CurrentTask.Title}' Is Deprioritized ...");
                    break;

                case PrioritizeCurrent:
                    manager.PrioritizeCurrentTask();
                    Print($"Current Task '{manager.CurrentTask.Title}' Is Prioritized ...");
                    break;

                case UnscheduleCurrent:
                    manager.UnscheduleCurrentTask();
                    Print($"Current Task '{manager.CurrentTask.Title}' Is Unscheduled ...");
                    break;

                case ScheduleCurrent:
                    status = executor.ScheduleCurrentTask();
                    if (IsQuit(status))
                    {
                        return(true);
                    }
                    Print($"Current Task '{manager.CurrentTask.Title}' is successfully scheduled ...");
                    break;

                case StretchCurrentDeadline:
                    status = executor.StretchCurrentTaskDeadline();
                    if (IsQuit(status))
                    {
                        return(true);
                    }
                    break;

                case ResetCurrentDeadline:
                    status = executor.ResetCurrentTaskDeadline();
                    if (IsQuit(status))
                    {
                        return(true);
                    }
                    break;

                case ResetCurrentBuffer:
                    status = executor.ResetCurrentTaskBuffer();
                    if (IsQuit(status))
                    {
                        return(true);
                    }
                    break;

                case EditCurrentTitle:
                    status = executor.EditCurrentTaskTitle();
                    if (IsQuit(status))
                    {
                        return(true);
                    }
                    break;

                case EditCurrentDescription:
                    status = executor.EditCurrentTaskDescription();
                    if (IsQuit(status))
                    {
                        return(true);
                    }
                    break;

                case ViewAllTasks:
                    executor.View_AllTasks(commands);
                    break;

                case ViewSelect:     // select certain tasks to view
                    executor.View_SelectedTasks(commands);
                    break;

                case ViewArchive:     // should implement -detail flag detector later
                    executor.View_Archives(commands);
                    break;

                default:
                    throw new BadCommandException($"Command '{mainCommand}' is not recognized");
                }
            }
            catch (BadFileParsingException e)
            {
                PrintWarning(Help.CorruptFileInstruction);
                ZDebugUtil.PrintError(e);
            }
            catch (BadCommandException e)
            {
                PrintWarning(Help.BadCommandInstruction);
                ZDebugUtil.PrintError(e);
            }
            catch (Exception e)
            {
                ZDebugUtil.PrintError(e);
            }
            return(false);
        }
        private void session_StandardDataReceived(object sender, StandardDataReceivedEventArgs e)
        {
            if (e.Type == StandardStreamType.OUTPUT)
            {
                if (Status != ConsoleStatus.ACCESSGRANTED)
                {
                    if (e.Data == "login as: ")
                    {
                        Status = ConsoleStatus.LOGINAS;
                    }
                    else if (e.Data.EndsWith("'s password: "******"Passphrase for key "))
                    {
                        Status = ConsoleStatus.PRIVATEKEY;
                        OnPasswordRequested();
                    }

                    StandardOutput += e.Data;
                }
                else
                {
                    char[] data = new char[e.Data.Length];
                    int    read = 0;

                    bool gotESC = false;
                    bool gotOSC = false;
                    bool gotCSI = false;

                    for (var i = 0; i < e.Data.Length; i++)
                    {
                        char c = e.Data[i];

                        if (gotOSC)
                        {
                            if (c == 7) // BEL
                            {
                                gotOSC = false;
                            }
                        }
                        else if (gotCSI)
                        {
                            if (c >= 64 && c <= 126) // @ to ~
                            {
                                gotCSI = false;
                            }
                        }
                        else if (gotESC)
                        {
                            if (c == 91) // [
                            {
                                gotCSI = true;
                            }
                            else if (c == 93) // ]
                            {
                                gotOSC = true;
                            }

                            gotESC = false;
                        }
                        else if (c == 27) // ESC
                        {
                            gotESC = true;
                        }
                        else
                        {
                            data[read++] = c;
                        }
                    }

                    string output = new string(data, 0, read);
                    if (output.EndsWith("Password: "******"[sudo] password for "))
                    {
                        OnPasswordRequested();
                    }

                    StandardOutput += output;
                }
            }

            else if (e.Type == StandardStreamType.ERROR)
            {
                if (Status != ConsoleStatus.ACCESSGRANTED)
                {
                    string[] lines = e.Data.Split(_splitby, StringSplitOptions.RemoveEmptyEntries);

                    if (Array.IndexOf(lines, "Access granted") >= 0)
                    {
                        Status = ConsoleStatus.ACCESSGRANTED;
                        _session.Connected();
                    }
                    else if (Array.IndexOf(lines, "Store key in cache? (y/n) ") >= 0)
                    {
                        Status = ConsoleStatus.STOREHOST;
                    }
                    else if (Array.IndexOf(lines, "Update cached key? (y/n, Return cancels connection) ") >= 0)
                    {
                        Status = ConsoleStatus.UPDATEHOST;
                    }
                    else if (Array.Find <string>(lines, line => line.StartsWith("FATAL ERROR:")) != null)
                    {
                        Status = ConsoleStatus.ERROR;
                    }
                }

                StandardError += e.Data;
            }
        }
 public static bool Bad(ConsoleStatus status)
 {
     return(status != ConsoleStatus.OK);
 }
 public ConsoleStatusChangedEventArgs(ConsoleStatus status)
 {
     Status = status;
 }
 public static bool IsCancel(ConsoleStatus status)
 {
     return(status == ConsoleStatus.Cancel);
 }
        private void session_StandardDataReceived(object sender, StandardDataReceivedEventArgs e) {
            if (e.Type == StandardStreamType.OUTPUT) {
                if (Status != ConsoleStatus.ACCESSGRANTED) {
                    if (e.Data == "login as: ")
                        Status = ConsoleStatus.LOGINAS;
                    else if (e.Data.EndsWith("'s password: "******"Passphrase for key ")) {
                        Status = ConsoleStatus.PRIVATEKEY;
                        OnPasswordRequested();
                    }

                    StandardOutput += e.Data;
                }
                else {
                    char[] data = new char[e.Data.Length];
                    int read = 0;

                    bool gotESC = false;
                    bool gotOSC = false;
                    bool gotCSI = false;

                    for (var i = 0; i < e.Data.Length; i++) {
                        char c = e.Data[i];

                        if (gotOSC) {
                            if (c == 7) // BEL
                                gotOSC = false;
                        }
                        else if (gotCSI) {
                            if (c >= 64 && c <= 126) // @ to ~
                                gotCSI = false;
                        }
                        else if (gotESC) {
                            if (c == 91) // [
                                gotCSI = true;
                            else if (c == 93) // ]
                                gotOSC = true;

                            gotESC = false;
                        }
                        else if (c == 27) // ESC
                            gotESC = true;
                        else
                            data[read++] = c;
                    }

                    string output = new string(data, 0, read);
                    if (output.EndsWith("Password: "******"[sudo] password for "))
                        OnPasswordRequested();

                    StandardOutput += output;
                }
            }

            else if (e.Type == StandardStreamType.ERROR) {
                if (Status != ConsoleStatus.ACCESSGRANTED) {
                    string[] lines = e.Data.Split(_splitby, StringSplitOptions.RemoveEmptyEntries);

                    if (Array.IndexOf(lines, "Access granted") >= 0) {
                        Status = ConsoleStatus.ACCESSGRANTED;
                        _session.Connected();
                    }
                    else if (Array.IndexOf(lines, "Store key in cache? (y/n) ") >= 0)
                        Status = ConsoleStatus.STOREHOST;
                    else if (Array.IndexOf(lines, "Update cached key? (y/n, Return cancels connection) ") >= 0)
                        Status = ConsoleStatus.UPDATEHOST;
                    else if (Array.Find<string>(lines, line => line.StartsWith("FATAL ERROR:")) != null)
                        Status = ConsoleStatus.ERROR;
                }

                StandardError += e.Data;
            }
        }