/// <summary>
        /// Получить контент сообщения.
        /// </summary>
        /// <param name="contentLink"></param>
        /// <returns></returns>
        public virtual MessageContent GetMessageContent(int contentLink)
        {
            UnitOfWork work = BeginWork();

            MessageContentInfo contentInfo = work.Get <DAO.MessageContentInfo>(contentLink).ToObj();

            if (contentInfo == null)
            {
                return(null);
            }

            MessageContentStreamBase stream = ConstructMessageContentStream(contentInfo.LINK, work, DataStreamMode.READ, contentInfo.ContentType().Encoding());

            stream.ReadTimeout = this.ExecuteTimeout;

            if (contentInfo.Length == null)
            {
                contentInfo.Length = (int)stream.Length;
            }

            var content = new MessageContent();

            content.ApplyInfo(contentInfo);
            content.Value = new MessageContentReader(stream, this.bufferSize);

            return(content);
        }
Example #2
0
        public int Insert(MessageContentInfo contentInfo)
        {
            var messageContentId = 0;

            IDataParameter[] parms = null;

            var sqlInsert = BaiRongDataProvider.TableStructureDao.GetInsertSqlString(contentInfo.ToNameValueCollection(), ConnectionString, TableName, out parms);

            using (var conn = GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        messageContentId = ExecuteNonQueryAndReturnId(trans, sqlInsert, parms);

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        throw;
                    }
                }
            }

            return messageContentId;
        }
Example #3
0
        public int Insert(MessageContentInfo contentInfo)
        {
            var messageContentID = 0;

            IDataParameter[] parms = null;

            var SQL_INSERT = BaiRongDataProvider.TableStructureDao.GetInsertSqlString(contentInfo.ToNameValueCollection(), ConnectionString, TABLE_NAME, out parms);

            using (var conn = GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        ExecuteNonQuery(trans, SQL_INSERT, parms);

                        messageContentID = BaiRongDataProvider.DatabaseDao.GetSequence(trans, TABLE_NAME);

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        throw;
                    }
                }
            }

            return(messageContentID);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static DAO.MessageContentInfo ToDao(this MessageContentInfo obj, DAO.Message msg)
        {
            if (obj == null)
            {
                return(null);
            }

            #region Validate parameters
            if (msg == null)
            {
                throw new ArgumentNullException("msg");
            }
            #endregion

            var dao = new DAO.MessageContentInfo();
            dao.Comment  = obj.Comment;
            dao.FileSize = obj.FileSize;
            dao.Length   = obj.Length;
            dao.LINK     = obj.LINK;
            dao.Message  = msg;
            dao.Name     = obj.Name;
            dao.Type     = obj.Type;

            return(dao);
        }
Example #5
0
        public static void AddContent(int publishmentSystemID, int messageID, string displayName, string color, string content, string ipAddress, string cookieSN, string wxOpenID, string userName)
        {
            DataProviderWX.MessageDAO.AddUserCount(messageID);
            var contentInfo = new MessageContentInfo {
                ID = 0, PublishmentSystemID = publishmentSystemID, MessageID = messageID, IPAddress = ipAddress, CookieSN = cookieSN, WXOpenID = wxOpenID, UserName = userName, ReplyCount = 0, LikeCount = 0, IsReply = false, ReplyID = 0, DisplayName = displayName, Color = color, Content = content, AddDate = DateTime.Now
            };

            DataProviderWX.MessageContentDAO.Insert(contentInfo);
        }
Example #6
0
        public static void AddReply(int publishmentSystemID, int messageID, int replyContentID, string displayName, string content, string ipAddress, string cookieSN, string wxOpenID, string userName)
        {
            DataProviderWx.MessageDao.AddUserCount(messageID);
            var contentInfo = new MessageContentInfo {
                Id = 0, PublishmentSystemId = publishmentSystemID, MessageId = messageID, IpAddress = ipAddress, CookieSn = cookieSN, WxOpenId = wxOpenID, UserName = userName, ReplyCount = 0, LikeCount = 0, IsReply = true, ReplyId = replyContentID, DisplayName = displayName, Color = string.Empty, Content = content, AddDate = DateTime.Now
            };

            DataProviderWx.MessageContentDao.Insert(contentInfo);
            DataProviderWx.MessageContentDao.AddReplyCount(replyContentID);
        }
 /// <summary>
 /// Сохранить контент сообщения.
 /// </summary>
 /// <param name="contentInfo"></param>
 /// <param name="stream"></param>
 /// <param name="cancellationToken"></param>
 public Task SaveMessageContent(MessageContentInfo contentInfo, IAsyncEnumerable <char[]> stream, CancellationToken cancellationToken = default)
 {
     return(Task.Run(() =>
     {
         using (var content = new MessageContent())
         {
             content.ApplyInfo(contentInfo);
             content.Value = new AsyncStreamTextReader(stream);
             _dataAdapter.SaveMessageContent(content);
         }
     }));
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="info"></param>
        public static void ApplyInfo(this MessageContent obj, MessageContentInfo info)
        {
            #region Validate parameters
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            #endregion

            mapper.Map <MessageContentInfo, MessageContent>(info, obj);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="src"></param>
        /// <param name="dest"></param>
        public static void CloneTo(this MessageContentInfo src, MessageContentInfo dest)
        {
            #region Validate parameters
            if (src == null)
            {
                throw new ArgumentNullException("src");
            }

            if (dest == null)
            {
                throw new ArgumentNullException("dest");
            }
            #endregion

            mapper.Map <MessageContentInfo, MessageContentInfo>(src, dest);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="dao"></param>
        /// <returns></returns>
        public static MessageContentInfo ToObj(this DAO.MessageContentInfo dao)
        {
            if (dao == null)
            {
                return(null);
            }

            var obj = new MessageContentInfo();

            obj.Comment     = dao.Comment;
            obj.FileSize    = dao.FileSize;
            obj.Length      = dao.Length;
            obj.LINK        = dao.LINK;
            obj.MessageLINK = dao.Message.LINK;
            obj.Name        = dao.Name;
            obj.Type        = dao.Type;

            return(obj);
        }
Example #11
0
        public List <MessageContentInfo> GetReplyContentInfoList(int messageID, int replyID)
        {
            var list = new List <MessageContentInfo>();

            string SQL_WHERE =
                $"WHERE {MessageContentAttribute.IsReply} = '{true}' AND {MessageContentAttribute.MessageID} = {messageID} AND {MessageContentAttribute.ReplyID} = {replyID}";
            var SQL_SELECT = BaiRongDataProvider.TableStructureDao.GetSelectSqlString(ConnectionString, TABLE_NAME, 0, SqlUtils.Asterisk, SQL_WHERE, "ORDER BY ID DESC");

            using (var rdr = ExecuteReader(SQL_SELECT))
            {
                while (rdr.Read())
                {
                    var itemInfo = new MessageContentInfo(rdr);
                    list.Add(itemInfo);
                }
                rdr.Close();
            }

            return(list);
        }
Example #12
0
        public List<MessageContentInfo> GetReplyContentInfoList(int messageId, int replyId)
        {
            var list = new List<MessageContentInfo>();

            string sqlWhere =
                $"WHERE {MessageContentAttribute.IsReply} = '{true}' AND {MessageContentAttribute.MessageId} = {messageId} AND {MessageContentAttribute.ReplyId} = {replyId}";
            var sqlSelect = BaiRongDataProvider.TableStructureDao.GetSelectSqlString(ConnectionString, TableName, 0, SqlUtils.Asterisk, sqlWhere, "ORDER BY ID DESC");

            using (var rdr = ExecuteReader(sqlSelect))
            {
                while (rdr.Read())
                {
                    var itemInfo = new MessageContentInfo(rdr);
                    list.Add(itemInfo);
                }
                rdr.Close();
            }

            return list;
        }
Example #13
0
        public List <MessageContentInfo> GetMessageContentInfoList(int publishmentSystemID, int messageID)
        {
            var messageContentInfoList = new List <MessageContentInfo>();

            string SQL_WHERE =
                $"WHERE {MessageContentAttribute.PublishmentSystemID} = {publishmentSystemID} AND {MessageContentAttribute.MessageID} = {messageID} AND ReplyID = 0";

            var SQL_SELECT = BaiRongDataProvider.TableStructureDao.GetSelectSqlString(ConnectionString, TABLE_NAME, 0, SqlUtils.Asterisk, SQL_WHERE, null);

            using (var rdr = ExecuteReader(SQL_SELECT))
            {
                while (rdr.Read())
                {
                    var messageContentInfo = new MessageContentInfo(rdr);
                    messageContentInfoList.Add(messageContentInfo);
                }
                rdr.Close();
            }

            return(messageContentInfoList);
        }
Example #14
0
        public List<MessageContentInfo> GetMessageContentInfoList(int publishmentSystemId, int messageId)
        {
            var messageContentInfoList = new List<MessageContentInfo>();

            string sqlWhere =
                $"WHERE {MessageContentAttribute.PublishmentSystemId} = {publishmentSystemId} AND {MessageContentAttribute.MessageId} = {messageId} AND ReplyID = 0";

            var sqlSelect = BaiRongDataProvider.TableStructureDao.GetSelectSqlString(ConnectionString, TableName, 0, SqlUtils.Asterisk, sqlWhere, null);

            using (var rdr = ExecuteReader(sqlSelect))
            {
                while (rdr.Read())
                {
                    var messageContentInfo = new MessageContentInfo(rdr);
                    messageContentInfoList.Add(messageContentInfo);
                }
                rdr.Close();
            }

            return messageContentInfoList;
        }
Example #15
0
        void rptContents_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var contentInfo = new MessageContentInfo(e.Item.DataItem);

                var ltlItemIndex   = e.Item.FindControl("ltlItemIndex") as Literal;
                var ltlDisplayName = e.Item.FindControl("ltlDisplayName") as Literal;
                var ltlContent     = e.Item.FindControl("ltlContent") as Literal;
                var ltlIsReply     = e.Item.FindControl("ltlIsReply") as Literal;
                var ltlWxOpenId    = e.Item.FindControl("ltlWXOpenID") as Literal;
                var ltlIpAddress   = e.Item.FindControl("ltlIPAddress") as Literal;
                var ltlAddDate     = e.Item.FindControl("ltlAddDate") as Literal;

                ltlItemIndex.Text = (e.Item.ItemIndex + 1).ToString();

                ltlDisplayName.Text = contentInfo.DisplayName;
                ltlContent.Text     = contentInfo.Content;
                ltlIsReply.Text     = contentInfo.IsReply ? "评论" : "留言";
                ltlWxOpenId.Text    = contentInfo.WxOpenId;
                ltlIpAddress.Text   = contentInfo.IpAddress;
                ltlAddDate.Text     = DateUtils.GetDateAndTimeString(contentInfo.AddDate);
            }
        }
        /// <summary>
        /// Сохранить контент сообщения.
        /// </summary>
        /// <param name="content"></param>
        public virtual void SaveMessageContent(MessageContent content)
        {
            #region Validate parameters
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }
            #endregion

            MessageContentInfo contentInfo = content.ContentInfo();
            ContentType        contentType = contentInfo.ContentType();
            Encoding           encoding    = contentType.Encoding();

            using (UnitOfWork work = BeginWork())
            {
                int msgLink = content.MessageLINK.Value;
                var msg     = work.Get <DAO.Message>(msgLink);
                if (msg == null)
                {
                    throw new MessageNotFoundException(msgLink);
                }

                DAO.MessageContentInfo dao = contentInfo.ToDao(msg);

                if (dao.LINK == 0)
                {
                    work.Save(dao);
                }
                else
                {
                    work.Update <DAO.MessageContentInfo>(ref dao);
                }

                if (content.Value != null)
                {
                    using (MessageContentStreamBase stream = ConstructMessageContentStream(dao.LINK, work, DataStreamMode.WRITE, encoding))
                    {
                        stream.WriteTimeout = this.ExecuteTimeout;

                        var buffer = new char[this.bufferSize];
                        int charsReaded;
                        do
                        {
                            charsReaded = content.Value.Read(buffer, 0, buffer.Length);
                            if (charsReaded > 0)
                            {
                                stream.Write(buffer, 0, charsReaded);
                            }
                        } while (charsReaded > 0);

                        if (dao.Length == null)
                        {
                            dao.Length = (int)stream.Length;
                            work.Update <DAO.MessageContentInfo>(ref dao);
                        }

                        work.End();
                    }
                }
                else
                {
                    work.End();
                }

                contentInfo = dao.ToObj();
                content.ApplyInfo(contentInfo);
            }
        }
Example #17
0
        //static Process _process;
        //static int _processId;

        static async Task Main(string[] args)
        {
            System.Threading.Thread.Sleep(1000);

            //TaskScheduler.UnobservedTaskException += (s, e) =>
            //{
            //	if (e.Exception != null)
            //	{
            //		foreach (Exception ex in e.Exception.InnerExceptions)
            //		{
            //			//LogError(ex);
            //		}
            //	}

            //	e.SetObserved();
            //};

            try
            {
                //var startInfo = new ProcessStartInfo()
                //{
                //	FileName = @"C:\Projects\Keysystems.Microservices\WebApplication1\bin\Debug\netcoreapp3.0\WebApplication1.exe",
                //	UseShellExecute = false,
                //	//CreateNoWindow = true,
                //	Arguments = "--Urls http://*:5005"
                //};

                //using (var process = Process.Start(startInfo))
                //{
                //	_processId = process.Id;


                using (IChannelHubClient hub = new ChannelHubClient("http://*****:*****@"Data Source=.\SQLEXPRESS; Initial Catalog=EsbliteClient_v3.8; User ID=rms; Password=rms";
                    //await hub.SetSettingsAsync(newSettings);

                    await hub.OpenChannelAsync();

                    await hub.RunChannelAsync();

                    (List <Message>, int)messages = await hub.GetMessagesAsync(null, null, null);

                    if (messages.Item1.Count > 0)
                    {
                        Message msg = await hub.GetMessageAsync(messages.Item1.First().LINK.Value);

                        //int? resMsg = await hub.ReceiveMessage(msg.LINK.Value);
                        using (TextReader bodyReader = await hub.ReadMessageBodyAsync(msg.LINK.Value))
                        {
                            string body = await bodyReader.ReadToEndAsync();
                        }

                        MessageContentInfo contentInfo = msg.Contents[0];
                        using (TextReader contentReader = await hub.ReadMessageContentAsync(contentInfo.LINK))
                        {
                            string content = await contentReader.ReadToEndAsync();

                            byte[] data = Convert.FromBase64String(content);
                            File.WriteAllBytes(contentInfo.Name, data);
                        }
                    }


                    //var contentInfo = new MessageContentInfo()
                    //{
                    //	MessageLINK = msg.LINK.Value,
                    //	Name = "Новый2"
                    //};
                    //var contentStream = new StringReader("Hello, World!");
                    //await hub.SaveMessageContent(contentInfo, contentStream);

                    Console.ReadLine();
                    await hub.CloseChannelAsync();

                    await hub.LogoutAsync();
                }

                //Console.ReadLine();
                //_cancellationSource.Cancel();
                //}
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                //Process.GetProcessById(_processId)?.Kill();
                Console.ReadLine();
            }
        }