Beispiel #1
0
        public static void garbageCollection()
        {
            // visit all BWCM playlists, record all message IDs and media IDs for field values
            HashSet<int> references = new HashSet<int>();
            foreach (Player p in players) {
                foreach (Slide s in p.slides) {
                    references.Add(s.id);
                    foreach (Field f in s.fields) {
                        references.Add(f.mediaID);
                    }
                }
            }

            // list all BWCM messages and remove unused
            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;

            int msgcount = 0;
            messageTO[] messages = messageServ.list(mcrit, null);
            foreach (messageTO msg in messages) {
                if (references.Contains(msg.id)) {
                    msgcount++;
                    continue;
                }
                Global.d("marked message " + msg.id + ": " + msg.name + " for deletion");
                messageServ.delete(msg.id, true);
            }

            // list all BWCM media items and remove unused
            ScalaWS.Media.searchCriteriaTO[] fcrit = new ScalaWS.Media.searchCriteriaTO[1]; fcrit[0] = new ScalaWS.Media.searchCriteriaTO();
            fcrit[0].column = "categoryId"; fcrit[0].value = managedCatID.ToString();
            fcrit[0].restriction = ScalaWS.Media.restrictionEnum.EQUALS; fcrit[0].restrictionSpecified = true;

            int mediacount = 0;
            mediaTO[] medias = mediaServ.list(fcrit, null);
            foreach (mediaTO media in medias) {
                if ((DateTime.Now - media.lastModified).TotalHours < 1.0) {
                    // don't delete stuff that was just uploaded
                    continue;
                }
                if (references.Contains(media.id)) {
                    mediacount++;
                    continue;
                }
                Global.d("marked media " + media.id + ": " + media.path + "/" + media.name + " for deletion");
                mediaServ.delete(media.id, true);
            }

            Global.d("garbage collection completed, matched " + msgcount + " messages and " + mediacount + " media items");
            referencedMedia = references;
        }
Beispiel #2
0
        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");
        }
Beispiel #3
0
        // get groups and player names from Scala
        public static void loadData()
        {
            Global.d("Scala.loadData");
            players.Clear();
            templates.Clear();

            try {
                // find category
                ScalaWS.Playlist.searchCriteriaTO[] plcrit = new ScalaWS.Playlist.searchCriteriaTO[1]; plcrit[0] = new ScalaWS.Playlist.searchCriteriaTO();
                plcrit[0].column = "name"; plcrit[0].value = Global.cfg("catManaged");
                plcrit[0].restriction = ScalaWS.Playlist.restrictionEnum.EQUALS; plcrit[0].restrictionSpecified = true;
                ScalaWS.Playlist.categoryTO[] cats = playlistServ.listCategories(plcrit, null);
                if (cats.Length != 1) throw new Exception("Did not find managed category named '" + Global.cfg("catManaged") + "' (Web.config:catManaged)");
                managedCatID = cats[0].id;

                // get templates in master category
                ScalaWS.Template.searchCriteriaTO[] tcrit = new ScalaWS.Template.searchCriteriaTO[1]; tcrit[0] = new ScalaWS.Template.searchCriteriaTO();
                tcrit[0].column = "categoryId"; tcrit[0].value = managedCatID.ToString();
                tcrit[0].restriction = ScalaWS.Template.restrictionEnum.EQUALS; tcrit[0].restrictionSpecified = true;

                templateTO[] temps = templateServ.list(tcrit, null);
                foreach (templateTO templateTO in temps) {
                    try {
                        Template template = new Template(templateTO.id, templateTO.name);
                        templateDataFieldTO[] fields = templateServ.getFiles(template.id, true);
                        foreach (templateDataFieldTO fieldTO in fields) {
                            if (fieldTO.type != templateFieldTypeEnum.IMAGE) continue;
                            Field field = new Field(fieldTO.name);
                            field.templateFieldID = fieldTO.id;
                            template.fields.Add(field);
                        }

                        fields = templateServ.getFields(template.id, true);
                        foreach (templateDataFieldTO fieldTO in fields) {
                            if (fieldTO.name == "SlideTime")
                                template.durationFieldID = fieldTO.id;
                        }
                        template.sortFields();
                        templates.Add(template);
                    } catch (Exception e) {
                        Global.d("Failed to load template data: " + e);
                    }
                }

                // find playlists
                plcrit[0].column = "categoryId"; plcrit[0].value = managedCatID.ToString();
                ScalaWS.Playlist.playlistTO[] playlists = playlistServ.list(plcrit, null);
                foreach (playlistTO playlist in playlists) {
                    Player player = new Player(playlist.id, playlist.name);
                    players.Add(player);

                    ScalaWS.Playlist.playlistItemTO[] items = playlistServ.getPlaylistItems(playlist.id, true);
                    foreach (ScalaWS.Playlist.playlistItemTO item in items) {
                        try {
                            // if (item.playlistItemType != playlistItemTypeEnum.MESSAGE) continue; // not supported by ScalaWS, hopefully no non-message items show up in this playlist
                            // item.mediaID is the message ID, item.id is the playlistItemID
                            if (item.mediaId == 0) continue; // sub-playlist?

                            messageTO message = messageServ.get(item.mediaId, true);
                            Slide slide = new Slide(item.mediaId, message.name);
                            player.slides.Add(slide);

                            slide.templateID = message.templateId;

                            if (item.useValidRange) {
                                slide.startDate = item.startValidDate.ToShortDateString();
                                if (slide.startDate == "1/1/0001") slide.startDate = null;
                                slide.stopDate = item.endValidDate.ToShortDateString();
                                if (slide.stopDate == "1/1/0001") slide.stopDate = null;
                            }

                            /* // time range is disabled
                            timeScheduleTO[] times = playlistServ.getTimeSchedules(item.id, true);
                            if (times.Length > 0) {
                                slide.startTime = times[0].startTime;
                                if (slide.startTime == "0:00" || slide.startTime == "00:00") slide.startTime = null;
                                slide.stopTime = times[0].endTime;
                                if (slide.stopTime == "24:00") slide.stopTime = null;
                                slide.days = new List<string>();
                                foreach (weekdayEnum day in times[0].days) {
                                    slide.days.Add(day.ToString().Substring(0,3).ToLower());
                                }
                            }
                            */

                            messageDataFieldTO[] fields = messageServ.getFiles(item.mediaId, true);
                            List<string> foundFields = new List<string>();
                            foreach (messageDataFieldTO fieldTO in fields) {
                                Field field = new Field(fieldTO.name);
                                field.mediaID = Convert.ToInt32(fieldTO.value);
                                field.widget = Widget.renderList.Find(Widget.byMediaID(field.mediaID));
                                if (field.widget == null) {
                                    field.widget = new WidgetImage(); // the non-widget widget
                                }

                                slide.fields.Add(field);
                                foundFields.Add(fieldTO.name);
                            }

                            fields = messageServ.getFields(item.mediaId, true);
                            foreach (messageDataFieldTO fieldTO in fields) {
                                if (fieldTO.name == "SlideTime")
                                    try { slide.duration = Convert.ToInt32(fieldTO.value); } catch {}
                            }
                            if (slide.duration == 0)
                                slide.duration = player.info.defaultDuration;

                            // missing fields = WidgetNone
                            Template t = templates.Find(Template.byID(slide.templateID));
                            foreach (Field tf in t.fields) {
                                if (!foundFields.Contains(tf.name)) {
                                    Field nf = new Field(tf.name);
                                    nf.widget = new WidgetNone();
                                    slide.fields.Add(nf);
                                }
                            }

                        } catch (Exception e) {
                            Global.d("Failed to load playlist item in " + player.name + ": " + e);
                        }
                    }
                }

                // get crawl message text
                ScalaWS.Message.searchCriteriaTO[] mcrit = new ScalaWS.Message.searchCriteriaTO[1]; mcrit[0] = new ScalaWS.Message.searchCriteriaTO();
                mcrit[0].column = "name"; mcrit[0].value = Global.cfg("crawlMessage");
                mcrit[0].restriction = ScalaWS.Message.restrictionEnum.EQUALS; mcrit[0].restrictionSpecified = true;

                messageTO[] msgs = messageServ.list(mcrit, null);
                if (msgs.Length == 0)
                    throw new Exception("Cannot find crawl message named '" + Global.cfg("crawlMessage") + "'");
                messageTO msg = msgs[0];
                messageDataFieldTO[] f = messageServ.getFields(msg.id, true);
                crawlTextField = f[0];

            } catch (Exception e) {
                Global.d("Scala.loadData: " + e);
            }

            Global.d("end Scala.loadData: " + players.Count + " players and " + templates.Count + " templates loaded.");
        }