示例#1
0
        public static bool Add(AdvancedEntity en, DispatchType type)
        {
            switch (type)
            {
            case DispatchType.ArmyGround: return(SafelyAddTo(armyGroundList, en, "DispatchManager", type));

            case DispatchType.ArmyHeli: return(SafelyAddTo(armyHeliList, en, "DispatchManager", type));

            case DispatchType.ArmyRoadBlock: return(SafelyAddTo(armyRoadblockList, en, "DispatchManager", type));

            case DispatchType.CopGround: return(SafelyAddTo(copGroundList, en, "DispatchManager", type));

            case DispatchType.CopHeli: return(SafelyAddTo(copHeliList, en, "DispatchManager", type));

            case DispatchType.CopRoadBlock: return(SafelyAddTo(copRoadblockList, en, "DispatchManager", type));

            case DispatchType.Emergency: return(SafelyAddTo(emList, en, "DispatchManager", type));

            case DispatchType.Shield: return(SafelyAddTo(shieldList, en, "DispatchManager", type));

            case DispatchType.Stinger: return(SafelyAddTo(stingerList, en, "DispatchManager", type));

            default: return(false);
            }
        }
示例#2
0
        //-----------------------------------------------------------------------------------------
        //Misc Helpers
        //-----------------------------------------------------------------------------------------

        /// <summary>
        /// Attaches the specified callback method and interval to a timer object. Returns the timer object.
        /// dispatchType defaults to OnSpooledThread, which here means it will execute on the timer's execution thread.
        /// Set dispatchType to OnMainThread or OnMainThreadAsync if the callback interacts with UI elements.
        /// </summary>
        /// <returns></returns>
        public static Timer CREATE_TIMER(Action callback, int millisecond_interval, DispatchType dispatchType = DispatchType.OnSpooledThread)
        {
            Timer timer = new Timer(millisecond_interval);

            switch (dispatchType)
            {
            case DispatchType.OnSpooledThread:
                timer.Elapsed += (object obj, ElapsedEventArgs e) => callback();
                break;

            case DispatchType.OnMainThread:
                timer.Elapsed += (object obj, ElapsedEventArgs e) =>
                {
                    Application.Current.Dispatcher.Invoke(() => callback());
                };
                break;

            case DispatchType.OnMainThreadAsync:
                Action action = () => callback();
                timer.Elapsed += (object obj, ElapsedEventArgs e) =>
                {
                    Application.Current.Dispatcher.BeginInvoke(action, System.Windows.Threading.DispatcherPriority.Normal);
                };
                break;
            }
            timer.AutoReset = true;
            timer.Enabled   = true;
            return(timer);
        }
        public override void ChangeDispatchType(Guid messageId, DispatchType sourceType, DispatchType targetType, int itemCount)
        {
            var recipientQueue1 = sourceType == DispatchType.AbTest ? RecipientQueue.AbTestRecipient : RecipientQueue.Recipient;
            var recipientQueue2 = targetType == DispatchType.AbTest ? RecipientQueue.AbTestRecipient : RecipientQueue.Recipient;

            var connection = new SqlConnection(ConnectionString);
            var command    = connection.CreateCommand();

            command.CommandText = "UPDATE TOP(@ItemCount) [DispatchQueue] SET [RecipientQueue] = @TargetQueue, [DispatchType] = @TargetType, [LastModified] = @LastModified WHERE [MessageID] = @MessageID AND [RecipientQueue] = @SourceQueue AND [InProgress] = 0";
            command.Parameters.Add(new SqlParameter("@ItemCount", (object)itemCount));
            command.Parameters.Add(new SqlParameter("@TargetQueue", (object)recipientQueue2));
            command.Parameters.Add(new SqlParameter("@TargetType", (object)targetType));
            command.Parameters.Add(new SqlParameter("@LastModified", (object)DateTime.UtcNow));
            command.Parameters.Add(new SqlParameter("@MessageID", (object)messageId));
            command.Parameters.Add(new SqlParameter("@SourceQueue", (object)recipientQueue1));

            ExecuteRetry.Retry(() =>
            {
                using (connection)
                    using (command)
                    {
                        connection.Open();
                        command.ExecuteNonQuery();
                    }
            });
        }
示例#4
0
        public object Invoke(DispatchIdentifier id, DispatchType dispType, JsValue[] args, out Type returnType)
        {
            if (id.Tag == DispatchIdentifierType.String) {
                if (id.AsString == "length") {
                    return GetLength(dispType, out returnType);
                }
                else {
                    returnType = typeof(void);
                    return null;
                }
            }
            else {
                int intId = id.AsInt;
                if (intId == this.target.Length) {
                    return GetLength(dispType, out returnType);
                }

                if (intId >= 0 && intId < this.target.Length) {
                    Debug.WriteLine(string.Format("{0}, {1}[{2}]", dispType, this.target, id));
                    if (dispType == DispatchType.PropertyGet) {
                        returnType = this.elementType;
                        return this.target.GetValue(intId);
                    }

                    if (dispType == DispatchType.PropertySet) {
                        object value = this.bridge.UnwrapValue(args.First(), this.elementType);
                        this.target.SetValue(value, intId);
                        returnType = typeof(void);
                        return null;
                    }
                }
            }

            throw new NotSupportedException();
        }
示例#5
0
        public object Invoke(DispatchIdentifier id, DispatchType dispType, JsValue[] jsArgs, out Type returnType)
        {
            MemberInfo member = GetMember(id.AsString);
            if (member == null) {
                returnType = typeof(void);
                return null;
            }

            Debug.WriteLine(string.Format("{0}, {1}.{2}", dispType, this.target, member.Name));
            if (member is MethodInfo && dispType == DispatchType.PropertyGet) {
                var method = (MethodInfo)member;
                return GetMethodAsProperty((MethodInfo)member, this.target, out returnType);
            }

            var args = this.bridge.UnwrapParameters(jsArgs, dispType, member);
            if (dispType.IsMethod()) {
                var method = (MethodBase)member;
                returnType = method.IsConstructor ? method.DeclaringType : ((MethodInfo)method).ReturnType;
                return method.Invoke(this.target, args);
            }

            if (dispType.IsPropertyGet()) {
                var pi = (PropertyInfo)member;
                returnType = pi.PropertyType;
                return pi.GetValue(this.target, null);
            }

            if (dispType.IsPropertyPut()) {
                var pi = (PropertyInfo)member;
                pi.SetValue(this.target, args.First(), null);
                returnType = typeof(void);
                return null;
            }
            throw new NotSupportedException();
        }
示例#6
0
        public Listener(IConnectionWrapper connection, string name, DispatchType dispatchType, bool autoDelete, IDictionary <string, object> arguments = null, string topicFilter = "#") :
            base(connection, dispatchType, name, autoDelete, arguments)
        {
            _topicFilter = topicFilter;

            CreateConsumer();
            BindQueueToExchange();
        }
示例#7
0
 public EventHandlerManager(DispatchType dt)
 {
     // mDispatcher = dt == DispatchType.Socket ? msSocketDispatcher : msEventDispatcher;
     switch (dt)
     {
     case DispatchType.Event: mDispatcher = msEventDispatcher; break;
     }
     //list.Add(this);
 }
示例#8
0
 public async Task Dispatch(ESBContext context,
                            ResponseHandle responseHandle,
                            DispatchType dispatchType)
 {
     if (commands.TryGetValue(dispatchType, out IDispachCommand command))
     {
         await command.Dispatch(context, responseHandle);
     }
 }
示例#9
0
        protected RabbitCore(IConnectionWrapper connection, DispatchType dispatchType, string name, bool autoDelete, IDictionary <string, object> arguments = null)
        {
            DispatchType = dispatchType;
            Name         = name;
            Connection   = connection;
            AutoDelete   = autoDelete;
            Arguments    = arguments;

            ModelWrapper = Connection.CreateModel();
            SetupQueue();
        }
示例#10
0
        public object Invoke(DispatchIdentifier id, DispatchType dispType, JsValue[] jsArgs, out Type returnType)
        {
            if (dispType.IsMethod()) {
                return InvokeMethod(dispType, id, jsArgs, out returnType);
            }

            if (dispType.IsPropertyPut()) {
                return SetProperty(id, jsArgs, out returnType);
            }

            if (dispType.IsPropertyGet()) {
                return GetProperty(id, out returnType);
            }

            throw new NotSupportedException();
        }
示例#11
0
        // Token: 0x06003BC6 RID: 15302 RVA: 0x0010CDC8 File Offset: 0x0010B1C8
        public void Dispatch(string mm, object[] data = null, DispatchType type = DispatchType.IMME, float delay = 2f)
        {
            if (type != DispatchType.IMME)
            {
                if (type != DispatchType.MANUAL)
                {
                    if (type == DispatchType.TIMER)
                    {
                        if (this.mmDic.ContainsKey(mm))
                        {
                            this.mmDic[mm](data);
                        }

//						Singleton<TaskRunner>.Instance.RunDelayTask(delay, true, delegate
//						{
//							if (this.mmDic.ContainsKey(mm))
//							{
//								this.mmDic[mm](data);
//							}
//						});
                    }
                }
                else if (this.muDic.ContainsKey(mm))
                {
                    this.muDic[mm] = data;
                }
                else
                {
                    this.muDic.Add(mm, data);
                }
            }
            else
            {
                if (this.mmDic.ContainsKey(mm))
                {
                    this.mmDic[mm](data);
                    return;
                }
                if (this.log)
                {
                    this.Log("MM:" + mm + " do not exist");
                }
            }
        }
示例#12
0
        public bool Enlist(CommandContext ctx, string type)
        {
            var          org   = new OrgController().GetOrgId(ctx.Guild);
            DispatchType dType = null;

            try
            {
                switch (type)
                {
                case "medical":
                    dType = this.GetDispatchType(type);
                    var newsub = new OrgDispatch();
                    newsub.OrgId        = org;
                    newsub.DispatchType = dType.DispatchTypeId;

                    MultiBotDb.OrgDispatch.Add(newsub);
                    MultiBotDb.SaveChanges();
                    break;

                default: ctx.RespondAsync("Enlistment types include: 'medical', please try again"); break;
                }

                var en = new MultiBotDb().OrgDispatch.FirstOrDefault(x => x.OrgId == org && x.DispatchType == dType.DispatchTypeId);

                if (en != null)
                {
                    ctx.RespondAsync("You have been successfully subscribed to 'medical'");
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                ctx.RespondAsync("something went wrong");
                return(false);
            }
        }
示例#13
0
#pragma warning restore CS4014

        private async Task HandleDispatchEventAsync(DispatchType code, string payload)
        {
            switch (code)
            {
            case DispatchType.Ready:
            {
                var ready = JsonConvert.DeserializeObject <ReadyPayload>(payload);
                _sessionId        = ready.SessionId;
                _guildsToDownload = ready.Guilds.Count();
                this.Ready?.Invoke().ConfigureAwait(false);
                break;
            }

            case DispatchType.GuildMemberUpdate:
            {
                var member = JsonConvert.DeserializeObject <DiscordGuildMember>(payload);
                member = this.Guilds.First(x => x.Id == member.GuildId).Members.FirstOrDefault(x => x.UserData.Id == member.UserData.Id);
                this.MemberUpdated?.Invoke(member).ConfigureAwait(false);
                break;
            }

            case DispatchType.TypingStart:
            {
                var    typing = JsonConvert.DeserializeObject <TypingStartPayload>(payload);
                var    guild  = this.Guilds.FirstOrDefault(x => x.Id == (typing.GuildId ?? 0));
                object channel;
                if (guild != null)
                {
                    channel = guild.Channels.FirstOrDefault(x => x.Id == typing.ChannelId);
                }
                else
                {
                    channel = this.PrivateChannels.FirstOrDefault(x => x.Id == typing.ChannelId);
                }
                this.TypingStarted?.Invoke(typing.UserId, channel).ConfigureAwait(false);
                break;
            }

            case DispatchType.PresenceUpdate:
            {
                var presence = JsonConvert.DeserializeObject <PresencePayload>(payload);
                var guild    = this.Guilds.FirstOrDefault(x => x.Id == presence.GuildId);
                if (guild != null)
                {
                    var member = guild.Members.FirstOrDefault(x => x.UserData.Id == presence.User.Id);
                    member.RoleIds           = presence.RoleIds;
                    member.Nickname          = presence.Nickname;
                    member.UserData.Status   = presence.Status;
                    member.UserData.Activity = presence.Activity;
                    this.PresenceUpdated?.Invoke(guild, member).ConfigureAwait(false);
                }
                break;
            }

            case DispatchType.GuildCreate:
            {
                var guild = JsonConvert.DeserializeObject <DiscordGuild>(payload);
                this._internalGuilds.Add(guild);
                this._downloadedGuilds++;
                foreach (var member in guild.Members)
                {
                    member.Guild = guild;
                    member.Roles = guild.Roles.Where(x => member.RoleIds.Any(a => a == x?.Id)) as IReadOnlyList <DiscordGuildRole?>;
                }
                this.GuildCreated?.Invoke(guild).ConfigureAwait(false);
                if (this._guildsToDownload == this._downloadedGuilds)
                {
                    this.Guilds          = this._internalGuilds;
                    this.PrivateChannels = await GetPrivateChannelsAsync().ConfigureAwait(false);

                    this.GuildsDownloaded?.Invoke(this.Guilds).ConfigureAwait(false);
                }
                break;
            }

            case DispatchType.MessageCreate:
            {
                var msg = JsonConvert.DeserializeObject <DiscordMessage>(payload);
                this.MessageReceived?.Invoke(msg).ConfigureAwait(false);
                if (msg.Content.StartsWith(CommandsProvider.Prefix))
                {
                    var args = await CommandsProvider.ParseArguementsAsync(msg).ConfigureAwait(false);

                    Command?cmd;
                    bool    sub = false;
                    cmd = CommandsProvider.CommandsList.FirstOrDefault(x => (x?.CommandName == args[0]) || (x?.Aliases?.FirstOrDefault(a => a == args[0]) != null));
                    if (cmd == null)
                    {
                        var group = CommandsProvider.GroupCommandsList.FirstOrDefault(x => (x?.GroupName == args[0]) || (x?.Aliases?.FirstOrDefault(a => a == args[0]) != null));
                        cmd = group?.SubCommands.FirstOrDefault(x => (x.CommandName == args[1]) || (x.Aliases?.FirstOrDefault(a => a == args[1]) != null));
                        if (cmd == null && group?.ExecuteMethod != null)
                        {
                            cmd = new Command()
                            {
                                Method       = group?.ExecuteMethod,
                                MethodParams = group?.ExecuteMethod.GetParameters()
                            }
                        }
                        ;
                        else if (cmd != null)
                        {
                            sub = true;
                        }
                        else
                        {
                            break;
                        }
                    }
                    await CommandsProvider.ExecuteCommandAsync(args, (Command)cmd, sub, this, msg);
                }
                break;
            }

            case DispatchType.GuildMemberAdd:
            {
                var usr = JsonConvert.DeserializeObject <DiscordGuildMember>(payload);
                this.MemberAdded?.Invoke(this.Guilds.FirstOrDefault(x => x.Id == usr.GuildId), usr).ConfigureAwait(false);
                break;
            }

            case DispatchType.GuildMemberRemove:
            {
                var data = JsonConvert.DeserializeObject <MemberRemovedPayload>(payload);
                this.MemberRemoved?.Invoke(this.Guilds.FirstOrDefault(x => x.Id == data.GuildId), data.User).ConfigureAwait(false);
                break;
            }

            case DispatchType.Resumed:
            {
                this.GatewayResumed?.Invoke().ConfigureAwait(false);
                break;
            }

            default:
            {
                this.UnknownEventReceived?.Invoke($"Unknown Dispatch Type: {(int)code}", $"\n{payload}").ConfigureAwait(false);
                break;
            }
            }
        }
示例#14
0
        private void ConfigureMethod(MethodInfo method, ParameterInfo[] parameters)
        {
            var returnType = method.ReturnType;
            var isVoid     = returnType == typeof(void);

            if (isVoid)
            {
                _dispatchType    |= DispatchType.Void;
                LogicalReturnType = returnType;
            }
            else if (typeof(Promise).IsAssignableFrom(returnType))
            {
                _dispatchType |= DispatchType.Promise;
                var promise = returnType.GetOpenTypeConformance(typeof(Promise <>));
                LogicalReturnType = promise != null
                    ? promise.GetGenericArguments()[0]
                    : typeof(object);
            }
            else if (typeof(Task).IsAssignableFrom(returnType))
            {
                _dispatchType |= DispatchType.Task;
                var task = returnType.GetOpenTypeConformance(typeof(Task <>));
                LogicalReturnType = task != null
                    ? task.GetGenericArguments()[0]
                    : typeof(object);
            }
            else
            {
                LogicalReturnType = returnType;
            }

            if (!method.IsGenericMethodDefinition)
            {
                switch (parameters.Length)
                {
                    #region Early Bound
                case 0:
                    _delegate = isVoid
                                   ? (Delegate)RuntimeHelper.CreateCallNoArgs(method)
                                   : RuntimeHelper.CreateFuncNoArgs(method);
                    _dispatchType |= DispatchType.FastNoArgs;
                    return;

                case 1:
                    _delegate = isVoid
                                  ? (Delegate)RuntimeHelper.CreateCallOneArg(method)
                                  : RuntimeHelper.CreateFuncOneArg(method);
                    _dispatchType |= DispatchType.FastOneArg;
                    return;

                case 2:
                    _delegate = isVoid
                                  ? (Delegate)RuntimeHelper.CreateCallTwoArgs(method)
                                  : RuntimeHelper.CreateFuncTwoArgs(method);
                    _dispatchType |= DispatchType.FastTwoArgs;
                    return;

                case 3:
                    _delegate = isVoid
                                  ? (Delegate)RuntimeHelper.CreateCallThreeArgs(method)
                                  : RuntimeHelper.CreateFuncThreeArgs(method);
                    _dispatchType |= DispatchType.FastThreeArgs;
                    return;

                case 4:
                    _delegate = isVoid
                                  ? (Delegate)RuntimeHelper.CreateCallFourArgs(method)
                                  : RuntimeHelper.CreateFuncFourArgs(method);
                    _dispatchType |= DispatchType.FastFourArgs;
                    return;

                case 5:
                    _delegate = isVoid
                                  ? (Delegate)RuntimeHelper.CreateCallFiveArgs(method)
                                  : RuntimeHelper.CreateFuncFiveArgs(method);
                    _dispatchType |= DispatchType.FastFiveArgs;
                    return;

                    #endregion
                default:
                    _dispatchType |= DispatchType.LateBound;
                    return;
                }
            }

            var argSources = parameters
                             .Where(p => p.ParameterType.ContainsGenericParameters)
                             .Select(p => Tuple.Create(p.Position, p.ParameterType))
                             .ToList();
            if (returnType.ContainsGenericParameters)
            {
                if (IsAsync)
                {
                    returnType = returnType.GenericTypeArguments[0];
                }
                argSources.Add(Tuple.Create(UseReturn, returnType));
            }
            var methodArgs  = method.GetGenericArguments();
            var typeMapping = new Tuple <int, int> [methodArgs.Length];
            foreach (var source in argSources)
            {
                var sourceArg = source.Item2;
                if (sourceArg.IsGenericParameter)
                {
                    if (methodArgs.Length == 1 && methodArgs[0] == sourceArg)
                    {
                        typeMapping[0] = Tuple.Create(source.Item1, UseArgument);
                    }
                    continue;
                }
                var sourceGenericArgs = sourceArg.GetGenericArguments();
                for (var i = 0; i < methodArgs.Length; ++i)
                {
                    if (typeMapping[i] != null)
                    {
                        continue;
                    }
                    var index = Array.IndexOf(sourceGenericArgs, methodArgs[i]);
                    if (index >= 0)
                    {
                        typeMapping[i] = Tuple.Create(source.Item1, index);
                    }
                }
                if (!typeMapping.Contains(null))
                {
                    break;
                }
            }
            if (typeMapping.Contains(null))
            {
                throw new InvalidOperationException(
                          $"Type mapping for {method.GetDescription()} could not be inferred");
            }

            _mapping       = typeMapping;
            _dispatchType |= DispatchType.LateBound;
            _closed        = new ConcurrentDictionary <MethodInfo, MethodDispatch>();
        }
示例#15
0
 public object InvokeRemoteMember(int targetId, DispatchIdentifier dispId, DispatchType dispType, object[] args)
 {
     InvokeMemberMessage msg = new InvokeMemberMessage {
         TargetId = targetId,
         DispatchId = dispId,
         DispatchType = dispType,
         Parameters = WrapParameters(args)
     };
     this.session.SendMessage(msg);
     JsValue value = DispatchAndReturn();
     return WrapRemoteValue(value);
 }
示例#16
0
        private object InvokeMethod(DispatchType dispType, DispatchIdentifier id, JsValue[] jsArgs, out Type returnType)
        {
            // if remote delegate, shouldn't be here, let client side handle that case
            // overridden methods might exist in the properties map,
            // otherwise try and invoke the method on the target

            MethodBase method = this.targetType.GetMethod(id.AsString);
            if (method == null) {
                object value;
                if (this.properties.TryGetValue(id.AsString, out value)) {
                    var del = value as Delegate;
                    if (del != null) {
                        var args = this.bridge.UnwrapParameters(jsArgs, dispType, del.Method);
                        del.DynamicInvoke(args);
                    }
                }
                returnType = typeof(void);
                return null;
            }
            else {
                var args = this.bridge.UnwrapParameters(jsArgs, dispType, method);
                returnType = method.IsConstructor ? method.DeclaringType : ((MethodInfo)method).ReturnType;
                return method.Invoke(this.target, args);
            }
        }
示例#17
0
 public void Read(NetworkReader reader)
 {
     Name = reader.ReadString();
     DispatchType = (DispatchType)reader.ReadByte();
 }
示例#18
0
 public override void Read(NetworkReader reader)
 {
     TargetId = reader.ReadInt32();
     DispatchId = new DispatchIdentifier();
     DispatchId.Read(reader);
     DispatchType = (DispatchType)reader.ReadByte();
     int len = reader.ReadInt32();
     Parameters = new JsValue[len];
     for (int i = 0; i < len; i++) {
         JsValue value = new JsValue();
         value.Read(reader);
         Parameters[i] = value;
     }
 }
示例#19
0
        public void OnInvokeMemberMessage(int targetId, DispatchIdentifier dispId, DispatchType dispatchType,
			params JsValue[] parameters)
        {
            ReadMessage(new InvokeMemberMessage {
                TargetId = targetId,
                //MemberId = memberId,
                DispatchId = dispId,
                DispatchType = dispatchType,
                Parameters = parameters
            });
        }
示例#20
0
        /// <summary>
        /// Invokes the relevant dispatch method.
        /// </summary>
        /// <param name="dispatchType">Type of the dispatch.</param>
        /// <param name="factoryGuid">The factory GUID.</param>
        /// <param name="numericId">The numeric id.</param>
        /// <param name="guidId">The GUID id.</param>
        private static void InvokeDispatchMethod(DispatchType dispatchType, Guid factoryGuid, int numericId, Guid guidId)
        {
            string name = GetFactoryObjectName(factoryGuid);

            try
            {
                using (var cacheRefresher = new CacheRefresher())
                {
                    var asyncResultsList = new List <IAsyncResult>();

                    LogStartDispatch();

                    // Go through each configured node submitting a request asynchronously
                    foreach (XmlNode n in GetDistributedNodes())
                    {
                        SetWebServiceUrlFromNode(cacheRefresher, n);

                        // Add the returned WaitHandle to the list for later checking
                        switch (dispatchType)
                        {
                        case DispatchType.RefreshAll:
                            asyncResultsList.Add(cacheRefresher.BeginRefreshAll(factoryGuid, _login, _password, null,
                                                                                null));
                            break;

                        case DispatchType.RefreshByGuid:
                            asyncResultsList.Add(cacheRefresher.BeginRefreshByGuid(factoryGuid, guidId, _login,
                                                                                   _password, null, null));
                            break;

                        case DispatchType.RefreshByNumericId:
                            asyncResultsList.Add(cacheRefresher.BeginRefreshById(factoryGuid, numericId, _login,
                                                                                 _password, null, null));
                            break;

                        case DispatchType.RemoveById:
                            asyncResultsList.Add(cacheRefresher.BeginRemoveById(factoryGuid, numericId, _login,
                                                                                _password, null, null));
                            break;
                        }
                    }


                    List <WaitHandle> waitHandlesList;
                    IAsyncResult[]    asyncResults = GetAsyncResults(asyncResultsList, out waitHandlesList);

                    int errorCount = 0;

                    // Once for each WaitHandle that we have, wait for a response and log it
                    // We're previously submitted all these requests effectively in parallel and will now retrieve responses on a FIFO basis
                    for (int waitCalls = 0; waitCalls < asyncResults.Length; waitCalls++)
                    {
                        int handleIndex = WaitHandle.WaitAny(waitHandlesList.ToArray(), TimeSpan.FromSeconds(15));

                        try
                        {
                            // Find out if the call succeeded
                            switch (dispatchType)
                            {
                            case DispatchType.RefreshAll:
                                cacheRefresher.EndRefreshAll(asyncResults[waitCalls]);
                                break;

                            case DispatchType.RefreshByGuid:
                                cacheRefresher.EndRefreshByGuid(asyncResults[waitCalls]);
                                break;

                            case DispatchType.RefreshByNumericId:
                                cacheRefresher.EndRefreshById(asyncResults[waitCalls]);
                                break;

                            case DispatchType.RemoveById:
                                cacheRefresher.EndRemoveById(asyncResults[waitCalls]);
                                break;
                            }
                        }
                        catch (WebException ex)
                        {
                            LogDispatchNodeError(ex);

                            errorCount++;
                        }
                        catch (Exception ex)
                        {
                            LogDispatchNodeError(ex);

                            errorCount++;
                        }
                    }

                    LogDispatchBatchResult(errorCount);
                }
            }
            catch (Exception ee)
            {
                LogDispatchBatchError(ee);
            }
        }
示例#21
0
 public Dispatcher(IConnectionWrapper connection, string name, DispatchType dispatchType, bool autoDelete, IDictionary <string, object> arguments = null) :
     base(connection, dispatchType, name, autoDelete, arguments)
 {
 }
示例#22
0
        /// <summary>
        /// Invokes the relevant dispatch method.
        /// </summary>
        /// <param name="dispatchType">Type of the dispatch.</param>
        /// <param name="factoryGuid">The factory GUID.</param>
        /// <param name="numericId">The numeric id.</param>
        /// <param name="guidId">The GUID id.</param>
        private static void InvokeDispatchMethod(DispatchType dispatchType, Guid factoryGuid, int numericId, Guid guidId)
        {
            string name = GetFactoryObjectName(factoryGuid);

            try
            {
                using (var cacheRefresher = new CacheRefresher())
                {
                    var asyncResultsList = new List<IAsyncResult>();

                    LogStartDispatch();

                    // Go through each configured node submitting a request asynchronously
                    foreach (XmlNode n in GetDistributedNodes())
                    {
                        SetWebServiceUrlFromNode(cacheRefresher, n);

                        // Add the returned WaitHandle to the list for later checking
                        switch (dispatchType)
                        {
                            case DispatchType.RefreshAll:
                                asyncResultsList.Add(cacheRefresher.BeginRefreshAll(factoryGuid, _login, _password, null,
                                                                                    null));
                                break;
                            case DispatchType.RefreshByGuid:
                                asyncResultsList.Add(cacheRefresher.BeginRefreshByGuid(factoryGuid, guidId, _login,
                                                                                       _password, null, null));
                                break;
                            case DispatchType.RefreshByNumericId:
                                asyncResultsList.Add(cacheRefresher.BeginRefreshById(factoryGuid, numericId, _login,
                                                                                     _password, null, null));
                                break;
                            case DispatchType.RemoveById:
                                asyncResultsList.Add(cacheRefresher.BeginRemoveById(factoryGuid, numericId, _login,
                                                                                    _password, null, null));
                                break;
                        }
                    }


                    List<WaitHandle> waitHandlesList;
                    IAsyncResult[] asyncResults = GetAsyncResults(asyncResultsList, out waitHandlesList);

                    int errorCount = 0;

                    // Once for each WaitHandle that we have, wait for a response and log it
                    // We're previously submitted all these requests effectively in parallel and will now retrieve responses on a FIFO basis
                    for (int waitCalls = 0; waitCalls < asyncResults.Length; waitCalls++)
                    {
                        int handleIndex = WaitHandle.WaitAny(waitHandlesList.ToArray(), TimeSpan.FromSeconds(15));

                        try
                        {
                            // Find out if the call succeeded
                            switch (dispatchType)
                            {
                                case DispatchType.RefreshAll:
                                    cacheRefresher.EndRefreshAll(asyncResults[waitCalls]);
                                    break;
                                case DispatchType.RefreshByGuid:
                                    cacheRefresher.EndRefreshByGuid(asyncResults[waitCalls]);
                                    break;
                                case DispatchType.RefreshByNumericId:
                                    cacheRefresher.EndRefreshById(asyncResults[waitCalls]);
                                    break;
                                case DispatchType.RemoveById:
                                    cacheRefresher.EndRemoveById(asyncResults[waitCalls]);
                                    break;
                            }
                        }
                        catch (WebException ex)
                        {
                            LogDispatchNodeError(ex);

                            errorCount++;
                        }
                        catch (Exception ex)
                        {
                            LogDispatchNodeError(ex);

                            errorCount++;
                        }
                    }

                    LogDispatchBatchResult(errorCount);
                }
            }
            catch (Exception ee)
            {
                LogDispatchBatchError(ee);
            }
        }
示例#23
0
        private Dispatcher CreateDispatcher(string name, DispatchType type, bool autoDelete, IDictionary <string, object> arguments)
        {
            var dispatcher = new Dispatcher(GetConnection(), name, type, autoDelete, arguments);

            return(dispatcher);
        }
示例#24
0
 private object GetLength(DispatchType dispType, out Type returnType)
 {
     if (dispType == DispatchType.PropertyGet) {
         Debug.WriteLine(string.Format("{0}, {1}.Length", dispType, this.target));
         returnType = this.target.Length.GetType();
         return this.target.Length;
     }
     throw new NotSupportedException();
 }
示例#25
0
 protected BaseContainer(DispatchType request, TClassContent content)
 {
     Request = request;
     Content = content;
 }
示例#26
0
        private Listener CreateListenerInstance(string name, DispatchType type, bool autoDelete, IDictionary <string, object> arguments, string topicFilter = "#")
        {
            var listener = new Listener(GetConnection(), name, type, autoDelete, arguments, topicFilter);

            return(listener);
        }