Esempio n. 1
0
        /// <summary>
        /// Dispatcher method for using threading to accomplish work that must happen on the actual (remote) Host.
        /// Using threads to increase efficiency and reduce busy waits.  All work that requires communication
        /// with the remote host, is done on a worker thread.  Each Host has a unique thread, but the threads
        /// are throttled from a system wide standpoint, based on the number of available network drive letters.
        /// </summary>
        public void DoWork()
        {
            if (workQ.Count > 0)
            {
                WorkStatus = HostVMStatus.Working;
                HostOperations _op = workQ[0];
                workQ.RemoveAt(0);
                switch (_op)
                {
                case HostOperations.Connect:
                    CommThread = new Thread(Connect);
                    break;

                case HostOperations.Start:
                    CommThread = new Thread(startEPRs);
                    break;

                case HostOperations.Stop:
                    CommThread = new Thread(destroy);
                    break;

                case HostOperations.Clone:
                    CommThread = new Thread(clone);
                    break;

                default:
                    throw new Exception("Unknown HostOperation in DoWork: " + (int)_op);
                }
                CommThread.Start();
            }
        }
Esempio n. 2
0
        public async Task GetHostAsync_ValidParameters_ExpectedResult()
        {
            IUKFastECloudClient client = Substitute.For <IUKFastECloudClient>();

            client.GetAsync <Host>("/ecloud/v1/hosts/123").Returns(new Host()
            {
                ID = 123
            });

            var ops      = new HostOperations <Host>(client);
            var hostitem = await ops.GetHostAsync(123);

            Assert.AreEqual(123, hostitem.ID);
        }
Esempio n. 3
0
 /// <summary>
 /// Constructor. Just does LOCAL initialization.  No remote communication happens in here.
 /// </summary>
 /// <param name="pNetPath">network Path to the Remote host</param>
 /// <param name="pWork">Initial operation -- usually a Connect</param>
 /// <param name="pForce">Whether to "force" a connection.  Menas to start the remote EPR service if it is not executing</param>
 public HostVM(string pNetPath, HostOperations pWork, bool pForce)
 {
     specifiedIPs  = new List <string>();
     workQ         = new List <HostOperations>();
     EPRs          = new List <EPRInstance>();
     availProfiles = new Collection <DeviceProfile>();
     processNetPath(pNetPath);
     forceConn = pForce;
     if (pWork != HostOperations.Idle)
     {
         workQ.Add(pWork);
     }
     workStatus = WorkQ.Count > 0 ? HostVMStatus.Pending : HostVMStatus.Idle;
     CommThread = null;
 }
Esempio n. 4
0
        public async Task GetHostsAsync_ExpectedResult()
        {
            IUKFastECloudClient client = Substitute.For <IUKFastECloudClient>();

            client.GetAllAsync(Arg.Any <UKFastClient.GetPaginatedAsyncFunc <Host> >(), null).Returns(Task.Run <IList <Host> >(() =>
            {
                return(new List <Host>()
                {
                    new Host(),
                    new Host()
                });
            }));

            var ops   = new HostOperations <Host>(client);
            var hosts = await ops.GetHostsAsync();

            Assert.AreEqual(2, hosts.Count);
        }
Esempio n. 5
0
        public async Task GetHostsPaginatedAsync_ExpectedClientCall()
        {
            IUKFastECloudClient client = Substitute.For <IUKFastECloudClient>();

            client.GetPaginatedAsync <Host>("/ecloud/v1/hosts").Returns(Task.Run(() =>
            {
                return(new Paginated <Host>(client, "/ecloud/v1/hosts", null, new Response.ClientResponse <System.Collections.Generic.IList <Host> >()
                {
                    Body = new Response.ClientResponseBody <System.Collections.Generic.IList <Host> >()
                    {
                        Data = new List <Host>()
                        {
                            new Host(),
                            new Host()
                        }
                    }
                }));
            }));

            var ops       = new HostOperations <Host>(client);
            var paginated = await ops.GetHostsPaginatedAsync();

            Assert.AreEqual(2, paginated.Items.Count);
        }
Esempio n. 6
0
        public async Task GetHostAsync_InvalidHostID_ThrowsUKFastClientValidationException()
        {
            var ops = new HostOperations <Host>(null);

            await Assert.ThrowsExceptionAsync <UKFastClientValidationException>(() => ops.GetHostAsync(0));
        }