Exemplo n.º 1
0
 protected long GetGlobalJoinKey(IComponentControl componentControl, SendEventBase eventData)
 {
     return(HashHelper.GetInt64(
                componentControl.SystemName,
                eventData.TypeSystemName,
                eventData.JoinKey.ToString(),
                eventData.EventCategory.ToString(),
                (eventData.Importance ?? EventImportance.Unknown).ToString(),
                eventData.Version));
 }
Exemplo n.º 2
0
 protected void SetServerTime(SendEventBase eventData)
 {
     if (eventData.StartDate == null)
     {
         eventData.StartDate = DateTime.Now;
     }
     if (CanConvertToServerDate())
     {
         eventData.StartDate = ToServerTime(eventData.StartDate.Value);
     }
     eventData.IsServerTime = true;
 }
Exemplo n.º 3
0
 public BufferEventData(IComponentControl componentControl, SendEventBase eventBase)
 {
     if (componentControl == null)
     {
         throw new ArgumentNullException("componentControl");
     }
     if (eventBase == null)
     {
         throw new ArgumentNullException("eventBase");
     }
     ComponentControl = componentControl;
     SendEventBase    = eventBase;
     Init();
 }
Exemplo n.º 4
0
        public AddEventResult AddEvent(SendEventBase eventBase)
        {
            var inputEvent = new BufferEventData(eventBase.ComponentControl, eventBase);

            if (eventBase.Ignore)
            {
                // если игнорируем, то в очередь НЕ помещем
                inputEvent.Status = AddEventStatus.Removed;
                return(new AddEventResult(inputEvent));
            }
            var outputEvent = AddOrJoin(inputEvent);

            return(new AddEventResult(outputEvent));
        }
Exemplo n.º 5
0
 protected void PrepareEventAfterCreation(SendEventBase eventData)
 {
     if (eventData == null)
     {
         return;
     }
     try
     {
         var preparer = Client.EventPreparer;
         if (preparer != null)
         {
             preparer.Prepare(eventData);
         }
     }
     catch (Exception exception)
     {
         ClientInternal.InternalLog.Error("Ошибка в PrepareEventAfterCreation: " + exception.Message, exception);
     }
 }
Exemplo n.º 6
0
        internal SendEventResponse SendEventWrapper(SendEventBase sendEventBase)
        {
            if (sendEventBase == null)
            {
                throw new ArgumentNullException("sendEventBase");
            }
            if (sendEventBase.Ignore)
            {
                return(ResponseHelper.GetClientErrorResponse <SendEventResponse>("Событие проигнорировано"));
            }

            PrepareDataHelper.PrepareEvent(sendEventBase);

            if (sendEventBase.IsServerTime == false)
            {
                SetServerTime(sendEventBase);
            }

            var data = new SendEventData()
            {
                Category        = sendEventBase.EventCategory,
                ComponentId     = sendEventBase.ComponentControl.Info.Id,
                Count           = sendEventBase.Count,
                Importance      = sendEventBase.Importance,
                JoinInterval    = sendEventBase.JoinInterval,
                JoinKey         = sendEventBase.JoinKey,
                Message         = sendEventBase.Message,
                StartDate       = sendEventBase.StartDate,
                TypeCode        = sendEventBase.TypeCode,
                TypeDisplayName = sendEventBase.TypeDisplayName,
                TypeSystemName  = sendEventBase.TypeSystemName,
                Version         = sendEventBase.Version
            };

            data.Properties.CopyFrom(sendEventBase.Properties);

            return(ApiService.SendEvent(data));
        }
Exemplo n.º 7
0
        protected void SendOneEvent(BufferEventData bufferEventData)
        {
            if (Client.CanSendData == false)
            {
                return;
            }
            if (Client.CanConvertToServerDate() == false)
            {
                return;
            }
            bool success = false;

            try
            {
                int oldCount = 0;

                SendEventBase eventBase = null;

                lock (bufferEventData.SynchRoot)
                {
                    oldCount = bufferEventData.SendEventBase.Count.Value;
                    if (bufferEventData.Status != AddEventStatus.WaitForSend)
                    {
                        success = true;
                        return;
                    }
                    eventBase = bufferEventData.SendEventBase.CreateBaseCopy();
                    bufferEventData.Status = AddEventStatus.BeginSend;
                }

                var response = eventBase.Send();

                lock (bufferEventData.SynchRoot)
                {
                    bufferEventData.LastAttempSendOrJoinDate = DateTime.Now;
                    if (response.Success)
                    {
                        bufferEventData.EventId     = response.Data.EventId;
                        bufferEventData.EventTypeId = response.Data.EventTypeId;
                        bufferEventData.Errors      = 0;
                        bufferEventData.LastSuccessSendOrJoinDate = bufferEventData.LastAttempSendOrJoinDate;

                        // вычтим из текущего Count то что отправили
                        if (bufferEventData.SendEventBase.Count < int.MaxValue)
                        {
                            bufferEventData.SendEventBase.Count -= oldCount;
                        }
                        if (bufferEventData.SendEventBase.Count < 0)
                        {
                            bufferEventData.SendEventBase.Count = 0;
                        }

                        if (bufferEventData.Status != AddEventStatus.Removed)
                        {
                            if (bufferEventData.SendEventBase.Count > 1)
                            {
                                bufferEventData.Status = AddEventStatus.WaitForJoin;
                            }
                            else
                            {
                                bufferEventData.Status = AddEventStatus.Sended;
                            }
                        }
                        success = true;
                    }
                }
            }
            catch (Exception exception)
            {
                Client.InternalLog.Error("Ошибка отправки события из очереди", exception);
            }
            finally
            {
                lock (bufferEventData.SynchRoot)
                {
                    if (success)
                    {
                    }
                    else
                    {
                        if (bufferEventData.Status != AddEventStatus.Removed)
                        {
                            bufferEventData.Status = AddEventStatus.WaitForSend;
                        }
                        bufferEventData.Errors++;
                    }
                }
            }
        }