Exemple #1
0
 private void SendComplexMsg(string queueName, MfTask task)
 {
     using (var mq = new MessageQueue(queueName))
     {
         var msg = new Message
         {
             Label       = "[MFiles]" + task.Title,
             Recoverable = true,
             Body        = task
         };
         mq.Send(msg);
         Trace.TraceInformation("【成功发送消息】{0},{1}", msg.Body, DateTime.Now);
     }
 }
Exemple #2
0
        public void AddNotice2Msmq(Vault vault, int objType, int objClass, string title, string content, int assignTo, string otherPropValues)
        {
            var traceFile = GetTraceFile();

            Log(string.Format("begin {0},{1},{2},{3},{4},{5},{6}", traceFile, objType, objClass, title, content, assignTo, otherPropValues));
            Trace.AutoFlush = true;
            Trace.Listeners.Add(new TextWriterTraceListener(traceFile));

            var vualtGuid = vault.GetGUID();
            var pcName    = LocalConfig.GetComputerFullName();

            var queueName  = ".\\private$\\" + vualtGuid + "_" + objType;
            var queueName2 = @"FormatName:Direct=OS:" + pcName + "\\private$\\" + vualtGuid + "_" + objType;

            Trace.TraceInformation("【消息队列】{0}", queueName);
            try
            {
                //CreateNewQueue(queueName);
                var mqs = GetPrivateMqList(pcName);
                Trace.TraceInformation("【私有队列】共有:{0}个", mqs.Count);
                foreach (string mq in mqs)
                {
                    Trace.TraceInformation("【私有队列】{0}", mq);
                }
                if (!IsExisted(mqs, queueName))
                {
                    Log(string.Format("before {0}", queueName));
                    CreateNewQueue(queueName);
                    Log(string.Format("after {0}", queueName));
                    //  throw new Exception("【消息队列】" + queueName + "不存在");
                }
            }
            catch (Exception ex)
            {
                Log(string.Format("queue operation error {0},{1} ", queueName, ex.Message));
                Trace.TraceError("【消息队列】{0},{1}", queueName, ex.Message);
                throw;
            }

            var msg = new MfTask
            {
                VualtGuid    = vualtGuid,
                ObjType      = objType,
                ObjClass     = objClass,
                Title        = title,
                Content      = content,
                AssignTo     = assignTo
                , OtherProps = Trans2MfProps(otherPropValues)
                               //OtherPropDef = otherPropDef,
                               //OtherPropValue = otherPropValue
            };

            try
            {
                SendComplexMsg(queueName2, msg);
            }
            catch (Exception ex)
            {
                Trace.TraceError("【发送消息失败】{0},{1}", queueName, ex.Message);
                throw;
            }

            GC.Collect(0, GCCollectionMode.Forced);
        }