public IActionResult Index()
        {
            long idLab = 0;
            long idPc  = 0;

            try
            {
                idLab = int.Parse(HttpContext.Request.Query["lab"]);
                idPc  = int.Parse(HttpContext.Request.Query["pc"]);
            }
            catch { }

            string json = HttpContext.Session.GetString(Constants.USER);

            if (string.IsNullOrWhiteSpace(json))
            {
                return(RedirectToAction("Index", "Auth"));
            }


            var user = JsonConvert.DeserializeObject <User>(json);

            var lab = clientLab.Get(user.Id, idLab);
            var pc  = clientPc.GetById(idPc);

            if (idLab > 0 && idPc > 0)
            {
                if (pc == null)
                {
                    return(RedirectToAction("Index", "Computers"));
                }
                if (!lab.ComputerSet.Any(obj => obj.Id == pc.Id))
                {
                    if (pc == null)
                    {
                        return(RedirectToAction("Index", "Computers"));
                    }
                }
            }
            else
            {
                if (!(lab.User.Id == user.Id))
                {
                    return(RedirectToAction("Index", "Computers"));
                }
            }

            UserComputer userComputer = new UserComputer();

            userComputer.User       = user;
            userComputer.Computer   = pc ?? new Computer();
            userComputer.Laboratory = lab;
            userComputer.UrlRest    = idLab > 0 && idPc == 0 ? "http://3.94.151.158:8082/register/command/laboratory" : "http://3.94.151.158:8082/register/command";

            return(View(userComputer));
        }
Esempio n. 2
0
        public void BuildComputers()
        {
            //TODO: get with repo
            var id            = BuilderParams.ComputerId;
            var computerToUse = new Computer();

            var validityDates = GetComputerUseValidityDates();

            var userComputer = new UserComputer(computerToUse.Id, BuilderParams.UserId, validityDates.Item1, validityDates.Item2);

            this.User.Computers.Add(userComputer);
        }
Esempio n. 3
0
        private void CheckGPUStatus(object callBack, ElapsedEventArgs e)
        {
            var gpuList      = DeviceManager.GetAllGPUInformation();
            var computerName = Environment.MachineName;
            var currentUser  = Environment.UserName;
            var macAddress   = MacAddress.GetFirstMacAddress();
            var time         = DateTime.Now.ToString("dd/MM/yyyy H:mm:ss");

            var          PCID     = UserConfig == null || UserConfig.PCID.Equals("default") ? $"{computerName}-{currentUser}-{macAddress}" : UserConfig.PCID;
            UserComputer computer = new UserComputer(PCID, ServiceConfig.UserID, time, gpuList);

            HttpRequest.SendPostRequest(ServiceConfig.ServerAddress, JsonConverter.ConvertToJson(computer));
        }
Esempio n. 4
0
        private void SetupServiceSection()
        {
            //Service status
            bool isRunning = ServiceManager.CheckIfServiceRunning(SERVICE_NAME);

            if (isRunning)
            {
                this.Dispatcher.Invoke(() =>
                {
                    ServiceStatusIndicator.Fill       = new SolidColorBrush(Colors.Green);
                    ServiceStatusTextBlock.Text       = "Running";
                    ServiceStatusTextBlock.Foreground = new SolidColorBrush(Colors.Green);
                    systemTrayIcon.Icon = new Icon(SERVICE_RUNNING_ICON);
                    ToolTipsText       += "Running";
                });
            }
            else
            {
                this.Dispatcher.Invoke(() =>
                {
                    ServiceStatusIndicator.Fill       = new SolidColorBrush(Colors.Red);
                    ServiceStatusTextBlock.Text       = "Stopped";
                    ServiceStatusTextBlock.Foreground = new SolidColorBrush(Colors.Red);
                    systemTrayIcon.Icon = new Icon(SERVICE_DOWN_ICON);
                    ToolTipsText       += "Service Down";
                });
            }
            //Server
            UserComputer computer      = new UserComputer("TestingConnection", 999, "", new List <UserGPU>());
            var          returnRequest = HttpRequest.SendPostRequest(ServiceConfig.ServerAddress, JsonConverter.ConvertToJson(computer));

            if (returnRequest.Equals("OK") || returnRequest.Contains("200"))
            {
                this.Dispatcher.Invoke(() =>
                {
                    ServerStatusTextBlock.Foreground = new SolidColorBrush(Colors.Green);
                    ServerStatusTextBlock.Text       = "Online";
                });
            }
            else
            {
                this.Dispatcher.Invoke(() =>
                {
                    ServerStatusTextBlock.Foreground = new SolidColorBrush(Colors.Red);
                    ServerStatusTextBlock.Text       = "Offline";
                    systemTrayIcon.Icon = new Icon(SERVER_DOWN_ICON);
                    ToolTipsText       += "\nServer: Offine";
                });
            }

            //Internet status
            if (ConnectionStatus.IsConnected())
            {
                this.Dispatcher.Invoke(() =>
                {
                    InternetStatusTextBlock.Foreground = new SolidColorBrush(Colors.Green);
                    InternetStatusTextBlock.Text       = "Connected";
                });
            }
            else
            {
                this.Dispatcher.Invoke(() =>
                {
                    InternetStatusTextBlock.Foreground = new SolidColorBrush(Colors.Red);
                    InternetStatusTextBlock.Text       = "Disconnected";
                    systemTrayIcon.Icon = new Icon(INTERNET_DOWN_ICON);
                    ToolTipsText       += "\nInternet: Disconnected";
                });
            }
        }