示例#1
0
        static async void ParseMessage(string message)
        {
            Message msg = MessageParser.Deserialize(message);

            Console.WriteLine($"[From Client]: {message}");

            switch (msg.Command)
            {
            case "UpdateDataRequest":
                _ = UpdateEveryVinylSend();
                break;

            case "AddVinyl":
                var vinylToAdd = MessageParser.DeserializeType <VinylDTO>(msg.Data.ToString());
                await srvVinyls.AddVinyl(vinylToAdd.ID, vinylToAdd.InStock);

                _ = ConfirmSend();
                break;

            case "RemoveVinyl":
                var vinylToRemove = MessageParser.DeserializeType <int>(msg.Data.ToString());

                await srvVinyls.RemoveStockVinyl(vinylToRemove, 1);

                _ = ConfirmSend();
                break;

            case "TimeInterval":
                float timeInterval = MessageParser.DeserializeType <float>(msg.Data.ToString());

                timeTracker.ProcessTimeInterval(timeInterval);
                break;

            case "Subscribe":
                if (vinylSubscr == null)
                {
                    vinylSubscr = MessageParser.DeserializeType <VinylDTO>(msg.Data.ToString());
                    _           = Task.Run(() => RemoveOneVinylInTime());
                    _           = ConfirmSend();
                }
                break;

            case "Unsubscribe":
                var vinyl = MessageParser.DeserializeType <VinylDTO>(msg.Data.ToString());
                if (vinyl.ID == vinylSubscr.ID)
                {
                    vinylSubscr = null;
                    _           = ConfirmSend();
                }
                break;
            }
        }