コード例 #1
0
        public void Trigger(string eventName, SwrveBaseMessage baseMessage)
        {
            try {
                if (CanMakeTriggerRequest())
                {
                    lastTriggerRequestTime = SwrveHelper.GetMilliseconds();

                    Dictionary <int, string>           _reasons  = campaignReasons;
                    Dictionary <int, SwrveBaseMessage> _messages = campaignMessages;
                    campaignReasons  = new Dictionary <int, string>();
                    campaignMessages = new Dictionary <int, SwrveBaseMessage>();

                    String endpoint = getEndpoint("talk/game/" + swrve.ApiKey + "/user/" + swrve.UserId + "/trigger");
                    Dictionary <string, object> triggerJson = new Dictionary <string, object> ();
                    triggerJson.Add("trigger_name", eventName);
                    triggerJson.Add("displayed", baseMessage != null);
                    triggerJson.Add("reason", baseMessage == null ? "The loaded campaigns returned no conversation or message" : string.Empty);

                    // Add campaigns that were not displayed
                    IList <object> campaignsJson = new List <object> ();
                    Dictionary <int, string> .Enumerator campaignIt = _reasons.GetEnumerator();
                    while (campaignIt.MoveNext())
                    {
                        int    campaignId = campaignIt.Current.Key;
                        String reason     = campaignIt.Current.Value;

                        Dictionary <string, object> campaignInfo = new Dictionary <string, object> ();
                        campaignInfo.Add("id", campaignId);
                        campaignInfo.Add("displayed", false);
                        campaignInfo.Add("reason", (reason == null) ? string.Empty : reason);

                        if (_messages.ContainsKey(campaignId))
                        {
                            SwrveBaseMessage _baseMessage = _messages [campaignId];
                            campaignInfo.Add(_baseMessage.GetBaseMessageType() + "_id", _baseMessage.Id);
                        }
                        campaignsJson.Add(campaignInfo);
                    }

                    // Add campaign that was shown, if available
                    if (baseMessage != null)
                    {
                        Dictionary <string, object> campaignInfo = new Dictionary <string, object> ();
                        campaignInfo.Add("id", baseMessage.Campaign.Id);
                        campaignInfo.Add("displayed", true);
                        campaignInfo.Add(baseMessage.GetBaseMessageType() + "_id", baseMessage.Id);
                        campaignInfo.Add("reason", string.Empty);

                        campaignsJson.Add(campaignInfo);
                    }
                    triggerJson.Add("campaigns", campaignsJson);

                    MakeRequest(endpoint, triggerJson);
                }
            } catch (Exception exp) {
                SwrveLog.LogError("QA request talk session failed: " + exp.ToString());
            }
        }
コード例 #2
0
ファイル: SwrveQAUser.cs プロジェクト: smdx24/CPI-Source-Code
 public void Trigger(string eventName, SwrveBaseMessage baseMessage)
 {
     try
     {
         if (!CanMakeTriggerRequest())
         {
             return;
         }
         lastTriggerRequestTime = SwrveHelper.GetMilliseconds();
         Dictionary <int, string>           dictionary  = campaignReasons;
         Dictionary <int, SwrveBaseMessage> dictionary2 = campaignMessages;
         campaignReasons  = new Dictionary <int, string>();
         campaignMessages = new Dictionary <int, SwrveBaseMessage>();
         string endpoint = getEndpoint("talk/game/" + swrve.ApiKey + "/user/" + swrve.UserId + "/trigger");
         Dictionary <string, object> dictionary3 = new Dictionary <string, object>();
         dictionary3.Add("trigger_name", eventName);
         dictionary3.Add("displayed", baseMessage != null);
         dictionary3.Add("reason", (baseMessage == null) ? "The loaded campaigns returned no conversation or message" : string.Empty);
         IList <object> list = new List <object>();
         Dictionary <int, string> .Enumerator enumerator = dictionary.GetEnumerator();
         while (enumerator.MoveNext())
         {
             int    key   = enumerator.Current.Key;
             string value = enumerator.Current.Value;
             Dictionary <string, object> dictionary4 = new Dictionary <string, object>();
             dictionary4.Add("id", key);
             dictionary4.Add("displayed", false);
             dictionary4.Add("reason", (value == null) ? string.Empty : value);
             if (dictionary2.ContainsKey(key))
             {
                 SwrveBaseMessage swrveBaseMessage = dictionary2[key];
                 dictionary4.Add(swrveBaseMessage.GetBaseMessageType() + "_id", swrveBaseMessage.Id);
             }
             list.Add(dictionary4);
         }
         if (baseMessage != null)
         {
             Dictionary <string, object> dictionary4 = new Dictionary <string, object>();
             dictionary4.Add("id", baseMessage.Campaign.Id);
             dictionary4.Add("displayed", true);
             dictionary4.Add(baseMessage.GetBaseMessageType() + "_id", baseMessage.Id);
             dictionary4.Add("reason", string.Empty);
             list.Add(dictionary4);
         }
         dictionary3.Add("campaigns", list);
         MakeRequest(endpoint, dictionary3);
     }
     catch (Exception ex)
     {
         SwrveLog.LogError("QA request talk session failed: " + ex.ToString());
     }
 }
コード例 #3
0
 public void Trigger(string eventName, SwrveBaseMessage baseMessage)
 {
     try
     {
         if (this.CanMakeTriggerRequest())
         {
             this.lastTriggerRequestTime = SwrveHelper.GetMilliseconds();
             Dictionary <int, string>           dictionary  = this.campaignReasons;
             Dictionary <int, SwrveBaseMessage> dictionary2 = this.campaignMessages;
             this.campaignReasons  = new Dictionary <int, string>();
             this.campaignMessages = new Dictionary <int, SwrveBaseMessage>();
             string endpoint = this.getEndpoint(string.Concat(new string[]
             {
                 "talk/game/",
                 this.swrve.ApiKey,
                 "/user/",
                 this.swrve.UserId,
                 "/trigger"
             }));
             Dictionary <string, object> dictionary3 = new Dictionary <string, object>();
             dictionary3.Add("trigger_name", eventName);
             dictionary3.Add("displayed", baseMessage != null);
             dictionary3.Add("reason", (baseMessage != null) ? string.Empty : "The loaded campaigns returned no conversation or message");
             IList <object> list = new List <object>();
             Dictionary <int, string> .Enumerator enumerator = dictionary.GetEnumerator();
             while (enumerator.MoveNext())
             {
                 KeyValuePair <int, string> current = enumerator.Current;
                 int key = current.Key;
                 KeyValuePair <int, string> current2 = enumerator.Current;
                 string value = current2.Value;
                 Dictionary <string, object> dictionary4 = new Dictionary <string, object>();
                 dictionary4.Add("id", key);
                 dictionary4.Add("displayed", false);
                 dictionary4.Add("reason", (value != null) ? value : string.Empty);
                 if (dictionary2.ContainsKey(key))
                 {
                     SwrveBaseMessage swrveBaseMessage = dictionary2[key];
                     dictionary4.Add(swrveBaseMessage.GetBaseMessageType() + "_id", swrveBaseMessage.Id);
                 }
                 list.Add(dictionary4);
             }
             if (baseMessage != null)
             {
                 list.Add(new Dictionary <string, object>
                 {
                     {
                         "id",
                         baseMessage.Campaign.Id
                     },
                     {
                         "displayed",
                         true
                     },
                     {
                         baseMessage.GetBaseMessageType() + "_id",
                         baseMessage.Id
                     },
                     {
                         "reason",
                         string.Empty
                     }
                 });
             }
             dictionary3.Add("campaigns", list);
             this.MakeRequest(endpoint, dictionary3);
         }
     }
     catch (Exception ex)
     {
         SwrveLog.LogError("QA request talk session failed: " + ex.ToString());
     }
 }