예제 #1
0
    /*
     *"data" : {
     * "run" : 1000,
     * "event" : 2000,
     * "name" : "gold"
     * }
     */
    eventDesc tryLoadingEventDesc(IDictionary <string, string> data)
    {
        if (data == null)
        {
            return(null);
        }
        eventDesc ret = new eventDesc();

        if (!data.ContainsKey("run"))
        {
            return(null);
        }
        if (!Int64.TryParse(data["run"], out ret.run))
        {
            return(null);
        }
        if (!data.ContainsKey("event"))
        {
            return(null);
        }
        if (!Int64.TryParse(data["event"], out ret.evn))
        {
            return(null);
        }
        if (!data.ContainsKey("name"))
        {
            ret.baseDesc = "";
        }
        else
        {
            ret.baseDesc = data["name"];
        }
        if (!data.ContainsKey("date"))
        {
            ret.eventDate = "";
        }
        else
        {
            ret.eventDate = data["date"];
        }
        if (!data.ContainsKey("energy"))
        {
            ret.energy = 0;
        }
        else
        {
            ret.energy = 0;
            double.TryParse(data["energy"], out ret.energy);
        }
        if (data.ContainsKey("desc"))
        {
            ret.humName = data["desc"];
        }
        return(ret);
    }
예제 #2
0
    public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e)
    {
        if (e.Message == null)
        {
            Debug.Log("Null message received");
            return;
        }
        Debug.Log("Received a new message from: " + e.Message.From);
        //e.Message.data; ->dict
        //e.Message.Notification.Title;
        //e.Message.Notification.Body;

        if (e.Message.Notification == null)
        {
            Debug.Log("Got message with data only? ");
        }


        eventDesc newEvent = tryLoadingEventDesc(e.Message.Data);

        if (newEvent == null)
        {
            Debug.Log("Malformed data in message");
            return;
        }
        if (e.Message.Notification != null)
        {
            NotificationUI.spawnNotification(e.Message.Notification.Title, e.Message.Notification.Body, newEvent);
            if (EventRestAPI.Instance != null)
            {
                EventRestAPI.Instance.processNewNotification(newEvent, false);
            }
            else
            { //we are asleep?
                EventRestAPI.notificationsWoken.Add(newEvent);
            }
        }
        else
        {
            //probably means that you got message from clicking on notification outside
            //do not spawn notification, just process data...
            EventRestAPI.notificationsWoken.Add(newEvent); //no guarantee this will fire first...
            if (EventRestAPI.Instance != null && EventRestAPI.Instance.lifecycleReady)
            {
                EventRestAPI.Instance.reloadNotified();
            }
        }
    }
예제 #3
0
    public static void spawnNotification(string title, string body, eventDesc ev)
    {
        if (notifications == null)
        {
            notifications = new List <NotificationUI>();
        }
        if (prefab == null)
        {
            prefab = Resources.Load <NotificationUI>("Prefabs/Notification");
        }
        if (prefab == null)
        {
            Debug.Log("Fix notification prefab Prefabs/Notification");
            return;
        }
        NotificationUI newNote = Instantiate <NotificationUI>(prefab);
        GameObject     canv    = GameObject.FindGameObjectWithTag("Canvas");

        if (canv == null)
        {
            Debug.Log("Add canvas tag to your canvas");
            return;
        }
        newNote.gameObject.transform.SetParent(canv.transform, false);
        if (ev != null)
        {
            string date = ev.eventDate;
            if (date == null)
            {
                date = "";
            }
            newNote.textbox.text = string.Format("{0}: ( {1} {2} / {3} : {4} ) \n {5}", title, date, ev.run, ev.evn, ev.baseDesc, body);
        }
        else
        {
            Debug.Log("Event not parsed?");
            newNote.textbox.text = string.Format("{0}: InValid event", title);
        }
        newNote.ev = ev;
        notifications.Add(newNote);
        newNote.updateLocation = true;
        newNote.updatePos();
    }
예제 #4
0
    void Format(eventDesc dsc, string comment)
    {
        if (nameField != null)
        {
            if (dsc.humName != null)
            {
                nameField.text = string.Format(" {0}: {3} ({4}), {5}TeV", dsc.humName, dsc.run, dsc.evn, dsc.baseDesc, dsc.eventDate, dsc.energy);
            }
            else
            {
                nameField.text = string.Format(" {0}/{1}: {2} ({3}), {4}TeV", dsc.run, dsc.evn, dsc.baseDesc, dsc.eventDate, dsc.energy);
            }
        }
        //Debug.Log(comment);

        if (commentField != null)
        {
            commentField.text = comment;
        }
    }