/*  ---------------------------- 2D ---------------------------- */
        private void initGrid()
        {
            machineMap machines = ClientServerUtil.getInstance().getFactory();

            if (machines == null || machines.map == null)
            {
                return;
            }
            foreach (machineMapEntry machine in machines.map)
            {
                string   instanceID = machine.key;
                int      classID    = getClassIdFromItemId(instanceID);
                position pos        = machine.value;
                GridItem newItem    = new GridItem();
                Image    img        = icons.getImage(classID);
                newItem.Content = img;

#if DEBUG
                Console.WriteLine("MainWindow.initGrid: instanceID = " + instanceID);
                Console.WriteLine("MainWindow.initGrid: classID = " + classID);
#endif

                Size s = GridC.GetTileSize();
                newItem.Width      = s.Width;
                newItem.Height     = s.Height;
                newItem.Angle      = getAngleFromDirection(pos.direction);
                newItem.instanceId = instanceID;
                GridC.placeItem(newItem, pos.x, pos.y);
            }
        }
        private void SendMessage()
        {
            ClientServerUtil csu = ClientServerUtil.getInstance();

            csu.SendChatMessage(inputBox.Text);
            inputBox.Text = "";
        }
Пример #3
0
 public static ClientServerUtil getInstance()
 {
     if (instance == null)
     {
         instance = new ClientServerUtil();
     }
     return(instance);
 }
        private void SetEmptyConsumerTick()
        {
            ClientServerUtil csu       = ClientServerUtil.getInstance();
            string           machineID = grid.selectedItems[0].instanceId;
            int consumerEmptyCount     = Convert.ToInt32(ConsumerEmptyTextBox.Text);

            csu.SetEmptyConsumerTickCount(machineID, consumerEmptyCount);
        }
        /* ends here */

        private void DeleteFactoryClick(object sender, System.Windows.RoutedEventArgs e)
        {
            string           factoryString = (string)FactoryList.SelectedItem;
            int              factoryID     = getIdFromFactoryString(factoryString);
            ClientServerUtil csu           = ClientServerUtil.getInstance();

            csu.deleteFactory(factoryID);
            FactoryList.Items.Clear();
            initFactoryPulldown(csu);
        }
        private void initFactoryPulldown(ClientServerUtil loginService)
        {
            var data      = new Dictionary <int, string>();
            var factories = loginService.getFactories();

            foreach (int actId in factories.Keys)
            {
                FactoryList.Items.Add(ToString(actId, factories[actId]));
            }
        }
        private void DrehenButton_ClickRight(object sender, RoutedEventArgs e)
        {
            ClientServerUtil csu = ClientServerUtil.getInstance();

            //2D
            foreach (Client.Classes.GridItem item in GridC.SelectedItems)
            {
                csu.rotateItemRight(item.instanceId);
            }
        }
        private void LogoutEvent(object sender, System.Windows.RoutedEventArgs e)
        {
            ClientServerUtil usr = ClientServerUtil.getInstance();

            usr.logout();
            LoginPanel.IsOpen          = true;
            UsernameIfLoggedIn.Content = "";
            clearToolbox();
            clearGrid();
            clearFactoryPulldown();
        }
        private void UserInviteClick(object sender, System.Windows.RoutedEventArgs e)
        {
            var username = UserInvite.Text;

            string factoryString = (string)FactoryList.SelectedItem;
            int    factoryID     = getIdFromFactoryString(factoryString);

            ClientServerUtil csu     = ClientServerUtil.getInstance();
            String           message = csu.addMemberToMemberAccess(factoryID, username, factoryString);

            showPopUp(message);
            UserInvite.Clear();
        }
        //2D
        private void RotateUIElement(string itemId)
        {
            Console.WriteLine("MainWindow: Rotate called.");
            ClientServerUtil csu = ClientServerUtil.getInstance();
            position         p   = csu.getPosition(itemId);

            if (p != null)
            {
                int      angle = getAngleFromDirection(p.direction);
                GridItem it    = GetItemFromID(itemId);
                // Invoke ChangeTextBox with 1 parameter (TextForTextBox)
                GridC.Dispatcher.BeginInvoke(new SetAngleDelegate(it.set_angle), new object[] { angle });
            }
        }
        public void login()
        {
            int[]            scriptableIDs = null;
            ClientServerUtil csu           = ClientServerUtil.getInstance();
            bool             login         = csu.Login(username, password);

            if (login)
            {
                success = true;
                csu.RegisterInvitationMqListener(obs);
                scriptableIDs = csu.GetScriptableMachines();
            }
            LoginEvent(this, new LoginEventArgs(success, username, password, scriptableIDs));
        }
        //2D
        private void MoveUIElement(string itemId)
        {
            ClientServerUtil csu = ClientServerUtil.getInstance();
            position         p   = csu.getPosition(itemId);

            if (p != null)
            {
                GridItem it = GetItemFromID(itemId);
                // Invoke ChangeTextBox with 1 parameter (TextForTextBox)
                GridC.Dispatcher.BeginInvoke(new MoveUIElementDelegate(GridC.moveItem), new object[] { it, p.x, p.y });
                #if DEBUG
                Console.WriteLine("MoveUIElement: x = " + p.x + " und y = " + p.y);
                #endif
            }
        }
        private void CreateSimulationElement(string itemId)
        {
            ClientServerUtil csu = ClientServerUtil.getInstance();
            position         p   = csu.getPosition(itemId);

            if (p != null)
            {
                ToolboxItem toolboxItem = toolbox.Dispatcher.Invoke(new GetItemForIdDelegate(toolbox.getItemForId), new object[] { getClassIdFromItemId(itemId) }) as ToolboxItem;
                //TextBox it = GridC.Dispatcher.Invoke(new GetGridItemDelegate(GridC.getGridItem), new object[] {  }) as GridItem;
                //it.instanceId = itemId;
                //GridC.Dispatcher.BeginInvoke(new CreateSimulationElementDelegate(GridC.placeItem), new object[] { it, p.x, p.y });
                #if DEBUG
                Console.WriteLine("CreateSimulationElement: new TextBox created at x = " + p.x + " y = " + p.y);
                #endif
            }
        }
        private void NewProjectEvent(object sender, System.Windows.RoutedEventArgs e)
        {
            int    height = int.Parse(FactorySizeYInput.Text);
            int    width  = int.Parse(FactorySizeXInput.Text);
            string name   = FactoryNameInput.Text;
            int    facId  = ClientServerUtil.getInstance().createFactory(name, width, height);

            Height.Text = height.ToString();
            Width.Text  = width.ToString();

            clearFactoryPulldown();
            initFactoryPulldown(ClientServerUtil.getInstance());
            FactoryList.SelectedItem = ToString(facId, name);

            NewProjectConfigPanel.IsOpen = false;
        }
        private void UserLoginCheck(object sender, System.Windows.RoutedEventArgs e)
        {
            ClientServerUtil csu = ClientServerUtil.getInstance();

            csu.serverPc = ServerInput.Text;
            var username = UsernameInput.Text;
            var password = PasswordInput.Text;

            try
            {
                csu.login(username, password, this);
                LoginPanel.IsOpen          = false;
                UsernameIfLoggedIn.Content = "Eingeloggt als \n" + UsernameInput.Text;
                initFactoryPulldown(csu);
            }
            catch (LoginException ex)
            {
                Console.WriteLine(ex.StackTrace);
                showPopUp(ex.Message);
            }
        }
        public MainWindow()
        {
            InitializeComponent();

            //ConsoleManager.Show();

            icons          = LoadIconSet();
            this.Focusable = false;

            Width.Text  = lines.Length.ToString();
            Height.Text = lines.Width.ToString();

            grid    = new GridModel(lines.Width, lines.Length, icons);
            Loaded += new RoutedEventHandler(OnGridLoaded);

            SimulationSpeedTextBox.Text = "" + 3;
            ConsumerEmptyTextBox.Text   = "" + 0;

            DataContext       = grid;
            view.ClipToBounds = false;

            CreateToolbox();
            Hide3DGrid();

            optionWindow              = new OptionsWindow();
            optionWindow.configEvent += new EventHandler(optionWindow_configEvent);

            pluginWindow = new PluginWindow();
            pluginWindow.InitializeComboBox(icons.GetAvailablePlugins());
            pluginWindow.pluginEvent += new EventHandler(pluginWindow_pluginEvent);

            chatWindow = new ChatWindow();

            csu = ClientServerUtil.getInstance();
            csu.ClientServerEvent += new ClientServerEventHandler(csu_clientServerEvent);

            FactoryControll.IsEnabled  = false;
            LoggedInControll.IsEnabled = false;
        }
        private void FactorySelected(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            if (FactoryList.Items.Count > 0)
            {
                ClientServerUtil usr             = ClientServerUtil.getInstance(); // TODO ServerInput.Text setzen
                string           selectedFactory = (string)FactoryList.SelectedItem;
                int id = getIdFromFactoryString(selectedFactory);

                usr.connectToFactory(id);
                usr.registerFactoryMQListener(id, this);

                clearToolbox();
                initToolbox();

                // 2D
                clearGrid();
                initGrid();

                Width.Text  = usr.getAreaWidth().ToString();
                Height.Text = usr.getAreaLength().ToString();
            }
        }
        public void Update(string factory, string itemId, long publisher, string mqEvent)
        {
            Console.WriteLine("_____________MQ-Event: " + mqEvent + "______________");
            Console.WriteLine("InstanceID: " + itemId);
            Console.WriteLine("Factory: " + factory);
            Console.WriteLine("Publisher: " + publisher);

            switch (mqEvent)
            {
            case "create":
                CreateUIElement(itemId);
                break;

            case "move":
                MoveUIElement(itemId);
                break;

            case "rotate-left":
            case "rotate-right":
                RotateUIElement(itemId);
                break;

            case "delete":
                DeleteUIElement(itemId);
                break;

            case "added":
                String message = "Du wurdest erfolgreich zu " + factory + " hinzugefügt";
                this.Dispatcher.Invoke(new ShowPopUpDelegate(showPopUp), new object[] { message });
                Console.WriteLine("Regist-Nachricht beim Eingeladenen geworfen!");
                refreshFactoryPulldownAsynchron();
                break;

            case "updateProducts":
                GridC.Dispatcher.Invoke(new ClearProductsDelegate(GridC.clearProducts), new object[] { });
                this.Dispatcher.Invoke(new PopulateGridDelegate(populateGrid), new object[] { ClientServerUtil.getInstance().getProducts() });
                break;
            }
        }
        private void StartSimulationEvent(object sender, System.Windows.RoutedEventArgs e)
        {
            ClientServerUtil csu = ClientServerUtil.getInstance();

            csu.simulate();
        }
 private void refreshFactoryPulldownAsynchron()
 {
     this.Dispatcher.Invoke(new ClearFactoryPulldownDelegate(this.clearFactoryPulldown), new object[] { });
     this.Dispatcher.Invoke(new InitFactoryPulldownDelegate(this.initFactoryPulldown), new object[] { ClientServerUtil.getInstance() });
 }
        private void ProduceButtonClickEvent(object sender, System.Windows.RoutedEventArgs e)
        {
            ClientServerUtil csu = ClientServerUtil.getInstance();

            csu.produce();
        }
        protected void OnSaveButtonClicked(object sender, System.Windows.RoutedEventArgs e)
        {
            ClientServerUtil csu = ClientServerUtil.getInstance();

            csu.Save();
        }
 public static ClientServerUtil getInstance()
 {
     if (instance == null)
         instance = new ClientServerUtil();
     return instance;
 }
 private void initFactoryPulldown(ClientServerUtil loginService)
 {
     var data = new Dictionary<int, string>();
     var factories = loginService.getFactories();
     foreach (int actId in factories.Keys)
     {
         FactoryList.Items.Add(ToString(actId, factories[actId]));
     }
 }