Exemple #1
0
        public void CountEmployees()
        {
            Console.Clear();
            Console.WriteLine("Count workers:" + " " + Workers.Count() + "\nCount managers: " + " " + Managers.Count() + "\nCount taskmasters:" + " " + Taskmasters.Count());
            var sum = Workers.Count() + Managers.Count() + Taskmasters.Count();

            Console.WriteLine("\nAll employees" + " " + sum);
        }
 internal string GetDefaultName()
 {
     if (!Habitat.isCyclops)
     {
         var amount = Managers.Count(manager => manager.Habitat != null && !manager.Habitat.isCyclops);
         return($"Base {amount}");
     }
     else
     {
         var amount = Managers.Count(manager => manager.Habitat != null && manager.Habitat.isCyclops);
         return($"Cyclops Base {amount}");
     }
 }
Exemple #3
0
        public void MainLoop()
        {
            Menu();
            string selection = "m";
            bool   loop      = true;

            do
            {
                selection = Console.ReadLine();
                switch (selection)
                {
                case "a":
                case "A":
                    Managers = (List <Manager>)LoadTableFromCsv <Manager>("Manager");
                    MiscUtility.WriteLineFormatted($"Added {Managers.Count()} managers onto the stack.\n", ConsoleColor.Green);
                    break;

                case "b":
                case "B":
                    try
                    {
                        MiscUtility.WriteLineFormatted($"Inserted {InsertManagers()} records into the database.", ConsoleColor.Green);
                    }
                    catch (SqlException e)
                    {
                        MiscUtility.WriteLineFormatted(e.Message, ConsoleColor.Red);
                    }
                    break;

                case "c":
                case "C":
                    Orders = (List <Order>)LoadTableFromCsv <Order>("Order");
                    MiscUtility.WriteLineFormatted($"Added {Orders.Count()} orders onto the stack.\n", ConsoleColor.Green);
                    break;

                case "d":
                case "D":
                    try
                    {
                        MiscUtility.WriteLineFormatted($"Inserted {InsertOrders()} records into the database.", ConsoleColor.Green);
                    }
                    catch (SqlException e)
                    {
                        MiscUtility.WriteLineFormatted(e.Message, ConsoleColor.Red);
                    }
                    break;

                case "e":
                case "E":
                    Returns = (List <Return>)LoadTableFromCsv <Return>("Return");
                    MiscUtility.WriteLineFormatted($"Added {Returns.Count()} orders onto the stack.\n", ConsoleColor.Green);
                    break;

                case "f":
                case "F":
                    try
                    {
                        MiscUtility.WriteLineFormatted($"Inserted {InsertReturns()} records into the database.", ConsoleColor.Green);
                    }
                    catch (SqlException e)
                    {
                        MiscUtility.WriteLineFormatted(e.Message, ConsoleColor.Red);
                    }
                    break;

                case "m":
                case "M":
                    Menu();
                    break;

                case "q":
                case "Q":
                    loop = false;
                    break;

                default:
                    Console.WriteLine("Invalid selection.\n");
                    Menu();
                    break;
                }
                Console.WriteLine();
            } while (loop);
        }
Exemple #4
0
        public void Validate()
        {
            Provisioner = Provisioner ?? defaultProvisioner;
            DrivePrefix = DrivePrefix ?? defaultDrivePrefix;
            Setup       = Setup ?? new SetupOptions();
            Hosting     = Hosting ?? new HostingOptions();
            Vpn         = Vpn ?? new VpnOptions();
            HiveNode    = HiveNode ?? new HiveNodeOptions();
            Docker      = Docker ?? new DockerOptions();
            Image       = Image ?? new ImageOptions();
            Network     = Network ?? new NetworkOptions();
            Consul      = Consul ?? new ConsulOptions();
            Vault       = Vault ?? new VaultOptions();
            Log         = Log ?? new LogOptions();
            Dashboard   = Dashboard ?? new DashboardOptions();
            HiveFS      = HiveFS ?? new HiveFSOptions();
            Proxy       = Proxy ?? new ProxyOptions();
            HiveMQ      = HiveMQ ?? new HiveMQOptions();

            Setup.Validate(this);
            Network.Validate(this);
            Hosting.Validate(this);
            Vpn.Validate(this);
            HiveNode.Validate(this);
            Docker.Validate(this);
            Image.Validate(this);
            Consul.Validate(this);
            Vault.Validate(this);
            Log.Validate(this);
            Dashboard.Validate(this);
            HiveFS.Validate(this);
            Proxy.Validate(this);
            HiveMQ.Validate(this);

            new HostingManagerFactory().Validate(this);

            if (TimeSources == null || TimeSources.Length == 0 || TimeSources.Count(ts => string.IsNullOrWhiteSpace(ts)) > 0)
            {
                TimeSources = new string[] { "pool.ntp.org" };
            }

            if (NodeDefinitions == null || NodeDefinitions.Count == 0)
            {
                throw new HiveDefinitionException("At least one hive node must be defined.");
            }

            foreach (var node in NodeDefinitions.Values)
            {
                node.Validate(this);
            }

            if (Name == null)
            {
                throw new HiveDefinitionException($"The [{nameof(HiveDefinition)}.{nameof(Name)}] property is required.");
            }

            if (!IsValidName(Name))
            {
                throw new HiveDefinitionException($"The [{nameof(HiveDefinition)}.{nameof(Name)}={Name}] property is not valid.  Only letters, numbers, periods, dashes, and underscores are allowed.");
            }

            if (Datacenter == null)
            {
                throw new HiveDefinitionException($"The [{nameof(HiveDefinition)}.{nameof(Datacenter)}] property is required.");
            }

            if (!IsValidName(Datacenter))
            {
                throw new HiveDefinitionException($"The [{nameof(HiveDefinition)}.{nameof(Datacenter)}={Datacenter}] property is not valid.  Only letters, numbers, periods, dashes, and underscores are allowed.");
            }

            if (!string.IsNullOrEmpty(PackageProxy))
            {
                var packageCacheUris = PackageProxy.Split(',');

                for (int i = 0; i < packageCacheUris.Length; i++)
                {
                    packageCacheUris[i] = packageCacheUris[i].Trim();

                    if (!Uri.TryCreate(packageCacheUris[i], UriKind.Absolute, out var aptProxyUri))
                    {
                        throw new HiveDefinitionException($"The [{nameof(HiveDefinition)}.{nameof(PackageProxy)}={PackageProxy}] includes [{packageCacheUris[i]}] which is not a valid URI.");
                    }

                    if (aptProxyUri.Scheme != "http")
                    {
                        throw new HiveDefinitionException($"The [{nameof(HiveDefinition)}.{nameof(PackageProxy)}={PackageProxy}] includes [{packageCacheUris[i]}] which does not have the [http] scheme.");
                    }
                }
            }

            var managementNodeCount = Managers.Count();

            if (managementNodeCount == 0)
            {
                throw new HiveDefinitionException("Hives must have at least one management node.");
            }
            else if (managementNodeCount > 5)
            {
                throw new HiveDefinitionException("Hives may not have more than [5] management nodes.");
            }
            else if (!NeonHelper.IsOdd(managementNodeCount))
            {
                throw new HiveDefinitionException("Hives must have an odd number of management nodes: [1, 3, or 5]");
            }

            // Ensure that each node has a valid unique or NULL IP address.

            NetworkCidr nodesSubnet   = null;
            NetworkCidr vpnPoolSubnet = null;

            if (Network.NodesSubnet != null)
            {
                nodesSubnet = NetworkCidr.Parse(Network.NodesSubnet);
            }

            if (Vpn.Enabled)
            {
                vpnPoolSubnet = NetworkCidr.Parse(Network.VpnPoolSubnet);
            }

            var addressToNode = new Dictionary <string, NodeDefinition>();

            foreach (var node in SortedNodes)
            {
                if (node.PrivateAddress != null)
                {
                    NodeDefinition conflictNode;

                    if (addressToNode.TryGetValue(node.PrivateAddress, out conflictNode))
                    {
                        throw new HiveDefinitionException($"Node [name={node.Name}] has invalid private IP address [{node.PrivateAddress}] that conflicts with node [name={conflictNode.Name}].");
                    }
                }
            }

            foreach (var node in SortedNodes)
            {
                if (node.PrivateAddress != null)
                {
                    if (!IPAddress.TryParse(node.PrivateAddress, out var address))
                    {
                        throw new HiveDefinitionException($"Node [name={node.Name}] has invalid private IP address [{node.PrivateAddress}].");
                    }

                    if (vpnPoolSubnet != null && vpnPoolSubnet.Contains(address))
                    {
                        throw new HiveDefinitionException($"Node [name={node.Name}] has private IP address [{node.PrivateAddress}] within the hosting [{nameof(Network.VpnPoolSubnet)}={Network.VpnPoolSubnet}].");
                    }

                    if (nodesSubnet != null && !nodesSubnet.Contains(address))
                    {
                        throw new HiveDefinitionException($"Node [name={node.Name}] has private IP address [{node.PrivateAddress}] that is not within the hosting [{nameof(Network.NodesSubnet)}={Network.NodesSubnet}].");
                    }
                }
                else if (!Hosting.IsCloudProvider)
                {
                    throw new HiveDefinitionException($"Node [name={node.Name}] is not assigned a private IP address.  This is required when deploying to a [{nameof(Environment)}={Environment}] hosting environment.");
                }
            }

            // Verify that we have nodes identified for persisting log data if logging is enabled.

            if (Log.Enabled)
            {
                if (Nodes.Where(n => n.Labels.LogEsData).Count() == 0)
                {
                    throw new HiveDefinitionException($"At least one node must be configured to store log data by setting [{nameof(NodeDefinition.Labels)}.{nameof(NodeLabels.LogEsData)}=true] when hive logging is enabled.");
                }
            }
        }