public async void GetCPUsFromDatabaseTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetCpusFromDatabase")
                          .Options;
            var cpu = new Cpus {
                Name = "test name", Speed = "3.6 Ghtz", Cores = 6, Price = 413.99M
            };
            List <Cpu> listofcpus = null;

            using (var context = new CheapWareContext(options))
            {
                context.Add(cpu);
                context.SaveChanges();
            }

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                listofcpus = await service.GetCpus();
            }


            using (var context = new CheapWareContext(options))
            {
                Assert.Single(listofcpus);
                Assert.Equal("test name", context.Cpus.Single().Name);
            }
        }
        public async void GetCpusByNameTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetComputerCaseByNameDatabase")
                          .Options;
            var cpu1 = new Cpus {
                Name = "test name1", Cores = 4, Speed = "3.4Ghz", Price = 90.99M
            };
            var cpu2 = new Cpus {
                Name = "test name2", Cores = 4, Speed = "3.6Ghz", Price = 100.99M
            };


            Cpu cpu = null;

            using (var context = new CheapWareContext(options))
            {
                context.Add(cpu1);
                context.Add(cpu2);
                context.SaveChanges();
            }

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                cpu = await service.GetCpuByName("test name1");
            }

            using (var context = new CheapWareContext(options))
            {
                Assert.Equal(4, cpu.Cores);
                Assert.Equal("3.4Ghz", cpu.Speed);
                Assert.Equal(90.99M, cpu.Price);
            }
        }
Exemple #3
0
        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendLine($"Computer type: {Name}");
            builder.AppendLine("Current configuration:");
            builder.AppendLine($"   CPU: {Cpus.ToStatus()}");
            builder.AppendLine($"   Storage: {Hards.ToStatus()}");
            builder.AppendLine($"   RAM: {Rams.ToStatus()}");
            builder.AppendLine($"   GPU: {Gpus.ToStatus()}");
            builder.AppendLine($"   Network: {Networks.ToStatus()}");
            builder.AppendLine($"   Wireless: {Wirelesses.ToStatus()}");
            builder.AppendLine($"   Sources: {Sources.ToStatus()}");
            builder.AppendLine($"   Motherboard: {Motherboard}");

            string motherboardLoad = GetMotherboardLoadString();

            builder.AppendLine($"Motherboard configuration: {motherboardLoad}");

            int   currentLoad    = GetSourceLoad();
            int   maximumLoad    = MaximumSourceLoad();
            float percentageLoad = (float)currentLoad / maximumLoad;

            builder.AppendLine($"Current source load: {currentLoad}/{maximumLoad} - {percentageLoad:00.##}");

            return(builder.ToString());
        }
Exemple #4
0
 private int GetSourceLoad()
 {
     return(Rams.Select(x => x.LoadUsage).Sum() +
            Hards.Select(x => x.LoadUsage).Sum() +
            Cpus.Select(x => x.LoadUsage).Sum() +
            Gpus.Select(x => x.LoadUsage).Sum() +
            Networks.Select(x => x.LoadUsage).Sum() +
            Wirelesses.Select(x => x.LoadUsage).Sum() +
            Motherboard.LoadUsage);
 }
        public async Task <ActionResult> Details(string name)
        {
            var request = CreateRequestToService(HttpMethod.Get, "api/cpus/" + name);

            try
            {
                var response = await HttpClient.SendAsync(request);

                if (!response.IsSuccessStatusCode)
                {
                    TempData["statuscode"] = response.StatusCode;
                    return(View("Error"));
                }
                string jsonString = await response.Content.ReadAsStringAsync();

                Cpus cpu = JsonConvert.DeserializeObject <Cpus>(jsonString);

                return(View(cpu));
            }
            catch (HttpRequestException)
            {
                return(View("Error"));
            }
        }
        /// <summary>
        ///   Renders the argument string from this instance.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            var sb = new StringBuilder();

            // Container identification
            sb.OptionIfExists("--name ", Name);
            sb.OptionIfExists("--pid=", Pid);
            sb.OptionIfExists("--uts=", Uts);
            sb.OptionIfExists("--ipc=", Ipc);
            if (!string.IsNullOrWhiteSpace(CidFile))
            {
                sb.Append($" --cidfile=\"{CidFile}\"");
            }

            if (null != HostIpMappings && 0 != HostIpMappings.Count)
            {
                sb.Append(" --add-host=");
                foreach (var mapping in HostIpMappings)
                {
                    sb.Append($"--add-host={mapping.Item1}:{mapping.Item2}");
                }
            }

            if (Ulimit.Count > 0)
            {
                foreach (var ulimit in Ulimit)
                {
                    sb.Append($" --ulimit {ulimit}");
                }
            }

            // Block IO bandwidth (Blkio) constraint
            if (null != BlockIoWeight)
            {
                sb.Append($" --blkio-weight {BlockIoWeight.Value}");
            }
            sb.OptionIfExists("--blkio-weight-device=", BlockIoWeightDevices);
            sb.OptionIfExists("--device-read-bps ", DeviceReadBps);
            sb.OptionIfExists("--device-read-iops=", DeviceReadIops);
            sb.OptionIfExists("--device-write-bps=", DeviceWriteBps);
            sb.OptionIfExists("--device-write-iops=", DeviceWriteIops);

            // Runtime privilege and Linux capabilities
            sb.OptionIfExists("--cap-add=", CapabilitiesToAdd);
            sb.OptionIfExists("--cap-drop=", CapabilitiesToRemove);
            if (Privileged)
            {
                sb.Append(" --privileged");
            }
            sb.OptionIfExists("--device=", Device);

            // Network settings
            sb.OptionIfExists("--dns=", Dns);
            sb.OptionIfExists("--dns-opt=", DnsOpt);
            sb.OptionIfExists("--dns-search=", DnsSearch);
            sb.OptionIfExists("--hostname ", Hostname);
            if (!PublishAllPorts)
            {
                sb.OptionIfExists("-p ", PortMappings);
            }
            else
            {
                sb.Append(" -P");
            }

            // Native health check
            sb.OptionIfExists("--health-cmd=", HealthCheckCmd);
            sb.OptionIfExists("--health-interval=", HealthCheckInterval);
            sb.OptionIfExists("--health-timeout=", HealthCheckTimeout);
            sb.OptionIfExists("--health-start-period=", HealthCheckStartPeriod);
            sb.OptionIfExists("--no-healthcheck", HealthCheckDisabled);

            if (HealthCheckRetries > 0)
            {
                sb.Append($" --health-retries={HealthCheckRetries}");
            }


            sb.OptionIfExists("--cgroup-parent ", ParentCGroup);
            sb.OptionIfExists("-e ", Environment);
            sb.OptionIfExists("--env-file=", EnvironmentFiles);

            if (Interactive)
            {
                sb.Append(" -i");
            }

            if (Tty)
            {
                sb.Append(" -t");
            }

            sb.OptionIfExists("-u ", AsUser);

            if (AutoRemoveContainer)
            {
                sb.Append(" --rm");
            }

            sb.OptionIfExists("-v ", Volumes);
            sb.OptionIfExists("--volume-driver ", VolumeDriver);
            sb.OptionIfExists("--volumes-from=", VolumesFrom);
            sb.OptionIfExists("-w ", WorkingDirectory);

            sb.OptionIfExists("--link=", Links);
            sb.OptionIfExists("-l ", Labels);
            sb.OptionIfExists("--group-add=", Groups);
            sb.OptionIfExists("--network ", Network);
            sb.OptionIfExists("--ip ", Ipv4);
            sb.OptionIfExists("--ip6 ", Ipv6);

            if (RestartPolicy.No != RestartPolicy)
            {
                switch (RestartPolicy)
                {
                case RestartPolicy.Always:
                    sb.Append(" --restart always");
                    break;

                case RestartPolicy.OnFailure:
                    sb.Append(" --restart on-failure");
                    break;

                case RestartPolicy.UnlessStopped:
                    sb.Append(" --restart unless-stopped");
                    break;

                default:
                    sb.Append(" --restart no");
                    break;
                }
            }

            // Memory management
            sb.SizeOptionIfValid("--memory=", Memory, 4 * 1024 * 1024 /*4m*/);
            sb.SizeOptionIfValid("--memory-swap=", MemorySwap);
            sb.OptionIfExists("--memory-swappiness=", MemorySwappiness);
            sb.SizeOptionIfValid("--memory-reservation=", MemoryReservation);
            sb.SizeOptionIfValid("--kernel-memory=", KernelMemory);
            if (OomKillDisable)
            {
                sb.Append(" --oom-kill-disable");
            }

            // Cpu management
            if (!Cpus.IsApproximatelyEqualTo(float.MinValue))
            {
                sb.Append($" --cpus=\"{Cpus}\"");
            }
            sb.OptionIfExists("--cpuset-cpus=", CpusetCpus);
            if (CpuShares != int.MinValue)
            {
                sb.Append($" --cpu-shares=\"{CpuShares}\"");
            }

            // Runtime
            if (Runtime != ContainerRuntime.Default)
            {
                sb.Append($" --runtime={Runtime.ToString().ToLower()}");
            }

            var isolation = Isolation.ToDocker();

            if (null != isolation)
            {
                sb.Append($" --isolation {Isolation.ToDocker()}");
            }
            return(sb.ToString());
        }
Exemple #7
0
 public Environment DeepClone()
 {
     return(new Environment(Cpus.Select(x => x.DeepClone()).ToArray()));
 }
Exemple #8
0
 public void Initialize() => Cpus.ForEach(x => x.Initialize());