Exemplo n.º 1
1
        public RoomViewModel(MainViewModel mainViewModel, Room room, IList<User> users)
            : base(true)
        {
            Description = room;
              MainViewModel = mainViewModel;
              Messages = new ObservableCollection<MessageViewModel>();
              allInRoom = new UserViewModel(new User("Все в комнате", Color.Black), this);
              messageIds = new HashSet<long>();
              Users = new ObservableCollection<UserViewModel>(users == null
            ? Enumerable.Empty<UserViewModel>()
            : room.Users.Select(user => new UserViewModel(users.Single(u => u.Equals(user)), this)));

              SendMessageCommand = new Command(SendMessage, Obj => ClientModel.Client != null);
              PastReturnCommand = new Command(PastReturn);
              AddFileCommand = new Command(AddFile, Obj => ClientModel.Client != null);
              InviteInRoomCommand = new Command(InviteInRoom, Obj => ClientModel.Client != null);
              KickFromRoomCommand = new Command(KickFromRoom, Obj => ClientModel.Client != null);
              ClearSelectedMessageCommand = new Command(ClearSelectedMessage, Obj => ClientModel.Client != null);

              MainViewModel.AllUsers.CollectionChanged += AllUsersCollectionChanged;
              NotifierContext.ReceiveMessage += ClientReceiveMessage;
              NotifierContext.RoomRefreshed += ClientRoomRefreshed;
        }
Exemplo n.º 2
0
        public AudioTabViewModel()
            : base(NameKey, SettingsTabCategory.Audio)
        {
            OutputDevices = ClientModel.Player.Devices;
              InputDevices = ClientModel.Recorder.Devices;
              InputConfigs = new[]
              {
            new AudioQuality(1, 8, 22050),
            new AudioQuality(1, 16, 22050),
            new AudioQuality(1, 8, 44100),
            new AudioQuality(1, 16, 44100)
              };

              SelectedOutputIndex = OutputDevices.IndexOf(Settings.Current.OutputAudioDevice);
              SelectedInputIndex = InputDevices.IndexOf(Settings.Current.InputAudioDevice);
              SelectedConfigIndex = InputConfigs.IndexOf(new AudioQuality(1, Settings.Current.Bits, Settings.Current.Frequency));

              if (SelectedOutputIndex == -1)
            SelectedOutputIndex = 0;

              if (SelectedInputIndex == -1)
            SelectedInputIndex = 0;

              if (SelectedConfigIndex == -1)
            SelectedConfigIndex = 0;

              SelectButtonName = Settings.Current.RecorderKey.ToString();

              SelectKeyCommand = new Command(SelectKey);
        }
Exemplo n.º 3
0
        public MainViewModel(MainWindow mainWindow)
            : base(null, true)
        {
            window = mainWindow;
              window.Closed += WindowClosed;
              Rooms = new ObservableCollection<RoomViewModel>();
              Plugins = new ObservableCollection<PluginViewModel>();
              Dispatcher = mainWindow.Dispatcher;

              KeyBoard.KeyDown += OnKeyDown;
              KeyBoard.KeyUp += OnKeyUp;

              NotifierContext.Connected += CreateSubscriber<ConnectEventArgs>(ClientConnect);
              NotifierContext.ReceiveMessage += CreateSubscriber<ReceiveMessageEventArgs>(ClientReceiveMessage);
              NotifierContext.ReceiveRegistrationResponse += CreateSubscriber<RegistrationEventArgs>(ClientRegistration);
              NotifierContext.RoomClosed += CreateSubscriber<RoomEventArgs>(ClientRoomClosed);
              NotifierContext.RoomOpened += CreateSubscriber<RoomEventArgs>(ClientRoomOpened);
              NotifierContext.AsyncError += CreateSubscriber<AsyncErrorEventArgs>(ClientAsyncError);
              NotifierContext.PluginLoaded += CreateSubscriber<PluginEventArgs>(ClientPluginLoaded);
              NotifierContext.PluginUnloading += CreateSubscriber<PluginEventArgs>(ClientPluginUnloading);

              EnableServerCommand = new Command(EnableServer, _ => !ServerModel.IsInited && !ClientModel.IsInited);
              DisableServerCommand = new Command(DisableServer, _ => ServerModel.IsInited);
              ConnectCommand = new Command(Connect, _ => !ClientModel.IsInited);
              DisconnectCommand = new Command(Disconnect, _ => ClientModel.IsInited);
              ExitCommand = new Command(_ => window.Close());
              CreateRoomCommand = new Command(CreateRoom, _ => ClientModel.IsInited);
              DeleteRoomCommand = new Command(DeleteRoom, _ => ClientModel.IsInited);
              ExitFromRoomCommand = new Command(ExitFromRoom, _ => ClientModel.IsInited);
              OpenFilesDialogCommand = new Command(OpenFilesDialog, _ => ClientModel.IsInited);
              OpenAboutProgramCommand = new Command(OpenAboutProgram);
              OpenSettingsCommand = new Command(OpenSettings);

              ClearTabs();
        }
    public PluginSettingTabViewModel(string name) : base(name) 
    {
      Plugins = new ObservableCollection<PluginInfoViewModel>();

      LoadCommand = new Command(Load, o => ClientModel.IsInited || ServerModel.IsInited);
      UnloadCommand = new Command(Unload, o => ClientModel.IsInited || ServerModel.IsInited);

      Refresh();
    }
Exemplo n.º 5
0
    public UserViewModel(User info, RoomViewModel roomViewModel)
      : base(false)
    {
      Info = info;
      RoomViewModel = roomViewModel;

      SetRoomAdminCommand = new Command(SetRoomAdmin, Obj => ClientModel.Client != null);
      UserClickCommand = new Command(UserClick);
    }
Exemplo n.º 6
0
        public PluginSettingTabViewModel()
            : base(NameKey, SettingsTabCategory.Plugins)
        {
            Plugins = new ObservableCollection<PluginInfoViewModel>();

              LoadCommand = new Command(Load, o => ClientModel.IsInited || ServerModel.IsInited);
              UnloadCommand = new Command(Unload, o => ClientModel.IsInited || ServerModel.IsInited);

              Refresh();
        }
Exemplo n.º 7
0
        public SettingsViewModel(SettingsView view)
            : base(false)
        {
            window = view;
              CloseSettingsCommand = new Command(CloseSettings);

              Tabs = new SettingsTabViewModel[]
              {
            new ClientTabViewModel("Клиент"),
            new ServerTabViewModel("Сервер"),
            new AudioTabViewModel("Звук"),
            new PluginSettingTabViewModel("Плагины")
              };

              SelectedTab = Tabs[0];
        }
Exemplo n.º 8
0
        public SettingsViewModel(SettingsView view)
            : base(null, false)
        {
            window = view;
              CloseSettingsCommand = new Command(CloseSettings);

              Tabs = new SettingsTabViewModel[]
              {
            new ClientTabViewModel(),
            new ServerTabViewModel(),
            new AudioTabViewModel(),
            new PluginSettingTabViewModel()
              };

              SelectedTab = Tabs[0];
        }
Exemplo n.º 9
0
    public PluginViewModel(string pluginName)
      : base(false)
    {
      try
      {
        var plugin = ClientModel.Plugins.GetPlugin(pluginName);
        if (plugin == null)
          return;

        Header = plugin.MenuCaption;
        PluginName = plugin.Name;
        InvokeCommand = new Command(Invoke);
      }
      catch(Exception e)
      {
        ClientModel.Logger.Write(e);
      }
    } 
Exemplo n.º 10
0
        public MainViewModel(MainWindow mainWindow)
            : base(true)
        {
            window = mainWindow;
              window.Closed += WindowClosed;
              Rooms = new ObservableCollection<RoomViewModel>();
              AllUsers = new ObservableCollection<UserViewModel>();
              Plugins = new ObservableCollection<PluginViewModel>();
              Dispatcher = mainWindow.Dispatcher;

              KeyBoard.KeyDown += OnKeyDown;
              KeyBoard.KeyUp += OnKeyUp;

              NotifierContext.Connected += ClientConnect;
              NotifierContext.ReceiveMessage += ClientReceiveMessage;
              NotifierContext.ReceiveRegistrationResponse += ClientRegistration;
              NotifierContext.RoomRefreshed += ClientRoomRefreshed;
              NotifierContext.RoomClosed += ClientRoomClosed;
              NotifierContext.RoomOpened += ClientRoomOpened;
              NotifierContext.AsyncError += ClientAsyncError;
              NotifierContext.PluginLoaded += ClientPluginLoaded;
              NotifierContext.PluginUnloading += ClientPluginUnloading;

              ClearTabs();

              EnableServerCommand = new Command(EnableServer, obj => ServerModel.Server == null);
              DisableServerCommand = new Command(DisableServer, obj => ServerModel.Server != null);
              ConnectCommand = new Command(Connect, obj => ClientModel.Client == null);
              DisconnectCommand = new Command(Disconnect, obj => ClientModel.Client != null);
              ExitCommand = new Command(obj => window.Close());
              CreateRoomCommand = new Command(CreateRoom, obj => ClientModel.Client != null);
              DeleteRoomCommand = new Command(DeleteRoom, obj => ClientModel.Client != null);
              ExitFromRoomCommand = new Command(ExitFromRoom, obj => ClientModel.Client != null);
              OpenFilesDialogCommand = new Command(OpenFilesDialog, obj => ClientModel.Client != null);
              OpenAboutProgramCommand = new Command(OpenAboutProgram);
              OpenSettingsCommand = new Command(OpenSettings);
        }
Exemplo n.º 11
0
        public MessageViewModel(UserViewModel sender, string fileName, FileDescription fileDescription, RoomViewModel room)
            : this(Room.SpecificMessageId, room, true)
        {
            NotifierContext.DownloadProgress += ClientDownloadProgress;
              NotifierContext.PostedFileDeleted += ClientPostedFileDeleted;

              Sender = sender;
              File = fileDescription;
              Progress = 0;
              Title = string.Format(From, DateTime.Now.ToString(TimeFormat));

              string sizeDim = string.Empty;
              float size = 0;

              if (fileDescription.Size < 1024)
              {
            sizeDim = ByteStr;
            size = fileDescription.Size;
              }

              if (fileDescription.Size >= 1024 && fileDescription.Size < 1024 * 1024)
              {
            sizeDim = KByteStr;
            size = fileDescription.Size / 1024.0f;
              }

              if (fileDescription.Size >= 1024 * 1024)
              {
            sizeDim = MByteStr;
            size = fileDescription.Size / (1024.0f * 1024.0f);
              }

              Text = fileName + string.Format(SizeFormat, size, sizeDim);
              Type = MessageType.File;
              DownloadFileCommand = new Command(DownloadFile, Obj => ClientModel.Client != null);
        }
Exemplo n.º 12
0
        public MessageViewModel(long messageId, UserViewModel sender, UserViewModel receiver, string message, bool isPrivate, RoomViewModel room)
            : this(messageId, room, false)
        {
            Text = message;
              Sender = sender;
              Receiver = receiver;
              Type = isPrivate ? MessageType.Private : MessageType.Common;

              EditMessageCommand = new Command(EditMessage, Obj => ClientModel.Client != null);

              Title = string.Format(isPrivate ? PMForm : From, DateTime.Now.ToString(TimeFormat));
        }
Exemplo n.º 13
0
        public MessageViewModel(long messageId, DateTime messageTime, string senderNick, string receiverNick, string message, bool isPrivate, RoomViewModel room)
            : this(messageId, room, false)
        {
            Text = message;
              Sender = new UserViewModel(senderNick, room);
              Receiver = new UserViewModel(receiverNick, room);
              Type = isPrivate ? MessageType.Private : MessageType.Common;

              EditMessageCommand = new Command(EditMessage, _ => ClientModel.Client != null);

              var localMessageTime = messageTime.ToLocalTime();
              Title = Localizer.Instance.Localize(isPrivate ? PMFormKey : FromKey, localMessageTime.ToString(TimeFormat));
        }
Exemplo n.º 14
0
        public MessageViewModel(DateTime messageTime, string senderNick, FileId fileId, RoomViewModel roomVm)
            : this(Room.SpecificMessageId, roomVm, true)
        {
            this.fileId = fileId;

              Sender = new UserViewModel(senderNick, parentRoom);
              Progress = 0;

              var localMessageTime = messageTime.ToLocalTime();
              Title = Localizer.Instance.Localize(FromKey, localMessageTime.ToString(TimeFormat));

              var sizeDim = string.Empty;
              var size = 0L;

              using (var client = ClientModel.Get())
              {
            var file = GetFile(client, fileId);

            if (file.Size < 1024)
            {
              sizeDim = Localizer.Instance.Localize(ByteStrKey);
              size = file.Size;
            }

            if (file.Size >= 1024 && file.Size < 1024 * 1024)
            {
              sizeDim = Localizer.Instance.Localize(KByteStrKey);
              size = file.Size / 1024;
            }

            if (file.Size >= 1024 * 1024)
            {
              sizeDim = Localizer.Instance.Localize(MByteStrKey);
              size = file.Size / (1024 * 1024);
            }

            Text = file.Name + string.Format(SizeFormat, size, sizeDim);
              }

              Type = MessageType.File;
              DownloadFileCommand = new Command(DownloadFile, _ => ClientModel.Api != null);

              NotifierContext.DownloadProgress += CreateSubscriber<FileDownloadEventArgs>(ClientDownloadProgress);
              NotifierContext.PostedFileDeleted += CreateSubscriber<FileDownloadEventArgs>(ClientPostedFileDeleted);
        }
Exemplo n.º 15
0
        private void Init(MainViewModel main, IList<string> usersNicks)
        {
            mainViewModel = main;
              Messages = new ObservableCollection<MessageViewModel>();
              SelectedReceiver = allInRoom = new UserViewModel(AllInRoomKey, null, this);
              recivers = new List<UserViewModel>();
              messageIds = new HashSet<long>();

              var userViewModels = usersNicks == null
            ? Enumerable.Empty<UserViewModel>()
            : usersNicks.Select(user => new UserViewModel(user, this));
              Users = new ObservableCollection<UserViewModel>(userViewModels);

              SendMessageCommand = new Command(SendMessage, _ => ClientModel.Api != null && ClientModel.Client.IsConnected);
              PastReturnCommand = new Command(PastReturn);
              AddFileCommand = new Command(AddFile, _ => ClientModel.Api != null);
              InviteInRoomCommand = new Command(InviteInRoom, _ => ClientModel.Api != null);
              KickFromRoomCommand = new Command(KickFromRoom, _ => ClientModel.Api != null);
              ClearSelectedMessageCommand = new Command(ClearSelectedMessage);
              EnableVoiceCommand = new Command(EnableVoice, _ => Type == RoomType.Voice && !Enabled);
              DisableVoiceCommand = new Command(DisableVoice, _ => Type == RoomType.Voice && Enabled);

              NotifierContext.ReceiveMessage += CreateSubscriber<ReceiveMessageEventArgs>(ClientReceiveMessage);
              NotifierContext.RoomOpened += CreateSubscriber<RoomEventArgs>(ClientRoomOpened);
              NotifierContext.RoomRefreshed += CreateSubscriber<RoomEventArgs>(ClientRoomRefreshed);
        }
Exemplo n.º 16
0
        public PostedFileViewModel(ClientGuard client, PostedFile postedFile, PostedFileRoomViewModel parent)
            : base(parent, false)
        {
            this.parent = parent;

              FileId = postedFile.File.Id;
              FileName = postedFile.File.Name;

              RemoveCommand = new Command(Remove, _ => ClientModel.Api != null);
        }