Esempio n. 1
0
        private async void OnAddInfo(object args)
        {
            if (AddInfoName == null ||
                string.IsNullOrWhiteSpace(AddInfoName))
            {
                Errors.Add(new Error {
                    Message = "Specify the name of the channel you want to create.", Verbose = "Specify the name of the channel you want to create."
                });
                return;
            }

            try
            {
                var info = ServerInfos.FirstOrDefault(i => i.Name.Equals(AddInfoName));
                if (info == null)
                {
                    var channelInfo = new ChannelInfo {
                        Name = AddInfoName
                    };
                    info = InfoFactory.GetInfo(channelInfo);
                    ServerInfos.Add(info);
                }

                UserInfos.Add(info);

                SelectedInfo = (InfoDecorator)info;

                if (info is Channel)
                {
                    var clientMessage = new Message {
                        SenderConnectionId = User.Name, Data = AddInfoName, MessageType = MessageType.SubscribeToChannel
                    };

                    await dipSocketClient.SendMessageAsync(clientMessage);
                }
            }
            catch (Exception ex)
            {
                Errors.Add(new Error {
                    Message = ex.Message, Verbose = ex.ToString()
                });
            }
            finally
            {
                AddInfoName = string.Empty;
            }
        }
Esempio n. 2
0
        private async Task DisconnectSocketAsync(bool writeNotification = true)
        {
            if (socketClient != null)
            {
                try
                {
                    if (socketClient.State.Equals(WebSocketState.Open))
                    {
                        var clientMessage = new DipSocket.Messages.Message
                        {
                            SenderConnectionId = strategyAssemblyManager.Id,
                            Data        = strategy.Name,
                            MessageType = DipSocket.Messages.MessageType.UnsubscribeFromChannel
                        };

                        await socketClient.SendMessageAsync(clientMessage);
                    }

                    await DisposeSocketAsync(writeNotification);
                }
                catch (Exception ex)
                {
                    Logger.Log($"DisconnectSocketAsync {ex.Message}", Prism.Logging.Category.Exception, Prism.Logging.Priority.High);

                    if (writeNotification)
                    {
                        ViewModelContext.UiDispatcher.Invoke(() =>
                        {
                            NotificationsAdd(new Message {
                                MessageType = MessageType.Error, Text = $"Disconnect - {ex.Message}", TextVerbose = ex.ToString()
                            });
                        });
                    }
                }
            }
        }