Beispiel #1
0
        /// <inheritdoc />
        /// <summary>
        /// 执行命令
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public override void Handle(PublishItem args)
        {
            try
            {
                List <RecordInfo> items = JsonConvert.DeserializeObject <List <RecordInfo> >(args.Content);
                foreach (var info in items)
                {
                    StringBuilder code = new StringBuilder();

                    code.AppendLine("<table style='width:99%'><col style='width:120px'/><col/><col style='width:120px'/><col/>");
                    code.AppendLine($"<tr style='border-bottom: silver 1px solid;padding: 4px'><td>类型</td><td>{info.TypeName}</td><td>序号</td><td>{info.Index}</td></tr>");
                    code.AppendLine($"<tr style='border-bottom: silver 1px solid;padding: 4px'><td>标识</td><td>{info.RequestID}</td><td>时间</td><td>{DateTime.Now}({info.Time})</td></tr>");
                    code.AppendLine($"<tr style='border-bottom: silver 1px solid;padding: 4px'><td>机器</td><td>{info.Machine}</td><td>用户</td><td>{info.User}</td></tr>");
                    code.AppendLine("</table>");
                    switch (info.Type)
                    {
                    case LogType.Monitor:
                        FormatMonitor(code, info);
                        break;

                    default:
                        code.Append($"<div>{info.Message.Replace("\n", "<br/>")}</div>");
                        break;
                    }
                    WebSocketPooler.Instance?.Publish("Log", code.ToString());
                }
            }
            catch (Exception e)
            {
                LogRecorder.Exception(e);
            }
        }
        internal bool SendPublishItem(PublishItem item)
        {
            try
            {
                if (!IsConnected)
                {
                    return(false);
                }

                var message = SendObjectToJsonStreamWithResponse(publishRouteCode, item);
                SocketResult <string> result;
                if (message != null && message.TryReadFromJsonStream(out result))
                {
                    if (result != null && result.Code != "200")
                    {
                        return(false);
                    }
                }
                else if (message == null)
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Beispiel #3
0
 /// <summary>
 /// 执行命令
 /// </summary>
 /// <param name="args"></param>
 /// <returns></returns>
 public override void Handle(PublishItem args)
 {
     try
     {
         var info = JsonConvert.DeserializeObject <RecordInfo>(args.Content);
         LogRecorder.Push(info);
     }
     catch (Exception e)
     {
         LogRecorder.Exception(e);
     }
 }
 /// <summary>
 /// 新增远程推送失败记录
 /// </summary>
 /// <param name="agentId">消息队列代理器Id</param>
 /// <param name="publishItem">推送内容</param>
 public bool AddRemotePushFailureRecord(Guid agentId, PublishItem publishItem)
 {
     try
     {
         GetEntities <RemotePushFailureRecord>().InsertOne(new RemotePushFailureRecord()
         {
             Content = publishItem, AgentId = agentId
         });
         return(true);
     }
     catch { }
     return(false);
 }
Beispiel #5
0
        /// <inheritdoc />
        /// <summary>
        /// 执行命令
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public override void Handle(PublishItem args)
        {
            try
            {
                if (args.Content != null)
                {
                    LogRecorder.BaseRecorder.RecordLog(JsonConvert.DeserializeObject <List <RecordInfo> >(args.Content));
                    return;
                }


                if (args.Tson == null || args.Tson[0] == 0 || args.Tson[0] > 2)
                {
                    return;
                }
                ITsonDeserializer serializer = args.Tson[0] == 1
                    ? new TsonDeserializerV1(args.Tson) as ITsonDeserializer
                    : new TsonDeserializer(args.Tson);

                using (serializer)
                {
                    switch (serializer.DataType)
                    {
                    case TsonDataType.Object:
                        RecordInfo info = new RecordInfo();
                        RecordInfoTson.FromTson(serializer, info);
                        LogRecorder.BaseRecorder.RecordLog(info);
                        break;

                    case TsonDataType.Array:
                        serializer.ReadType();
                        int size = serializer.ReadLen();
                        List <RecordInfo> infos = new List <RecordInfo>();
                        for (int idx = 0; !serializer.IsBad && idx < size; idx++)
                        {
                            info = new RecordInfo();
                            serializer.Begin(out _);
                            RecordInfoTson.FromTson(serializer, info);
                            serializer.End();
                            infos.Add(info);
                        }
                        LogRecorder.BaseRecorder.RecordLog(infos);
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                LogRecorder.Exception(e);
            }
        }
Beispiel #6
0
 /// <summary>
 /// 执行命令
 /// </summary>
 /// <param name="args"></param>
 /// <returns></returns>
 public override void Handle(PublishItem args)
 {
     if (args.SubTitle == "Flush")
     {
         Flush();
         return;
     }
     try
     {
         var data = JsonConvert.DeserializeObject <WaringItem>(args.Content);
         Waring(data.Host, data.Api, data.Message);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
Beispiel #7
0
 /// <summary>
 ///     发送广播
 /// </summary>
 /// <param name="item"></param>
 /// <param name="socket"></param>
 /// <returns></returns>
 public static bool Publish(this ZSocket socket, PublishItem item)
 {
     if (item.Tson != null)
     {
         return(item.SubTitle == null
             ? Publish(socket, PubDescriptionTson, item.Title, item.Tson)
             : Publish(socket, PubDescriptionTson2, item.Title, item.SubTitle, item.Tson));
     }
     if (item.Buffer != null)
     {
         return(item.SubTitle == null
             ? Publish(socket, PubDescriptionData, item.Title, item.Buffer)
             : Publish(socket, PubDescriptionData2, item.Title, item.SubTitle, item.Buffer));
     }
     return(item.SubTitle == null
         ? Publish(socket, PubDescriptionJson, item.Title, item.Content.ToZeroBytes())
         : Publish(socket, PubDescriptionJson2, item.Title, item.SubTitle, item.Content.ToZeroBytes()));
 }
Beispiel #8
0
 /// <summary>
 /// 事件代理远程推送
 /// </summary>
 /// <param name="publishItem">推送信息</param>
 public void Publish(PublishItem publishItem)
 {
     try
     {
         Adapter.Publish(publishItem.Descriptions, publishItem.Content);
     }
     catch (Exception ex)
     {
         Task.Factory.StartNew((e) =>
         {
             var exception = e as Exception;
             if (exception != null && Logger != null)
             {
                 Logger.Error("事件代理远程推送失败!", exception);
             }
         }, ex);
         Storage.AddRemotePushFailureRecord(AgentId, publishItem);
     }
 }
Beispiel #9
0
        /// <param name="topic"></param>
        /// <param name="command"></param>
        /// <param name="argument"></param>
        /// <returns></returns>
        private static async Task <bool> PublishAsyncInner(string topic, string command, string argument)
        {
            try
            {
                var frame = new PublishItem
                {
                    Topic    = topic,
                    Command  = command,
                    Argument = argument
                };
                var msg = new Message <Null, string> {
                    Value = JsonHelper.SerializeObject(frame)
                };
                var ret = await producer.ProduceAsync(topic, msg);

                return(ret.Status == PersistenceStatus.Persisted);
            }
            catch (Exception e)
            {
                LogRecorder.Exception(e, "Kafka Production<Error>");
                return(false);
            }
        }
Beispiel #10
0
        /// <summary>
        /// 消息处理
        /// </summary>
        /// <param name="station"></param>
        /// <param name="message"></param>
        public static void OnMessagePush(ZeroService station, string message)
        {
            station.NetPool.Commit();
            PublishItem frame = null;

            try
            {
                frame = JsonHelper.DeserializeObject <PublishItem>(message);
            }
            catch (Exception e)
            {
                station.NetPool.OnError(e, "格式错误");
                return;
            }
            Interlocked.Increment(ref station.CallCount);

            try
            {
                var executer = new ApiExecuter
                {
                    Station = station,
                    Item    = new ApiCallItem
                    {
                        Station  = frame.Topic,
                        Command  = frame.Command,
                        Argument = frame.Argument
                    }
                };
                executer.Execute().Wait();
            }
            catch (Exception e)
            {
                station.NetPool.OnError(e, "未处理异常");
                LogRecorder.Exception(e);
            }
        }
Beispiel #11
0
 /// <summary>
 /// 执行命令
 /// </summary>
 /// <param name="args"></param>
 /// <returns></returns>
 public override void Handle(PublishItem args)
 {
     try
     {
         if (args.SubTitle == "Save")
         {
             Save();
             return;
         }
         try
         {
             var data = JsonConvert.DeserializeObject <RouteData>(args.Content);
             End(data);
         }
         catch (Exception e)
         {
             Console.WriteLine(e);
         }
     }
     catch (Exception e)
     {
         LogRecorder.Exception(e);
     }
 }
 public void AddToPublishQueue(PublishItem item)
 {
     throw new NotImplementedException();
 }
Beispiel #13
0
        public ActionResult PublishItem(PublishItem model)
        {
            WebResult result = new WebResult
            {
                Code    = AppConst.MSG_ERR,
                Message = string.Empty
            };

            bool IsVip = false;//当前用户

            if (model.uid > 0)
            {
                var memb = MemberService.GetMemberFromUser(model.uid);
                if (memb != null && memb.Id > 0 && memb.Level != "" && memb.Level != "普通会员" && memb.VipOverDate.HasValue && memb.VipOverDate.Value > DateTime.Now)
                {
                    IsVip = true;
                }
            }
            //判断是否出售且用户为vip
            if (model.GoodsType == 0 && !IsVip)
            {
                result.Message = "非VIP用户不能发布出售信息!";
                return(Content(JsonConvert.SerializeObject(result)));
            }

            if (model.MainPicName.Equals(string.Empty))
            {
                //result.Message = "主图不能为空!";
                //return Content(JsonConvert.SerializeObject(result));
                model.MainPicName = "/Images/stock.jpg";
            }

            //Save Item
            var item = new St_good();

            item.AddTime = DateTime.Now;
            int uid = model.uid;

            if (uid > 0)
            {
                item.AddUser = uid;
                var member = MemberService.GetMemberFromUser(uid);
                if (member != null && member.Id > 0)
                {
                    item.MemberId = member.Id;
                }
            }
            item.Details = model.Details;
            if (!model.MainPicName.Equals(string.Empty))
            {
                try
                {
                    //DateTime now = DateTime.Now;
                    //string vpath = "/Site/Goods/" + now.ToString("yyyyMMdd") + "/";
                    //string realpath = Server.MapPath(vpath);
                    //if (!Directory.Exists(realpath))
                    //Directory.CreateDirectory(realpath);
                    //string filename = model.MainPic.FileName;
                    //if (System.IO.File.Exists(realpath + filename))
                    //{
                    //filename = now.Ticks.ToString() + "_" + filename;
                    //}
                    //model.MainPic.SaveAs(realpath + filename);
                    item.MainPic = model.MainPicName;
                }
                catch
                {
                }
            }
            item.CatId = model.CatId;
            if (model.CatId > 0)
            {
                var ccat = DBService.GetEntity <St_cat>(model.CatId);
                if (ccat != null && ccat.Id > 0)
                {
                    item.CatPath = ccat.Path;
                }
            }
            item.ModifyTime       = DateTime.Now;
            item.Name             = model.Name;
            item.Price            = model.Price;
            item.PriceDetail      = model.PriceDetail;
            item.Qty              = model.Qty;
            item.QtyDetail        = model.QtyDetail;
            item.Status           = 0;
            item.ViewCount        = 0;
            item.ContactViewCount = 0;
            item.GoodsType        = model.GoodsType;
            item.RealName         = model.RealName;
            item.QQ     = model.QQ;
            item.Mobile = model.Mobile;
            item.Tel    = model.Tel;
            item.Wechat = model.Wechat;
            item.Addr   = model.Addr;
            int gid = DBService.AddEntity <St_good>(item, true);

            if (gid > 0 && !string.IsNullOrEmpty(model.OPics))
            {
                var aids   = model.OPics.Split(',');
                var picids = new List <int>();
                int tempid = 0;
                foreach (var aid in aids)
                {
                    var pic = new St_pic();
                    pic.AddTime = DateTime.Now;
                    pic.PicType = 5;
                    pic.PicUrl  = aid;
                    int pid = DBService.AddEntity <St_pic>(pic, true);
                    //if (!string.IsNullOrEmpty(pid) && int.TryParse(pid, out tempid))
                    if (pid > 0)
                    {
                        picids.Add(pid);
                    }
                }
                if (picids.Count > 0)
                {
                    StockService.UpdateStockPics(gid, picids);
                }
            }

            //return RedirectToAction("Stocks", "Manage");
            //ViewBag.PCats = StockService.GetStockCats();
            //return View(model);
            result.Code = AppConst.MSG_SUCCESS;
            return(Content(JsonConvert.SerializeObject(result)));
        }
 public void AddToPublishQueue(PublishItem item)
 {
     PublishQueue.Save(item);
 }
Beispiel #15
0
        /// <summary>
        ///     广播消息解包
        /// </summary>
        /// <param name="messages"></param>
        /// <param name="item"></param>
        /// <param name="showError"></param>
        /// <returns></returns>
        public static bool Unpack(this ZMessage messages, out PublishItem item, bool showError = true)
        {
            if (messages == null)
            {
                item = null;
                return(false);
            }
            try
            {
                if (messages.Count < 3)
                {
                    item = null;
                    return(false);
                }
                var description = messages[1].Read();
                if (description.Length < 2)
                {
                    item = null;
                    return(false);
                }

                int end = description[0] + 2;
                if (end != messages.Count)
                {
                    item = null;
                    return(false);
                }

                item = new PublishItem
                {
                    Title     = messages[0].ReadString(),
                    State     = (ZeroOperatorStateType)description[1],
                    ZeroEvent = (ZeroNetEventType)description[1]
                };

                for (int idx = 2; idx < end; idx++)
                {
                    var bytes = messages[idx].Read();
                    if (bytes.Length == 0)
                    {
                        continue;
                    }
                    switch (description[idx])
                    {
                    case ZeroFrameType.SubTitle:
                        item.SubTitle = Encoding.UTF8.GetString(bytes);
                        break;

                    case ZeroFrameType.Station:
                        item.Station = Encoding.UTF8.GetString(bytes);
                        break;

                    case ZeroFrameType.Publisher:
                        item.Publisher = Encoding.UTF8.GetString(bytes);
                        break;

                    case ZeroFrameType.Content:
                        if (item.Content == null)
                        {
                            item.Content = Encoding.UTF8.GetString(bytes);
                        }
                        else
                        {
                            item.Values.Add(Encoding.UTF8.GetString(bytes));
                        }
                        break;

                    case ZeroFrameType.BinaryValue:
                        item.Buffer = bytes;
                        break;

                    case ZeroFrameType.TsonValue:
                        item.Tson = bytes;
                        break;

                    default:
                        item.Values.Add(Encoding.UTF8.GetString(bytes));
                        break;
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                ZeroTrace.WriteException("Unpack", e);
                item = null;
                return(false);
            }
            finally
            {
                messages.Dispose();
            }
        }
Beispiel #16
0
        private bool AddItem(Quote q, PriceBase priceBase, string observation)
        {
            bool added = true;

            List <QuoteItem> tmplst = new List <QuoteItem>(q.QuoteItems);

            if (tmplst.Exists(delegate(QuoteItem record)
            {
                if (record.PriceBase.ID == priceBase.ID)
                {
                    return(true);
                }
                return(false);
            }))
            {
                return(true);
            }

            QuoteItem qi = new QuoteItem();

            qi.Observation = observation;
            qi.Quote       = q;

            PublishItem    pi = ControllerManager.PublishList.GetPublishItem(q.Distributor, priceBase);
            PriceAttribute pa = null;

            if (pi != null)
            {
                // Lista de Precio (Publicada)
                qi.PriceBase     = priceBase;
                qi.Price         = pi.Price;
                qi.PriceCurrency = pi.PriceCurrency;
                qi.CurrencyRate  = pi.CurrencyRate;
                qi.Source        = pi.PublishList.PriceList.Name;
            }
            else
            {
                if (q.Distributor.PriceList != null)
                {
                    pa = ControllerManager.PriceAttribute.GetPriceAttribute(q.Distributor.PriceList.PriceGroup,
                                                                            priceBase);
                    if (pa != null)
                    {
                        // Pais
                        qi.PriceBase     = priceBase;
                        qi.Price         = pa.Price;
                        qi.PriceCurrency = pa.PriceCurrency;
                        qi.CurrencyRate  = pa.CurrencyRate;
                        qi.Source        = Resource.Business.GetString("Country");
                    }
                }

                if (pa == null)
                {
                    // Base
                    decimal?factor = null;
                    if (q.Distributor.PriceList != null)
                    {
                        if (q.Distributor.PriceList.PriceGroup.Adjust != null)
                        {
                            factor = q.Distributor.PriceList.PriceGroup.Adjust;
                        }
                    }
                    if (factor == null || factor == 0)
                    {
                        factor = 1;
                    }
                    qi.PriceBase     = priceBase;
                    qi.Price         = priceBase.PriceList / Convert.ToDecimal(factor);
                    qi.PriceCurrency = priceBase.PriceListCurrency;
                    qi.CurrencyRate  = priceBase.CurrencyRate;

                    if (priceBase.Status == PriceBaseStatus.Verified)
                    {
                        qi.Source = Resource.Business.GetString("Base");
                    }
                    else if (priceBase.Status == PriceBaseStatus.NotVerified)
                    {
                        qi.Source = Resource.Business.GetString("OutOfList");
                    }
                }
            }

            if (qi.Price > 0)
            {
                q.QuoteItems.Add(qi);
            }
            else
            {
                added = false;
            }

            return(added);
        }
Beispiel #17
0
        private bool ValidateQuoteItem(Quote q, PriceBase priceBase, QuoteItem qi, out decimal pL, out Currency plCurrency)
        {
            plCurrency = null;
            pL         = 0;

            PublishItem    pi = ControllerManager.PublishList.GetPublishItem(q.Distributor, priceBase);
            PriceAttribute pa = null;

            if (pi != null)
            {
                // Lista de Precio (Publicada)
                qi.PriceBase = priceBase;
                pL           = pi.Price;
                plCurrency   = pi.PriceCurrency;
                qi.Source    = pi.PublishList.PriceList.Name;
            }
            else
            {
                if (q.Distributor.PriceList != null)
                {
                    pa = ControllerManager.PriceAttribute.GetPriceAttribute(q.Distributor.PriceList.PriceGroup,
                                                                            priceBase);
                    if (pa != null)
                    {
                        // Pais
                        qi.PriceBase = priceBase;
                        pL           = pa.Price;
                        plCurrency   = pa.PriceCurrency;
                        qi.Source    = Resource.Business.GetString("Country");
                    }
                }

                if (pa == null)
                {
                    // Base o Fuera de Lista
                    decimal?factor = null;
                    if (q.Distributor.PriceList != null)
                    {
                        if (q.Distributor.PriceList.PriceGroup.Adjust != null)
                        {
                            factor = q.Distributor.PriceList.PriceGroup.Adjust;
                        }
                    }
                    if (factor == null || factor == 0)
                    {
                        factor = 1;
                    }
                    qi.PriceBase = priceBase;
                    pL           = priceBase.PriceList / Convert.ToDecimal(factor);
                    plCurrency   = priceBase.PriceListCurrency;

                    if (priceBase.Status == PriceBaseStatus.Verified)
                    {
                        qi.Source = Resource.Business.GetString("Base");
                    }
                    else if (priceBase.Status == PriceBaseStatus.NotVerified)
                    {
                        qi.Source = Resource.Business.GetString("OutOfList");
                    }
                }
            }

            decimal lastPrice = qi.Price;

            if (plCurrency != null)
            {
                qi.Price         = Math.Round(pL * lstRates[plCurrency.ID - 1, q.Currency.ID - 1].Rate, 3);
                qi.PriceCurrency = q.Currency;
                qi.CurrencyRate  = ControllerManager.CurrencyRate.GetLast(q.Currency);
            }

            return(lastPrice == qi.Price);
        }