コード例 #1
1
ファイル: GridFsHelper.cs プロジェクト: l-azai/medis.NET
        public async Task<bool> FileExistsAsync(string gfsname, MediaTypeEnum bucketName)
        {
            var bucket = new GridFSBucket(_db, new GridFSBucketOptions
            {
                BucketName = bucketName.ToString()
            });
            
            var filter = Builders<GridFSFileInfo>.Filter.Eq(x => x.Filename, gfsname);
            var fileInfo = await bucket.FindAsync(filter);

            return fileInfo.Any();
        }
コード例 #2
0
        /**
         * detach stream from video window
         * @param mediaType: stream mediaType- local, remote, PIP and content
         * @return true: successfully detached; false: fail to detach
         * */
        public static bool DetachStreamFromWindow(MediaTypeEnum mediaType, int streamId, int callHandle)
        {
            log.Debug("[detachStreamFromWindow] mediatype " + mediaType.ToString() + " from video window.");
            if (mediaType != MediaTypeEnum.PLCM_MF_STREAM_LOCAL)
            {
                if (invalidCallHandle != callHandle)
                {
                    var errNo = WrapperProxy.DetachStreamWnd(mediaType, streamId, callHandle);
                    if (ErrorNumberEnum.PLCM_SAMPLE_OK != errNo)
                    {
                        log.Error("detach stream from window failed. Error number = " + errNo.ToString());
                        return(false);
                    }
                }
                else
                {
                    log.Error("no such call to detach stream window");
                    return(false);
                }
            }
            else
            {//for local preview
             //when the media type is local, set the call handle to -1 (invalid call handle)
                var errNo = WrapperProxy.DetachStreamWnd(mediaType, streamId, invalidCallHandle);
                if (ErrorNumberEnum.PLCM_SAMPLE_OK != errNo)
                {
                    log.Error("detach stream from window failed. Error number = " + errNo.ToString());
                    return(false);
                }
            }

            return(true);
        }
コード例 #3
0
ファイル: GridFsHelper.cs プロジェクト: l-azai/medis.NET
        public async Task DownloadToStreamByNameAsync(string gfsname, Stream source, MediaTypeEnum bucketName) {
            var bucket = new GridFSBucket(_db, new GridFSBucketOptions
            {
                BucketName = bucketName.ToString()
            });

            await bucket.DownloadToStreamByNameAsync(gfsname, source);
        }
コード例 #4
0
ファイル: GridFsHelper.cs プロジェクト: l-azai/medis.NET
        public async Task<byte[]> DownloadAsBytesAsync(ObjectId id, MediaTypeEnum bucketName)
        {
            var bucket = new GridFSBucket(_db, new GridFSBucketOptions
            {
                BucketName = bucketName.ToString()
            });

            return await bucket.DownloadAsBytesAsync(id);
        }
コード例 #5
0
        public async Task DownloadToStreamAsync(ObjectId id, Stream source, MediaTypeEnum bucketName)
        {
            var bucket = new GridFSBucket(_mongoDatabase, new GridFSBucketOptions
            {
                BucketName = bucketName.ToString()
            });

            await bucket.DownloadToStreamAsync(id, source);
        }
コード例 #6
0
        public async Task DownloadToStreamByNameAsync(string gfsname, Stream source, MediaTypeEnum bucketName)
        {
            var bucket = new GridFSBucket(_mongoDatabase, new GridFSBucketOptions
            {
                BucketName = bucketName.ToString()
            });

            await bucket.DownloadToStreamByNameAsync(gfsname, source);
        }
コード例 #7
0
ファイル: GridFsHelper.cs プロジェクト: l-azai/medis.NET
        public async Task<GridFSDownloadStream> OpenDownloadStreamByNameAsync(string name, MediaTypeEnum bucketName)
        {
            var bucket = new GridFSBucket(_db, new GridFSBucketOptions
            {
                BucketName = bucketName.ToString()
            });

            return await bucket.OpenDownloadStreamByNameAsync(name);
        }
コード例 #8
0
ファイル: GridFsHelper.cs プロジェクト: l-azai/medis.NET
        public async Task<GridFSDownloadStream> OpenDownloadStreamAsync(ObjectId id, MediaTypeEnum bucketName)
        {
            var bucket = new GridFSBucket(_db, new GridFSBucketOptions
            {
                BucketName = bucketName.ToString()
            });

            return await bucket.OpenDownloadStreamAsync(id);
        }
コード例 #9
0
ファイル: GridFsHelper.cs プロジェクト: l-azai/medis.NET
 public async Task DownloadToStreamAsync(ObjectId id, Stream source, MediaTypeEnum bucketName)
 {
     var bucket = new GridFSBucket(_db, new GridFSBucketOptions
     {
         BucketName = bucketName.ToString()
     });
     
     await bucket.DownloadToStreamAsync(id, source);
 }
コード例 #10
0
ファイル: GridFsHelper.cs プロジェクト: l-azai/medis.NET
        public async Task<ObjectId> UploadFromStreamAsync(string gfsname, Stream source,string filename, MediaTypeEnum bucketName)
        {
            var bucket = new GridFSBucket(_db, new GridFSBucketOptions {
                BucketName = bucketName.ToString()
            });

            var options = new GridFSUploadOptions {
                Metadata = new BsonDocument {
                    { "filename", filename },
                    { "contentType", MimeMapping.GetMimeMapping(filename) }
                }
            };

            return await bucket.UploadFromStreamAsync(gfsname, source, options);
        }
コード例 #11
0
        /// <summary>
        /// Favorites or unfavorites a media item.
        /// </summary>
        /// <param name="inMediaType">The media item type to favorite. Either, <see cref="MediaTypeEnum.movie"/> or <see cref="MediaTypeEnum.tv"/>.</param>
        /// <param name="inMediaId">The media's ID.</param>
        /// <param name="inWatchlsit">Favorite or unfavorite media item.</param>
        public async Task favoriteMediaItem(MediaTypeEnum inMediaType, int inMediaId, bool inFavorite)
        {
            // Written, 05.12.2019

            if (inMediaType != MediaTypeEnum.movie && inMediaType != MediaTypeEnum.tv)
            {
                throw new ArgumentException("Expected MediaTypeEnum.movie or MediaTypeEnum.tv. invaild argument");
            }

            string  address     = String.Format("{0}/{1}/favorite?session_id={2}&api_key={3}", ApplicationInfomation.ACCOUNT_ADDRESS, this.id, this.session.session_id, ApplicationInfomation.API_KEY);
            JObject requestData = new JObject(
                new JProperty("media_type", inMediaType.ToString()),
                new JProperty("media_id", inMediaId),
                new JProperty("favorite", inFavorite));
            await WebResponse.toJObject(await WebResponse.sendRequestAsync(new Uri(address), System.Text.Encoding.UTF8.GetBytes(requestData.ToString())));
        }
コード例 #12
0
        public async Task <ObjectId> UploadFromStreamAsync(IFormFile file, MediaTypeEnum bucketName)
        {
            var bucket = new GridFSBucket(_mongoDatabase, new GridFSBucketOptions
            {
                BucketName = bucketName.ToString()
            });

            var options = new GridFSUploadOptions
            {
                Metadata = new BsonDocument {
                    { "filename", file.FileName },
                    { "contentType", file.ContentType }
                }
            };

            return(await bucket.UploadFromStreamAsync(file.FileName, file.OpenReadStream(), options));
        }
コード例 #13
0
        /// <summary>
        /// 返回响应类型
        /// </summary>
        /// <param name="mediaType">
        /// 枚举类型  json or xml
        /// </param>
        /// <returns>
        /// The <see cref="MediaTypeWithQualityHeaderValue"/>.
        /// </returns>
        public static MediaTypeWithQualityHeaderValue GetMediaTpye(MediaTypeEnum mediaType)
        {
            var pre = "application/";

            switch (mediaType)
            {
            case MediaTypeEnum.Json:
                pre = "application/";
                break;

            case MediaTypeEnum.Xml:
                pre = "application/";
                break;

            case MediaTypeEnum.Plain:
                pre = "text/";
                break;
            }

            return(new MediaTypeWithQualityHeaderValue(pre + mediaType.ToString().ToLower()));
        }
コード例 #14
0
ファイル: DatabaseService.cs プロジェクト: forkbomb/pikto
        public piktogramy EditPiktogram(string name, MediaTypeEnum mediumName, object mediumObject = null, string categoryName = null, object image = null)
        {
            piktogramy pikt = GetPiktogram(name);
            pikt.name = name ?? pikt.name;

            pikt.media_id = this.AddMedium(mediumName.ToString(), mediumObject);
            byte[] img;
            JpegBitmapEncoder encoder = new JpegBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(image as BitmapSource));
            using (MemoryStream ms = new MemoryStream())
            {
                encoder.Save(ms);
                img = ms.ToArray();
            }
            pikt.image = img;

            if (categoryName != null)
            {
                category cat = GetCategory(categoryName);
                pikt.category_id = cat.id;
            }

            db.SaveChanges();
            return pikt;
        }
コード例 #15
0
ファイル: DatabaseService.cs プロジェクト: forkbomb/pikto
        public void AddPiktogram(string name, MediaTypeEnum mediumName, object mediumObject, string categoryName, object image)
        {
            var piktogram = db.CreateObject<piktogramy>();
            piktogram.name = name;
            piktogram.media_id = this.AddMedium(mediumName.ToString(), mediumObject);

            category cat = GetCategory(categoryName);
            if (cat == null)
            {
                AddCategory(categoryName);
                cat = GetCategory(categoryName);
            }
            piktogram.category_id = cat.id;
            byte[] img;
            JpegBitmapEncoder encoder = new JpegBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(image as BitmapSource));
            using (MemoryStream ms = new MemoryStream())
            {
                encoder.Save(ms);
                img = ms.ToArray();
            }
            piktogram.image = img;
            // bardzo brzydko!
            piktogram.id = GetAllPiktograms().Count;
            // koniec brzydko
            db.piktogramies.AddObject(piktogram);
            db.SaveChanges();
        }
コード例 #16
0
ファイル: DatabaseService.cs プロジェクト: forkbomb/pikto
        public void AddPiktogram(string name, MediaTypeEnum mediumName, object mediumObject, string categoryName)
        {
            var piktogram = db.CreateObject<piktogramy>();
            piktogram.name = name;
            piktogram.media_id = this.AddMedium(mediumName.ToString(), mediumObject);

            category cat = GetCategory(categoryName);
            if (cat == null)
            {
                AddCategory(categoryName);
                cat = GetCategory(categoryName);
            }
            piktogram.category_id = cat.id;

            db.piktogramies.AddObject(piktogram);
            db.SaveChanges();
        }
コード例 #17
0
        public static bool AttachStreamToWindow(IntPtr wndHandle, int callHandle, MediaTypeEnum mediaType, int streamId, int width, int height)
        {
            log.Debug("[attachStreamToWindow] callHandle:" + callHandle + " mediatype:" + mediaType.ToString() + " streamId:" + streamId + " to window(width: " + width + " height: " + height + " )");
            var errNo = WrapperProxy.AttachStreamWnd(mediaType, streamId, callHandle, wndHandle, 0, 0, width, height);

            if (ErrorNumberEnum.PLCM_SAMPLE_OK != errNo)
            {
                log.Error("attach stream to window failed. Error number = " + errNo.ToString());
                return(false);
            }
            return(true);
        }
コード例 #18
0
        public async Task <IList <ServiceItem> > OnlineSearch(string keyword, MediaTypeEnum media)
        {
            QueryQL query = new QueryQL()
            {
                query     = @"
                            query ($search: String, $type: MediaType) {
                              anime: Page {
                                media(search: $search, type: $type) {
                                  coverImage {
                                    large
                                    color
                                  }
                                  startDate {
                                    year
                                  }
                                  seasonInt
                                  id
                                  idMal
                                  title {
                                    romaji
                                  }
                                  status
                                  episodes
                                  averageScore
                                  format
                                  description(asHtml: false)
                                }
                              }
                            }",
                variables = new Dictionary <string, dynamic>
                {
                    ["search"] = keyword,
                    ["type"]   = media.ToString()
                }
            };
            Dictionary <string, dynamic> result = await AnilistPostAsync(query);

            var items = new List <ServiceItem>();

            foreach (var item in result["data"]["anime"]["media"])
            {
                //using coalese expression (?? argument) can cause an exception.
                var itemstatus   = StatusEnum.Anilist_ItemStatus[item["status"].Value];
                int?seasonint    = (int?)item["seasonInt"];
                int season       = seasonint.HasValue ? seasonint.Value % 10 : 0;
                int?startdate    = (int?)item["startDate"]["year"];
                int?EpisodeCheck = (int?)item["episodes"];
                int episodes     = EpisodeCheck.HasValue ? EpisodeCheck.Value : default(int);
                var mal_id       = (item["idMal"] != null) ? item["idMal"] : -1;
                var serviceitem  = new ServiceItem()
                {
                    Service           = ServiceType.ANILIST,
                    MalID             = mal_id,
                    ServiceID         = (int)item["id"],
                    Title             = item["title"]["romaji"],
                    CoverImageUri     = item["coverImage"]["large"],
                    Description       = item["description"],
                    AverageScore      = (double?)item["averageScore"],
                    ItemStatus        = itemstatus,
                    SeriesStart       = startdate ?? 0,
                    Episodes_Chapters = episodes,
                    Season            = (SeasonsEnum?)season
                };
                items.Add(serviceitem);
            }
            return(items);
        }
コード例 #19
0
ファイル: GridFsHelper.cs プロジェクト: l-azai/medis.NET
        public async Task<byte[]> DownloadAsBytesByNameAsync(string gfsname, MediaTypeEnum bucketName) {
            var bucket = new GridFSBucket(_db, new GridFSBucketOptions
            {
                BucketName = bucketName.ToString()
            });

            return await bucket.DownloadAsBytesByNameAsync(gfsname);
        }
コード例 #20
0
 public static MediaType GetByEnum(MediaTypeEnum mediaTypeEnum)
 {
     return(GetDataModel().MediaTypes.FirstOrDefault(item => item.Name == mediaTypeEnum.ToString()));
 }