Exemple #1
0
        /// <summary>
        ///     判断是否已存在并插入数据
        /// </summary>
        /// <param name="vid">视频的vid</param>
        /// <param name="uri">uri</param>
        /// <returns>结果</returns>
        public VideoTable Insert(string vid, Uri uri)
        {
            var r0 = _videoTable.Query().Where(e => e.Vid.Equals(vid));

            var r1 = r0.Where(e =>
                              e.Referer.Protocol.Equals(uri.Scheme) &&
                              e.Referer.Host.Equals(uri.Host) &&
                              e.Referer.Path.Equals(uri.AbsolutePath) &&
                              (string.IsNullOrEmpty(uri.Query) && string.IsNullOrEmpty(e.Referer.Query) ||
                               e.Referer.Query.Equals(uri.Query)) &&
                              (string.IsNullOrEmpty(uri.Query) && string.IsNullOrEmpty(e.Referer.Query) ||
                               e.Referer.Query.Equals(uri.Query)));

            if (r0.Count() == 0 || r1.Count() == 0)
            {
                var video = new VideoTable
                {
                    Vid     = vid,
                    Referer = new Referer(uri)
                };
                return(Insert(video));
            }

            return(r0.FirstOrDefault());
        }
        /// <summary>
        ///     判断是否已存在并插入数据
        /// </summary>
        /// <param name="vid">视频的vid</param>
        /// <param name="uri">uri</param>
        /// <returns>结果</returns>
        public async Task <VideoTable> InsertAsync(string vid, Uri uri)
        {
            var r0 = _con.Video.Where(e => e.Vid.Equals(vid));

            var r1 = r0.Where(e =>
                              e.Referer.Protocol.Equals(uri.Scheme) &&
                              e.Referer.Host.Equals(uri.Host) &&
                              e.Referer.Path.Equals(uri.AbsolutePath) &&
                              (string.IsNullOrEmpty(uri.Query) && string.IsNullOrEmpty(e.Referer.Query) ||
                               e.Referer.Query.Equals(uri.Query)) &&
                              (string.IsNullOrEmpty(uri.Query) && string.IsNullOrEmpty(e.Referer.Query) ||
                               e.Referer.Query.Equals(uri.Query)));

            if (await r0.CountAsync() == 0 || await r1.CountAsync() == 0)
            {
                var video = new VideoTable
                {
                    Vid     = vid,
                    Referer = new Referer(uri)
                };
                return(await InsertAsync(video));
            }

            return(r0.FirstOrDefault());
        }
        public async Task <IActionResult> Post(VideoTable model, string Token)
        {
            var TokenApi = new Token
            {
                TokenDef = _config.GetValue <string>("Token:TokenDef")
            };

            if (TokenApi.TokenDef != Token)
            {
                return(this.StatusCode(StatusCodes.Status401Unauthorized, $"O Token informado não é autorizado."));
            }
            try
            {
                _repo.Add(model);
                if (await _repo.SaveChangesAsync())
                {
                    return(this.StatusCode(StatusCodes.Status200OK, model));
                }
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Banco de Dados Falhou.{ex.Message}"));
            }
            return(BadRequest());
        }
        public ActionResult Upload(VideoUploaderVM model)
        {
            if (ModelState.IsValid)
            {
                var filePath   = SaveToDisk(model.UploadFile);
                var inputAsset = videoManager.GetAsset(LocalAssetType.File, filePath: filePath);
                //var thumbnailAsset = videoManager.GetAsset(LocalAssetType.Thumbnail, inputAsset);
                //videoManager.PublishAsset(thumbnailAsset, false, ".bmp");
                //var audioOnlyAsset = videoManager.GetAsset(LocalAssetType.AudioOnly, inputAsset);
                //videoManager.PublishAsset(audioOnlyAsset);
                var mp4BitRate = videoManager.GetAsset(LocalAssetType.EncodedMp4, inputAsset);
                videoManager.PublishAsset(mp4BitRate);

                //save the video information to the database
                var vidTable = new VideoTable
                {
                    URL              = videoManager.StreamingUri.ToString(),
                    Thumbnail        = videoManager.ThumbnailUri.ToString(),
                    VideoDateCreated = DateTime.Now,
                    VideoDesc        = model.VideoDescription,
                    Title            = model.VideoTitle,
                    UserProfileID    = _profile.ID
                };
                VideoRep.Add(vidTable);

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Exemple #5
0
        /// <summary>
        ///     插入数据
        /// </summary>
        /// <param name="video"></param>
        /// <returns>结果</returns>
        public VideoTable Insert(VideoTable video)
        {
            var a = !_videoTable.Insert(video).IsNull;

            if (a)
            {
                return(video);
            }
            return(null);
        }
        /// <summary>
        ///     插入数据
        /// </summary>
        /// <param name="video"></param>
        /// <returns>结果</returns>
        public async Task <VideoTable> InsertAsync(VideoTable video)
        {
            var a = await _con.Video.AddAsync(video);

            if (await _con.SaveChangesAsync() > 0)
            {
                return(a.Entity);
            }
            return(null);
        }
 public VideoService()
 {
     _table = VideoTable.GetInstance();
 }
Exemple #8
0
 public static Video CreateVideo(Video video)
 {
     return(VideoTable.AddVideo(video));
 }
        async void OnIndusProdClicked(object sender, EventArgs e)
        {
            Notes = string.Empty;

            IndustryTable _industry = new IndustryTable();
            VideoTable    _video    = new VideoTable();

            //this is  special case or when necessary to Drop Table (expdate is iverdue or language changed)
            if (IndustryTable != null && !(IndustryTable.Equals(string.Empty)))
            {
                try
                {
                    //delete IndustryTable and VideoTable
                    int action = await App.LocalDatabase.DeleteIndustryTableAsync(_industry);

                    action = await App.LocalDatabase.DeleteVideoTableAsync(_video);

                    IndustryTable = null;
                }
                catch (Exception ex) { Notes = ex.Message.ToString() + "   table not droped....."; }
            }
            //await DisplayAlert("Sql Admin", SettingTable, "ok");
            //IndustryTable = null;
            if (IndustryTable == null || IndustryTable.Equals(string.Empty))
            {
                //1,. Create Table
                App.LocalDatabase.CreateIndustryTableAsync();
                App.LocalDatabase.CreateVideoTableAsync();
                Notes += "table created.....";
                //inser records, populate from API call (for this excercise use mock file)
                List <BelProductIndus> results = GetIndusJsonFile("BelzonaMobile.Data.app-manifest-ind-app-us.json");
                //results.Sort();
                results.Sort((x, y) => string.Compare(x.Code, y.Code, StringComparison.Ordinal));
                int master = 0; int child = 0;  string lastCode = string.Empty;
                foreach (var item in results)
                {
                    _video = new VideoTable();
                    if (item.Code != lastCode)
                    {
                        _industry           = new IndustryTable();
                        _industry.ID        = 0;
                        _industry.Title     = item.Title;
                        _industry.Code      = item.Code;
                        _industry.ShortDesc = Regex.Replace(item.ShortDesc, @"<(.|\n)*?>", string.Empty);
                        _industry.LongDesc  = item.LongDesc;
                        _industry.Favourite = 0;
                        int iM = await App.LocalDatabase.SaveIndustryAsync(_industry);

                        master++;
                    }
                    _video.ID               = 0;
                    _video.IndustryCode     = item.Code;
                    _video.VideoName        = item.VideoName;
                    _video.Size             = item.Size;
                    _video.YoutubeLink      = item.YoutubeLink;
                    _video.DataLink         = item.DataLink;
                    _video.VideoDescription = item.VideoDescription;
                    int iC = await App.LocalDatabase.SaveVideoAsync(_video);

                    lastCode = item.Code;
                    child++;
                }

                Notes = string.Format(@"Inserted {0} master \n {1} child records", master, child);
            }
            else
            {
                List <IndustryTable> results = await App.LocalDatabase.GetIndustryTablesAsync();

                //if (results != null) { _table.CurrentLingo = results.CurrentLingo; _table.ExpDate = results.ExpDate; }
                Notes = "Table Exisit ...." + results.Count.ToString();
            }
            await DisplayAlert(ProductTable, Notes, "ok");
        }