using Ayay.SerilogLogs;
using Core.WcfProtocol;
using Serilog;

namespace SHH.MjpegPlayer
{
    /// <summary>
    /// CoreImagesService 服务
    /// </summary>
    public class CoreImagesService : ICoreImagesService
    {
        private static readonly ILogger _sysLog = Log.ForContext("SourceContext", LogModules.Core);

        #region Defines

        /// <summary>
        /// 按秒统计
        /// </summary>
        public static SumByTime _sumBySecond = new SumByTime();

        #endregion

        #region UploadImage

        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public UploadImageReply UploadImage(UploadImageRequest req)
        {
            var reply = new UploadImageReply();

            try
            {
                // 日志准备
                _sumBySecond.Refresh("UploadImage");

                PrismMsg<UploadImageRequest>.Publish(req);
            }
            catch (Exception ex)
            {
                _sysLog.Warning($"上传图片失败, {ex.Message} {ex.StackTrace}");
                reply.ReplyFalt(ex.Message, ex.Source);
            }

            reply.ReplySuccess();
            return reply;
        }

        #endregion

        #region UploadImageOneWay

        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="req"></param>
        public void UploadImageOneWay(UploadImageRequest req)
        {
            try
            {
                _sumBySecond.Refresh("UploadImage");

                PrismMsg<UploadImageRequest>.Publish(req);
            }
            catch (Exception ex)
            {
                _sysLog.Warning($"上传图片失败, {ex.Message} {ex.StackTrace}");
            }
        }

        #endregion
    }
}
