public static ChannelSummaryResponse ToChannelSummaryResponse(this Domain.Channel.Channel channel,
                                                                      bool isMuted,
                                                                      Domain.Message.Message lastReadMessage,
                                                                      MemberSummary creator,
                                                                      CloudStorageConfiguration configuration)
        {
            var channelListResponse = new ChannelSummaryResponse();

            if (channel != null)
            {
                channelListResponse.Id                  = channel.Id;
                channelListResponse.IsClosed            = channel.IsClosed;
                channelListResponse.Created             = channel.Created;
                channelListResponse.Updated             = channel.Updated;
                channelListResponse.Name                = channel.Name;
                channelListResponse.Description         = channel.Description;
                channelListResponse.WelcomeMessage      = channel.WelcomeMessage;
                channelListResponse.Type                = channel.Type;
                channelListResponse.IsMuted             = isMuted;
                channelListResponse.CreatorId           = channel.CreatorId ?? creator?.Id;
                channelListResponse.Creator             = channel.Creator?.ToMemberSummary(configuration) ?? creator;
                channelListResponse.CreatorSaasUserId   = channel.Creator?.SaasUserId ?? creator?.SaasUserId;
                channelListResponse.LastMessage         = channel.Messages?.FirstOrDefault()?.ToMessageResponse(lastReadMessage, configuration);
                channelListResponse.UnreadMessagesCount = lastReadMessage != null?channel.Messages?.Count(x => x.Created > lastReadMessage.Created) ?? 0 : channel.Messages?.Count ?? 0;
            }

            return(channelListResponse);
        }
 public MessageService(
     IUnitOfWork unitOfWork,
     IContentStorage contentStorage,
     CloudStorageConfiguration cloudStorageConfiguration,
     AttachmentConfiguration attachmentConfiguration) : base(unitOfWork)
 {
     _contentStorage            = contentStorage;
     _cloudStorageConfiguration = cloudStorageConfiguration;
     _attachmentConfiguration   = attachmentConfiguration;
 }
 public ChannelService(IUnitOfWork unitOfWork,
                       IChannelMemberService channelMemberService,
                       IMemberService memberService,
                       CloudStorageConfiguration configuration,
                       IContentStorage contentStorage) : base(unitOfWork)
 {
     _channelMemberService = channelMemberService;
     _memberService        = memberService;
     _configuration        = configuration;
     _contentStorage       = contentStorage;
 }
        public void EncodeTest()
        {
            //Arrange
            var cloudStorageConfiguration = new CloudStorageConfiguration(CloudStorageAccount.DevelopmentStorageAccount, new Version());

            var queueVideoRepository = new QueueVideoRepository(cloudStorageConfiguration.StorageAccount.CreateCloudQueueClient());
            var videoRepository      = new FakeVideoRepository(_blobSource, _blobDestination);
            var screenshotRepository = new FakeScreenshotRepository(_blobDestination);
            var mediaInfoReader      = new MediaInfoReader();
            var encoder           = new Encoder();
            var fileSystemWrapper = new FileSystemWrapper();

            var queueProcess    = new QueueProcess(1000, queueVideoRepository);
            var downloadProcess = new DownloadProcess(5, videoRepository, fileSystemWrapper);
            var encoderProcess  = new EncodeProcess(5, encoder, videoRepository, mediaInfoReader, queueVideoRepository, fileSystemWrapper);
            var uploadProcess   = new UploadProcess(5, videoRepository, screenshotRepository, fileSystemWrapper);
            var finishProcess   = new FinishProcess(queueVideoRepository, videoRepository, fileSystemWrapper);

            var queueContainer    = new ProcessContainer <object, QueueInformation, DownloadInformation>(queueProcess, downloadProcess);
            var downloadContainer = new ProcessContainer <QueueInformation, DownloadInformation, EncodeInformation>(downloadProcess, encoderProcess);
            var encoderContainer  = new ProcessContainer <DownloadInformation, EncodeInformation, UploadInformation>(encoderProcess, uploadProcess);
            var uploadContainer   = new ProcessContainer <EncodeInformation, UploadInformation, object>(uploadProcess, finishProcess);

            var processManager = new EncodeProcessManager(queueVideoRepository.DeleteMessageLocal);

            processManager.Add(queueContainer);
            processManager.Add(downloadContainer);
            processManager.Add(encoderContainer);
            processManager.Add(uploadContainer);

            var timer = new Timer(UpdateMessages, queueVideoRepository, (int)queueVideoRepository.InvisibleTime.TotalMilliseconds / 2, (int)queueVideoRepository.InvisibleTime.TotalMilliseconds / 2);

            //Act & Assert
            Task task = processManager.Start();

            StartQueueWork();

            Thread.Sleep(30000);


            while (queueVideoRepository.ApproximateMessageCount > 0)
            {
                Thread.Sleep(60000);
            }

            //Thread.Sleep(50*60*1000);

            processManager.Stop();

            task.Wait();
        }
        public void EncodeTest()
        {
            //Arrange
            var cloudStorageConfiguration = new CloudStorageConfiguration(CloudStorageAccount.DevelopmentStorageAccount, new Version());

            var queueVideoRepository = new QueueVideoRepository(cloudStorageConfiguration.StorageAccount.CreateCloudQueueClient());
            var videoRepository = new FakeVideoRepository(_blobSource, _blobDestination);
            var screenshotRepository = new FakeScreenshotRepository(_blobDestination);
            var mediaInfoReader = new MediaInfoReader();
            var encoder = new Encoder();
            var fileSystemWrapper = new FileSystemWrapper();

            var queueProcess = new QueueProcess(1000, queueVideoRepository);
            var downloadProcess = new DownloadProcess(5, videoRepository, fileSystemWrapper);
            var encoderProcess = new EncodeProcess(5, encoder, videoRepository, mediaInfoReader, queueVideoRepository, fileSystemWrapper);
            var uploadProcess = new UploadProcess(5, videoRepository, screenshotRepository, fileSystemWrapper);
            var finishProcess = new FinishProcess(queueVideoRepository, videoRepository, fileSystemWrapper);

            var queueContainer = new ProcessContainer<object, QueueInformation, DownloadInformation>(queueProcess, downloadProcess);
            var downloadContainer = new ProcessContainer<QueueInformation, DownloadInformation, EncodeInformation>(downloadProcess, encoderProcess);
            var encoderContainer = new ProcessContainer<DownloadInformation, EncodeInformation, UploadInformation>(encoderProcess, uploadProcess);
            var uploadContainer = new ProcessContainer<EncodeInformation, UploadInformation, object>(uploadProcess, finishProcess);

            var processManager = new EncodeProcessManager(queueVideoRepository.DeleteMessageLocal);
            processManager.Add(queueContainer);
            processManager.Add(downloadContainer);
            processManager.Add(encoderContainer);
            processManager.Add(uploadContainer);

            var timer = new Timer(UpdateMessages, queueVideoRepository, (int) queueVideoRepository.InvisibleTime.TotalMilliseconds/2, (int) queueVideoRepository.InvisibleTime.TotalMilliseconds/2);

            //Act & Assert
            Task task = processManager.Start();
            StartQueueWork();

            Thread.Sleep(30000);


            while (queueVideoRepository.ApproximateMessageCount > 0)
            {
                Thread.Sleep(60000);
            }

            //Thread.Sleep(50*60*1000);

            processManager.Stop();

            task.Wait();
        }
        private void StartQueueWork()
        {
            var cloudStorageConfiguration = new CloudStorageConfiguration(CloudStorageAccount.DevelopmentStorageAccount, new Version());
            var queueVideoRepository      = new QueueVideoRepository(cloudStorageConfiguration.StorageAccount.CreateCloudQueueClient());

            string[] filePathes = Directory.GetFiles(_blobSource);

            foreach (string filePath in filePathes)
            {
                var message = new VideoMessage
                {
                    VideoFileHash = filePath
                };

                queueVideoRepository.AddMessage(message);
            }
        }
        protected override void Load(ContainerBuilder builder)
        {
            var configurationRoot = new ConfigurationBuilder()
                                    .AddJsonFile("appsettings.json")
                                    .Build();

            builder.RegisterInstance(
                configurationRoot)
            .As <IConfigurationRoot>();

            builder.Register(x =>
            {
                var storage = new AzureCloudStorage(configurationRoot["AzureStorage:ConnectionString"]);
                return(storage);
            })
            .As <IContentStorage>();

            builder.Register(x =>
            {
                var cfg = new CloudStorageConfiguration(
                    configurationRoot["AzureStorage:ContentStorageHost"],
                    configurationRoot["AzureStorage:MessageAttachmentsContainer"],
                    configurationRoot["AzureStorage:MemberAvatarsContainer"],
                    configurationRoot["AzureStorage:ChannelImagesContainer"],
                    configurationRoot["AzureStorage:TempContainerName"],
                    Convert.ToInt32(configurationRoot["AzureStorage:MessagePhotoSize"]));
                return(cfg);
            });

            builder.Register(x =>
            {
                var cfg = new AttachmentConfiguration(Convert.ToInt32(configurationRoot["MessageAttachments:Limit"]));
                return(cfg);
            });

            builder.Register(context =>
            {
                var lifetimeScope = context.Resolve <ILifetimeScope>();
                return(new AutofacServiceProvider(lifetimeScope));
            })
            .As <IServiceProvider>()
            .SingleInstance();
        }
Beispiel #8
0
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType <ChannelService>()
            .As <IChannelService>();

            builder.RegisterType <MemberService>()
            .As <IMemberService>();

            builder.RegisterType <MessageService>()
            .As <IMessageService>();

            builder.RegisterType <ChannelMemberService>()
            .As <IChannelMemberService>();

            builder.Register(x =>
            {
                var context           = x.Resolve <IComponentContext>();
                var configurationRoot = context.Resolve <IConfiguration>();

                var cfg = new CloudStorageConfiguration(
                    configurationRoot["AzureStorage:ContentStorageHost"],
                    configurationRoot["AzureStorage:MessageAttachmentsContainer"],
                    configurationRoot["AzureStorage:MemberAvatarsContainer"],
                    configurationRoot["AzureStorage:ChannelImagesContainer"],
                    configurationRoot["AzureStorage:TempContainerName"],
                    Convert.ToInt32(configurationRoot["AzureStorage:MessagePhotoSize"]));
                return(cfg);
            });

            builder.Register(x =>
            {
                var context           = x.Resolve <IComponentContext>();
                var configurationRoot = context.Resolve <IConfiguration>();

                var cfg = new AttachmentConfiguration(Convert.ToInt32(configurationRoot["MessageAttachments:Limit"]));
                return(cfg);
            });
        }
Beispiel #9
0
 public MemberService(IUnitOfWork unitOfWork,
                      CloudStorageConfiguration configuration) : base(unitOfWork)
 {
     _configuration = configuration;
 }
        public static ChannelResponse ToChannelResponse(this Domain.Channel.Channel channel, CloudStorageConfiguration configuration)
        {
            var channelResponse = new ChannelResponse();

            if (channel != null)
            {
                channelResponse.Id             = channel.Id;
                channelResponse.IsClosed       = channel.IsClosed;
                channelResponse.Updated        = channel.Updated;
                channelResponse.Created        = channel.Created;
                channelResponse.MembersCount   = channel.MembersCount;
                channelResponse.Name           = channel.Name;
                channelResponse.Description    = channel.Description;
                channelResponse.WelcomeMessage = channel.WelcomeMessage;
                channelResponse.Type           = channel.Type;
                channelResponse.CreatorId      = channel.CreatorId;
            }
            return(channelResponse);
        }
Beispiel #11
0
        public static MemberSummary ToMemberSummary(this Domain.Member.Member member, CloudStorageConfiguration configuration)
        {
            var summary = new MemberSummary();

            if (member != null)
            {
                summary.Id           = member.Id;
                summary.SaasUserId   = member.SaasUserId;
                summary.UserName     = member.Name;
                summary.Status       = member.Status;
                summary.Role         = member.Role;
                summary.IsAfk        = member.IsAfk;
                summary.Email        = member.Email;
                summary.LastActivity = member.LastActivity;
                summary.AvatarUrl    = member.PhotoName != null ? $"{configuration.ContentStorageHost}/{configuration.MemberAvatarsContainer}/{member.PhotoName}" : null;
            }
            return(summary);
        }
        private void StartQueueWork()
        {
            var cloudStorageConfiguration = new CloudStorageConfiguration(CloudStorageAccount.DevelopmentStorageAccount, new Version());
            var queueVideoRepository = new QueueVideoRepository(cloudStorageConfiguration.StorageAccount.CreateCloudQueueClient());

            string[] filePathes = Directory.GetFiles(_blobSource);

            foreach (string filePath in filePathes)
            {
                var message = new VideoMessage
                    {
                        VideoFileHash = filePath
                    };

                queueVideoRepository.AddMessage(message);
            }
        }
Beispiel #13
0
 public FileController(ILogger logger, CloudStorageConfiguration storageConfiguration, IContentStorage contentStorage) : base(logger)
 {
     _storageConfiguration = storageConfiguration;
     _contentStorage       = contentStorage;
 }
Beispiel #14
0
        public static MessageResponse ToMessageResponse(this Domain.Message.Message message, Domain.Message.Message lastReadMessage, CloudStorageConfiguration configuration)
        {
            var messageResponse = new MessageResponse();

            if (message != null)
            {
                messageResponse.Id        = message.Id;
                messageResponse.Created   = message.Created;
                messageResponse.Body      = message.Body;
                messageResponse.ImageUrl  = message.ImageUrl;
                messageResponse.ChannelId = message.ChannelId;
                messageResponse.Type      = message.Type;
                messageResponse.Updated   = message.Updated;
                messageResponse.Sender    = message.Owner.ToMemberSummary(configuration);
                messageResponse.IsRead    = lastReadMessage != null && message.Created <= lastReadMessage.Created;
            }
            return(messageResponse);
        }