Пример #1
0
        private videoArchive getVideoArchive(bool komin)
        {
            buildVideoArchive builder = new malmo.buildVideoArchive();

            videoArchive archive = new videoArchive();

            if (komin)
            {
                archive = (videoArchive)_cache["kominArchive"];
                if (archive == null)
                {
                    archive = builder.render(true);
                    _cache.Insert("kominArchive", archive, null, DateTime.UtcNow.AddMinutes(15), Cache.NoSlidingExpiration);
                }
            }
            else
            {
                archive = (videoArchive)_cache["Archive"];
                if (archive == null)
                {
                    archive = builder.render(false);
                    _cache.Insert("Archive", archive, null, DateTime.UtcNow.AddMinutes(15), Cache.NoSlidingExpiration);
                }
            }

            return(archive);
        }
Пример #2
0
        private void renderArchive(bool komin)
        {
            string renderName = "renderedArchive";

            if (komin)
            {
                renderName = "renderedKominArchive";
            }

            string response = (string)Cache[renderName];

            if (response == null)
            {
                helpers      helper  = new helpers();
                videoArchive archive = helper.getVideoArchive(komin);

                StringBuilder h          = new StringBuilder();
                int           categoryId = 1;
                foreach (videoCategory cat in archive.categories)
                {
                    h.AppendLine("<section class=\"va-group\" id=\"" + categoryId.ToString() + "\">");
                    h.AppendLine("<div class=\"va-video-list\">");
                    h.AppendLine("<div class=\"va-videolist-sectionheader\">");
                    h.AppendLine("<h2>" + cat.name + "</h2>");
                    h.AppendLine("<button class=\"expand-button\" tabindex=\"0\"><span>Visa alla</span></button>");
                    h.AppendLine("</div>");
                    h.AppendLine("<div class=\"va-videolist-container-outer\">");
                    h.AppendLine("<button class=\"slidearrow is-left is-invisible\" tabindex=\"-1\"></button>");
                    h.AppendLine("<button class=\"slidearrow is-right is-visible\" tabindex=\"-1\"></button>");
                    h.AppendLine("<div class=\"va-videolist-container not-expanded\">");
                    foreach (videoItem v in cat.videos)
                    {
                        h.AppendLine("<article>");
                        h.AppendLine("<a href=\"?bctid=" + v.id + "\" tabindex=\"-1\" title=\"" + v.shortDescription + "\">");
                        h.AppendLine("<figure class=\"va-thumb-cont\"><img src=\"" + v.thumbnailURL + "\" title=\"" + v.name + "\" class=\"va-thumb\" /></figure>");
                        h.AppendLine("<span class=\"va-title\">" + v.name + "</span>");
                        h.AppendLine("</a>");
                        h.AppendLine("</article>");
                    }
                    h.AppendLine("</div>");
                    h.AppendLine("</div>");
                    h.AppendLine("</div>");
                    h.AppendLine("</section>");
                    categoryId++;
                }
                response = h.ToString();
                if (categoryId > 3)
                {
                    Cache.Insert(renderName, response, null, DateTime.UtcNow.AddHours(6), Cache.NoSlidingExpiration);
                }
            }
            htmlResponse.Append(response);
        }
Пример #3
0
        private void createIndex(videoArchive archive, indexMessage message, Lucene.Net.Store.Directory index)
        {
            Lucene.Net.Index.IndexWriter writer;

            try
            {
                writer = new Lucene.Net.Index.IndexWriter(index, analyser, Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED);
                foreach (videoCategory cat in archive.categories)
                {
                    foreach (videoItem video in cat.videos)
                    {
                        string title = "";
                        if (!string.IsNullOrEmpty(video.name))
                        {
                            title = video.name;
                        }
                        string bctid = "";
                        if (!string.IsNullOrEmpty(video.id))
                        {
                            bctid = video.id;
                        }
                        string shortDescription = "";
                        if (!string.IsNullOrEmpty(video.shortDescription))
                        {
                            shortDescription = video.shortDescription;
                        }
                        string imageURL = "";
                        if (!string.IsNullOrEmpty(video.thumbnailURL))
                        {
                            imageURL = video.thumbnailURL;
                        }
                        if (!string.IsNullOrEmpty(video.videoStillURL))
                        {
                            imageURL = video.videoStillURL;
                        }
                        addVideoToIndex(bctid, title, shortDescription, imageURL, writer, message, index);
                    }
                }
                message.success = true;
                writer.Optimize();
                message.message = "Index built and optimized!";
                writer.Dispose();
            }

            catch (Exception ex)
            {
                message.success = false;
                message.message = ex.Message;
            }
        }
Пример #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            XmlWriterSettings writerSettings = new XmlWriterSettings();

            writerSettings.Encoding = new UTF8Encoding(false);
            writerSettings.Indent   = true;
            XmlWriter writer = XmlWriter.Create(Server.MapPath("videoSiteMap.xml"), writerSettings);

            writer.WriteStartDocument();
            writer.WriteStartElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9");
            writer.WriteAttributeString("xmlns", "video", null, "http://www.google.com/schemas/sitemap-video/1.0");

            string pubId  = "745456160001";
            string playId = "745456405001";

            videoArchive archive = (videoArchive)Cache["Archive"];

            if (archive == null)
            {
                buildVideoArchive builder = new buildVideoArchive();
                archive = builder.render(false);
            }
            if (archive != null)
            {
                foreach (videoCategory category in archive.categories)
                {
                    foreach (videoItem item in category.videos)
                    {
                        if (category.name == "Kommunfullmäktige")
                        {
                            pubId  = "2494809924001";
                            playId = "2821564386001";
                        }
                        writeTag(category.name, pubId, playId, item, writer);
                    }
                }
            }

            writer.WriteEndDocument();
            writer.Close();

            Response.Redirect("videoSiteMap.xml");
        }
Пример #5
0
        public string carouselHtml()
        {
            string response = (string)_cache["carousel"];

            if (response == null)
            {
                StringBuilder r       = new StringBuilder();
                int           counter = 0;
                r.AppendLine("<div class=\"videocarousel\">");
                videoArchive archive = getVideoArchive(false);
                foreach (videoCategory cat in archive.categories)
                {
                    if (cat.name == "Aktuellt")
                    {
                        foreach (videoItem v in cat.videos)
                        {
                            r.AppendLine("<div>");
                            r.AppendLine("<a title=\"" + v.shortDescription + "\" href=\"?bctid=" + v.id + "\" tabindex=\"-1\">");
                            r.AppendLine("<figure>");
                            r.AppendLine("<img src=\"" + v.videoStillURL + "\" alt=\"" + v.name + "\" />");
                            r.AppendLine("</figure>");
                            r.AppendLine("<span class=\"videoinfo\"><span class=\"slick_title\">" + v.name + "</span><span class=\"slick_description\">" + truncateString(v.shortDescription, 120) + "</span></span>");
                            r.AppendLine("</a>");
                            r.AppendLine("</div>");
                            counter++;
                            if (counter > 9)
                            {
                                break;
                            }
                        }
                    }
                }
                r.AppendLine("</div>");
                response = r.ToString();
                if (counter > 3)
                {
                    _cache.Insert("carousel", response, null, DateTime.UtcNow.AddMinutes(600), Cache.NoSlidingExpiration);
                }
            }

            return(response);
        }
Пример #6
0
 public indexMessage buildIndex(indexMessage message, bool komin)
 {
     if (komin)
     {
         if (kominArchive == null)
         {
             kominArchive = getVideoArchive(true);
         }
         createIndex(kominArchive, message, kominIndex);
     }
     else
     {
         if (publicArchive == null)
         {
             publicArchive = getVideoArchive(false);
         }
         createIndex(publicArchive, message, publicIndex);
     }
     return(message);
 }
Пример #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            XmlWriterSettings writerSettings = new XmlWriterSettings();

            writerSettings.Encoding = new UTF8Encoding(false);
            writerSettings.Indent   = true;
            XmlWriter writer = XmlWriter.Create(Server.MapPath("siteMap.xml"), writerSettings);

            writer.WriteStartDocument();
            writer.WriteStartElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9");

            videoArchive archive = (videoArchive)Cache["Archive"];

            if (archive == null)
            {
                buildVideoArchive builder = new buildVideoArchive();
                archive = builder.render(false);
            }
            if (archive != null)
            {
                foreach (videoCategory category in archive.categories)
                {
                    string priority = "0.5";
                    if (category.name == "Aktuellt")
                    {
                        priority = "1.0";
                    }

                    foreach (videoItem item in category.videos)
                    {
                        writeTag(item, writer, priority);
                    }
                }
            }

            writer.WriteEndDocument();
            writer.Close();

            Response.Redirect("siteMap.xml");
        }
Пример #8
0
        private videoArchive buildVideoArchive(bool komin)
        {
            videoArchive archive = new videoArchive();

            archive.categories = new List <videoCategory>();
            string mArchivePlayerBcId = string.Empty;

            string kfPlaylistBcId = "2623641282001";

            if (komin)
            {
                mArchivePlayerBcId = "1213665896001";
            }
            else
            {
                mArchivePlayerBcId = "1180742924001";
            }

            string videoFields = "id,name,shortDescription,videoStillURL,thumbnailURL,length,playsTotal,tags,customFields";

            var mRequest  = (HttpWebRequest)HttpWebRequest.Create(string.Format("http://api.brightcove.com/services/library?command=find_playlists_for_player_id&player_id={0}&video_fields={1}&token={2}", mArchivePlayerBcId, videoFields, MReadToken));
            var kfRequest = (HttpWebRequest)HttpWebRequest.Create(string.Format("http://api.brightcove.com/services/library?command=find_playlist_by_id&playlist_id={0}&video_fields={1}&token={2}", kfPlaylistBcId, videoFields, KFReadToken));

            mRequest.Method  = "POST";
            kfRequest.Method = "POST";

            //Get Malmö Account Items
            try
            {
                var    response         = mRequest.GetResponse();
                Stream dataStream       = response.GetResponseStream();
                string BCResponseString = string.Empty;
                using (StreamReader reader = new StreamReader(dataStream))
                {
                    BCResponseString = reader.ReadToEnd();

                    if (BCResponseString != null && BCResponseString != "null")
                    {
                        var results = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(BCResponseString);

                        foreach (dynamic category in results.items)
                        {
                            videoCategory cat = new videoCategory();
                            cat.name   = category.name;
                            cat.videos = new List <videoItem>();
                            foreach (dynamic video in category.videos)
                            {
                                bool kominVideo = false;
                                if (video.customFields != null)
                                {
                                    var customFields = video.customFields;
                                    foreach (dynamic field in customFields)
                                    {
                                        if (field.Name != null)
                                        {
                                            if (field.Name == "targetgroup")
                                            {
                                                if (field.Value == "Komin")
                                                {
                                                    kominVideo = true;
                                                }
                                            }
                                        }
                                    }
                                }
                                if (!kominVideo || kominVideo && komin)
                                {
                                    videoItem item = new videoItem();
                                    item.id               = video.id;
                                    item.name             = video.name.ToString().Replace("\"", "&quot");
                                    item.length           = video.length;
                                    item.playsTotal       = video.playsTotal;
                                    item.thumbnailURL     = video.thumbnailURL;
                                    item.videoStillURL    = video.videoStillURL;
                                    item.shortDescription = video.shortDescription.ToString().Replace("\"", "&quot");
                                    if (video.tags != null)
                                    {
                                        item.tags = new List <string>();
                                        var tags = video.tags;
                                        foreach (string tag in tags)
                                        {
                                            item.tags.Add((string)tag);
                                        }
                                    }

                                    cat.videos.Add(item);
                                }
                            }
                            archive.categories.Add(cat);
                        }
                    }
                }
            }
            catch { }
            ////Get KF Account Items
            try
            {
                var    response         = kfRequest.GetResponse();
                Stream dataStream       = response.GetResponseStream();
                string BCResponseString = string.Empty;
                using (StreamReader reader = new StreamReader(dataStream))
                {
                    BCResponseString = reader.ReadToEnd();

                    if (BCResponseString != null && BCResponseString != "null")
                    {
                        var results = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(BCResponseString);

                        videoCategory category = new videoCategory();
                        category.name   = results.name;
                        category.videos = new List <videoItem>();

                        foreach (dynamic video in results.videos)
                        {
                            videoItem item = new videoItem();
                            item.id               = video.id;
                            item.name             = video.name.ToString().Replace("\"", "&quot");
                            item.length           = video.length;
                            item.playsTotal       = video.playsTotal;
                            item.thumbnailURL     = video.thumbnailURL;
                            item.videoStillURL    = video.videoStillURL;
                            item.shortDescription = video.shortDescription.ToString().Replace("\"", "&quot");
                            if (video.tags != null)
                            {
                                item.tags = new List <string>();
                                var tags = video.tags;
                                foreach (string tag in tags)
                                {
                                    item.tags.Add((string)tag);
                                }
                            }

                            category.videos.Add(item);
                        }
                        archive.categories.Add(category);
                    }
                }
            }
            catch { }
            return(archive);
        }
Пример #9
0
        private string renderKFDropDownList(videoArchive archive)
        {
            StringBuilder html     = new StringBuilder();
            videoCategory kfVideos = new videoCategory();

            if (archive != null)
            {
                foreach (videoCategory category in archive.categories)
                {
                    if (category.name == "Kommunfullmäktige")
                    {
                        kfVideos = category;
                    }
                }
            }
            System.Data.DataTable kfTable = new System.Data.DataTable("KF Videor");
            kfTable.Columns.Add("id", typeof(string));
            kfTable.Columns.Add("name", typeof(string));
            kfTable.Columns.Add("year", typeof(int));
            kfTable.Columns.Add("month", typeof(int));

            if (kfVideos != null)
            {
                foreach (videoItem video in kfVideos.videos)
                {
                    int    month = 0;
                    int    year  = DateTime.Now.Year;
                    string id    = "0";
                    string name  = "KF Video";

                    if (video.id != null)
                    {
                        id = video.id;
                    }
                    if (video.name != null)
                    {
                        name = video.name;
                    }
                    if (video.tags != null)
                    {
                        foreach (string tag in video.tags)
                        {
                            //är det en månads-tagg
                            if (tag.ToUpper() == "JANUARI")
                            {
                                month = 1;
                            }
                            if (tag.ToUpper() == "FEBRUARI")
                            {
                                month = 2;
                            }
                            if (tag.ToUpper() == "MARS")
                            {
                                month = 3;
                            }
                            if (tag.ToUpper() == "APRIL")
                            {
                                month = 4;
                            }
                            if (tag.ToUpper() == "MAJ")
                            {
                                month = 5;
                            }
                            if (tag.ToUpper() == "JUNI")
                            {
                                month = 6;
                            }
                            if (tag.ToUpper() == "JULI")
                            {
                                month = 7;
                            }
                            if (tag.ToUpper() == "AUGUSTI")
                            {
                                month = 8;
                            }
                            if (tag.ToUpper() == "SEPTEMBER")
                            {
                                month = 9;
                            }
                            if (tag.ToUpper() == "OKTOBER")
                            {
                                month = 10;
                            }
                            if (tag.ToUpper() == "NOVEMBER")
                            {
                                month = 11;
                            }
                            if (tag.ToUpper() == "DECEMBER")
                            {
                                month = 12;
                            }

                            //eller en års-tag
                            string pattern = @"\d{4}";
                            System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(pattern);
                            if (r.IsMatch(tag))
                            {
                                year = Int32.Parse(tag);
                            }
                        }
                    }
                    kfTable.Rows.Add(id, name, year, month);
                }
            }
            //sortera sändningarna per år och månad
            System.Data.DataView dv = kfTable.DefaultView;
            dv.Sort = "year DESC, month DESC";

            //skapa en tabell över de unika åren
            System.Data.DataTable yearsTable = dv.ToTable(true, "year");

            //bygg listan
            html.AppendLine("<select onChange=\"kfListChange()\" id=\"kfList\">");
            foreach (System.Data.DataRow r in yearsTable.Rows)
            {
                html.AppendLine("\t<optgroup label=\"" + r["year"].ToString() + "\">");
                foreach (System.Data.DataRow kfRow in kfTable.Rows)
                {
                    if (kfRow["year"].ToString() == r["year"].ToString())
                    {
                        html.AppendLine("\t\t<option value=\"" + kfRow["id"].ToString() + "\">" + kfRow["name"].ToString().Replace(kfRow["year"].ToString(), "") + "</option>");
                    }
                }
                html.AppendLine("\t</optgroup>");
            }
            html.AppendLine("</select>");

            return(html.ToString());
        }