Ejemplo n.º 1
0
        private OpenHome.Xapp.JsonObject GetBoxTracking(List <Box> aBoxList)
        {
            Dictionary <string, int> modelCount           = new Dictionary <string, int>();
            Dictionary <string, int> softwareVersionCount = new Dictionary <string, int>();

            foreach (Box b in aBoxList)
            {
                if (!modelCount.ContainsKey(b.Model))
                {
                    modelCount.Add(b.Model, 1);
                }
                else
                {
                    modelCount[b.Model] += 1;
                }

                string softwareVersion = b.SoftwareVersion;
                // log nulls and blanks as Unknown
                if (softwareVersion == null || softwareVersion == String.Empty)
                {
                    softwareVersion = "Unknown";
                }
                if (!softwareVersionCount.ContainsKey(softwareVersion))
                {
                    softwareVersionCount.Add(softwareVersion, 1);
                }
                else
                {
                    softwareVersionCount[softwareVersion] += 1;
                }
            }
            var resultJson = new OpenHome.Xapp.JsonObject();

            var modelsJson = new OpenHome.Xapp.JsonArray <OpenHome.Xapp.JsonObject>();

            foreach (string modelName in modelCount.Keys)
            {
                OpenHome.Xapp.JsonObject modelJson = new OpenHome.Xapp.JsonObject();
                modelJson.Add("Name", new OpenHome.Xapp.JsonValueString(modelName));
                modelJson.Add("Value", new OpenHome.Xapp.JsonValueInt(modelCount[modelName]));
                modelsJson.Add(modelJson);
            }
            resultJson.Add("Models", modelsJson);

            var versionsJson = new OpenHome.Xapp.JsonArray <OpenHome.Xapp.JsonObject>();

            foreach (string version in softwareVersionCount.Keys)
            {
                OpenHome.Xapp.JsonObject versionJson = new OpenHome.Xapp.JsonObject();
                versionJson.Add("Name", new OpenHome.Xapp.JsonValueString(version));
                versionJson.Add("Value", new OpenHome.Xapp.JsonValueInt(softwareVersionCount[version]));
                versionsJson.Add(versionJson);
            }
            resultJson.Add("Versions", versionsJson);

            return(resultJson);
        }
Ejemplo n.º 2
0
        protected override void OnActivated(Session aSession)
        {
            // get the page model for this session
            IPageModel model = GetSessionModel(aSession);

            // enable analytics and send page view event if tracking
            aSession.Tracker.SetTracking(aSession.Tracking);
            aSession.Tracker.TrackPageView(Id);

            // update any ui widgets that reflect tracking state
            aSession.Send("DataCollectionEnabled", aSession.Tracking);

            // render widgets
            foreach (PageDefinitions.Widget widget in iPageDefinition.Widgets)
            {
                // get the value of the data from the page model
                Assert.Check(model != null);
                System.Reflection.PropertyInfo prop = model.GetType().GetProperty(widget.DataId);
                string data = prop.GetValue(model, null) as string;

                // create the json object
                OpenHome.Xapp.JsonObject json = new OpenHome.Xapp.JsonObject();

                // add the basic required properties
                json.Add("Id", new OpenHome.Xapp.JsonValueString(widget.Id));
                json.Add("DataId", new OpenHome.Xapp.JsonValueString(widget.DataId));
                json.Add("Value", new OpenHome.Xapp.JsonValueString(data));

                // add the optional allowed values
                if (widget.AllowedValues != null || widget.AllowedValuesSource != null)
                {
                    // get the list of string allowed values from either the widget XML or an IPageModel property
                    string[] allowedValuesStr = (widget.AllowedValues != null)
                                              ? widget.AllowedValues
                                              : model.GetType().GetProperty(widget.AllowedValuesSource).GetValue(model, null) as string[];

                    // create the json array of allowed values
                    OpenHome.Xapp.JsonArray <OpenHome.Xapp.JsonValueString> allowedValues = new OpenHome.Xapp.JsonArray <OpenHome.Xapp.JsonValueString>();

                    foreach (string value in allowedValuesStr)
                    {
                        allowedValues.Add(new OpenHome.Xapp.JsonValueString(value));
                    }

                    json.Add("AllowedValues", allowedValues);
                }

                // render the widget
                aSession.Send(widget.XappEvent, json);
            }
        }