Beispiel #1
0
 public void FindCloudletFaliure(string orgName, string appName, string appVers, double latitude, double longitude)
 {
     using (MobiledgeXIntegration mxi = new MobiledgeXIntegration(new CarrierInfoClass(), null, new UniqueIDClass(), new TestDeviceInfo()))
     {
         mxi.appName = appName;
         mxi.appVers = appVers;
         mxi.orgName = orgName;
         try
         {
             var task = Task.Run(async() =>
             {
                 mxi.useFallbackLocation = true;
                 mxi.SetFallbackLocation(longitude, latitude);
                 await RegisterHelper(mxi);
                 return(await FindCloudletHelper(mxi));
             });
         }
         catch (Exception e)
         {
             if (e.GetBaseException().GetType() == typeof(FindCloudletException))
             {
                 Assert.True(true);
             }
             else
             {
                 if (e.GetBaseException().GetType() != typeof(HttpException))
                 {
                     Assert.True(false);
                 }
             }
         }
     }
 }
Beispiel #2
0
 public void SetupEditorWindow()
 {
     settings         = Resources.Load <MobiledgeXSettings>("MobiledgeXSettings");
     mobiledgeXEditor = MobiledgeXEditorWindow.CreateInstance <MobiledgeXEditorWindow>();
     integration      = new MobiledgeXIntegration();
     mobiledgeXEditor.ShowPopup();
 }
Beispiel #3
0
 public void RegisterClientFaliure(string orgName, string appName, string appVers)
 {
     using (MobiledgeXIntegration mxi = new MobiledgeXIntegration(new CarrierInfoClass(), null, new UniqueIDClass(), new TestDeviceInfo()))
     {
         mxi.appName = appName;
         mxi.appVers = appVers;
         mxi.orgName = orgName;
         try
         {
             var task = Task.Run(async() =>
             {
                 await RegisterHelper(mxi);
             });
         }
         catch (Exception e)
         {
             if (e.GetBaseException().GetType() == typeof(HttpException))
             {
                 Assert.True(true);
             }
             else
             {
                 if (e.GetBaseException().GetType() != typeof(HttpException))
                 {
                     Assert.True(false);
                 }
             }
         }
     }
 }
Beispiel #4
0
        public async Task <bool> FindCloudletHelper(MobiledgeXIntegration mxi)
        {
            bool foundCloudlet = await mxi.FindCloudlet();

            await Task.Delay(TimeSpan.FromMilliseconds(1000));

            return(foundCloudlet);
        }
Beispiel #5
0
        public async Task <bool> RegisterHelper(MobiledgeXIntegration mxi)
        {
            bool check = await mxi.Register();

            await Task.Delay(TimeSpan.FromMilliseconds(1000));

            return(check);
        }
Beispiel #6
0
 public void RegisterClient(string orgName, string appName, string appVers)
 {
     using (MobiledgeXIntegration mxi = new MobiledgeXIntegration(new CarrierInfoClass(), null, new UniqueIDClass(), new TestDeviceInfo()))
     {
         mxi.appName = appName;
         mxi.appVers = appVers;
         mxi.orgName = orgName;
         var task = Task.Run(async() =>
         {
             return(await RegisterHelper(mxi));
         });
         Assert.True(task.Result);
     }
 }
Beispiel #7
0
 public void GetHost(string orgName, string appName, string appVers, string proto, int port)
 {
     using (MobiledgeXIntegration mxi = new MobiledgeXIntegration(new CarrierInfoClass(), null, new UniqueIDClass(), new TestDeviceInfo()))
     {
         mxi.appName = appName;
         mxi.appVers = appVers;
         mxi.orgName = orgName;
         var task = Task.Run(async() =>
         {
             return(await GetHostHelper(mxi, proto, port));
         });
         Debug.Log(task.Result);
         Assert.IsNotEmpty(task.Result);
     }
 }
Beispiel #8
0
 public void FindCloudlet(string orgName, string appName, string appVers)
 {
     using (MobiledgeXIntegration mxi = new MobiledgeXIntegration(new CarrierInfoClass(), null, new UniqueIDClass(), new TestDeviceInfo()))
     {
         mxi.appName = appName;
         mxi.appVers = appVers;
         mxi.orgName = orgName;
         var task = Task.Run(async() =>
         {
             bool registered = await RegisterHelper(mxi);
             Assert.True(registered, "Unable to register");
             return(await FindCloudletHelper(mxi));
         });
         Assert.True(task.Result);
     }
 }
Beispiel #9
0
 public void UDPTest(string orgName, string appName, string appVers, int timeOutMs)
 {
     using (MobiledgeXIntegration mxi = new MobiledgeXIntegration(new CarrierInfoClass(), null, new UniqueIDClass(), new TestDeviceInfo()))
     {
         mxi.appName = appName;
         mxi.appVers = appVers;
         mxi.orgName = orgName;
         var task = Task.Run(async() =>
         {
             string hostName = await GetHostHelper(mxi, "udp");
             MobiledgeXUDPClient udpClient = new MobiledgeXUDPClient(hostName, mxi.GetAppPort(LProto.L_PROTO_UDP).public_port);
             return(UDPMessageHelper(udpClient, "ping", timeOutMs));
         });
         Assert.True(task.Result == "pong");
     }
 }
        public void GetUrl(string orgName, string appName, string appVers, string proto, int port)
        {
            MobiledgeXIntegration mxi = new MobiledgeXIntegration(new CarrierInfoClass(), null, new UniqueIDClass(), new TestDeviceInfo());

            mxi.appName = appName;
            mxi.appVers = appVers;
            mxi.orgName = orgName;
            var task = Task.Run(async() =>
            {
                return(await GetUrlHelper(mxi, proto, port));
            });

            Debug.Log(task.Result);
            Assert.True(task.Result.Contains(proto));
            Assert.True(task.Result.Contains(port.ToString()));
        }
Beispiel #11
0
        public async Task <string> GetUrlHelper(MobiledgeXIntegration mxi, string proto, int port = 0)
        {
            bool registerCheck = await RegisterHelper(mxi);

            await Task.Delay(TimeSpan.FromMilliseconds(1000));

            if (!registerCheck)
            {
                throw new RegisterClientException("RegisterClient Failed");
            }

            bool findCloudletCheck = await FindCloudletHelper(mxi);

            await Task.Delay(TimeSpan.FromMilliseconds(1000));

            if (!findCloudletCheck)
            {
                throw new FindCloudletException("FindCloudlet Failed");
            }

            AppPort appPort;

            switch (proto)
            {
            case "udp":
                appPort = mxi.GetAppPort(LProto.L_PROTO_UDP, port);
                break;

            case "ws":
            case "wss":
            case "http":
            case "https":
            default:
                appPort = mxi.GetAppPort(LProto.L_PROTO_TCP, port);
                break;
            }

            if (appPort == null)
            {
                throw new AppPortException("AppPort Not Found");
            }

            string url = mxi.GetUrl(proto, appPort);

            return(url);
        }
        /// <summary>
        /// Performs register client to the DME confirm wether ther user provided the right fields or not
        /// </summary>
        /// <returns>boolean value</returns>
        public async Task <bool> CheckCredentials()
        {
            MobiledgeXIntegration integration = new MobiledgeXIntegration();
            bool checkResult = false;

            integration.UseWifiOnly(true);
            try
            {
                // Register and find cloudlet:
                clog("Registering to DME ...", "");
                checkResult = await integration.Register();

                bool foundCloudlet = await integration.FindCloudlet();

                if (!foundCloudlet)
                {
                    Debug.LogError("MobiledgeX: Couldn't Find findCloudletReply, Make Sure you created App Instances for your Application and they are deployed in the correct region.");
                    throw new FindCloudletException("No findCloudletReply");
                }
                return(checkResult);
            }
            catch (HttpRequestException httpre)
            {
                clog("MobiledgeX: RegisterClient HttpRequest Exception", httpre.Message + "\nStack Trace: " + httpre.StackTrace, true);
                return(false);
            }
            catch (RegisterClientException rce)
            {
                clog("MobiledgeX: RegisterClientException", rce.Message, true);
                return(false);
            }
            catch (FindCloudletException fce)
            {
                clog("MobiledgeX: Couldn't Find findCloudletReply, Make Sure you created App Instances for your Application and they are deployed in the correct region.",
                     fce.Message + "\nStack Trace: " + fce.StackTrace, true);
                return(false);
            }
            catch (Exception e)
            {
                clog("Unexpected Exception ", e.StackTrace, true);
                return(false);
            }
        }
Beispiel #13
0
 public void WebSocketTest(string orgName, string appName, string appVers, string proto, int port, int timeOutMs)
 {
     using (MobiledgeXIntegration mxi = new MobiledgeXIntegration(new CarrierInfoClass(), null, new UniqueIDClass(), new TestDeviceInfo()))
     {
         mxi.appName = appName;
         mxi.appVers = appVers;
         mxi.orgName = orgName;
         var getUrlTask = Task.Run(async() =>
         {
             return(await GetUrlHelper(mxi, proto, port));
         });
         string url = getUrlTask.Result + "/ws";
         MobiledgeXWebSocketClient wsClient = new MobiledgeXWebSocketClient();
         var sendWSMessage = Task.Run(async() =>
         {
             return(await WebsocketMessageHelper(wsClient, url, "hello", timeOutMs));
         });
         Assert.True(sendWSMessage.Result == "olleh");
     }
 }