Exemple #1
0
        private async void confirm()
        {
            //check whether the user has inputted the patientID
            if (patientID == null || patientID == "")
            {
                await NewInjection.window.ShowMessageAsync("Error", "Please enter Patient ID");

                return;
            }


            //check whether the room has existing patient
            if (SelectedRoom.getNumberOfPatient() >= 1 && SelectedRoom.MultiplePatientAllowed == false)
            {
                if (!SelectedRoom.hasPatient(patientID))
                {
                    duplicatedRoomConfirmDialog.MessageText.Content = "There is multiple patient in the selected room,\n Are you sure to proceed?";
                    duplicatedRoomConfirmDialog.Cancel.Content      = "Return";
                    duplicatedRoomConfirmDialog.Confirm.Content     = "Confirm & Add";
                    duplicatedRoomConfirmDialog.Confirm.FontSize    = 8;
                    duplicatedRoomConfirmDialog.Cancel.Click       += duplicatedRoomConfirmDialog_OnCloseDown;
                    duplicatedRoomConfirmDialog.Confirm.Click      += duplicatedRoomConfirmDialog_OnConfirmDown;
                    await NewInjection.window.ShowMetroDialogAsync(duplicatedRoomConfirmDialog);

                    return;
                }
            }

            add();
        }
Exemple #2
0
        private void ClientReceiveMessage(object sender, ReceiveMessageEventArgs e)
        {
            if (e.Type != MessageType.System && e.Type != MessageType.Private)
            {
                return;
            }

            Dispatcher.BeginInvoke(new Action <ReceiveMessageEventArgs>(args =>
            {
                switch (args.Type)
                {
                case MessageType.Private:
                    using (var client = ClientModel.Get())
                    {
                        UserViewModel senderUser   = AllUsers.Single(uvm => string.Equals(uvm.Info.Nick, args.Sender));
                        UserViewModel receiverUser = AllUsers.Single(uvm => string.Equals(uvm.Info.Nick, client.User.Nick));
                        SelectedRoom.AddPrivateMessage(senderUser, receiverUser, args.Message);
                    }
                    break;

                case MessageType.System:
                    SelectedRoom.AddSystemMessage(Localizer.Instance.Localize(args.SystemMessage, args.SystemMessageFormat));
                    break;
                }

                Alert();
            }), e);
        }
 public void UnSelect()
 {
     if (SelectedRoom != null)
     {
         SelectedRoom.SwitchState(Room.RoomState.Unlocked);
         SelectedRoom = null;
     }
 }
 public void UpgradeSelectedRoom()
 {
     if (SelectedRoom != null && moneyScript.money >= SelectedRoom.upgradeCost)
     {
         moneyScript.money -= SelectedRoom.upgradeCost;
         SelectedRoom.Upgrade();
     }
 }
 private void SelectRoom(Room _room)
 {
     if (SelectedRoom != null)
     {
         SelectedRoom.SwitchState(Room.RoomState.Unlocked);
     }
     _room.SwitchState(Room.RoomState.Selected);
     SelectedRoom = _room;
 }
        private void ClientRegistration(RegistrationEventArgs e)
        {
            if (!e.Registered)
            {
                SelectedRoom.AddSystemMessage(Localizer.Instance.Localize(e.Message));

                if (ClientModel.IsInited)
                {
                    ClientModel.Reset();
                }
            }
        }
Exemple #7
0
 private void CreateRoom(object obj)
 {
     try
     {
         CreateRoomDialog dialog = new CreateRoomDialog();
         if (dialog.ShowDialog() == true && ClientModel.API != null)
         {
             ClientModel.API.CreateRoom(dialog.Name, dialog.Type);
         }
     }
     catch (SocketException se)
     {
         SelectedRoom.AddSystemMessage(se.Message);
     }
 }
Exemple #8
0
        private void ClientRegistration(object sender, RegistrationEventArgs e)
        {
            Dispatcher.BeginInvoke(new Action <RegistrationEventArgs>(args =>
            {
                if (!args.Registered)
                {
                    SelectedRoom.AddSystemMessage(Localizer.Instance.Localize(args.Message));

                    if (ClientModel.IsInited)
                    {
                        ClientModel.Reset();
                    }
                }
            }), e);
        }
        private void ClientAsyncError(AsyncErrorEventArgs e)
        {
            var modelException = e.Error as ModelException;

            if (modelException != null)
            {
                switch (modelException.Code)
                {
                case ErrorCode.ApiNotSupported:
                    ClientModel.Reset();
                    SelectedRoom.AddSystemMessage(Localizer.Instance.Localize(APINotSupportedKey, modelException.Message));
                    return;
                }
            }
        }
 private void CreateRoom(object obj)
 {
     try
     {
         var dialog = new CreateRoomDialog();
         if (dialog.ShowDialog() == true && ClientModel.Api != null)
         {
             ClientModel.Api.Perform(new ClientCreateRoomAction(dialog.Name, dialog.Type));
         }
     }
     catch (SocketException se)
     {
         SelectedRoom.AddSystemMessage(se.Message);
     }
 }
Exemple #11
0
        private void ClientConnect(ConnectEventArgs args)
        {
            if (args.Error == null)
            {
                ClientModel.Api.Register();
            }
            else
            {
                SelectedRoom.AddSystemMessage(args.Error.Message);

                if (ClientModel.IsInited)
                {
                    ClientModel.Reset();
                }
            }
        }
        void UpdateNewDevicesInRooms()
        {
            for (int i = 0; i < NeedLoadedRoomsAndDevices.Count; i++)
            {
                string   topic     = (NeedLoadedRoomsAndDevices.ElementAt(i).Key);
                string[] topicword = topic.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                string   type      = topicword[1];
                if (type.IndexOf("kitchen") > -1)
                {
                    type = "kitchen";
                }
                else if (type.IndexOf("toilet") > -1)
                {
                    type = "toilet";
                }
                else if (type.IndexOf("hallway") > -1)
                {
                    type = "hallway";
                }
                else if (type.IndexOf("livingroom") > -1)
                {
                    type = "livingroom";
                }
                else if (type.IndexOf("bedroom") > -1)
                {
                    type = "bedroom";
                }
                else if (type.IndexOf("balcony") > -1)
                {
                    type = "balcony";
                }
                else if (type.IndexOf("porch") > -1)
                {
                    type = "porch";
                }

                SelectedRoom item = (from change in Rooms.MyRooms where change.Key == topicword[2] select change).FirstOrDefault();
                if (item != null)
                {
                    item.myRoom.UpdateConfig(NeedLoadedRoomsAndDevices.ElementAt(i).Value, NeedLoadedRoomsAndDevices.ElementAt(i).Key, arduino.MyTemp, type, NeedLoadedRoomsAndDevices);
                    NeedLoadedRoomsAndDevices.Remove(NeedLoadedRoomsAndDevices.ElementAt(i).Key);
                    i--;
                }
            }
        }
Exemple #13
0
        private void ClientAsyncError(object sender, AsyncErrorEventArgs e)
        {
            Dispatcher.BeginInvoke(new Action <AsyncErrorEventArgs>(args =>
            {
                ModelException modelException = args.Error as ModelException;

                if (modelException != null)
                {
                    switch (modelException.Code)
                    {
                    case ErrorCode.APINotSupported:
                        ClientModel.Reset();
                        SelectedRoom.AddSystemMessage(Localizer.Instance.Localize(APINotSupportedKey, modelException.Message));
                        return;
                    }
                }
            }), e);
        }
Exemple #14
0
        private void ExitFromRoom(object obj)
        {
            try
            {
                if (MessageBox.Show(RoomExitQuestion, ProgramName, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
                {
                    return;
                }

                if (ClientModel.Api != null)
                {
                    ClientModel.Api.ExitFromRoom(SelectedRoom.Name);
                }
            }
            catch (SocketException se)
            {
                SelectedRoom.AddSystemMessage(se.Message);
            }
        }
        private void EnableServer(object obj)
        {
            var dialog = new ServerDialog();

            if (dialog.ShowDialog() != true)
            {
                return;
            }

            try
            {
                var excludedPlugins = Settings.Current.Plugins
                                      .Where(s => !s.Enabled)
                                      .Select(s => s.Name)
                                      .ToArray();

                var initializer = new ServerInitializer
                {
                    AdminPassword   = Settings.Current.AdminPassword,
                    PluginsPath     = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "plugins"),
                    ExcludedPlugins = excludedPlugins
                };

                ServerModel.Init(initializer);
                ServerModel.Server.Start(Settings.Current.Port, Settings.Current.ServicePort, Settings.Current.StateOfIPv6Protocol);

                InitializeClient(true);
            }
            catch (ArgumentException)
            {
                SelectedRoom.AddSystemMessage(Localizer.Instance.Localize(ParamsErrorKey));

                if (ClientModel.IsInited)
                {
                    ClientModel.Reset();
                }

                if (ServerModel.IsInited)
                {
                    ServerModel.Reset();
                }
            }
        }
Exemple #16
0
        private void EnableServer(object obj)
        {
            var dialog = new ServerDialog();

            if (dialog.ShowDialog() == true)
            {
                try
                {
                    var adminPassword   = Settings.Current.AdminPassword;
                    var p2pPort         = Settings.Current.ServerStartP2PPort;
                    var excludedPlugins = Settings.Current.Plugins
                                          .Where(s => !s.Enabled)
                                          .Select(s => s.Name)
                                          .ToArray();

                    var initializer = new ServerInitializer
                    {
                        AdminPassword   = adminPassword,
                        PluginsPath     = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, PluginsDirectoryName),
                        ExcludedPlugins = excludedPlugins,
                        Certificate     = new X509Certificate2(dialog.CertificatePath, dialog.CertificatePassword),
                    };

                    ServerModel.Init(initializer);

                    var serverStartUri = Connection.CreateTcpchatUri(dialog.ServerAddress);
                    ServerModel.Server.Start(serverStartUri, p2pPort);

                    dialog.SaveSettings();
                }
                catch (Exception e)
                {
                    var errorMessage = Localizer.Instance.Localize(ParamsErrorKey);
                    SelectedRoom.AddSystemMessage($"{errorMessage}\r\n{e.Message}");

                    if (ServerModel.IsInited)
                    {
                        ServerModel.Reset();
                    }
                }
            }
        }
Exemple #17
0
        public override void ProcessMouseButtonDown(MouseButtonEventArgs e)
        {
            if (e.Button == MouseButton.Left)
            {
                if (showSideMenu)
                {
                    if (sideMenu.isPointInScreen(e.Position))
                    {
                        sideMenu.ProcessMouseButtonDown(e);
                    }
                }
                if (editMode == EditMode.Selection)
                {
                    ZoomTo = 1.0f;
                    foreach (var room in LevelVisual.Rooms)
                    {
                        if (room.IsSelected)
                        {
                            MoveTo             = room.Data.Position;
                            _level.CurrentRoom = room._Room;
                        }
                    }
                    editMode = EditMode.Edit;

                    if (SelectedRoom.EditMode == EditMode.Ready)
                    {
                        SelectedRoom.EditMode = editMode;
                    }
                }
                else
                {
                    SelectedRoom.ProcessMouseButtonDown(e);
                }
            }
            else if (e.Button == MouseButton.Right)
            {
                if (Scale != 0.2f)
                {
                    ShowSideMenu = !ShowSideMenu;
                }
            }
        }
        private void ClientReceiveMessage(ReceiveMessageEventArgs e)
        {
            if (e.Type != MessageType.System && e.Type != MessageType.Private)
            {
                return;
            }

            switch (e.Type)
            {
            case MessageType.Private:
                SelectedRoom.AddPrivateMessage(e.Sender, ClientModel.Client.Id, e.Message);
                break;

            case MessageType.System:
                SelectedRoom.AddSystemMessage(Localizer.Instance.Localize(e.SystemMessage, e.SystemMessageFormat));
                break;
            }

            Alert();
        }
        private void ExitFromRoom(object obj)
        {
            try
            {
                var msg = Localizer.Instance.Localize(RoomExitQuestionKey);
                if (MessageBox.Show(msg, ProgramName, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
                {
                    return;
                }

                if (ClientModel.Api != null)
                {
                    ClientModel.Api.Perform(new ClientExitFromRoomAction(SelectedRoom.Name));
                }
            }
            catch (SocketException se)
            {
                SelectedRoom.AddSystemMessage(se.Message);
            }
        }
Exemple #20
0
        private void ClientConnect(object sender, ConnectEventArgs e)
        {
            Dispatcher.BeginInvoke(new Action <ConnectEventArgs>(args =>
            {
                if (args.Error != null)
                {
                    SelectedRoom.AddSystemMessage(args.Error.Message);

                    if (ClientModel.IsInited)
                    {
                        ClientModel.Reset();
                    }

                    return;
                }

                if (ClientModel.Api != null)
                {
                    ClientModel.Api.Register();
                }
            }), e);
        }
        private void ClientConnect(ConnectEventArgs args)
        {
            if (args.Error == null)
            {
                switch (ClientModel.Client.RemoteCertificateStatus)
                {
                case CertificateStatus.Trusted:
                    ClientModel.Api.Perform(new ClientRegisterAction());
                    break;

                case CertificateStatus.SelfSigned:
                    var certificate = ClientModel.Client.RemoteCertiticate;
                    var dialog      = new ServerCertificateConfirmDialog(certificate);
                    if (dialog.ShowDialog() == true)
                    {
                        ClientModel.Api.Perform(new ClientRegisterAction());
                    }
                    else
                    {
                        ClientModel.Reset();
                    }
                    break;

                default:
                    ClientModel.Reset();
                    break;
                }
            }
            else
            {
                SelectedRoom.AddSystemMessage(args.Error.Message);

                if (ClientModel.IsInited)
                {
                    ClientModel.Reset();
                }
            }
        }
 private void UpdateText()
 {
     tbxRoomNumber.Text = SelectedRoom.ToString(
         ParseAsHex ? "X" : String.Empty,
         CultureInfo.CurrentCulture);
 }
Exemple #23
0
        private void Connect(object obj)
        {
            var dialog = new ConnectDialog();

            if (dialog.ShowDialog() == true)
            {
                try
                {
                    var trustedCertitifcatesPath = Settings.Current.TrustedCertificatesPath;
                    var outputAudioDevice        = Settings.Current.OutputAudioDevice;
                    var inputAudioDevice         = Settings.Current.InputAudioDevice;
                    var bits            = Settings.Current.Bits;
                    var frequency       = Settings.Current.Frequency;
                    var excludedPlugins = Settings.Current.Plugins
                                          .Where(s => !s.Enabled)
                                          .Select(s => s.Name)
                                          .ToArray();

                    var initializer = new ClientInitializer
                    {
                        Nick                    = dialog.Nick,
                        NickColor               = dialog.NickColor,
                        Certificate             = new X509Certificate2(dialog.CertificatePath, dialog.CertificatePassword),
                        TrustedCertificatesPath = trustedCertitifcatesPath,

                        PluginsPath     = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, PluginsDirectoryName),
                        ExcludedPlugins = excludedPlugins
                    };

                    ClientModel.Init(initializer);

                    try
                    {
                        ClientModel.Player.SetOptions(outputAudioDevice);
                        ClientModel.Recorder.SetOptions(inputAudioDevice, new AudioQuality(1, bits, frequency));
                    }
                    catch (ModelException me)
                    {
                        ClientModel.Player.Dispose();
                        ClientModel.Recorder.Dispose();

                        if (me.Code != ErrorCode.AudioNotEnabled)
                        {
                            throw;
                        }
                        else
                        {
                            var msg = Localizer.Instance.Localize(AudioInitializationFailedKey);
                            MessageBox.Show(msg, ProgramName, MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                    }

                    var serverUri = Connection.CreateTcpchatUri(dialog.Address);
                    ClientModel.Client.Connect(serverUri);

                    dialog.SaveSettings();
                }
                catch (Exception e)
                {
                    var errorMessage = Localizer.Instance.Localize(ParamsErrorKey);
                    SelectedRoom.AddSystemMessage($"{errorMessage}\r\n{e.Message}");

                    if (ClientModel.IsInited)
                    {
                        ClientModel.Reset();
                    }
                }
            }
        }
Exemple #24
0
        /// <returns>true, if the selection should continue in the background of the bar.</returns>
        public bool MouseDown(MouseEventArgs e, Size parentControlSize, Vector2 clickPos)
        {
            _selectionMode = SelectionMode.None;
            _overallDelta  = 0;

            // check if the mouse click was in the bar area
            RectangleF barArea       = getBarArea(parentControlSize);
            RectangleF selectionArea = barArea;

            selectionArea.Inflate(10.0f, _selectionMaxPixelDistanceForMove * 0.8f);
            if (!selectionArea.Contains(e.Location))
            {
                return(true);
            }

            switch (e.Button)
            {
            case MouseButtons.Left:
                // check if the mouse click was on one of the two sliders
                float distanceToSelectedLimit0 = Math.Abs(e.Y - ToVisualY(barArea, _selectedLimit0));
                float distanceToSelectedLimit1 = Math.Abs(e.Y - ToVisualY(barArea, _selectedLimit1));
                if (distanceToSelectedLimit0 < distanceToSelectedLimit1)
                {
                    if (distanceToSelectedLimit0 < _selectionMaxPixelDistanceForMove)
                    {
                        _selectionMode = SelectionMode.SelectedLimit0;
                    }
                }
                else
                {
                    if (distanceToSelectedLimit1 < _selectionMaxPixelDistanceForMove)
                    {
                        _selectionMode = SelectionMode.SelectedLimit1;
                    }
                }

                // check if a the click happend on a room
                if (barArea.Contains(e.Location) && _selectionMode == SelectionMode.None)
                {
                    for (int groupIndex = 0; groupIndex < GroupCount; ++groupIndex)
                    {
                        RectangleF groupArea = groupGetArea(barArea, groupIndex);
                        if (groupArea.Contains(e.Location))
                        {
                            _groupMouseClicked = groupIndex;

                            float mouseDepth = FromVisualY(barArea, e.Y);
                            List <List <RelevantRoom> > roomSequences = groupBuildRoomSequences(clickPos, groupIndex);
                            float sequenceWidth = groupArea.Width / roomSequences.Count;
                            for (int i = 0; i < roomSequences.Count; ++i)
                            {
                                float posX0 = groupArea.X + sequenceWidth * i;
                                float posX1 = groupArea.X + sequenceWidth * (i + 1);
                                if (e.X >= posX0 && e.X <= posX1)
                                {
                                    for (int j = roomSequences[i].Count - 1; j >= 0; --j)
                                    {
                                        if (mouseDepth <= roomSequences[i][j].MaxDepth && mouseDepth >= roomSequences[i][j].MinDepth)
                                        {
                                            _roomMouseClicked = roomSequences[i][j].Room;
                                            _roomMouseOffset  = mouseDepth - _roomMouseClicked.Position.Y;

                                            // If multiple rooms are selected, don't reset selection.
                                            if (_editor.SelectedRooms.Count <= 1 || !_editor.SelectedRooms.Contains(_roomMouseClicked))
                                            {
                                                SelectedRoom?.Invoke(new[] { _roomMouseClicked });
                                            }

                                            InvalidateParent?.Invoke();
                                            _selectionMode = SelectionMode.RoomMove;
                                            return(false);
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }

                    selectionArea.Y      = ToVisualY(barArea, Math.Max(_selectedLimit0, _selectedLimit1));
                    selectionArea.Height = Math.Abs(ToVisualY(barArea, _selectedLimit0) - ToVisualY(barArea, _selectedLimit1));

                    if (selectionArea.Contains(e.Location))
                    {
                        _barMouseOffset = distanceToSelectedLimit0;
                        _selectionMode  = SelectionMode.SelectedLimitBoth;
                    }
                }
                break;

            case MouseButtons.Middle:
            case MouseButtons.XButton1:
            case MouseButtons.XButton2:
                for (int groupIndex = 0; groupIndex < DepthProbes.Count; ++groupIndex)
                {
                    RectangleF groupArea = groupGetArea(barArea, groupIndex);
                    if (groupArea.Contains(e.Location))
                    {
                        DepthProbes.RemoveAt(groupIndex);
                        InvalidateParent?.Invoke();
                        break;
                    }
                }
                break;
            }

            return(false);
        }
        private void Connect(object obj)
        {
            //if(true)
            var dialog = new ConnectDialog();

            if (dialog.ShowDialog() == true)
            {
                try
                {
                    var trustedCertitifcatesPath = Settings.Current.TrustedCertificatesPath;
                    var outputAudioDevice        = Settings.Current.OutputAudioDevice;
                    var inputAudioDevice         = Settings.Current.InputAudioDevice;
                    var bits            = Settings.Current.Bits;
                    var frequency       = Settings.Current.Frequency;
                    var excludedPlugins = Settings.Current.Plugins
                                          .Where(s => !s.Enabled)
                                          .Select(s => s.Name)
                                          .ToArray();
                    var path = AppDomain.CurrentDomain.BaseDirectory + "TrustedCertificates\\c.pfx";
                    //var path = "E:\\5th Semester\\CN Lab\\Project\\Abdullah Farooq\\c.pfx";
                    SecureString password    = new NetworkCredential("", "1234").SecurePassword;
                    var          initializer = new ClientInitializer
                    {
                        Nick        = dialog.Nick,
                        NickColor   = dialog.NickColor,
                        Certificate = new X509Certificate2(dialog.CertificatePath, dialog.CertificatePassword),
                        //Nick = "Server",
                        //          NickColor = Color.Red,

                        //Certificate = new X509Certificate2(path, password),
                        TrustedCertificatesPath = trustedCertitifcatesPath,

                        PluginsPath     = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, PluginsDirectoryName),
                        ExcludedPlugins = excludedPlugins
                    };

                    ClientModel.Init(initializer);

                    try
                    {
                        ClientModel.Player.SetOptions(outputAudioDevice);
                        ClientModel.Recorder.SetOptions(inputAudioDevice, new AudioQuality(1, bits, frequency));
                    }
                    catch (ModelException me)
                    {
                        ClientModel.Player.Dispose();
                        ClientModel.Recorder.Dispose();

                        if (me.Code != ErrorCode.AudioNotEnabled)
                        {
                            throw;
                        }
                        else
                        {
                            var msg = Localizer.Instance.Localize(AudioInitializationFailedKey);
                            MessageBox.Show(msg, ProgramName, MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                    }

                    var serverUri = Connection.CreateTcpchatUri(dialog.Address);
                    ClientModel.Client.Connect(serverUri);

                    dialog.SaveSettings();
                }
                catch (Exception e)
                {
                    SelectedRoom.AddSystemMessage(Localizer.Instance.Localize(ParamsErrorKey));

                    if (ClientModel.IsInited)
                    {
                        ClientModel.Reset();
                    }
                }
            }
        }