Example #1
0
        // Start() is a time to do this, but can change if the device moves to a new location.
        // The return string is just an example. Your server protocol and connection strings
        // will determine the correct connection parameters.
        async Task <String> RegisterAndFindCloudlet()
        {
            // For Demo App purposes, it's the TCP app port. Your app may point somewhere else:
            NetTest.Site site;

            string aCarrierName = integration.GetCarrierName();

            clog("aCarrierName: " + aCarrierName);


            clog("Calling DME to register client...");
            bool registered = false;

            registered = await integration.Register();

            if (!registered)
            {
                clog("Exceptions, or app not found. Not Registered!");
                return(null);
            }
            else
            {
                FindCloudletReply reply;
                clog("Finding Cloudlet...");
                reply = await integration.FindCloudlet();


                // Handle reply status:
                bool found = false;
                if (reply == null)
                {
                    clog("FindCloudlet call failed.");
                    return("");
                }

                switch (reply.status)
                {
                case FindCloudletReply.FindStatus.FIND_UNKNOWN:
                    clog("FindCloudlet status unknown. No edge cloudlets.");
                    break;

                case FindCloudletReply.FindStatus.FIND_NOTFOUND:
                    clog("FindCloudlet Found no edge cloudlets in range.");
                    break;

                case FindCloudletReply.FindStatus.FIND_FOUND:
                    found = true;
                    break;
                }

                if (found)
                {
                    // Edge cloudlets found!
                    clog("Edge cloudlets found!");

                    // Where is this app specific edge enabled cloud server:
                    clog("GPS location: longitude: " + reply.cloudlet_location.longitude + ", latitude: " + reply.cloudlet_location.latitude);

                    // Where is the URI for this app specific edge enabled cloud server:
                    clog("fqdn: " + reply.fqdn);
                    // AppPorts?
                    clog("On ports: ");

                    foreach (AppPort ap in reply.ports)
                    {
                        clog("Port: proto: " + ap.proto + ", prefix: " +
                             ap.fqdn_prefix + ", path_prefix: " + ap.path_prefix + ", port: " +
                             ap.public_port);

                        // We're looking for one of the TCP app ports:
                        if (ap.proto == LProto.L_PROTO_TCP)
                        {
                            // Add to test targets.
                            if (ap.path_prefix == "")
                            {
                                site = new NetTest.Site {
                                    host = ap.fqdn_prefix + reply.fqdn,
                                    port = ap.public_port
                                };
                                site.testType = NetTest.TestType.CONNECT;
                            }
                            else
                            {
                                site = new NetTest.Site {
                                    L7Path = ap.fqdn_prefix + reply.fqdn + ":" + ap.public_port + ap.path_prefix
                                };
                                site.testType = NetTest.TestType.CONNECT;
                            }
                            if (useAltServer)
                            {
                                site.host = host;
                            }
                            port      = site.port;
                            l7Path    = site.L7Path;
                            site.host = "mextest-app-cluster.frankfurt-main.tdg.mobiledgex.net";
                            integration.netTest.sites.Enqueue(site);
                        }
                    }
                    integration.netTest.doTest(true);
                }
            }

            // The WebSocket URI:
            return(host + ":" + port);
        }
    async Task SceneFlow()
    {
        // Register Client
        edgeConnectionSteps.gameObject.SetActive(true);
        edgeConnectionSteps.registerClientStep.GetComponentInChildren <Image>().enabled = true;
        await Task.Delay(TimeSpan.FromSeconds(3));

        edgeConnectionSteps.gameObject.SetActive(false);
        statusText.text = "Register Client";
        infoText.text   = InfoText(step);
        while (statusAnimator.GetInteger("Step") != 1)
        {
            await Task.Delay(TimeSpan.FromSeconds(.1));
        }
        nextButton.interactable = false;
        mxi = new MobiledgeXIntegration();
        try
        {
            statusText.text = "Register Client\n <b> Org Name:</b> " + settings.orgName + "\n <b>App Name:</b> " + settings.appName + "\n <b>App Version:</b> " + settings.appVers;
            await mxi.Register();

            await Task.Delay(TimeSpan.FromSeconds(2));

            statusAnimator.SetTrigger("Start");
            await Task.Delay(TimeSpan.FromSeconds(.1));

            statusText.color = Color.green;
            detailedInfoButton.gameObject.SetActive(true);
            detailedStatusText.text = "Register Client Status : " + mxi.RegisterStatus;
            statusText.text         = "Verified";
        }
        catch (RegisterClientException)
        {
            statusText.text = "Failed to verify";
            errorPanel.SetActive(true);
            errorText.text = "Restart, Error in RegisterClient, check Console for more details";
            return;
        }
        statusAnimator.SetTrigger("End");
        await Task.Delay(TimeSpan.FromSeconds(2));

        nextButton.interactable = true;
        while (statusAnimator.GetInteger("Step") != 2)
        {
            await Task.Delay(TimeSpan.FromSeconds(.1));
        }
        edgeConnectionSteps.registerClientStep.GetComponentInChildren <Image>().enabled = false;
        edgeConnectionSteps.findCloudletStep.GetComponentInChildren <Image>().enabled   = true;
        edgeConnectionSteps.gameObject.SetActive(true);
        await Task.Delay(TimeSpan.FromSeconds(3));

        edgeConnectionSteps.gameObject.SetActive(false);

        detailedInfoButton.gameObject.SetActive(false);
        nextButton.interactable = false;
        statusAnimator.SetTrigger("Reset");
        statusText.color = Color.black;
        statusText.text  = "";
        await Task.Delay(TimeSpan.FromSeconds(1.5));



        // Find Cloudlet
        statusText.text = "Find Cloudlet";
        await Task.Delay(TimeSpan.FromSeconds(1));

        statusAnimator.SetTrigger("Start");
        try
        {
            await mxi.FindCloudlet();


            string portsString = "<b>Ports:</b>";
            foreach (AppPort appPort in mxi.FindCloudletReply.ports)
            {
                portsString += "\n Port : (" + appPort.proto + ") " + appPort.public_port;
            }
            FindCloudletReply findCloudletReply = mxi.FindCloudletReply;
            detailedStatusText.text = "<b>FindCloudlet Status:</b> " + findCloudletReply.status +
                                      "\n<b>Cloudlet Location:</b> " + findCloudletReply.cloudlet_location.longitude + ", " + findCloudletReply.cloudlet_location.latitude
                                      + "\n<b>Application URL:</b> " + findCloudletReply.fqdn + "\n" + portsString;

            detailedInfoButton.gameObject.SetActive(true);
            planeAnimator.gameObject.GetComponent <MeshRenderer>().material.SetFloat("Alpha", 1);
            cameraAniamtor.SetTrigger("CameraMove");
            await Task.Delay(TimeSpan.FromSeconds(1));

            planeAnimator.enabled   = true;
            nextButton.interactable = true;
            while (statusAnimator.GetInteger("Step") != 3)
            {
                await Task.Delay(TimeSpan.FromSeconds(.1));
            }
            nextButton.interactable = false;
            await Task.Delay(TimeSpan.FromSeconds(1));

            cameraAniamtor.SetTrigger("CameraBack");
            await Task.Delay(TimeSpan.FromSeconds(1));

            planeAnimator.gameObject.SetActive(false);
            statusText.text = "Cloudlet Found";
        }
        catch (FindCloudletException)
        {
            errorPanel.SetActive(true);
            errorText.text = "Restart, Error in FindCloudlet, check Console for more details";
            return;
        }
        statusAnimator.SetTrigger("End");
        await Task.Delay(TimeSpan.FromSeconds(2));

        statusAnimator.SetTrigger("Reset");
        detailedInfoButton.gameObject.SetActive(false);
        statusText.text = "";
        await Task.Delay(TimeSpan.FromSeconds(1.5));


        //  GetAppPort
        edgeConnectionSteps.findCloudletStep.GetComponentInChildren <Image>().enabled = false;
        edgeConnectionSteps.getAppPortStep.GetComponentInChildren <Image>().enabled   = true;
        edgeConnectionSteps.gameObject.SetActive(true);
        await Task.Delay(TimeSpan.FromSeconds(3));

        edgeConnectionSteps.gameObject.SetActive(false);
        statusText.text         = "Connect to the desired port";
        nextButton.interactable = true;
        while (statusAnimator.GetInteger("Step") != 4)
        {
            await Task.Delay(TimeSpan.FromSeconds(.1));
        }
        statusText.text = "Select The desired protocol";
        while (statusAnimator.GetInteger("Step") != 5)
        {
            await Task.Delay(TimeSpan.FromSeconds(.1));
        }
        nextButton.interactable = false;
        await Task.Delay(TimeSpan.FromSeconds(1.5));

        statusAnimator.SetTrigger("Start");
        cameraAniamtor.SetTrigger("CameraMove");
        await Task.Delay(TimeSpan.FromSeconds(1));

        protoPanel.SetActive(true);
        await Task.Delay(TimeSpan.FromSeconds(1.5));

        nextButton.interactable = false;
        while (statusAnimator.GetInteger("Step") != 6)
        {
            await Task.Delay(TimeSpan.FromSeconds(.1));
        }
        protoPanel.SetActive(false);
        nextButton.interactable = false;
        cameraAniamtor.SetTrigger("CameraBack");
        await Task.Delay(TimeSpan.FromSeconds(2));

        statusText.text = "Port Found";
        statusAnimator.SetTrigger("End");
        await Task.Delay(TimeSpan.FromSeconds(1.5));

        statusAnimator.SetTrigger("Reset");


        // GetUrl
        edgeConnectionSteps.getAppPortStep.GetComponentInChildren <Image>().enabled = false;
        edgeConnectionSteps.getUrlStep.GetComponentInChildren <Image>().enabled     = true;
        edgeConnectionSteps.gameObject.SetActive(true);
        await Task.Delay(TimeSpan.FromSeconds(3));

        edgeConnectionSteps.gameObject.SetActive(false);
        await Task.Delay(TimeSpan.FromSeconds(1));

        statusText.text = "";
        IncrementStep();
        cameraAniamtor.SetTrigger("CameraMove");
        await Task.Delay(TimeSpan.FromSeconds(1));

        L7protoPanel.SetActive(true);
        List <RectTransform> L7protos = (L7protoPanel.transform as RectTransform).Cast <RectTransform>().ToList();

        switch (selectedProto)
        {
        case LProto.L_PROTO_HTTP:
            L7protos.Find(proto => proto.gameObject.name == "TCP").gameObject.SetActive(false);
            L7protos.Find(proto => proto.gameObject.name == "WebSocket").gameObject.SetActive(false);
            L7protos.Find(proto => proto.gameObject.name == "UDP").gameObject.SetActive(false);
            break;

        case LProto.L_PROTO_TCP:
            L7protos.Find(proto => proto.gameObject.name == "UDP").gameObject.SetActive(false);
            L7protos.Find(proto => proto.gameObject.name == "HTTP").gameObject.SetActive(false);
            break;

        case LProto.L_PROTO_UDP:
            L7protos.Find(proto => proto.gameObject.name == "TCP").gameObject.SetActive(false);
            L7protos.Find(proto => proto.gameObject.name == "WebSocket").gameObject.SetActive(false);
            L7protos.Find(proto => proto.gameObject.name == "HTTP").gameObject.SetActive(false);
            break;
        }

        while (statusAnimator.GetInteger("Step") != 8)
        {
            await Task.Delay(TimeSpan.FromSeconds(.1));
        }
        L7protoPanel.SetActive(false);

        cameraAniamtor.SetTrigger("CameraBack");
        await Task.Delay(TimeSpan.FromSeconds(1));

        statusText.text = "Connected";
        connectedParticleEffect.SetActive(true);
        detailedInfoButton.gameObject.SetActive(true);
        detailedStatusText.text = "GetUrl(\"" + selectedL7Proto + "\"):\n" + url;
        loadingBall.enabled     = true;
    }
Example #3
0
        // Start() is a time to do this, but can change if the device moves to a new location.
        async Task <string> RegisterAndFindCloudlet()
        {
            // For Demo App purposes, it's the TCP app port. Your app may point somewhere else:
            string tcpAppPort = "";

            NetTest.HostAndPort hostAndPort = null;

            string aCarrierName = integration.GetCarrierName();

            clog("aCarrierName: " + aCarrierName);


            clog("Calling DME to register client...");
            bool registered = false;

            registered = await integration.Register();

            if (registered)
            {
                FindCloudletReply reply;
                clog("Finding Cloudlet...");
                reply = await integration.FindCloudlet();


                // Handle reply status:
                bool found = false;
                if (reply == null)
                {
                    clog("FindCloudlet call failed.");
                    return("");
                }

                switch (reply.status)
                {
                case FindCloudletReply.FindStatus.FIND_UNKNOWN:
                    clog("FindCloudlet status unknown. No edge cloudlets.");
                    break;

                case FindCloudletReply.FindStatus.FIND_NOTFOUND:
                    clog("FindCloudlet Found no edge cloudlets in range.");
                    break;

                case FindCloudletReply.FindStatus.FIND_FOUND:
                    found = true;
                    break;
                }

                if (found)
                {
                    // Edge cloudlets found!
                    clog("Edge cloudlets found!");

                    // Where is this app specific edge enabled cloud server:
                    clog("GPS location: longitude: " + reply.cloudlet_location.longitude + ", latitude: " + reply.cloudlet_location.latitude);

                    // Where is the URI for this app specific edge enabled cloud server:
                    clog("fqdn: " + reply.fqdn);
                    // AppPorts?
                    Debug.Log("On ports: ");

                    foreach (AppPort ap in reply.ports)
                    {
                        clog("Port: proto: " + ap.proto + ", prefix: " +
                             ap.fqdn_prefix + ", path_prefix: " + ap.path_prefix + ", port: " +
                             ap.public_port);

                        // We're looking for one of the TCP app ports:
                        if (ap.proto == LProto.L_PROTO_TCP)
                        {
                            tcpAppPort = reply.fqdn + ":" + ap.public_port;
                            // FQDN prefix to append to base FQDN in FindCloudlet response. May be empty.
                            if (ap.fqdn_prefix != "")
                            {
                                tcpAppPort = ap.fqdn_prefix + tcpAppPort;
                            }

                            // Add to test targets.
                            hostAndPort = new NetTest.HostAndPort {
                                host = ap.fqdn_prefix + reply.fqdn, port = ap.public_port
                            };
                            netTest.sites.Enqueue(hostAndPort);
                        }
                    }
                }
                clog("FindCloudlet found: [" + tcpAppPort + "]");
            }

            return(tcpAppPort);
        }