Exemplo n.º 1
0
    void OnGUI()
    {
        if (!this.loggedin)
        {
            this.email = GUI.TextField(new Rect(10, 10, 800, 100), this.email);
            GUI.Label(new Rect(10, 220, 500, 1000), this.message);
            if (GUI.Button(new Rect(10, 115, 250, 100), "Create User"))
            {
                try
                {
                    KiiUser user = KiiUser.BuilderWithEmail(this.email).WithName("U" + Environment.TickCount).Build();
                    user.Register("pa$$sword");
                    this.message  = "SUCCESS";
                    this.loggedin = true;
                    this.message  = "";
                }
                catch (KiiCorp.Cloud.Storage.NetworkException e)
                {
                    this.message = "ERROR: " + e.GetType() + "\n" +
                                   "Status=" + e.Status + "\n" +
                                   "Data=" + e.Data.ToString() + "\n" +
                                   "InnerExcepton=" + e.InnerException.GetType() + "\n" +
                                   "InnerExcepton.Message=" + e.InnerException.Message + "\n" +
                                   "InnerExcepton.Stacktrace=" + e.InnerException.StackTrace + "\n" +
                                   "Source=" + e.Source + "\n" +
                                   e.Message + "\n" + e.StackTrace;
                }
                catch (Exception e)
                {
                    this.message = "ERROR: " + e.GetType() + " " + e.Message + "\n" + e.StackTrace;
                }
            }
        }
        else
        {
            GUI.Label(new Rect(10, 220, 500, 1000), message);
            try
            {
                if (this.experiment == null)
                {
                    this.experiment       = KiiExperiment.GetByID("8a835c5b-3508-41a9-9a7e-a348c513a426");
                    this.appliedVariation = experiment.GetAppliedVariation(experiment.Variations[0]);
                    ConversionEvent viewCnvEvent = this.experiment.GetConversionEventByName("viewed");
                    KiiEvent        viewKiiEvent = this.appliedVariation.EventForConversion(viewCnvEvent);
                    KiiAnalytics.Upload(viewKiiEvent);
                }
                if (this.buttonCaption == null)
                {
                    JsonObject json = this.appliedVariation.VariableSet;
                    this.buttonCaption = json.GetString("caption");
                }

                if (GUI.Button(new Rect(10, 10, 250, 100), this.buttonCaption))
                {
                    ConversionEvent cnvEvent = experiment.GetConversionEventByName("clicked");
                    KiiEvent        kiiEvent = this.appliedVariation.EventForConversion(cnvEvent);
                    KiiAnalytics.Upload(kiiEvent);
                    Application.Quit();
                }
                if (GUI.Button(new Rect(265, 10, 250, 100), "Cancel"))
                {
                    Application.Quit();
                }
            }
            catch (Exception e)
            {
                this.message = "ERROR: " + e.GetType() + " " + e.Message + "\n" + e.StackTrace;
            }
        }
    }
Exemplo n.º 2
0
 void OnGUI()
 {
     if (!this.loggedin)
     {
         this.email = GUI.TextField(new Rect(10, 10, 800, 100), this.email);
         GUI.Label(new Rect(10, 220, 500, 1000), this.message);
         if (GUI.Button(new Rect(10, 115, 250, 100), "Create User"))
         {
             KiiUser user = KiiUser.BuilderWithEmail(this.email).WithName("U" + Environment.TickCount).Build();
             user.Register("pa$$sword", (KiiUser registeredUser, Exception e) => {
                 if (e != null)
                 {
                     this.message = "ERROR: failed to register user " + e.GetType() + " " + e.Message + "\n" + e.StackTrace;
                 }
                 else
                 {
                     this.message  = "SUCCESS";
                     this.loggedin = true;
                     this.message  = "";
                 }
             });
         }
     }
     else
     {
         GUI.Label(new Rect(10, 220, 500, 1000), message);
         if (!this.initializedExperiment)
         {
             this.initializedExperiment = true;
             Debug.Log("#####Call KiiExperiment.GetByID");
             KiiExperiment.GetByID("f1b00500-eae2-11e3-a0e4-22000a84b8f5", (KiiExperiment experiment, Exception e) => {
                 Debug.Log("#####End KiiExperiment.GetByID");
                 if (e != null)
                 {
                     Debug.Log("#####Error KiiExperiment.GetByID");
                     this.message = "ERROR: KiiExperiment.GetByID failed!! " + e.GetType() + " " + e.Message + "\n" + e.StackTrace;
                     return;
                 }
                 Debug.Log("#####Success KiiExperiment.GetByID");
                 this.experiment              = experiment;
                 this.appliedVariation        = this.experiment.GetAppliedVariation(this.experiment.Variations[0]);
                 ConversionEvent viewCnvEvent = this.experiment.GetConversionEventByName("viewed");
                 KiiEvent viewKiiEvent        = this.appliedVariation.EventForConversion(viewCnvEvent);
                 KiiAnalytics.Upload((Exception e1) => {
                     if (e1 != null)
                     {
                         this.message = "ERROR: KiiAnalytics.Upload('viewed') failed!! " + e1.GetType() + " " + e1.Message + "\n" + e1.StackTrace;
                     }
                     else
                     {
                         this.message = "Event 'viewed' is Uploaded!!";
                     }
                 }
                                     , viewKiiEvent);
                 if (this.buttonCaption == null)
                 {
                     JsonObject json    = this.appliedVariation.VariableSet;
                     this.buttonCaption = json.GetString("caption");
                 }
             });
         }
         if (GUI.Button(new Rect(10, 10, 250, 100), this.buttonCaption))
         {
             ConversionEvent cnvEvent = this.experiment.GetConversionEventByName("clicked");
             KiiEvent        kiiEvent = this.appliedVariation.EventForConversion(cnvEvent);
             KiiAnalytics.Upload((Exception e2) => {
                 if (e2 != null)
                 {
                     this.message = "ERROR: KiiAnalytics.Upload(clicked) failed!! " + e2.GetType() + " " + e2.Message + "\n" + e2.StackTrace;
                 }
                 else
                 {
                     this.message = "Event 'clicked' is Uploaded!!";
                 }
             }, kiiEvent);
         }
         if (GUI.Button(new Rect(265, 10, 250, 100), "Cancel"))
         {
             Application.Quit();
         }
     }
 }