public void ImportVideos() { /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Import articles with video enabled /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string publicKey = MyGlobals.VideoPublicKey; string secretKey = MyGlobals.VideoSecretKey; int feedNumber; int tempCatID; int tempEntryID; string tempSlug; int PageTabId = 1; //Validation below. I added these validation methods beneath the ImportVideos() method if (!int.TryParse(MyGlobals.VideoFeedText, out feedNumber)) { MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "Invalid video feed number. Stopping"; return; } if (!BraftonVideoClass.ValidateVideoPublicKey(publicKey)) { MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "Invalid video public key. Stopping."; return; } if (!BraftonVideoClass.ValidateGuid(secretKey)) { MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "Invalid video public key. Stopping."; return; } //This is establishing the URLs for the video api,creating a new videoClient object, and then using the client libraries to get the video articles from the feed - Ly //string baseUrl = "http://api.video.brafton.com"; //string basePhotoUrl = "http://pictures.directnews.co.uk/v2/"; string baseUrl = "http://" + MyGlobals.VideoBaseURL + "/v2/"; string basePhotoUrl = "http://" + MyGlobals.VideoPhotoURL + "/v2/"; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "<br>***********************************************<br>"; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "<br>***********Global base URL- brafton.cs***********************<br>"; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + baseUrl; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "<br>***********************************************<br>"; AdferoVideoClient videoClient = new AdferoVideoClient(baseUrl, publicKey, secretKey); AdferoClient client = new AdferoClient(baseUrl, publicKey, secretKey); AdferoPhotoClient photoClient = new AdferoPhotoClient(basePhotoUrl); AdferoVideoOutputsClient xc = new AdferoVideoClient(baseUrl, publicKey, secretKey).VideoOutputs(); AdferoVideoDotNet.AdferoArticles.ArticlePhotos.AdferoArticlePhotosClient photos = client.ArticlePhotos(); string scaleAxis = AdferoVideoDotNet.AdferoPhotos.Photos.AdferoScaleAxis.X; AdferoVideoDotNet.AdferoArticles.Feeds.AdferoFeedsClient feeds = client.Feeds(); AdferoVideoDotNet.AdferoArticles.Feeds.AdferoFeedList feedList = feeds.ListFeeds(0, 10); AdferoVideoDotNet.AdferoArticles.Articles.AdferoArticlesClient articles = client.Articles(); AdferoVideoDotNet.AdferoArticles.Articles.AdferoArticleList articleList = articles.ListForFeed(feedList.Items[feedNumber].Id, "live", 0, 100); int articleCount = articleList.Items.Count; AdferoVideoDotNet.AdferoArticles.Categories.AdferoCategoriesClient categories = client.Categories(); foreach (AdferoVideoDotNet.AdferoArticles.Articles.AdferoArticleListItem item in articleList.Items) { int brafId = item.Id; AdferoVideoDotNet.AdferoArticles.Articles.AdferoArticle article = articles.Get(brafId); MyGlobals.brafID = brafId; string brafIDForInsert = brafId.ToString(); string presplashLink; if (article.Fields.ContainsKey("preSplash")) { presplashLink = article.Fields["preSplash"]; } else { presplashLink = ""; } #region Build Embed /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Build the embed to be added to the content section of the blog entry /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string display = "<video id='video-" + brafIDForInsert + "' class='ajs-default-skin atlantis-js' controls preload='auto' width='512' height='288' poster='" + presplashLink + "'>"; // For each Video Output foreach (AdferoVideoDotNet.AdferoArticlesVideoExtensions.VideoOutputs.AdferoVideoOutputListItem vidOut in videoClient.VideoOutputs().ListForArticle(brafId, 0, 20).Items) { int vidid = vidOut.Id; string displayType = ""; var z = xc.Get(vidid); displayType = z.Path.Substring(z.Path.Length - 3); if (displayType == "flv") { displayType = "flash"; } if (displayType == "ebm") { displayType = "webm"; } string displayPath = z.Path; string displayHeight = z.Height.ToString(); display = display + "<source src='" + displayPath + "' type='video/" + displayType + "' data-resolution='" + displayHeight + "' />"; } // Add the closing tag and the atlantis script display = display + "</video><script type='text/javascript'>var atlantisVideo = AtlantisJS.Init({videos: [{id: 'video-" + brafIDForInsert + "'}]});</script>"; #endregion Build embed #region set globals /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Set Global Variables in Globals.cs /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //This area adds all the fields to the Global variables class so that they are accessible from the BraftonVideoClass //I know there is a better way to do this but I did it this was for simplicity and in case I needed them somewhere else string addDate = article.Fields["date"]; MyGlobals.tempID = brafIDForInsert; if (article.Fields.ContainsKey("title")) { MyGlobals.tempTitle = article.Fields["title"]; } else { MyGlobals.tempTitle = ""; } if (article.Fields.ContainsKey("extract")) { MyGlobals.tempExtract = article.Fields["extract"]; } else { MyGlobals.tempExtract = ""; } if (article.Fields.ContainsKey("content")) { MyGlobals.tempcontent = article.Fields["content"]; } else { MyGlobals.tempcontent = ""; } MyGlobals.tempDate = DateTime.Parse(addDate); MyGlobals.tempPaths = display; #endregion tempEntryID = BraftonVideoClass.InsertVideoPost(); tempSlug = article.Fields["title"]; #region Update Permalink /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Update permalink /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string permalink; string slug = strip(tempSlug); //Create Permalink using (DNNDataLayerDataContext dnnContext = new DNNDataLayerDataContext()) { Brafton.Modules.BraftonImporter7_02_02.dbDataLayer.Blog_Entry pk = dnnContext.Blog_Entries.FirstOrDefault(x => x.BraftonID == brafIDForInsert); //Update the permalink if (pk != null) { permalink = "/blog/EntryId/" + pk.EntryID + "/" + slug; pk.PermaLink = permalink; dnnContext.SubmitChanges(); } } #endregion Update Permalink #region Categories /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Add categories to Blog_Entry_Categories table /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// foreach (AdferoVideoDotNet.AdferoArticles.Categories.AdferoCategoryListItem cats in client.Categories().ListForArticle(brafId, 0, 20).Items) { int categoryId; int catTest = cats.Id; string catName = categories.Get(catTest).Name; if (catName == null) { catName = "Uncategorized"; } int pID = categories.Get(catTest).ParentId; string catslug = strip(catName) + ".aspx"; using (DNNDataLayerDataContext dnnContext = new DNNDataLayerDataContext()) { Brafton.Modules.BraftonImporter7_02_02.dbDataLayer.Blog_Category ca = dnnContext.Blog_Categories.FirstOrDefault(x => x.Category == catName); //Insert into category if (ca != null) { categoryId = ca.CatID; } else { Blog_Category newBlogCat = new Blog_Category(); newBlogCat.Category = catName; newBlogCat.Slug = catslug; newBlogCat.ParentID = pID; newBlogCat.PortalID = 0; dnnContext.Blog_Categories.InsertOnSubmit(newBlogCat); dnnContext.SubmitChanges(); categoryId = newBlogCat.CatID; } Brafton.Modules.BraftonImporter7_02_02.dbDataLayer.Blog_Entry_Category bec = dnnContext.Blog_Entry_Categories.FirstOrDefault(x => x.EntryID == tempEntryID && x.CatID == categoryId); if (bec == null) { Blog_Entry_Category newBlogEntryCat = new Blog_Entry_Category(); newBlogEntryCat.EntryID = tempEntryID; newBlogEntryCat.CatID = categoryId; dnnContext.Blog_Entry_Categories.InsertOnSubmit(newBlogEntryCat); dnnContext.SubmitChanges(); } } } #endregion Categories } #endregion Video Import }
public static int InsertVideoPost() { using (DNNDataLayerDataContext dnnContext = new DNNDataLayerDataContext()) { #region Get all the values //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "ID:" + brafId + "Date:" + article.Fields["date"] + "CONTENT:" + article.Fields["content"] + "<br>"; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "Paths " + MyGlobals.tempPaths + "<br>"; string BraftonID = MyGlobals.tempID; string Title = MyGlobals.tempTitle; string Extract = MyGlobals.tempExtract; DateTime AddedDate = MyGlobals.tempDate; DateTime LastUpdate = DateTime.Today; int brafID = MyGlobals.brafID; //we still need to build permalinks string permalink = ""; int returnId; //add the embed code to the content string embeddedEntry = createEmbedCode(); //now lets add the photos addPhotos(brafID, embeddedEntry, Extract); string completeEntry = MyGlobals.CompleteContent; string completeExtract = MyGlobals.CompleteExtract; //MyGlobals.imageInfo = MyGlobals.imageInfo + completeExtract; #endregion Brafton.Modules.BraftonImporter7_02_02.dbDataLayer.Blog_Entry pk = dnnContext.Blog_Entries.FirstOrDefault(x => x.BraftonID == BraftonID); //IF there is an article then we update if (pk != null) { //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "<br>***********************************************<br>"; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "************Check DB**********************<br>"; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + completeExtract; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "************Updating Extract**********************<br>"; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + completeExtract; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "<br>***********************************************<br>"; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "************Updating Entry/Content**********************<br>"; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + completeEntry; //MyGlobals.MyGlobalError = MyGlobals.MyGlobalError + "<br>***********************************************<br>"; int lastDayUpd = pk.LastUpdatedOn.Value.DayOfYear; int todayDay = 0; //int todayDay = DateTime.Today.DayOfYear; TODO turn this back on returnId = pk.EntryID; //Needed to check for updates to Categories //Unless it was updated today if (lastDayUpd != todayDay) { #region Update pk.Title = Title; pk.Published = true;//This is default unless the client wants to have articles go into draft status this functionality is not built at all as of yet pk.Description = completeExtract; pk.BraftonID = BraftonID; pk.Entry = completeEntry; pk.LastUpdatedOn = LastUpdate; pk.AddedDate = AddedDate; pk.BlogID = 1; pk.PermaLink = permalink; pk.AllowComments = false; dnnContext.SubmitChanges(); #endregion } } else //Else we insert { #region Insert Blog_Entry newBlogEntry = new Blog_Entry(); newBlogEntry.Title = Title; newBlogEntry.Published = true;//This is default unless the client wants to have articles go into draft status this functionality is not built at all as of yet newBlogEntry.Description = completeExtract; newBlogEntry.BraftonID = BraftonID; newBlogEntry.Entry = completeEntry; newBlogEntry.LastUpdatedOn = LastUpdate; newBlogEntry.AddedDate = AddedDate; newBlogEntry.BlogID = 1; newBlogEntry.PermaLink = permalink; newBlogEntry.AllowComments = false; dnnContext.Blog_Entries.InsertOnSubmit(newBlogEntry); dnnContext.SubmitChanges(); returnId = newBlogEntry.EntryID; #endregion } return(returnId); } }
partial void UpdateBlog_Entry(Blog_Entry instance);
partial void DeleteBlog_Entry(Blog_Entry instance);
partial void InsertBlog_Entry(Blog_Entry instance);