Beispiel #1
0
        public void PushMessageToClients(ICollection subscribers, IMessage message)
        {
            MessageDestination  destination         = base.GetDestination(message) as MessageDestination;
            SubscriptionManager subscriptionManager = destination.SubscriptionManager;

            if ((subscribers != null) && (subscribers.Count > 0))
            {
                IMessage message2 = message.Clone() as IMessage;
                foreach (string str in subscribers)
                {
                    MessageClient subscriber = subscriptionManager.GetSubscriber(str);
                    if (subscriber != null)
                    {
                        if (log.get_IsDebugEnabled())
                        {
                            if (message2 is BinaryMessage)
                            {
                                log.Debug(__Res.GetString("MessageServicePushBinary", new object[] { message.GetType().Name, str }));
                            }
                            else
                            {
                                log.Debug(__Res.GetString("MessageServicePush", new object[] { message.GetType().Name, str }));
                            }
                        }
                        base._messageBroker.GetEndpoint(subscriber.Endpoint).Push(message2, subscriber);
                    }
                }
            }
        }
        private void RouteMessage(NetIncomingMessage msg)
        {
            try
            {
                MessageDestination dest = (MessageDestination)msg.ReadByte();
                switch (dest)
                {
                case MessageDestination.Game:
                    ProcessGameMessage(msg);
                    break;

                case MessageDestination.System:
                    ProcessServerMessage(msg);
                    break;

                default:
                    console.WriteWarn("Malformed message.  Invalid desination byte: " + (byte)dest);
                    RecycleMessage(msg);
                    break;
                }
            }
            catch (IndexOutOfRangeException)
            {
                console.WriteWarn("Malformed message.  Could not read desination byte.");
                RecycleMessage(msg);
            }
            catch (Exception e)
            {
                console.WriteWarn("Unknown exception during Message routing: ", e);
                RecycleMessage(msg);
            }
        }
Beispiel #3
0
        internal static void MessageBeginPost(MessageDestination destination, int messageType, IntPtr floatValue, IntPtr playerEntity)
        {
            if (firstMessage)
            {
                // there is no event which intercepts between
                // the registering part and the first message (weaponlist in cstrike case)
                // so we need to initialize the game mode before the first message so we can
                // intercept this valuable information
                switch (Server.GameDirectory)
                {
                case "cstrike":
                    CounterStrike.CounterStrike.Init();
                    break;
                }
                firstMessage = false;
            }

                        #if DEBUG
            messageInformation = new MessageInformation(destination, messageType, floatValue, playerEntity);
            messageInformation.CallTimeBegin = DateTime.Now;
                        #endif

            message_header   = new MessageHeader(destination, messageType, floatValue, playerEntity);
            message_elements = new List <object>();

            MetaModEngine.SetResult(MetaResult.Handled);
        }
Beispiel #4
0
 public MessageHeader(MessageDestination destination, int messageType, IntPtr floatValue, IntPtr entity)
 {
     this.Destination = destination;
     this.MessageType = messageType;
     this.FloatValue  = floatValue;
     this.Entity      = entity;
 }
Beispiel #5
0
        public FrmNewMessage(MessageDestination state, Employee sender, IMessageThread thread = null)
        {
            if (null == sender)
            {
                MessageBox.Show("Invalid employee, please relog and try again.");
                Close();
                return;
            }

            InitializeComponent();

            //Cannot switch on object types, so here we are using a classic ElIf chain
            if (thread is UserThreadView)
            {
                _defaultSubject = (thread as UserThreadView).OpeningSubject;
            }
            else if (thread is UserThread)
            {
                //get the subject from the oldest message sent
                _defaultSubject = (thread as UserThread).Messages.OrderBy(t => t.DateTimeSent).First().Subject;
            }
            else
            {
                _defaultSubject = "";
            }

            _thread             = thread;
            _messageDestination = state;
            _sender             = sender;
            _threadManager      = new RealThreadManager(AppData.DataStoreType.msssql);

            SetupWindow();
        }
Beispiel #6
0
 public MessageHeader(MessageDestination destination, int messageType, IntPtr floatValue, IntPtr entity)
 {
     this.Destination = destination;
     this.MessageType = messageType;
     this.FloatValue = floatValue;
     this.Entity = entity;
 }
Beispiel #7
0
 public MessageInformation(MessageDestination destination, int messageType, IntPtr val, IntPtr playerEdict)
 {
     MessageDestination = destination;
     MessageType        = messageType;
     Value       = val;
     PlayerEdict = playerEdict;
     Arguments   = new List <MessageArgument>();
 }
Beispiel #8
0
        private ICollection GetSubscribers(IMessage message)
        {
            MessageDestination destination = this._dataService.GetDestination(message) as MessageDestination;
            IList subscribers = destination.SubscriptionManager.GetSubscribers();

            subscribers.Remove(message.clientId);
            return(subscribers);
        }
Beispiel #9
0
        /// <summary>
        /// Returns a collection of client Ids of the clients subscribed to receive this message.
        /// If the message has a subtopic header, the subtopics are used to filter the subscribers.
        /// If there is no subtopic header, subscribers to the destination with no subtopic are used.
        /// If a subscription has a selector expression associated with it and evalSelector is true,
        /// the subscriber is only returned if the selector expression evaluates to true.
        /// </summary>
        /// <param name="message">The message to send to subscribers.</param>
        /// <param name="evalSelector">Indicates whether evaluate selector expressions.</param>
        /// <returns>Collection of subscribers.</returns>
        /// <remarks>
        /// Use this method to do additional processing to the subscribers list.
        /// </remarks>
        public ICollection GetSubscriber(IMessage message, bool evalSelector)
        {
            MessageDestination  destination         = GetDestination(message) as MessageDestination;
            SubscriptionManager subscriptionManager = destination.SubscriptionManager;
            ICollection         subscribers         = subscriptionManager.GetSubscribers(message, evalSelector);

            return(subscribers);
        }
Beispiel #10
0
        public unsafe void MessageBegin(MessageDestination msg_dest, int msg_type, Vec3 pOrigin, Entity ed)
        {
            float[] fvec = pOrigin.GetArray();

            fixed(float *pvec = fvec)
            {
                ef.MessageBegin((int)msg_dest, msg_type, pvec, ed.UPointer);
            }
        }
Beispiel #11
0
        public void PushMessageToClients(IMessage message)
        {
            MessageDestination destination = base.GetDestination(message) as MessageDestination;
            ICollection        subscribers = destination.SubscriptionManager.GetSubscribers(message);

            if ((subscribers != null) && (subscribers.Count > 0))
            {
                this.PushMessageToClients(subscribers, message);
            }
        }
Beispiel #12
0
 public static gl.MessageDestination VersGlobal(this MessageDestination e)
 {
     if (e == null)
     {
         return(null);
     }
     return(new gl.MessageDestination {
         dateeffacement = e.dateEffacement, datelecture = e.dateLecture, idconversation = e.idConversation, iddestinataire = e.idDestinataire
     });
 }
Beispiel #13
0
 public static cl.MessageDestination VersClient(this MessageDestination e)
 {
     if (e == null)
     {
         return(null);
     }
     return(new cl.MessageDestination {
         dateEffacement = e.dateEffacement, dateLecture = e.dateLecture, idConversation = e.idConversation, idDestinataire = e.idDestinataire
     });
 }
Beispiel #14
0
        /// <summary>
        /// Begins with the sending of a message.
        /// </summary>
        /// <param name="destination">
        /// The destination of a message. <see cref="MessageDestination"/>
        /// </param>
        /// <param name="msg_type">
        /// The integer value of the message type. <see cref="System.Int32"/>
        /// </param>
        /// <param name="flValue">
        /// A float value? <see cref="IntPtr"/>
        /// </param>
        /// <param name="player">
        /// If send to a specific player, the player entity has to be supplied here <see cref="IntPtr"/>
        /// </param>
        public static void Begin(MessageDestination destination, int messageType, IntPtr floatValue, IntPtr playerEntity)
        {
                        #if DEBUG
            messageInformation = new MessageInformation(destination, messageType, floatValue, playerEntity);
            messageInformation.CallTimeBegin = DateTime.Now;
                        #endif

            MetaModEngine.engineFunctions.MessageBegin(destination, messageType, floatValue, playerEntity);
            count = 0;
        }
Beispiel #15
0
        /// <summary>
        /// Pushes a message to all clients that are subscribed to the destination targeted by this message.
        /// </summary>
        /// <param name="message">The Message to push to the destination's subscribers.</param>
        public void PushMessageToClients(IMessage message)
        {
            MessageDestination  destination         = GetDestination(message) as MessageDestination;
            SubscriptionManager subscriptionManager = destination.SubscriptionManager;
            ICollection         subscribers         = subscriptionManager.GetSubscribers(message);

            if (subscribers != null && subscribers.Count > 0)
            {
                PushMessageToClients(subscribers, message);

                //Asynchronous invocation sample:
                //BeginPushMessageToClients(new AsyncCallback(OnPushEnd), subscribers, message);
            }
        }
Beispiel #16
0
        /*
         * string contenuJson = JsonConvert.SerializeObject(e, Formatting.Indented);
         * StringContent contenu = new StringContent(contenuJson, Encoding.UTF8, "application/json");
         * HttpResponseMessage reponse = _client.PutAsync($"Arbre/Bloquer/", contenu).Result;
         *  if (!reponse.IsSuccessStatusCode)
         *  {
         *      throw new Exception("Echec de la réception de données.");
         * }
         * var x = reponse.Content.ReadAsStringAsync().Result;
         *  return bool.Parse(x);
         */
        public bool Creer(int id1, int id2, MessageDestination e)
        {
            string              contenuJson = JsonConvert.SerializeObject(e, Formatting.Indented);
            StringContent       contenu     = new StringContent(contenuJson, Encoding.UTF8, "application/json");
            HttpResponseMessage reponse     = _client.PostAsync($"MessageDestination/Creer/{id1}/{id2}", contenu).Result;

            if (!reponse.IsSuccessStatusCode)
            {
                throw new Exception("Echec de la réception de données.");
            }
            var x = reponse.Content.ReadAsStringAsync().Result;

            return(bool.Parse(x));
        }
Beispiel #17
0
        /*
         * public void SendToFaction(BitStream data, ushort domainId, ushort typeId, long factionId, bool reliable = true)
         * {
         *  IMyFaction faction = MyAPIGateway.Session.Factions.TryGetFactionById(factionId);
         *  if (faction == null)
         *      Log.Error("Failed to find faction " + factionId);
         *  else
         *      foreach (ulong steamId in faction.SteamIds())
         *          SendToPlayer(data, domainId, typeId, steamId, reliable);
         * }
         */

        static void Send(BitStream data, ushort domainId, ushort typeId, MessageDestination dest, ulong destId = 0, bool reliable = true)
        {
            Log.Trace($"Sending {data.ByteLength} bytes to {dest}/{destId}/{domainId}/{typeId}");
            ulong senderId = (MyAPIGateway.Session.Player != null) ? MyAPIGateway.Session.Player.SteamUserId : 0;

            byte[] bytes = FormatMessage(data, domainId, typeId, senderId);

            MainThread.TryOnMainThread(() =>
            {
                if (!SendMessageToDest(bytes, dest, destId, reliable))
                {
                    Log.Error(new MessageTooLongException(bytes.Length));
                }
            });
        }
Beispiel #18
0
 static bool SendMessageToDest(byte[] data, MessageDestination dest, ulong destId, bool reliable)
 {
     if (dest == MessageDestination.Server)
     {
         return(MyAPIGateway.Multiplayer.SendMessageToServer(HandlerRegistrar.HandlerId, data, reliable));
     }
     else if (dest == MessageDestination.Player)
     {
         return(MyAPIGateway.Multiplayer.SendMessageTo(HandlerRegistrar.HandlerId, data, destId, reliable));
     }
     else if (dest == MessageDestination.All)
     {
         return(MyAPIGateway.Multiplayer.SendMessageToOthers(HandlerRegistrar.HandlerId, data, reliable));
     }
     else
     {
         return(true);
     }
 }
Beispiel #19
0
        /// <summary>
        /// The default contructor initiate a new instance. Set empty Msg and Type.Null if no parameters passed to it.
        /// <paramref name="msg">Optional parameter to set a new message.</param>
        /// <paramref name="type">Optional parameter to set a new type.</paramref>
        /// </summary>
        //public Message(string msg = "", MessageType type = MessageType.None)
        //{
        //    Type = type;
        //    Msg = msg;
        //}
        #endregion

        #region Method
        public static void WriteAll(
            string message,
            MessageType type,
            MessageDestination destination = MessageDestination.None,
            string format = "")
        {
            MessageDestination ActiveDestination = destination;
            string             ActiveFormat      = format;

            // if the destination not passed take the destination from the configuration variable.
            if (ActiveDestination == MessageDestination.None)
            {
                ActiveDestination = Configuration.Destination;
            }

            // if the format not passed take the format from the configuration variable.
            if (ActiveFormat == "")
            {
                ActiveFormat = Configuration.Format;
            }

            // Write to Log.
            if (ActiveDestination.HasFlag(MessageDestination.Log))
            {
                if (Configuration.Log.Type.HasFlag(type))
                {
                    Log.Write(Message: message, type: type);
                }
            }

            if (ActiveDestination.HasFlag(MessageDestination.EventLog))
            {
                //if (Configuration.EventLog.Type.HasFlag(type))
                //    EventLog.Write(Message: message);
            }
        }
 public static void SendWeapPickupMessage(MessageDestination destination, WeapPickupMessage val)
 {
     SendWeapPickupMessage(destination, IntPtr.Zero, IntPtr.Zero , val.WeaponID);
 }
Beispiel #21
0
		internal static void MessageBeginPost(MessageDestination destination, int messageType, IntPtr floatValue, IntPtr playerEntity)
		{
			if (firstMessage) {
				// there is no event which intercepts between
				// the registering part and the first message (weaponlist in cstrike case)
				// so we need to initialize the game mode before the first message so we can
				// intercept this valuable information
				switch (Server.GameDirectory) {
				case "cstrike":
					CounterStrike.CounterStrike.Init();
					break;
				}
				firstMessage = false;
			}

			#if DEBUG
			messageInformation = new MessageInformation(destination, messageType, floatValue, playerEntity);
			messageInformation.CallTimeBegin = DateTime.Now;
			#endif

			message_header = new MessageHeader(destination, messageType, floatValue, playerEntity);
			message_elements = new List<object>();

			MetaModEngine.SetResult(MetaResult.Handled);
			}
        public static void SendVoiceMaskMessage(MessageDestination destination, IntPtr floatValue, IntPtr playerEntity, long AudiblePlayersIndexbitSum, long ServerBannedPlayersIndexBitSum)
        {
            Message.Begin(destination, Message.GetUserMessageID("VoiceMask"), floatValue, playerEntity);

            Message.WriteLong(AudiblePlayersIndexbitSum);
            Message.WriteLong(ServerBannedPlayersIndexBitSum);
            Message.End();
        }
 public static void SendTutorTextMessage(MessageDestination destination, IntPtr floatValue, IntPtr playerEntity, TutorTextMessage val)
 {
     SendTutorTextMessage(destination, floatValue,playerEntity , val.Unknown1, val.Unknown2, val.Unknown3, val.Unknown4, val.Unknown5);
 }
Beispiel #24
0
 public MessageClient AddSubscriber(IClient client, string messageClientId, string endpointId, MessageDestination messageDestination, Subtopic subtopic, Selector selector)
 {
     lock (_objLock)
     {
         if (subtopic != null)
         {
             MessagingAdapter serviceAdapter = this._messageDestination.ServiceAdapter as MessagingAdapter;
             if ((serviceAdapter != null) && !serviceAdapter.AllowSubscribe(subtopic))
             {
                 ASObject extendedData = new ASObject();
                 extendedData["subtopic"] = subtopic.Value;
                 throw new MessageException(extendedData);
             }
         }
         if (!this._subscribers.Contains(messageClientId))
         {
             MessageClient messageClient = new MessageClient(client, messageDestination.SubscriptionManager, messageClientId, endpointId, messageDestination)
             {
                 Subtopic = subtopic,
                 Selector = selector
             };
             client.RegisterMessageClient(messageClient);
             this.AddSubscriber(messageClient);
             return(messageClient);
         }
         return(this._subscribers[messageClientId] as MessageClient);
     }
 }
Beispiel #25
0
        public override IMessage ServiceMessage(IMessage message)
        {
            if (message is CommandMessage)
            {
                CommandMessage message2 = message as CommandMessage;
                switch (message2.operation)
                {
                case 0:
                {
                    if (FluorineContext.Current.Client == null)
                    {
                        FluorineContext.Current.SetCurrentClient(base.GetMessageBroker().ClientRegistry.GetClient(message));
                    }
                    RemotingConnection connection = null;
                    foreach (IConnection connection2 in FluorineContext.Current.Client.Connections)
                    {
                        if (connection2 is RemotingConnection)
                        {
                            connection = connection2 as RemotingConnection;
                            break;
                        }
                    }
                    if (connection == null)
                    {
                        connection = new RemotingConnection(this, null, FluorineContext.Current.Client.Id, null);
                        FluorineContext.Current.Client.Renew(connection.ClientLeaseTime);
                        connection.Initialize(FluorineContext.Current.Client);
                    }
                    break;
                }

                case 2:
                {
                    if (FluorineContext.Current.Client != null)
                    {
                        FluorineContext.Current.Client.Renew();
                    }
                    IMessage[] pendingMessages = null;
                    this._waitingPollRequests.Increment();
                    int waitIntervalMillis = (base._channelSettings.WaitIntervalMillis != -1) ? base._channelSettings.WaitIntervalMillis : 0xea60;
                    if (FluorineContext.Current.Client != null)
                    {
                        FluorineContext.Current.Client.Renew();
                    }
                    if (message2.HeaderExists(CommandMessage.FluorineSuppressPollWaitHeader))
                    {
                        waitIntervalMillis = 0;
                    }
                    if (!FluorineConfiguration.Instance.FluorineSettings.Runtime.AsyncHandler)
                    {
                        waitIntervalMillis = 0;
                    }
                    if ((base._channelSettings.MaxWaitingPollRequests <= 0) || (this._waitingPollRequests.Value >= base._channelSettings.MaxWaitingPollRequests))
                    {
                        waitIntervalMillis = 0;
                    }
                    if ((message.destination != null) && (message.destination != string.Empty))
                    {
                        string             clientId    = message2.clientId as string;
                        MessageDestination destination = base.GetMessageBroker().GetDestination(message.destination) as MessageDestination;
                        MessageClient      subscriber  = destination.SubscriptionManager.GetSubscriber(clientId);
                        subscriber.Renew();
                        pendingMessages = subscriber.GetPendingMessages();
                    }
                    else if (FluorineContext.Current.Client != null)
                    {
                        pendingMessages = FluorineContext.Current.Client.GetPendingMessages(waitIntervalMillis);
                    }
                    this._waitingPollRequests.Decrement();
                    if ((pendingMessages == null) || (pendingMessages.Length == 0))
                    {
                        return(new AcknowledgeMessage());
                    }
                    return(new CommandMessage {
                            operation = 4, body = pendingMessages
                        });
                }
                }
            }
            return(base.ServiceMessage(message));
        }
        public static void SendVGUIMenuMessage(MessageDestination destination, IntPtr floatValue, IntPtr playerEntity, byte MenuID, short KeyBitSum, char Time, byte MultiPart, string Name)
        {
            Message.Begin(destination, Message.GetUserMessageID("VGUIMenu"), floatValue, playerEntity);

            Message.WriteByte(MenuID);
            Message.WriteShort(KeyBitSum);
            Message.WriteChar(Time);
            Message.WriteByte(MultiPart);
            Message.WriteString(Name);
            Message.End();
        }
 public static void SendViewModeMessage(MessageDestination destination, IntPtr playerEntity, ViewModeMessage val)
 {
     SendViewModeMessage(destination, IntPtr.Zero, playerEntity );
 }
 public static void SendTutorStateMessage(MessageDestination destination, IntPtr floatValue, IntPtr playerEntity, TutorStateMessage val)
 {
     SendTutorStateMessage(destination, floatValue,playerEntity );
 }
        public static void SendWeapPickupMessage(MessageDestination destination, IntPtr floatValue, IntPtr playerEntity, byte WeaponID)
        {
            Message.Begin(destination, Message.GetUserMessageID("WeapPickup"), floatValue, playerEntity);

            Message.WriteByte(WeaponID);
            Message.End();
        }
 public static void SendWeapPickupMessage(MessageDestination destination, IntPtr floatValue, IntPtr playerEntity, WeapPickupMessage val)
 {
     SendWeapPickupMessage(destination, floatValue,playerEntity , val.WeaponID);
 }
 public static void SendWeaponListMessage(MessageDestination destination, WeaponListMessage val)
 {
     SendWeaponListMessage(destination, IntPtr.Zero, IntPtr.Zero , val.WeaponName, val.PrimaryAmmoID, val.PrimaryAmmoMaxAmount, val.SecondaryAmmoID, val.SecondaryAmmoMaxAmount, val.SlotID, val.NumberInSlot, val.WeaponID, val.Flags);
 }
 public static void SendWeaponListMessage(MessageDestination destination, IntPtr floatValue, IntPtr playerEntity, WeaponListMessage val)
 {
     SendWeaponListMessage(destination, floatValue,playerEntity , val.WeaponName, val.PrimaryAmmoID, val.PrimaryAmmoMaxAmount, val.SecondaryAmmoID, val.SecondaryAmmoMaxAmount, val.SlotID, val.NumberInSlot, val.WeaponID, val.Flags);
 }
        public static void SendWeaponListMessage(MessageDestination destination, IntPtr floatValue, IntPtr playerEntity, string WeaponName, byte PrimaryAmmoID, byte PrimaryAmmoMaxAmount, byte SecondaryAmmoID, byte SecondaryAmmoMaxAmount, byte SlotID, byte NumberInSlot, byte WeaponID, byte Flags)
        {
            Message.Begin(destination, Message.GetUserMessageID("WeaponList"), floatValue, playerEntity);

            Message.WriteString(WeaponName);
            Message.WriteByte(PrimaryAmmoID);
            Message.WriteByte(PrimaryAmmoMaxAmount);
            Message.WriteByte(SecondaryAmmoID);
            Message.WriteByte(SecondaryAmmoMaxAmount);
            Message.WriteByte(SlotID);
            Message.WriteByte(NumberInSlot);
            Message.WriteByte(WeaponID);
            Message.WriteByte(Flags);
            Message.End();
        }
 public static void SendVoiceMaskMessage(MessageDestination destination, VoiceMaskMessage val)
 {
     SendVoiceMaskMessage(destination, IntPtr.Zero, IntPtr.Zero , val.AudiblePlayersIndexbitSum, val.ServerBannedPlayersIndexBitSum);
 }
 public static void SendVoiceMaskMessage(MessageDestination destination, IntPtr floatValue, IntPtr playerEntity, VoiceMaskMessage val)
 {
     SendVoiceMaskMessage(destination, floatValue,playerEntity , val.AudiblePlayersIndexbitSum, val.ServerBannedPlayersIndexBitSum);
 }
 public static void SendVGUIMenuMessage(MessageDestination destination, IntPtr floatValue, IntPtr playerEntity, VGUIMenuMessage val)
 {
     SendVGUIMenuMessage(destination, floatValue,playerEntity , val.MenuID, val.KeyBitSum, val.Time, val.MultiPart, val.Name);
 }
Beispiel #37
0
        /// <summary>
        /// Begins with the sending of a message.
        /// </summary>
        /// <param name="destination">
        /// The destination of a message. <see cref="MessageDestination"/>
        /// </param>
        /// <param name="msg_type">
        /// The integer value of the message type. <see cref="System.Int32"/>
        /// </param>
        /// <param name="flValue">
        /// A float value? <see cref="IntPtr"/>
        /// </param>
        /// <param name="player">
        /// If send to a specific player, the player entity has to be supplied here <see cref="IntPtr"/>
        /// </param>
        public static void Begin(MessageDestination destination, int messageType, IntPtr floatValue, IntPtr playerEntity)
        {
            #if DEBUG
            messageInformation = new MessageInformation(destination, messageType, floatValue, playerEntity);
            messageInformation.CallTimeBegin = DateTime.Now;
            #endif

            MetaModEngine.engineFunctions.MessageBegin(destination, messageType, floatValue, playerEntity);
            count = 0;
        }
Beispiel #38
0
        public override object ServiceMessage(IMessage message)
        {
            CommandMessage     commandMessage     = message as CommandMessage;
            MessageDestination messageDestination = base.GetDestination(message) as MessageDestination;

            if (commandMessage == null)
            {
                if (log.get_IsDebugEnabled())
                {
                    log.Debug(__Res.GetString("MessageServiceRoute", new object[] { messageDestination.Id, message.clientId }));
                }
                if ((FluorineContext.Current != null) && (FluorineContext.Current.Client != null))
                {
                    FluorineContext.Current.Client.Renew();
                }
                return(messageDestination.ServiceAdapter.Invoke(message));
            }
            string        clientId   = commandMessage.clientId as string;
            MessageClient subscriber = messageDestination.SubscriptionManager.GetSubscriber(clientId);

            switch (commandMessage.operation)
            {
            case 0:
                if (subscriber == null)
                {
                    if (clientId == null)
                    {
                        clientId = Guid.NewGuid().ToString("D");
                    }
                    if (log.get_IsDebugEnabled())
                    {
                        log.Debug(__Res.GetString("MessageServiceSubscribe", new object[] { messageDestination.Id, clientId }));
                    }
                    string header = commandMessage.GetHeader("DSEndpoint") as string;
                    commandMessage.clientId = clientId;
                    if ((messageDestination.ServiceAdapter != null) && messageDestination.ServiceAdapter.HandlesSubscriptions)
                    {
                        messageDestination.ServiceAdapter.Manage(commandMessage);
                    }
                    Subtopic subtopic = null;
                    Selector selector = null;
                    if (commandMessage.headers != null)
                    {
                        if (commandMessage.headers.ContainsKey(CommandMessage.SelectorHeader))
                        {
                            selector = Selector.CreateSelector(commandMessage.headers[CommandMessage.SelectorHeader] as string);
                        }
                        if (commandMessage.headers.ContainsKey("DSSubtopic"))
                        {
                            subtopic = new Subtopic(commandMessage.headers["DSSubtopic"] as string);
                        }
                    }
                    IClient client = FluorineContext.Current.Client;
                    client.Renew();
                    subscriber = messageDestination.SubscriptionManager.AddSubscriber(client, clientId, header, messageDestination, subtopic, selector);
                }
                return(new AcknowledgeMessage {
                    clientId = clientId
                });

            case 1:
                if (log.get_IsDebugEnabled())
                {
                    log.Debug(__Res.GetString("MessageServiceUnsubscribe", new object[] { messageDestination.Id, clientId }));
                }
                if ((messageDestination.ServiceAdapter != null) && messageDestination.ServiceAdapter.HandlesSubscriptions)
                {
                    messageDestination.ServiceAdapter.Manage(commandMessage);
                }
                if (subscriber != null)
                {
                    subscriber.Unsubscribe();
                }
                return(new AcknowledgeMessage());

            case 2:
                if (subscriber == null)
                {
                    ServiceException exception = new ServiceException(string.Format("MessageClient is not subscribed to {0}", commandMessage.destination))
                    {
                        FaultCode = "Server.Processing.NotSubscribed"
                    };
                    throw exception;
                }
                FluorineContext.Current.Client.Renew();
                messageDestination.ServiceAdapter.Manage(commandMessage);
                return(new AcknowledgeMessage());

            case 5:
                if ((messageDestination.ServiceAdapter != null) && messageDestination.ServiceAdapter.HandlesSubscriptions)
                {
                    messageDestination.ServiceAdapter.Manage(commandMessage);
                }
                return(true);
            }
            if (log.get_IsDebugEnabled())
            {
                log.Debug(__Res.GetString("MessageServiceUnknown", new object[] { commandMessage.operation, messageDestination.Id }));
            }
            messageDestination.ServiceAdapter.Manage(commandMessage);
            return(new AcknowledgeMessage());
        }
Beispiel #39
0
        /*
         * void OnPushEnd(IAsyncResult result)
         * {
         *  EndPushMessageToClients(result);
         * }
         */

        /// <summary>
        /// Pushes a message to the specified clients (subscribers).
        /// </summary>
        /// <param name="subscribers">Collection of subscribers.</param>
        /// <param name="message">The Message to push to the subscribers.</param>
        /// <remarks>
        /// The Collection of subscribers is a collection of client Id strings.
        /// </remarks>
        public void PushMessageToClients(ICollection subscribers, IMessage message)
        {
            MessageDestination  destination         = GetDestination(message) as MessageDestination;
            SubscriptionManager subscriptionManager = destination.SubscriptionManager;

            if (subscribers != null && subscribers.Count > 0)
            {
                IMessage messageClone = message.Copy() as IMessage;

                /*
                 *              if( subscribers.Count > 1 )
                 *              {
                 *                      messageClone.SetHeader(MessageBase.DestinationClientIdHeader, BinaryMessage.DestinationClientGuid);
                 *                      messageClone.clientId = BinaryMessage.DestinationClientGuid;
                 *                      //Cache the message
                 *                      MemoryStream ms = new MemoryStream();
                 *                      AMFSerializer amfSerializer = new AMFSerializer(ms);
                 *                      //TODO this should depend on endpoint settings
                 *                      amfSerializer.UseLegacyCollection = false;
                 *                      amfSerializer.WriteData(ObjectEncoding.AMF3, messageClone);
                 *                      amfSerializer.Flush();
                 *                      byte[] cachedContent = ms.ToArray();
                 *                      ms.Close();
                 *                      BinaryMessage binaryMessage = new BinaryMessage();
                 *                      binaryMessage.body = cachedContent;
                 *                      //binaryMessage.Prepare();
                 *                      messageClone = binaryMessage;
                 *              }
                 */
                foreach (string clientId in subscribers)
                {
                    MessageClient client = subscriptionManager.GetSubscriber(clientId);
                    if (client == null)
                    {
                        continue;
                    }
                    if (log.IsDebugEnabled)
                    {
                        if (messageClone is BinaryMessage)
                        {
                            log.Debug(__Res.GetString(__Res.MessageServicePushBinary, message.GetType().Name, clientId));
                        }
                        else
                        {
                            log.Debug(__Res.GetString(__Res.MessageServicePush, message.GetType().Name, clientId));
                        }
                    }

                    IEndpoint endpoint = _messageBroker.GetEndpoint(client.EndpointId);
                    if (endpoint != null)
                    {
                        endpoint.Push(messageClone, client);
                    }
                    else
                    {
                        //We should never get here
                        if (log.IsErrorEnabled)
                        {
                            log.Error(string.Format("Missing endpoint for message client {0}", client.ClientId));
                        }
                    }
                }
            }
        }
        public static void SendViewModeMessage(MessageDestination destination, IntPtr floatValue, IntPtr playerEntity)
        {
            Message.Begin(destination, Message.GetUserMessageID("ViewMode"), floatValue, playerEntity);

            Message.End();
        }
Beispiel #41
0
        public async Task process(IConfiguration config)
        {
            // creando AvroSchemas from clases
            AvroSerializerSettings settings = new AvroSerializerSettings();

            settings.Resolver = new AvroPublicMemberContractResolver();
            var endpontSchema = AvroSerializer.Create <Endpoint> (settings).WriterSchema.ToString();

            var messageDSchema = AvroSerializer.Create <MessageDestination> (settings).WriterSchema.ToString();

            Console.WriteLine("Endpoint Schema: " + endpontSchema);
            Console.WriteLine("Message Destination Schema: " + messageDSchema);

            Console.WriteLine("RouterProcess");
            var sConfig = new StreamConfig <StringSerDes, StringSerDes> ();

            sConfig.ApplicationId       = config["SPRING_CLOUD_APPLICATION_GROUP"];
            sConfig.BootstrapServers    = config["SPRING_CLOUD_STREAM_KAFKA_BINDER_BROKERS"];
            sConfig.AutoOffsetReset     = AutoOffsetReset.Earliest;
            sConfig.SchemaRegistryUrl   = config["SchemaRegistryUrl"];
            sConfig.AutoRegisterSchemas = true;
            sConfig.NumStreamThreads    = 1;
            sConfig.Acks = Acks.All;
            //sConfig.Debug = "consumer,cgrp,topic,fetch";
            sConfig.AddConsumerConfig("allow.auto.create.topics", "true");
            sConfig.MaxTaskIdleMs         = 50;
            sConfig.InnerExceptionHandler = (e) => ExceptionHandlerResponse.CONTINUE;

            var      timeout = TimeSpan.FromSeconds(10);
            DateTime dt      = DateTime.Now;

            MessageDestination op = new MessageDestination();

            var           serializer = new SchemaAvroSerDes <OrderProduct>();
            StreamBuilder builder    = new StreamBuilder();

            var table = builder.Table(config["endpoints"],
                                      new Int32SerDes(),
                                      new SchemaAvroSerDes <Endpoint> (),
                                      InMemory <int, Endpoint> .As(config["endpoints-table"]));

            builder.Stream <int, OrderProduct, Int32SerDes, SchemaAvroSerDes <OrderProduct> >(config["spring.cloud.stream.bindings.input.destination"])
            .Map <int, OrderProduct>((k, v) =>
            {
                return(KeyValuePair.Create(v.product_id, v));
            })
            .Peek((k, v) =>
            {
                Console.WriteLine($"Sending message {k}  to endpoint {v.product_id}");
                //calcular metrica
            })
            .Join(table, (orderProduct, endpoint) => {
                Console.WriteLine("OrderProduct: " + orderProduct?.order_id);
                Console.WriteLine("Endpoint: " + endpoint?.endpoint_id);

                op = new MessageDestination {
                    messageId = orderProduct.order_id,
                    endpoint  = endpoint,
                    payload   = orderProduct
                };
                return(op);
            })
            .Peek((k, v) =>
            {
                Console.WriteLine($"Sending message {k}  to endpoint {v.endpoint.endpoint_url}");
                // crear metricas
                if (_messageCounterList != null)
                {
                    var counterMessage = Metrics
                                         .CreateCounter($"router_{v.endpoint.endpoint_id}_processed_total", $"Number of messages sent to {v.endpoint.endpoint_url}");

                    counterMessage.Inc();

                    _messageCounterList.Add(counterMessage);
                }
            })
            .Print(Printed <int, MessageDestination> .ToOut());

            Topology t = builder.Build();

            Console.WriteLine(t.Describe());

            KafkaStream stream = new KafkaStream(t, sConfig);

            bool isRunningState = false;

            stream.StateChanged += (old, @new) => {
                if (@new.Equals(KafkaStream.State.RUNNING))
                {
                    isRunningState = true;
                }
            };

            await stream.StartAsync();

            while (!isRunningState)
            {
                Thread.Sleep(250);
                if (DateTime.Now > dt + timeout)
                {
                    break;
                }
            }

            if (isRunningState)
            {
                Console.WriteLine("Stream running state is " + isRunningState.ToString());
            }
        }
 public static void SendTutorTextMessage(MessageDestination destination, TutorTextMessage val)
 {
     SendTutorTextMessage(destination, IntPtr.Zero, IntPtr.Zero , val.Unknown1, val.Unknown2, val.Unknown3, val.Unknown4, val.Unknown5);
 }
 public static void SendVGUIMenuMessage(MessageDestination destination, VGUIMenuMessage val)
 {
     SendVGUIMenuMessage(destination, IntPtr.Zero, IntPtr.Zero , val.MenuID, val.KeyBitSum, val.Time, val.MultiPart, val.Name);
 }
Beispiel #44
0
 public SubscriptionManager(MessageDestination messageDestination)
 {
     this._messageDestination = messageDestination;
     this._subscribers        = new Hashtable();
 }
 public static void SendTrainMessage(MessageDestination destination, TrainMessage val)
 {
     SendTrainMessage(destination, IntPtr.Zero, IntPtr.Zero , val.Speed);
 }
        public override IMessage ServiceMessage(IMessage message)
        {
            if (FluorineContext.Current.Client != null)
            {
                FluorineContext.Current.Client.Renew();
            }

            if (message is CommandMessage)
            {
                CommandMessage commandMessage = message as CommandMessage;
                switch (commandMessage.operation)
                {
                case CommandMessage.PollOperation:
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug(__Res.GetString(__Res.Endpoint_HandleMessage, this.Id, message.ToString()));
                    }

                    if (FluorineContext.Current.Client != null)
                    {
                        FluorineContext.Current.Client.Renew();
                    }

                    //IMessage[] messages = null;
                    IList messages = null;
                    _waitingPollRequests.Increment();
                    int waitIntervalMillis = this.ChannelDefinition.Properties.WaitIntervalMillis != -1 ? this.ChannelDefinition.Properties.WaitIntervalMillis : 60000;        // int.MaxValue;

                    if (commandMessage.HeaderExists(CommandMessage.FluorineSuppressPollWaitHeader))
                    {
                        waitIntervalMillis = 0;
                    }
                    //If async handling was not set long polling is not supported
                    if (!FluorineConfiguration.Instance.FluorineSettings.Runtime.AsyncHandler)
                    {
                        waitIntervalMillis = 0;
                    }
                    if (this.ChannelDefinition.Properties.MaxWaitingPollRequests <= 0 || _waitingPollRequests.Value >= this.ChannelDefinition.Properties.MaxWaitingPollRequests)
                    {
                        waitIntervalMillis = 0;
                    }

                    if (message.destination != null && message.destination != string.Empty)
                    {
                        string             clientId           = commandMessage.clientId as string;
                        MessageDestination messageDestination = this.GetMessageBroker().GetDestination(message.destination) as MessageDestination;
                        MessageClient      client             = messageDestination.SubscriptionManager.GetSubscriber(clientId);
                        client.Renew();
                        //messages = client.GetPendingMessages();
                    }
                    else
                    {
                        //if (FluorineContext.Current.Client != null)
                        //    messages = FluorineContext.Current.Client.GetPendingMessages(waitIntervalMillis);
                    }

                    if (FluorineContext.Current.Client != null)
                    {
                        IEndpointPushHandler handler = FluorineContext.Current.Client.GetEndpointPushHandler(this.Id);
                        if (handler != null)
                        {
                            messages = handler.GetPendingMessages();
                        }
                        if (messages == null)
                        {
                            lock (handler.SyncRoot)
                            {
                                Monitor.Wait(handler.SyncRoot, waitIntervalMillis);
                            }
                            messages = handler.GetPendingMessages();
                        }
                    }

                    _waitingPollRequests.Decrement();
                    IMessage response = null;
                    if (messages == null || messages.Count == 0)
                    {
                        response = new AcknowledgeMessage();
                    }
                    else
                    {
                        CommandMessage resultMessage = new CommandMessage();
                        resultMessage.operation = CommandMessage.ClientSyncOperation;
                        resultMessage.body      = messages;
                        response = resultMessage;
                    }
                    if (log.IsDebugEnabled)
                    {
                        log.Debug(__Res.GetString(__Res.Endpoint_Response, this.Id, response.ToString()));
                    }
                    return(response);
                }

                case CommandMessage.SubscribeOperation:
                {
                    /*
                     * if (FluorineContext.Current.Client == null)
                     *  FluorineContext.Current.SetCurrentClient(this.GetMessageBroker().ClientRegistry.GetClient(message));
                     * RemotingConnection remotingConnection = null;
                     * foreach (IConnection connection in FluorineContext.Current.Client.Connections)
                     * {
                     *  if (connection is RemotingConnection)
                     *  {
                     *      remotingConnection = connection as RemotingConnection;
                     *      break;
                     *  }
                     * }
                     * if (remotingConnection == null)
                     * {
                     *  remotingConnection = new RemotingConnection(this, null, FluorineContext.Current.Client.Id, null);
                     *  FluorineContext.Current.Client.Renew(this.ClientLeaseTime);
                     *  remotingConnection.Initialize(FluorineContext.Current.Client);
                     * }
                     * FluorineWebContext webContext = FluorineContext.Current as FluorineWebContext;
                     * webContext.SetConnection(remotingConnection);
                     */

                    if (this.ChannelDefinition.Properties.IsPollingEnabled)
                    {
                        //Create and forget, client will close the notifier
                        IEndpointPushHandler handler = FluorineContext.Current.Client.GetEndpointPushHandler(this.Id);
                        if (handler == null)
                        {
                            handler = new EndpointPushNotifier(this, FluorineContext.Current.Client);
                        }

                        /*
                         * lock (_endpointPushHandlers.SyncRoot)
                         * {
                         *  _endpointPushHandlers.Add(notifier.Id, notifier);
                         * }
                         */
                    }
                }
                break;

                case CommandMessage.DisconnectOperation:
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug(__Res.GetString(__Res.Endpoint_HandleMessage, this.Id, message.ToString()));
                    }

                    if (FluorineContext.Current.Client != null && FluorineContext.Current.Client.IsValid)
                    {
                        IList messageClients = FluorineContext.Current.Client.MessageClients;
                        if (messageClients != null)
                        {
                            foreach (MessageClient messageClient in messageClients)
                            {
                                messageClient.Invalidate();
                            }
                        }
                        FluorineContext.Current.Client.Invalidate();
                    }
                    if (FluorineContext.Current.Session != null)
                    {
                        FluorineContext.Current.Session.Invalidate();
                    }
                    //Disconnect command is received from a client channel.
                    //The response returned by this method is not guaranteed to get to the client, which is free to terminate its physical connection at any point.
                    IMessage response = new AcknowledgeMessage();

                    if (log.IsDebugEnabled)
                    {
                        log.Debug(__Res.GetString(__Res.Endpoint_Response, this.Id, response.ToString()));
                    }
                    return(response);
                }
                }
            }
            return(base.ServiceMessage(message));
        }
Beispiel #47
0
            public Message(PureMessage parent, string name, MessageType type, MessageDestination dest, string message)
            {
                this.parent = parent;

                this.name = name;
                this.type = type;
                this.dest = dest;
                this.message = message;
            }
        public static void SendTutorTextMessage(MessageDestination destination, IntPtr floatValue, IntPtr playerEntity, string Unknown1, byte Unknown2, short Unknown3, short Unknown4, short Unknown5)
        {
            Message.Begin(destination, Message.GetUserMessageID("TutorText"), floatValue, playerEntity);

            Message.WriteString(Unknown1);
            Message.WriteByte(Unknown2);
            Message.WriteShort(Unknown3);
            Message.WriteShort(Unknown4);
            Message.WriteShort(Unknown5);
            Message.End();
        }
 public static void SendViewModeMessage(MessageDestination destination, ViewModeMessage val)
 {
     SendViewModeMessage(destination, IntPtr.Zero, IntPtr.Zero );
 }
Beispiel #50
0
 public PlayerSpawnMessage(PureMessage parent, string name, MessageType type, MessageDestination dest, string message)
     : base(parent, name, type, dest, message)
 {
     this.triggerOnce = true;
 }
Beispiel #51
0
        public bool Modifier(int id, int id2, MessageDestination e)
        {
            return(new MessageDestinationService().Modifier(id, id2, e.VersClient()));

            throw new NotImplementedException();
        }
Beispiel #52
0
 public PlayerJoinMessage(PureMessage parent, string name, MessageType type, MessageDestination dest, string message)
     : base(parent, name, type, dest, message)
 {
 }
 public static void SendTutorStateMessage(MessageDestination destination, IntPtr playerEntity, TutorStateMessage val)
 {
     SendTutorStateMessage(destination, IntPtr.Zero, playerEntity );
 }
Beispiel #54
0
        public ICollection GetSubscriber(IMessage message, bool evalSelector)
        {
            MessageDestination destination = base.GetDestination(message) as MessageDestination;

            return(destination.SubscriptionManager.GetSubscribers(message, evalSelector));
        }
 public static void SendViewModeMessage(MessageDestination destination, IntPtr floatValue, IntPtr playerEntity, ViewModeMessage val)
 {
     SendViewModeMessage(destination, floatValue,playerEntity );
 }
Beispiel #56
0
        public unsafe void BuildSoundMsg(Entity entity, int channel, string sample, float volume, float attenuation, int fFlags, int pitch, MessageDestination msg_dest, int msg_type, Vec3 pOrigin, Entity ed)
        {
            float[] forg = pOrigin.GetArray();

            fixed(float *porg = forg)
            {
                ef.BuildSoundMsg(entity.UPointer, channel, sample, volume, attenuation, fFlags, pitch, (int)msg_dest, msg_type, porg, ed.UPointer);
            }
        }
 public static void SendTutorStateMessage(MessageDestination destination, TutorStateMessage val)
 {
     SendTutorStateMessage(destination, IntPtr.Zero, IntPtr.Zero );
 }
Beispiel #58
0
        /// <summary>
        /// Handles a message routed to the service by the MessageBroker.
        /// </summary>
        /// <param name="message">The message that should be handled by the service.</param>
        /// <returns>The result of the message processing.</returns>
        public override object ServiceMessage(IMessage message)
        {
            CommandMessage     commandMessage     = message as CommandMessage;
            MessageDestination messageDestination = GetDestination(message) as MessageDestination;

            if (commandMessage != null)
            {
                string             clientId           = commandMessage.clientId as string;
                MessageClient      messageClient      = messageDestination.SubscriptionManager.GetSubscriber(clientId);
                AcknowledgeMessage acknowledgeMessage = null;
                switch (commandMessage.operation)
                {
                case CommandMessage.SubscribeOperation:
                    if (messageClient == null)
                    {
                        if (clientId == null)
                        {
                            clientId = Guid.NewGuid().ToString("D");
                        }

                        if (log.IsDebugEnabled)
                        {
                            log.Debug(__Res.GetString(__Res.MessageServiceSubscribe, messageDestination.Id, clientId));
                        }

                        string endpointId = commandMessage.GetHeader(MessageBase.EndpointHeader) as string;
                        if (_messageBroker.GetEndpoint(endpointId) == null)
                        {
                            ServiceException serviceException = new ServiceException("Endpoint was not specified");
                            serviceException.FaultCode = "Server.Processing.MissingEndpoint";
                            throw serviceException;
                        }
                        commandMessage.clientId = clientId;

                        if (messageDestination.ServiceAdapter != null && messageDestination.ServiceAdapter.HandlesSubscriptions)
                        {
                            try
                            {
                                acknowledgeMessage = messageDestination.ServiceAdapter.Manage(commandMessage) as AcknowledgeMessage;
                            }
                            catch (MessageException me)
                            {
                                acknowledgeMessage = me.GetErrorMessage();
                                //Leave, do not subscribe
                                return(acknowledgeMessage);
                            }
                            catch (Exception ex)
                            {
                                //Guard against service adapter failure
                                acknowledgeMessage = ErrorMessage.GetErrorMessage(commandMessage, ex);
                                if (log.IsErrorEnabled)
                                {
                                    log.Error(__Res.GetString(__Res.ServiceAdapter_ManageFail, this.id, messageDestination.Id, commandMessage), ex);
                                }
                                //Leave, do not subscribe
                                return(acknowledgeMessage);
                            }
                        }

                        Subtopic subtopic = null;
                        Selector selector = null;
                        if (commandMessage.headers != null)
                        {
                            if (commandMessage.headers.ContainsKey(CommandMessage.SelectorHeader))
                            {
                                selector = Selector.CreateSelector(commandMessage.headers[CommandMessage.SelectorHeader] as string);
                            }
                            if (commandMessage.headers.ContainsKey(AsyncMessage.SubtopicHeader))
                            {
                                subtopic = new Subtopic(commandMessage.headers[AsyncMessage.SubtopicHeader] as string);
                            }
                        }
                        IClient client = FluorineContext.Current.Client;
                        client.Renew();
                        messageClient = messageDestination.SubscriptionManager.AddSubscriber(clientId, endpointId, subtopic, selector);
                        if (acknowledgeMessage == null)
                        {
                            acknowledgeMessage = new AcknowledgeMessage();
                        }
                        acknowledgeMessage.clientId = clientId;
                    }
                    else
                    {
                        acknowledgeMessage          = new AcknowledgeMessage();
                        acknowledgeMessage.clientId = clientId;
                    }
                    return(acknowledgeMessage);

                case CommandMessage.UnsubscribeOperation:
                    if (log.IsDebugEnabled)
                    {
                        log.Debug(__Res.GetString(__Res.MessageServiceUnsubscribe, messageDestination.Id, clientId));
                    }

                    if (messageDestination.ServiceAdapter != null && messageDestination.ServiceAdapter.HandlesSubscriptions)
                    {
                        try
                        {
                            acknowledgeMessage = messageDestination.ServiceAdapter.Manage(commandMessage) as AcknowledgeMessage;
                        }
                        catch (MessageException me)
                        {
                            acknowledgeMessage = me.GetErrorMessage();
                        }
                        catch (Exception ex)
                        {
                            //Guard against service adapter failure
                            acknowledgeMessage = ErrorMessage.GetErrorMessage(commandMessage, ex);
                            if (log.IsErrorEnabled)
                            {
                                log.Error(__Res.GetString(__Res.ServiceAdapter_ManageFail, this.id, messageDestination.Id, commandMessage), ex);
                            }
                        }
                    }
                    if (messageClient != null)
                    {
                        messageDestination.SubscriptionManager.RemoveSubscriber(messageClient);
                    }
                    if (acknowledgeMessage == null)
                    {
                        acknowledgeMessage = new AcknowledgeMessage();
                    }
                    return(acknowledgeMessage);

                case CommandMessage.PollOperation:
                {
                    if (messageClient == null)
                    {
                        ServiceException serviceException = new ServiceException(string.Format("MessageClient is not subscribed to {0}", commandMessage.destination));
                        serviceException.FaultCode = "Server.Processing.NotSubscribed";
                        throw serviceException;
                    }
                    IClient client = FluorineContext.Current.Client;
                    client.Renew();
                    try
                    {
                        acknowledgeMessage = messageDestination.ServiceAdapter.Manage(commandMessage) as AcknowledgeMessage;
                    }
                    catch (MessageException me)
                    {
                        acknowledgeMessage = me.GetErrorMessage();
                    }
                    catch (Exception ex)
                    {
                        //Guard against service adapter failure
                        acknowledgeMessage = ErrorMessage.GetErrorMessage(commandMessage, ex);
                        if (log.IsErrorEnabled)
                        {
                            log.Error(__Res.GetString(__Res.ServiceAdapter_ManageFail, this.id, messageDestination.Id, commandMessage), ex);
                        }
                    }
                    if (acknowledgeMessage == null)
                    {
                        acknowledgeMessage = new AcknowledgeMessage();
                    }
                    return(acknowledgeMessage);
                }

                case CommandMessage.ClientPingOperation:
                    if (messageDestination.ServiceAdapter != null && messageDestination.ServiceAdapter.HandlesSubscriptions)
                    {
                        try
                        {
                            messageDestination.ServiceAdapter.Manage(commandMessage);
                        }
                        catch (MessageException)
                        {
                            return(false);
                        }
                        catch (Exception ex)
                        {
                            //Guard against service adapter failure
                            if (log.IsErrorEnabled)
                            {
                                log.Error(__Res.GetString(__Res.ServiceAdapter_ManageFail, this.id, messageDestination.Id, commandMessage), ex);
                            }
                            return(false);
                        }
                    }
                    return(true);

                default:
                    if (log.IsDebugEnabled)
                    {
                        log.Debug(__Res.GetString(__Res.MessageServiceUnknown, commandMessage.operation, messageDestination.Id));
                    }
                    try
                    {
                        acknowledgeMessage = messageDestination.ServiceAdapter.Manage(commandMessage) as AcknowledgeMessage;
                    }
                    catch (MessageException me)
                    {
                        acknowledgeMessage = me.GetErrorMessage();
                    }
                    catch (Exception ex)
                    {
                        //Guard against service adapter failure
                        acknowledgeMessage = ErrorMessage.GetErrorMessage(commandMessage, ex);
                        if (log.IsErrorEnabled)
                        {
                            log.Error(__Res.GetString(__Res.ServiceAdapter_ManageFail, this.id, messageDestination.Id, commandMessage), ex);
                        }
                    }
                    if (acknowledgeMessage == null)
                    {
                        acknowledgeMessage = new AcknowledgeMessage();
                    }
                    return(acknowledgeMessage);
                }
            }
            else
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug(__Res.GetString(__Res.MessageServiceRoute, messageDestination.Id, message.clientId));
                }

                if (FluorineContext.Current != null && FluorineContext.Current.Client != null)//Not set when user code initiates push
                {
                    IClient client = FluorineContext.Current.Client;
                    client.Renew();
                }
                object result = messageDestination.ServiceAdapter.Invoke(message);
                return(result);
            }
        }
Beispiel #59
0
 public MessageInformation(MessageDestination destination, int messageType, IntPtr val, IntPtr playerEdict)
 {
     MessageDestination = destination;
     MessageType = messageType;
     Value = val;
     PlayerEdict = playerEdict;
     Arguments = new List<MessageArgument>();
 }