コード例 #1
0
ファイル: Scala.cs プロジェクト: jweather/bwcm
        public static string savePlayer(Player player)
        {
            string summary = "";
            // commit changes to Scala playlist and update local data
            Player old = players.Find(Player.byID(player.id));
            if (old == null) {
                Global.d("Scala.savePlayer got nonexistent player ID " + player.id);
                throw new ArgumentException("player ID " + player.id + " doesn't exist");
            }

            // save changes to Scala
            List<int> oldIDs = new List<int>();
            List<int> replaced = new List<int>();
            foreach (Slide s in old.slides) oldIDs.Add(s.id);

            // create new messages
            foreach (Slide slide in player.slides) {
                if (!slide.changed) {
                    oldIDs.Remove(slide.id);
                    continue;
                } else {
                    replaced.Add(slide.id);
                }

                // create new message
                Template template = templates.Find(Template.byID(slide.templateID));
                messageTO message = new messageTO();
                message.name = slide.name; message.templateId = slide.templateID; message.templateIdSpecified = true;
                List<messageDataFieldTO> fields = new List<messageDataFieldTO>();
                for (int f=0; f < slide.fields.Count; f++) {
                    Field field = slide.fields[f];
                    Field tfield = template.fields.Find(Field.byName(field.name));
                    if (tfield == null) continue; // no such field in template

                    if (field.widget != null && field.widget is WidgetNone)
                        continue; // no field value

                    messageDataFieldTO fieldTO = new messageDataFieldTO();
                    fieldTO.id = tfield.templateFieldID; fieldTO.idSpecified = true; // use template field ID
                    fieldTO.name = field.name;

                    // this should live in the Widget class
                    if (field.widget != null && !(field.widget is WidgetImage) && !(field.widget is WidgetVideo))
                        field.mediaID = field.widget.upload();

                    if (field.widget is WidgetTwitter && player.info.defaultTwitter == "") {
                        // update default twitter handle
                        WidgetTwitter wt = (WidgetTwitter)field.widget;
                        player.info.defaultTwitter = wt.handles;
                        Global.dataDirty = true;
                    }

                    fieldTO.value = field.mediaID.ToString();
                    fields.Add(fieldTO);
                }

                if (template.durationFieldID > 0) {
                    messageDataFieldTO fieldTO = new messageDataFieldTO();
                    fieldTO.id = template.durationFieldID; fieldTO.name = "SlideTime";
                    fieldTO.value = slide.duration.ToString();
                    fields.Add(fieldTO);
                }

                // workaround braindead 1.x API issues in release 10
                message.approvalStatus = ScalaWS.Message.approvalStatusEnum.DRAFT; message.approvalStatusSpecified = true;
                message = messageServ.create(message, fields.ToArray());
                if (oldIDs.Contains(slide.id))
                    summary += " -- updated " + slide.id + "=>" + message.id + ": " + message.name;
                else
                    summary += " -- added " + message.id + ": " + message.name;

                setApproval(message.id);
                messageServ.addCategory(message.id, true, managedCatID, true);

                // update IDs
                slide.id = message.id;
                slide.changed = false;
            }

            foreach (int id in oldIDs) {
                // deleted or replaced
                try {
                    messageServ.delete(id, true);
                } catch (Exception e) {
                    Global.d("Failed to delete slide " + id + ": " + e.Message);
                }
                thumbCache.Remove(id);
                if (!replaced.Contains(id))
                    summary += " -- deleted slide " + id;
            }

            // reorder messages in playlist
            ScalaWS.Playlist.playlistItemTO[] items = new ScalaWS.Playlist.playlistItemTO[player.slides.Count];
            Dictionary<int, timeScheduleTO> schedules = new Dictionary<int, timeScheduleTO>();
            for (int s=0; s < player.slides.Count; s++) {
                Slide slide = player.slides[s];
                items[s] = new ScalaWS.Playlist.playlistItemTO();
                items[s].mediaId = slide.id; items[s].mediaIdSpecified = true;

                if (slide.startDate != null || slide.stopDate != null) {
                    items[s].useValidRange = true; items[s].useValidRangeSpecified = true;
                    if (slide.startDate != null) {
                        items[s].startValidDate = DateTime.Parse(slide.startDate); items[s].startValidDateSpecified = true;
                    }
                    if (slide.stopDate != null) {
                        items[s].endValidDate = DateTime.Parse(slide.stopDate); items[s].endValidDateSpecified = true;
                    }
                }

                /* // time range is disabled
                if (slide.startTime != null || slide.stopTime != null || (slide.days != null && slide.days.Count < 7)) {
                    if (slide.startTime == null) slide.startTime = "00:00";
                    if (slide.stopTime == null) slide.stopTime = "24:00"; // no, it doesn't make sense
                    timeScheduleTO sched = new timeScheduleTO();
                    sched.startTime = slide.startTime;
                    sched.endTime = slide.stopTime;
                    sched.days = slide.scalaDays();
                    schedules.Add(slide.id, sched);
                }
                */
            }
            playlistServ.deleteAllPlaylistItems(player.id, true);
            foreach (ScalaWS.Playlist.playlistItemTO item in items) {
                try {
                    ScalaWS.Playlist.playlistItemTO playlistItem = playlistServ.addPlaylistItem(player.id, true, item);
                    if (schedules.ContainsKey(item.mediaId)) {
                        playlistServ.addTimeSchedule(playlistItem.id, true, schedules[item.mediaId]);
                    }
                } catch (Exception e) {
                    Global.d("savePlayer: failed to add item " + item.id + " to playlist " + player.name + ": " + e);
                }
            }

            // save changes locally
            players.Remove(old);
            players.Add(player);

            if (old.info != player.info) {
                summary += " -- updated settings";
                Global.dataDirty = true;
            }

            if (summary == "") summary = " -- reordered slides";
            return summary;
        }
コード例 #2
0
ファイル: Scala.cs プロジェクト: jweather/bwcm
        public static void queryTest()
        {
            // list all BWCM messages
            ScalaWS.Message.searchCriteriaTO[] mcrit = new ScalaWS.Message.searchCriteriaTO[1]; mcrit[0] = new ScalaWS.Message.searchCriteriaTO();
            mcrit[0].column = "categoryId"; mcrit[0].value = managedCatID.ToString();
            mcrit[0].restriction = ScalaWS.Message.restrictionEnum.EQUALS; mcrit[0].restrictionSpecified = true;
            messageTO[] messages = messageServ.list(mcrit, null);

            Global.d("retrieved " + messages.Length + " messages in one request");

            ScalaWS.Message.listResultCriteriaTO mlcrit = new ScalaWS.Message.listResultCriteriaTO();
            mlcrit.firstResult = 0; mlcrit.firstResultSpecified = true;
            const int chunk = 20;
            mlcrit.maxResults = chunk; mlcrit.maxResultsSpecified = true;
            List<messageTO> allmessages = new List<messageTO>();
            messages = new messageTO[0];
            do {
                messages = messageServ.list(mcrit, mlcrit);
                Global.d("got chunk with " + messages.Length + " messages");
                mlcrit.firstResult += messages.Length;
                allmessages.Concat<messageTO>(messages);
            } while (messages.Length == chunk);
            Global.d("total " + allmessages.Count + " messages received");
        }