Exemplo n.º 1
0
        /// <summary>
        /// The function which execute an action or a reaction register.
        /// </summary>
        /// <param name="obj">The parameters of the action / reaction register.</param>
        /// <returns></returns>
        public static int Callback(Packet obj)
        {
            Network.Client.Instance.SendDataToServer(new Network.NetTools.Packet
            {
                Name = obj.Name,
                Key  = obj.Key,
                Data = new KeyValuePair <Network.NetTools.PacketCommand, object>(Network.NetTools.PacketCommand.C_UNLOCK, null)
            });

            Console.WriteLine("Hello from " + _name);

            Console.WriteLine("--> " + obj.Data.Key);

            switch (obj.Data.Key)
            {
            case PacketCommand.S_DISCONNECT:
                Console.Error.WriteLine("Disconnect by the server");
                Environment.Exit(84);
                break;

            case PacketCommand.ERROR:
                Environment.Exit(84);
                break;

            case PacketCommand.ACTION:
            {
                ServiceActionContent data = JsonConvert.DeserializeObject <ServiceActionContent>(obj.Data.Value.ToString());
                _controller.Action(data);
                break;
            }

            case PacketCommand.REACTION_REGISTER:
            {
                Console.WriteLine("Lol");
                ReactionRegisterContent data = JsonConvert.DeserializeObject <ReactionRegisterContent>(obj.Data.Value.ToString());
                User user = data.Owner;
                Console.WriteLine("-------------->" + data.Owner.Email + " - " + data.ReactionName);
                foreach (var it in _tasks)
                {
                    if (it.Key.Email == user.Email)
                    {
                        _tasks[it.Key].Add(data, _controller.Reaction(data));
                        return(0);
                    }
                }
                _tasks.Add(user, new ThreadPool());
                _tasks[user].Add(data, _controller.Reaction(data));
                break;
            }

            default:
                break;
            }
            return(0);
        }
Exemplo n.º 2
0
        static void EnterCabinetMenu()
        {
            var draw        = true;
            var inputBuffer = "";

            if (cabinetItems == null)
            {
                Draw.MenuOverride = false;
                Draw.Fatal("Could not load cabinet items");

                Thread.Sleep(2000);

                return;
            }

            Draw.MenuOverride = true;

            while (true)
            {
                if (draw)
                {
                    var menu = "";

                    foreach (var item in cabinetItems)
                    {
                        menu += $"[{item.Key}] {item.Value}\n";
                    }

                    var entry = $"\nSelect a tool: {inputBuffer}";

                    Draw.Cabinet(menu, entry);

                    draw = false;
                }

                var input = ReaderHardware.Read();

                if (input.Length != 1)
                {
                    continue;
                }

                switch (input[0])
                {
                case 'A':
                    if (inputBuffer.Length > 0)
                    {
                        inputBuffer = inputBuffer.Substring(0, inputBuffer.Length - 1);
                    }

                    draw = true;
                    break;

                case 'B':
                    int.TryParse(inputBuffer, out var code);

                    if (cabinetItems.ContainsKey(code))
                    {
                        var item = cabinetItems[code];

                        Draw.MenuOverride = false;
                        Draw.Heading(config.Name, status.Warning);
                        Draw.Prompt($"Selected: {item}");
                        controller.Action(key, item);
                        ReaderHardware.Output(code);
                        Thread.Sleep(1000);
                        ReaderHardware.Output(0);
                        return;
                    }
                    else
                    {
                        inputBuffer = "";
                        draw        = true;
                    }
                    break;

                default:
                    inputBuffer += input;
                    draw         = true;
                    break;
                }
            }
        }