예제 #1
0
        public async Task <bool> PushRecommendedQuestionsNotification(
            RecommendedQuestionNotification recommendedQuestionNotification)
        {
            Logger.LogInformation($"{nameof(NotificationsMessageService)}.{nameof(PushRecommendedQuestionsNotification)}.Start");
            var info = await Db.UsersInfo.FindUserInfoAsync(recommendedQuestionNotification.NotifierId);

            if (info == null)
            {
                return(false);
            }
            var notification = new Notification
            {
                UserId          = recommendedQuestionNotification.NotifierId,
                Login           = info.FirstName + " " + info.LastName,
                SmallAvatarLink = MediaConverter.ToFullAvatarUrl(info.OriginalAvatarUrl, AvatarSizeType.Small),
                ActionType      = ActionType.Follow,
                EmmiterId       = recommendedQuestionNotification.QuestionId,
                ActionDate      = recommendedQuestionNotification.RecommendedDate
            };

            await PushNotification(recommendedQuestionNotification.UserToId, notification);

            Logger.LogInformation($"{nameof(NotificationsMessageService)}.{nameof(PushRecommendedQuestionsNotification)}.End");
            return(true);
        }
예제 #2
0
 public CommonAuthService(IJwtService jwtService, AuthorizationUnitOfWork db, ILogger <CommonAuthService> logger, MediaConverter mediaConverter)
 {
     Db             = db;
     JwtService     = jwtService;
     Logger         = logger;
     MediaConverter = mediaConverter;
 }
예제 #3
0
        private static async Task <bool> SendSegmentAsync(string fileName, IOwinContext context, StreamItem streamItem)
        {
            if (!string.IsNullOrEmpty(fileName) && streamItem.StreamContext is TranscodeContext tc)
            {
                using (await streamItem.RequestBusyLockAsync(SendDataCancellation.Token))
                {
                    var segment = await MediaConverter.GetSegmentFileAsync((VideoTranscoding)streamItem.TranscoderObject.TranscodingParameter, tc, fileName);

                    if (segment != null)
                    {
                        if (segment.Value.ContainerEnum is VideoContainer)
                        {
                            VideoTranscoding video    = (VideoTranscoding)streamItem.TranscoderObject.TranscodingParameter;
                            List <string>    profiles = ProfileMime.ResolveVideoProfile((VideoContainer)segment.Value.ContainerEnum, video.TargetVideoCodec, video.TargetAudioCodec, EncodingProfile.Unknown, 0, 0, 0, 0, 0, 0, Timestamp.None);
                            string           mime     = "video/unknown";
                            ProfileMime.FindCompatibleMime(streamItem.Profile, profiles, ref mime);
                            context.Response.ContentType = mime;
                        }
                        else if (segment.Value.ContainerEnum is SubtitleCodec)
                        {
                            context.Response.ContentType = SubtitleHelper.GetSubtitleMime((SubtitleCodec)segment.Value.ContainerEnum);
                        }
                        bool onlyHeaders = context.Request.Method == "HEAD" || context.Response.StatusCode == (int)HttpStatusCode.NotModified;
                        Logger.Debug("RetrieveStream: Sending file header only: {0}", onlyHeaders.ToString());

                        await SendWholeFileAsync(context, segment.Value.FileData, onlyHeaders);

                        // Close the Stream so that FFMpeg can replace the playlist file
                        segment.Value.FileData.Dispose();
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #4
0
        public static NewsRecommendedQuestionViewModel MapNewsRecommendedQuestionsViewModel(
            this NewsRecommendedQuestionDto dto, MediaConverter mediaConverter, IEnumerable <TagDb> dbTags, IEnumerable <PhotoDb> dbFirstPhotos,
            IEnumerable <PhotoDb> dbSecondPhotos, BackgroundSizeType backgroundSizeType)
        {
            var viewModel =
                QuestionDbToViewModel <NewsRecommendedQuestionViewModel>(dto, mediaConverter, dbTags, dbFirstPhotos,
                                                                         dbSecondPhotos, backgroundSizeType);

            viewModel.RecommendedUsers = new List <NewsUserViewModel>(dto.RecommendedUsers.Count);

            foreach (var user in dto.RecommendedUsers)
            {
                viewModel.RecommendedUsers.Add(new NewsUserViewModel
                {
                    UserId  = user.UserId,
                    Login   = user.FirstName + " " + user.LastName,
                    SexType = user.SexType
                });
            }



            viewModel.Priority = dto.Priority;
            viewModel.NewsType = NewsType.Recommended;

            return(viewModel);
        }
예제 #5
0
 public void StopTranscoding()
 {
     if (TranscodingParameter != null)
     {
         MediaConverter.StopTranscodeAsync(_clientId, TranscodingParameter.TranscodeId);
     }
 }
        public static UserInfoViewModel MapToUserInfoViewModel(
            this UserInfoDto dbEntity, MediaConverter mediaConverter)
        {
            var viewModel = new UserInfoViewModel
            {
                UserId         = dbEntity.UserId,
                Login          = dbEntity.FirstName + " " + dbEntity.LastName,
                Age            = dbEntity.BirthDate.Age(),
                SexType        = dbEntity.SexType,
                City           = dbEntity.City,
                Description    = dbEntity.Description,
                LargeAvatarUrl = mediaConverter.ToFullAvatarUrl(dbEntity.OriginalAvatarUrl, AvatarSizeType.Large),
                SmallAvatarUrl = mediaConverter.ToFullAvatarUrl(dbEntity.OriginalAvatarUrl, AvatarSizeType.Small),
                IsYouFollowed  = dbEntity.IsYouFollowed,
                IsHeFollowed   = dbEntity.IsHeFollowed,

                AskedQuestionsCount = dbEntity.AskedQuestionsCount,
                AnswersCount        = dbEntity.AnswersCount,
                FollowersCount      = dbEntity.FollowersCount,
                FollowedCount       = dbEntity.FollowingsCount,
                FavoritesCount      = dbEntity.FavoritesCount,
                CommentsCount       = dbEntity.CommentsCount,
            };

            return(viewModel);
        }
예제 #7
0
        public IActionResult  Post([ModelBinder(BinderType = typeof(JsonModelBinder))] RequestMediaJsonModel JsonModel, List <IFormFile> Images)
        {
            ResponseModel <List <ResponseModel <MediaFile> > > vResult;

            try
            {
                var workWithFiles = new MediaConverter(JsonModel.Base64Files, JsonModel.FileUrlList, Images).DownloadAndCreatePreview();
                if (!workWithFiles.IsOk)
                {
                    throw  new CustomException(workWithFiles.Code, workWithFiles.Message);
                }

                vResult = workWithFiles;
            }
            catch (CustomException ce)
            {
                return(BadRequest(ce.Message));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }

            return(Ok(vResult));
        }
예제 #8
0
        public async Task <bool> CommentNotification(CommentNotification commentNotification)
        {
            Logger.LogInformation($"{nameof(NotificationsMessageService)}.{nameof(CommentNotification)}.Start");
            var info = await Db.UsersInfo.FindUserInfoAsync(commentNotification.NotifierId);

            if (info == null)
            {
                return(false);
            }
            var sendToId = await Db.Notifications.GetUserIdForComment(commentNotification.CommentId);

            if (sendToId <= 0)
            {
                return(false);
            }

            var notification = new Notification
            {
                UserId          = commentNotification.NotifierId,
                Login           = info.FirstName + " " + info.LastName,
                SmallAvatarLink = MediaConverter.ToFullAvatarUrl(info.OriginalAvatarUrl, AvatarSizeType.Small),
                ActionType      = ActionType.Follow,
                EmmiterId       = commentNotification.CommentId,
                ActionDate      = commentNotification.CommentedDate
            };

            await PushNotification(sendToId, notification);

            Logger.LogInformation($"{nameof(NotificationsMessageService)}.{nameof(CommentNotification)}.End");
            return(true);
        }
예제 #9
0
 public void StopTranscoding()
 {
     if (TranscodingParameter != null)
     {
         MediaConverter.StopTranscodeAsync(Client.ClientId.ToString(), TranscodingParameter.TranscodeId).Wait();
     }
 }
예제 #10
0
 public NotificationsMessageService(ConnectionsHub hub, NotificationsDataUnitOfWork db, NotificationManager notificationManager, ILogger <NotificationsMessageService> logger, MediaConverter mediaConverter)
 {
     Db  = db;
     Hub = hub;
     NotificationManager = notificationManager;
     Logger         = logger;
     MediaConverter = mediaConverter;
 }
예제 #11
0
 public CommentsController(QuestionsUnitOfWork mainDb, ConnectionsHub hub, ILogger <ComplaintsController> logger,
                           MediaConverter mediaConverter)
 {
     MainDb         = mainDb;
     Hub            = hub;
     Logger         = logger;
     MediaConverter = mediaConverter;
 }
예제 #12
0
 public QuestionsController(QuestionsUnitOfWork mainDb, ILogger <QuestionsController> logger, ConnectionsHub hub,
                            MediaConverter mediaConverter)
 {
     MainDb         = mainDb;
     Logger         = logger;
     Hub            = hub;
     MediaConverter = mediaConverter;
 }
예제 #13
0
        public static UserFavoriteQuestionsViewModel MapToUserFavoriteQuestionsViewModel(
            this UserFavoriteQuestionDb dbEntity, MediaConverter mediaConverter, IEnumerable <TagDb> dbTags, IEnumerable <PhotoDb> dbFirstPhotos,
            IEnumerable <PhotoDb> dbSecondPhotos, BackgroundSizeType backgroundSizeType)
        {
            var viewModel =
                QuestionDbToViewModel <UserFavoriteQuestionsViewModel>(dbEntity, mediaConverter, dbTags, dbFirstPhotos, dbSecondPhotos, backgroundSizeType);

            return(viewModel);
        }
예제 #14
0
 public NewsQuestionsController(QuestionsUnitOfWork mainDb, DbContextOptions <TwoButtonsContext> dbOptions,
                                ConnectionsHub hub, ILogger <NewsQuestionsController> logger, MediaConverter mediaConverter)
 {
     MainDb         = mainDb;
     DbOptions      = dbOptions;
     Hub            = hub;
     Logger         = logger;
     MediaConverter = mediaConverter;
 }
예제 #15
0
 public ExternalAuthService(AuthorizationUnitOfWork db, ConnectionsHub hub, IVkService vkService,
                            IFbService fbService, ILogger <ExternalAuthService> logger, MediaConverter mediaConverter)
 {
     Db             = db;
     Hub            = hub;
     VkService      = vkService;
     FbService      = fbService;
     Logger         = logger;
     MediaConverter = mediaConverter;
 }
예제 #16
0
        protected virtual void OnChanged()
        {
            if (Text == null || Icon == null)
            {
                return;
            }

            textNode.Text    = Text;
            imageNode.Source = MediaConverter.ImageSourceFromBitmap(MediaConverter.GetBitmapByName(Icon));
        }
예제 #17
0
 public FriendsService(IOptions <FacebookAuthSettings> fbAuthSettingsAccessor,
                       IOptions <VkAuthSettings> vkAuthSettingsAccessor, IOptions <JwtSettings> jwtOptions,
                       SocialDataUnitOfWork socialDb, ILogger <FriendsService> logger, MediaConverter mediaConverter)
 {
     FbAuthSettings = fbAuthSettingsAccessor.Value;
     VkAuthSettings = vkAuthSettingsAccessor.Value;
     Logger         = logger;
     SocialDb       = socialDb;
     MediaConverter = mediaConverter;
 }
예제 #18
0
        public MainWindow()
        {
            Icon = MediaConverter.ImageSourceFromBitmap(Properties.Resources.Fire.ToBitmap());
            InitializeComponent();

            nvFrom.OnFormSubmit     += NvFrom_OnFormSubmit;
            core.RunWorkerCompleted += Core_RunWorkerCompleted;

            SetupLog();
        }
예제 #19
0
 public AccountService(AccountDataUnitOfWork accountDb, ConnectionsHub hub, IVkService vkService,
                       IFbService fbService, ILogger <AccountService> logger, MediaConverter mediaConverter)
 {
     Db             = accountDb;
     Hub            = hub;
     VkService      = vkService;
     FbService      = fbService;
     Logger         = logger;
     MediaConverter = mediaConverter;
 }
예제 #20
0
 public PreviewRecordingJob(DatabaseContext context,
                            IConfiguration config,
                            IHubContext <MessageHub> hub,
                            ChromaKeyParamGuesser chromaKeyParamGuesser,
                            MediaConverter converter)
 {
     this._context = context;
     this._config  = config;
     this.hub      = hub;
     this.chromaKeyParamGuesser = chromaKeyParamGuesser;
     this.converter             = converter;
 }
예제 #21
0
        public MediaManager(string ffmpegExecutablePath, string mp4boxExecutablePath, string host, string username, string password, int port)
        {
            this.converter = new MediaConverter(ffmpegExecutablePath, mp4boxExecutablePath);
            this.deployer  = new SFTPMediaDeployer(host, username, password, port);

            // Converter Events
            this.ConvertionDone += this.converter.ConvertionDone;
            this.OutputReceived += this.converter.OutputReceived;
            this.ErrorReceived  += this.converter.ErrorReceived;

            // Deployer Callback
            this.deployer.ProgressStatus = this.ProgressStatus;
        }
예제 #22
0
        /// <summary>
        /// Does the preparation to start a transcode stream
        /// </summary>
        internal static async Task <TranscodeContext> StartTranscodeStreamingAsync(EndPointSettings client, double startTime, double lengthTime, StreamItem newStreamItem)
        {
            if (STREAM_ITEMS.TryAdd(client.ClientId, newStreamItem))
            {
                await newStreamItem.BusyLock.WaitAsync();

                try
                {
                    if (newStreamItem?.TranscoderObject?.TranscodingParameter == null)
                    {
                        STREAM_ITEMS.TryRemove(client.ClientId, out _);
                        return(null);
                    }

                    if (!newStreamItem.TranscoderObject.StartTrancoding())
                    {
                        Logger.Debug("StreamControl: Transcoding busy for mediaitem {0}", newStreamItem.RequestedMediaItem);
                        return(null);
                    }

                    if (newStreamItem.IsLive)
                    {
                        newStreamItem.StreamContext = await MediaConverter.GetLiveStreamAsync(client.ClientId.ToString(), newStreamItem.TranscoderObject.TranscodingParameter, newStreamItem.LiveChannelId, true);
                    }
                    else
                    {
                        newStreamItem.StreamContext = await MediaConverter.GetMediaStreamAsync(client.ClientId.ToString(), newStreamItem.TranscoderObject.TranscodingParameter, startTime, lengthTime, true);
                    }

                    if (newStreamItem.StreamContext is TranscodeContext context)
                    {
                        context.UpdateStreamUse(true);
                        return(context);
                    }
                    else if (newStreamItem.StreamContext != null)
                    {
                        //We want a transcoded stream
                        newStreamItem.StreamContext.Dispose();
                        newStreamItem.StreamContext = null;
                    }

                    return(null);
                }
                finally
                {
                    newStreamItem.BusyLock.Release();
                }
            }

            return(null);
        }
예제 #23
0
        //public int UserId { get; set; }
        //public string Login { get; set; }
        //public int Age { get; set; }
        //public SexType SexType { get; set; }
        //public string Description { get; set; }
        //public string SmallAvatarUrl { get; set; }
        //public string LargeAvatarUrl { get; set; }
        //public bool IsYouFollowed { get; set; }
        //public bool IsHeFollowed { get; set; }

        //public int AskedQuestionsCount { get; set; }
        //public int AnswersCount { get; set; }
        //public int FollowersCount { get; set; }
        //public int FollowedCount { get; set; }
        //public int FavoritesCount { get; set; }
        //public int CommentsCount { get; set; }

        //public UserStatisticsViewModel UserStatistics { get; set; } = new UserStatisticsViewModel();
        //public List<UserContactsViewModel> Social { get; set; } = new List<UserContactsViewModel>();

        public static UserInfoViewModel CreateFromUserInfoDb(UserInfoDto userInfo, MediaConverter mediaConverter)
        {
            return(new UserInfoViewModel
            {
                BirthDate = userInfo.BirthDate,
                City = userInfo.City,
                Description = userInfo.Description,
                LargeAvatarUrl = mediaConverter.ToFullAvatarUrl(userInfo.OriginalAvatarUrl, AvatarSizeType.Large),
                SmallAvatarUrl = mediaConverter.ToFullAvatarUrl(userInfo.OriginalAvatarUrl, AvatarSizeType.Small),
                Login = userInfo.FirstName + " " + userInfo.LastName,
                SexType = userInfo.SexType,
                UserId = userInfo.UserId
            });
        }
예제 #24
0
 public static List <AnsweredListViewModel> MapAnsweredListDbToViewModel(
     this IEnumerable <AnsweredListDb> answeredList, MediaConverter mediaConverter)
 {
     return(answeredList.Select(v => new AnsweredListViewModel
     {
         UserId = v.UserId,
         Login = v.FirstName + " " + v.LastName,
         SmallAvatarUrl = mediaConverter.ToFullAvatarUrl(v.OriginalAvatarUrl, AvatarSizeType.Small),
         Age = v.BirthDate.Age(),
         SexType = v.SexType,
         IsHeFollowed = v.IsHeFollowed,
         IsYouFollowed = v.IsYouFollowed
     }).ToList());
 }
예제 #25
0
        public void IsConvertingToMp3()
        {
            MediaDownloader downloader   = new MediaDownloader();
            MediaFile       mediaFile    = MediaFile.CreateNew(VboxDownloadConvertTests.VboxDownloadVideo);
            string          existingPath = Path.Combine(Directory.GetCurrentDirectory(), mediaFile.Metadata.FileName + mediaFile.Metadata.FileExtension);

            if (!File.Exists(existingPath))
            {
                downloader.Download(mediaFile, Directory.GetCurrentDirectory());
            }

            MediaConverter converter = new MediaConverter();
            ConvertResult  result    = converter.Convert(mediaFile, existingPath, Directory.GetCurrentDirectory(), new MediaConverterMetadata(Bitrates.Kbps192));

            Assert.IsTrue(result.IsConverted);
            Assert.IsTrue(File.Exists(result.ConvertedPath));
        }
예제 #26
0
        /// <summary>
        /// Does the preparation to start a stream
        /// </summary>
        internal static async Task <StreamContext> StartOriginalFileStreamingAsync(string identifier)
        {
            if (STREAM_ITEMS.TryGetValue(identifier, out var currentStreamItem))
            {
                using (await currentStreamItem.RequestBusyLockAsync())
                {
                    if (currentStreamItem.IsActive)
                    {
                        currentStreamItem.TranscoderObject?.StopStreaming();
                        if (currentStreamItem.StreamContext is TranscodeContext context)
                        {
                            context.UpdateStreamUse(false);
                        }
                        else if (currentStreamItem.StreamContext != null)
                        {
                            currentStreamItem.StreamContext.Dispose();
                            currentStreamItem.StreamContext = null;
                        }
                    }

                    IMediaAccessor           mediaAccessor = ServiceRegistration.Get <IMediaAccessor>();
                    List <IResourceAccessor> resources     = new List <IResourceAccessor>();
                    foreach (var res in currentStreamItem.TranscoderObject.Metadata.FilePaths)
                    {
                        var path = ResourcePath.Deserialize(res.Value);
                        if (mediaAccessor.LocalResourceProviders.TryGetValue(path.BasePathSegment.ProviderId, out var resourceProvider) &&
                            resourceProvider is IBaseResourceProvider baseProvider && baseProvider.TryCreateResourceAccessor(res.Value, out var accessor))
                        {
                            using (accessor)
                            {
                                if (accessor is IFileSystemResourceAccessor)
                                {
                                    currentStreamItem.TranscoderObject.StartStreaming();
                                    currentStreamItem.StreamContext = await MediaConverter.GetFileStreamAsync(path);

                                    return(currentStreamItem.StreamContext);
                                }
                            }
                        }
                    }
                }
            }

            return(null);
        }
예제 #27
0
        public void ConversionEndedEventTest()
        {
            MediaDownloader downloader = new MediaDownloader();

            MediaFile file           = MediaFile.CreateNew(VboxDownloadVideo);
            string    downloadedPath = downloader.Download(file, Environment.GetFolderPath(Environment.SpecialFolder.Desktop)).DownloadPath;
            bool      converting     = false;

            MediaConverter converter = new MediaConverter();

            converter.MediaFileConvertionCompelete += delegate { converting = true; };
            converter.Convert(file, downloadedPath, Environment.GetFolderPath(Environment.SpecialFolder.Desktop), new MediaConverterMetadata
            {
                AudioBitrate = Bitrates.Kbps192,
                Extension    = SupportedConversionFormats.Mp3,
                FileName     = file.Metadata.FileName
            });

            Assert.AreEqual(true, converting);
        }
        private async Task ConvertFiles()
        {
            IsConversionInProgress = true;
            StartConversionCommand.RaiseCanExecuteChanged();
            BrowseTargetFolderCommand.RaiseCanExecuteChanged();

            if (!Directory.Exists(TargetFolderPath))
            {
                Directory.CreateDirectory(TargetFolderPath);
            }

            var converter = new MediaConverter(TargetFolderPath);
            await converter.ConvertFiles(InputItems.Select((item) => item.FilePath).ToArray());

            InputItems.Clear();

            IsConversionInProgress = false;
            StartConversionCommand.RaiseCanExecuteChanged();
            BrowseTargetFolderCommand.RaiseCanExecuteChanged();
        }
예제 #29
0
        public static T QuestionDbToViewModel <T>(this QuestionBaseDb dbEntity, MediaConverter mediaConverter, IEnumerable <TagDb> dbTags,
                                                  IEnumerable <PhotoDb> dbFirstPhotos, IEnumerable <PhotoDb> dbSecondPhotos, BackgroundSizeType backgroundSizeType) where T : QuestionBaseViewModel, new()
        {
            var question = new T
            {
                QuestionId = dbEntity.QuestionId,
                Condition  = dbEntity.Condition,
                Options    =
                    new List <Option>
                {
                    new Option(dbEntity.FirstAnswersCount, dbEntity.FirstOption),
                    new Option(dbEntity.SecondAnswersCount, dbEntity.SecondOption)
                },
                BackgroundUrl = dbEntity.OriginalBackgroundUrl != null?mediaConverter.ToFullBackgroundurlUrl(dbEntity.OriginalBackgroundUrl, backgroundSizeType) : null,
                                    QuestionType    = dbEntity.QuestionType,
                                    QuestionAddDate = dbEntity.AddedDate,
                                    Author          = new AuthorViewModel
                {
                    UserId         = dbEntity.UserId,
                    Login          = dbEntity.FirstName + " " + dbEntity.LastName,
                    SexType        = dbEntity.SexType,
                    SmallAvatarUrl = dbEntity.OriginalAvatarUrl != null?mediaConverter.ToFullAvatarUrl(dbEntity.OriginalAvatarUrl, AvatarSizeType.Small) : null
                },

                LikesCount       = dbEntity.LikesCount,
                DislikesCount    = dbEntity.DislikesCount,
                YourFeedbackType = dbEntity.YourFeedbackType,
                YourAnswerType   = dbEntity.YourAnswerType,
                IsFavorite       = dbEntity.IsFavorite,
                IsSaved          = dbEntity.IsSaved,
                CommentsCount    = dbEntity.CommentsCount,
                Tags             = dbTags.MapTagsDbToTagViewModel(),
                Photos           = new List <List <PhotoViewModel> >()
                {
                    dbFirstPhotos.MapPhotosDbToViewModel(mediaConverter), dbSecondPhotos.MapPhotosDbToViewModel(mediaConverter)
                }
            };

            return(question);
        }
예제 #30
0
        private async void HandleFileConversion(string filepath)
        {
            //Path.get
            string filename = Path.GetFileNameWithoutExtension(filepath);

            var job = new ConversionItem
            {
                Title = filename,
            };

            ConversionJobs.Add(job);
            ConversionJobsListView.ScrollIntoView(job);

            // Convert
            job.Status = ConversionJobStatus.Converting;
            filename   = MediaConverter.RemoveInvalidFilenameCharacters(filename);
            string dstFilepath = MediaConverter.EnsureUniqueFilepath($"{Settings.OutputFolder}\\{filename}.wav");
            await MediaConverter.FFmpegConvertToWavAsync(filepath, dstFilepath, Settings.OutputFrequency, Settings.OutputVolumeMultiplier);

            // Finish
            job.Status = ConversionJobStatus.Done;
        }