コード例 #1
0
ファイル: PluginHandler.cs プロジェクト: voloda/dnx
        private void PluginMessage(PluginMessage message, IAssemblyLoadContext assemblyLoadContext)
        {
            IPlugin plugin;

            if (_registeredPlugins.TryGetValue(message.PluginId, out plugin))
            {
                try
                {
                    plugin.ProcessMessage(message.Data, assemblyLoadContext);
                }
                catch (Exception exception)
                {
                    OnError(
                        message.PluginId,
                        PluginMessageMessageName,
                        errorMessage: Resources.FormatPlugin_EncounteredExceptionWhenProcessingPluginMessage(
                            message.PluginId,
                            exception.Message));
                }
            }
            else
            {
                OnError(
                    message.PluginId,
                    PluginMessageMessageName,
                    errorMessage: Resources.FormatPlugin_UnregisteredPluginIdCannotReceiveMessages(message.PluginId));
            }
        }
コード例 #2
0
        public void Run(List <PluginSetting> Settings, out List <PluginMessage> Responses)
        {
            List <PluginMessage> pluginMessages = new List <PluginMessage>();

            var checkedProcesses = CheckRunningProcesses.CheckProcess(Settings);

            if (checkedProcesses != null)
            {
                foreach (var i in checkedProcesses)
                {
                    if (i.ProcessIsRunning)
                    {
                        PluginMessage message = new PluginMessage();
                        message.severity = Severities.Informational;
                        message.facility = Facilities.log_audit;
                        message.msg      = i.Process.ProcessName + " operational.";

                        pluginMessages.Add(message);
                    }
                    else
                    {
                        PluginMessage message = new PluginMessage();
                        message.severity = Severities.Emergency;
                        message.facility = Facilities.kernel_messages;
                        message.msg      = i.ProcessToCheck + " not loaded.";

                        pluginMessages.Add(message);
                    }
                }
            }
            Responses = pluginMessages;
        }
コード例 #3
0
ファイル: PluginAdd.aspx.cs プロジェクト: jiaping/JPCMS
 public void Page_Load(object sender, EventArgs e)
 {
     MenuTabLabel.Text    = BuildNavString();
     PagePathLiteral.Text = BuildPagePath();
     message = new PluginMessage(PluginType);
     Init();
 }
コード例 #4
0
        public void ProcessMessages_RegisterPlugin_SendsPluginsProtocolWhenClientProtocolNotProvided()
        {
            var    assemblyLoadContext = CreateTestAssemblyLoadContext <TestPlugin>();
            var    serviceProvider     = new TestServiceProvider();
            object rawWrappedData      = null;
            var    pluginHandler       = new PluginHandler(serviceProvider, (data) => rawWrappedData = data);
            var    pluginMessage       = new PluginMessage
            {
                Data = new JObject
                {
                    { "AssemblyName", "CustomAssembly" },
                    { "TypeName", typeof(TestPlugin).FullName },
                },
                MessageName = "RegisterPlugin",
                PluginId    = RandomGuidId
            };

            pluginHandler.OnReceive(pluginMessage);
            pluginHandler.ProcessMessages(assemblyLoadContext);

            var messageBrokerData = Assert.IsType <PluginMessageBroker.PluginMessageWrapperData>(rawWrappedData);

            Assert.Equal(RandomGuidId, messageBrokerData.PluginId);
            var responseMessage = Assert.IsType <RegisterPluginResponseMessage>(messageBrokerData.Data);

            Assert.True(responseMessage.Success);
            Assert.Equal("RegisterPlugin", responseMessage.MessageName, StringComparer.Ordinal);
            Assert.Equal(3, responseMessage.Protocol);
        }
コード例 #5
0
        public void ProcessMessages_RegisterPlugin_SendsErrorWhenUnableToLocatePluginType()
        {
            var    assemblyLoadContext = CreateTestAssemblyLoadContext <TestPlugin>();
            var    serviceProvider     = new TestServiceProvider();
            object rawWrappedData      = null;
            var    pluginHandler       = new PluginHandler(serviceProvider, (data) => rawWrappedData = data);
            var    pluginMessage       = new PluginMessage
            {
                Data = new JObject
                {
                    { "AssemblyName", "CustomAssembly" },
                    { "TypeName", typeof(TestPlugin).FullName + "_" },
                },
                MessageName = "RegisterPlugin",
                PluginId    = RandomGuidId
            };
            var expectedErrorMessage =
                $"Could not locate plugin id '{RandomGuidId}' of type '{typeof(TestPlugin).FullName + "_"}' " +
                "in assembly 'CustomAssembly'.";

            pluginHandler.OnReceive(pluginMessage);
            pluginHandler.ProcessMessages(assemblyLoadContext);

            var messageBrokerData = Assert.IsType <PluginMessageBroker.PluginMessageWrapperData>(rawWrappedData);

            Assert.Equal(RandomGuidId, messageBrokerData.PluginId);
            var responseMessage = Assert.IsType <PluginResponseMessage>(messageBrokerData.Data);

            Assert.False(responseMessage.Success);
            Assert.Equal("RegisterPlugin", responseMessage.MessageName, StringComparer.Ordinal);
            Assert.Equal(expectedErrorMessage, responseMessage.Error, StringComparer.Ordinal);
        }
コード例 #6
0
ファイル: PluginHandler.cs プロジェクト: yossidev/dnx
        private void UnregisterMessage(PluginMessage message)
        {
            if (!_registeredPlugins.Remove(message.PluginId))
            {
                var faultedRegistrationIndex = _faultedRegisterPluginMessages.FindIndex(
                    faultedMessage => faultedMessage.PluginId == message.PluginId);

                if (faultedRegistrationIndex == -1)
                {
                    OnError(
                        message,
                        errorMessage: Resources.FormatPlugin_UnregisteredPluginIdCannotUnregister(message.PluginId));

                    return;
                }
                else
                {
                    _faultedRegisterPluginMessages.RemoveAt(faultedRegistrationIndex);
                }
            }

            SendMessage(
                message.PluginId,
                new PluginResponseMessage
            {
                MessageName = UnregisterPluginMessageName,
            });
        }
コード例 #7
0
        public void ProcessMessages_UnregisterPlugin_SendsErrorWhenUnregisteringUnknownPlugin()
        {
            var    assemblyLoadContext     = CreateTestAssemblyLoadContext <TestPlugin>();
            var    serviceProvider         = new TestServiceProvider();
            object rawWrappedData          = null;
            var    pluginHandler           = new PluginHandler(serviceProvider, (data) => rawWrappedData = data);
            var    unregisterPluginMessage = new PluginMessage
            {
                MessageName = "UnregisterPlugin",
                PluginId    = RandomGuidId
            };
            var expectedErrorMessage =
                $"No plugin with id '{RandomGuidId}' has been registered. Cannot unregister plugin.";

            pluginHandler.OnReceive(unregisterPluginMessage);
            pluginHandler.ProcessMessages(assemblyLoadContext);

            var messageBrokerData = Assert.IsType <PluginMessageBroker.PluginMessageWrapperData>(rawWrappedData);

            Assert.Equal(RandomGuidId, messageBrokerData.PluginId);
            var responseMessage = Assert.IsType <PluginResponseMessage>(messageBrokerData.Data);

            Assert.False(responseMessage.Success);
            Assert.Equal("UnregisterPlugin", responseMessage.MessageName, StringComparer.Ordinal);
            Assert.Equal(expectedErrorMessage, responseMessage.Error, StringComparer.Ordinal);
        }
コード例 #8
0
        public void ProcessMessages_RegisterPlugin_SendsErrorOnInvalidPluginTypes()
        {
            var    assemblyLoadContext = CreateTestAssemblyLoadContext <InvalidTestPlugin>();
            var    serviceProvider     = new TestServiceProvider();
            object rawWrappedData      = null;
            var    pluginHandler       = new PluginHandler(serviceProvider, (data) => rawWrappedData = data);
            var    pluginMessage       = new PluginMessage
            {
                Data = new JObject
                {
                    { "AssemblyName", "CustomAssembly" },
                    { "TypeName", typeof(InvalidTestPlugin).FullName },
                },
                MessageName = "RegisterPlugin",
                PluginId    = RandomGuidId
            };
            var expectedErrorMessage =
                $"Cannot process plugin message. Plugin id '{RandomGuidId}' of type " +
                "'Microsoft.Framework.DesignTimeHost.PluginHandlerFacts+InvalidTestPlugin' must be assignable " +
                "to type 'Microsoft.Framework.DesignTimeHost.IPlugin'.";

            pluginHandler.OnReceive(pluginMessage);
            pluginHandler.ProcessMessages(assemblyLoadContext);

            var messageBrokerData = Assert.IsType <PluginMessageBroker.PluginMessageWrapperData>(rawWrappedData);

            Assert.Equal(RandomGuidId, messageBrokerData.PluginId);
            var responseMessage = Assert.IsType <PluginResponseMessage>(messageBrokerData.Data);

            Assert.False(responseMessage.Success);
            Assert.Equal("RegisterPlugin", responseMessage.MessageName, StringComparer.Ordinal);
            Assert.Equal(expectedErrorMessage, responseMessage.Error, StringComparer.Ordinal);
        }
コード例 #9
0
ファイル: PluginHandler.cs プロジェクト: yossidev/dnx
        private void PluginMessage(PluginMessage message, IAssemblyLoadContext assemblyLoadContext)
        {
            IPlugin plugin;

            if (_registeredPlugins.TryGetValue(message.PluginId, out plugin))
            {
                try
                {
                    if (!plugin.ProcessMessage(message.Data, assemblyLoadContext))
                    {
                        // Plugin didn't handle the message. Notify the client that we no-oped so it can respond
                        // accordingly.
                        OnNoop(
                            message,
                            Resources.FormatPlugin_PluginCouldNotHandleMessage(message.PluginId, message.MessageName));
                    }
                }
                catch (Exception exception)
                {
                    OnError(
                        message,
                        errorMessage: Resources.FormatPlugin_EncounteredExceptionWhenProcessingPluginMessage(
                            message.PluginId,
                            exception.Message));
                }
            }
            else
            {
                OnError(
                    message,
                    errorMessage: Resources.FormatPlugin_UnregisteredPluginIdCannotReceiveMessages(message.PluginId));
            }
        }
コード例 #10
0
        public void ProcessMessages_RegisterPlugin_DoesNotCacheCreatedPlugin()
        {
            var assemblyLoadContext = CreateTestAssemblyLoadContext <CreationTestPlugin>();
            var creationChecker     = new PluginTypeCreationChecker();
            var serviceLookups      = new Dictionary <Type, object>
            {
                { typeof(PluginTypeCreationChecker), creationChecker }
            };
            var serviceProvider = new TestServiceProvider(serviceLookups);
            var pluginHandler   = new PluginHandler(serviceProvider, (_) => { });
            var pluginMessage   = new PluginMessage
            {
                Data = new JObject
                {
                    { "AssemblyName", "CustomAssembly" },
                    { "TypeName", typeof(CreationTestPlugin).FullName },
                },
                MessageName = "RegisterPlugin",
                PluginId    = RandomGuidId
            };

            pluginHandler.OnReceive(pluginMessage);
            pluginHandler.ProcessMessages(assemblyLoadContext);
            Assert.True(creationChecker.Created);
            creationChecker.Created = false;
            pluginHandler.OnReceive(pluginMessage);
            pluginHandler.ProcessMessages(assemblyLoadContext);
            Assert.True(creationChecker.Created);
        }
コード例 #11
0
        public void ProcessMessages_PluginMessage_SendsErrorWhenPluginNotRegistered()
        {
            var    assemblyLoadContext = CreateTestAssemblyLoadContext <TestPlugin>();
            var    serviceProvider     = new TestServiceProvider();
            object rawWrappedData      = null;
            var    pluginHandler       = new PluginHandler(serviceProvider, (data) => rawWrappedData = data);
            var    pluginMessage       = new PluginMessage
            {
                Data = new JObject
                {
                    { "Data", "Hello Plugin" },
                },
                MessageName = "PluginMessage",
                PluginId    = RandomGuidId
            };
            var expectedErrorMessage =
                $"Message received for unregistered plugin id '{RandomGuidId}'. Plugins must first be registered " +
                "before they can receive messages.";

            pluginHandler.OnReceive(pluginMessage);
            pluginHandler.ProcessMessages(assemblyLoadContext);

            var messageBrokerData = Assert.IsType <PluginMessageBroker.PluginMessageWrapperData>(rawWrappedData);

            Assert.Equal(RandomGuidId, messageBrokerData.PluginId);
            var responseMessage = Assert.IsType <PluginResponseMessage>(messageBrokerData.Data);

            Assert.False(responseMessage.Success);
            Assert.Equal("PluginMessage", responseMessage.MessageName, StringComparer.Ordinal);
            Assert.Equal(expectedErrorMessage, responseMessage.Error, StringComparer.Ordinal);
        }
コード例 #12
0
 private int GetCurrentRaceTimeMS(PluginMessage msg)
 {
     if (CurrentSessionStartTime == DateTime.MinValue)
     {
         return(0);
     }
     return((int)Math.Round((msg.CreationDate - CurrentSessionStartTime).TotalMilliseconds));
 }
コード例 #13
0
ファイル: Plugin_Start.ascx.cs プロジェクト: jiaping/JPCMS
 private void init()
 {
     message = new PluginMessage(PluginType);
     InstallButton.Visible = false;
     BackButton.Visible    = false;
     Page.ClientScript.RegisterOnSubmitStatement(this.GetType(), "showProgress", "mask.showProgressBar();");
     UploadButton.Text = "添加" + message.PluginLabel;
 }
コード例 #14
0
 public static void Log(PluginMessage msg)
 {
     if (_sLastCreatedLogviewer != null)
     {
         var entry = new PluginMessageEntry(msg);
         _sLastCreatedLogviewer.Append(entry);
     }
 }
コード例 #15
0
        /// <summary>  Handles the ProcessCheck timer events</summary>
        /// <param name="source">The source.</param>
        /// <param name="e">The <see cref="ElapsedEventArgs"/> instance containing the event data.</param>
        public void ProcessCheckEvent(Object source, ElapsedEventArgs e)
        {
            int countersToFix = 0;

            if (lastTimerEvent == new DateTime())
            {
                lastTimerEvent = DateTime.Now;
            }
            else
            {
                double currentLatency = DateTime.Now.Subtract(lastTimerEvent).TotalMilliseconds;
                timerLatency += currentLatency;

                //LogToConsole(currentLatency.ToString());
                if (timerLatency > 10000)
                {
                    var newcounters = (timerLatency - (timerLatency % 10000)) / 10000;
                    countersToFix = int.Parse(newcounters.ToString());
                    //LogToConsole("Timer: Adjusting clock by " + countersToFix + " ticks for latency of " + timerLatency);
                    timerLatency = timerLatency - (10000 * countersToFix);
                }

                lastTimerEvent = DateTime.Now;
            }

            //LogToConsole("Timer triggered : " + DateTime.Now.ToRfc3339String());
            // check each plugin for settings
            foreach (var plugin in Plugins)
            {
                if (countersToFix > 0)
                {
                    plugin.SecondsSinceLastEvent += countersToFix;
                }

                if (plugin.SecondsSinceLastEvent > plugin.TimeUntilEvent)
                {
                    PluginMessage pluginMessage = new PluginMessage();
                    var           thisProc      = new ProcessPluginThread(plugin, this);

                    Thread thisThread = new Thread(
                        new ThreadStart(
                            thisProc.Process
                            )
                        );

                    thisThread.Start();
                    LogToConsole(" - Processing plugin event for :" + plugin.Name);
                    //thisThread.Join();
                    plugin.SecondsSinceLastEvent = 0;
                }
                else
                {
                    plugin.SecondsSinceLastEvent += 1;
                }
            }

            return;
        }
コード例 #16
0
ファイル: Plugin_List.ascx.cs プロジェクト: jiaping/JPCMS
 protected void Page_Load(object sender, EventArgs e)
 {
     message = new PluginMessage(PluginType);
     helper  = new PluginHelper(PluginType);
     if (!IsPostBack)
     {
         DataBind();
     }
 }
コード例 #17
0
        public void TryRegisterFaultedPlugins_RecoversFaultedPluginRegistrations()
        {
            var pluginType      = typeof(MessageBrokerCreationTestPlugin);
            var typeNameLookups = new Dictionary <string, Type>
            {
                { pluginType.FullName, pluginType }
            };
            var testAssembly    = new TestAssembly(typeNameLookups);
            var assemblyLookups = new Dictionary <string, Assembly>
            {
                { "CustomAssembly", testAssembly }
            };
            var assemblyLoadContext = new FailureAssemblyLoadContext(assemblyLookups);
            var creationChecker     = new PluginTypeCreationChecker();
            var serviceLookups      = new Dictionary <Type, object>
            {
                { typeof(PluginTypeCreationChecker), creationChecker }
            };
            var    serviceProvider       = new TestServiceProvider(serviceLookups);
            object rawMessageBrokerData  = null;
            var    pluginHandler         = new PluginHandler(serviceProvider, (data) => rawMessageBrokerData = data);
            var    registerPluginMessage = new PluginMessage
            {
                Data = new JObject
                {
                    { "AssemblyName", "CustomAssembly" },
                    { "TypeName", typeof(MessageBrokerCreationTestPlugin).FullName },
                },
                MessageName = "RegisterPlugin",
                PluginId    = RandomGuidId
            };

            pluginHandler.OnReceive(registerPluginMessage);
            pluginHandler.ProcessMessages(assemblyLoadContext);

            var messageBrokerData = Assert.IsType <PluginMessageBroker.PluginMessageWrapperData>(rawMessageBrokerData);

            Assert.Equal(RandomGuidId, messageBrokerData.PluginId);
            var responseMessage = Assert.IsType <RegisterPluginResponseMessage>(messageBrokerData.Data);

            Assert.False(responseMessage.Success);
            Assert.Equal("RegisterPlugin", responseMessage.MessageName, StringComparer.Ordinal);
            Assert.NotEmpty(responseMessage.Error);
            Assert.False(creationChecker.Created);

            pluginHandler.TryRegisterFaultedPlugins(assemblyLoadContext);

            messageBrokerData = Assert.IsType <PluginMessageBroker.PluginMessageWrapperData>(rawMessageBrokerData);
            Assert.Equal(RandomGuidId, messageBrokerData.PluginId);
            responseMessage = Assert.IsType <RegisterPluginResponseMessage>(messageBrokerData.Data);
            Assert.True(responseMessage.Success);
            Assert.Equal("RegisterPlugin", responseMessage.MessageName, StringComparer.Ordinal);
            Assert.Equal(1, responseMessage.Protocol);
            Assert.Null(responseMessage.Error);
            Assert.True(creationChecker.Created);
        }
コード例 #18
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Message = new PluginMessage(PluginType);
            if (!IsPostBack)
            {
            }
            InitPage();

            refresh.Click += new EventHandler(refresh_Click);
        }
        /// <summary>
        /// Converts a ChangedItem to a protal cache message
        /// </summary>
        /// <param name="changedItem">ChangedItem to convert</param>
        /// <param name="entityRecordMessage">EntityRecordMessage with the corresponding entityName</param>
        /// <returns>Portal cache message converted from ChangedItem</returns>
        private PluginMessage CreateMessageForRemovedOrDeletedItem(RemovedOrDeletedItem changedItem, EntityRecordMessage entityRecordMessage)
        {
            if (changedItem == null)
            {
                return(null);
            }

            PluginMessage message;
            AssociateDisassociateMessage associateDisassociateMessage = entityRecordMessage as AssociateDisassociateMessage;

            ADXTrace.Instance.TraceWarning(TraceCategory.Application, string.Format("Converting ChangedItem/Deleted with EntityName: {0} and Type:{1} to Portal Cache Message", changedItem.RemovedItem.LogicalName, changedItem.Type.ToString()));

            if (associateDisassociateMessage == null || changedItem.RemovedItem.LogicalName == "adx_webpageaccesscontrolrule_webrole")
            {
                message = new PluginMessage
                {
                    MessageName = Constants.RemovedOrDeleted,
                    Target      = new PluginMessageEntityReference
                    {
                        Name        = null,
                        Id          = changedItem.RemovedItem.Id,
                        LogicalName = changedItem.RemovedItem.LogicalName,
                    },
                };
            }
            else
            {
                message = new PluginMessage
                {
                    MessageName = Constants.Disassociate,
                    Target      = new PluginMessageEntityReference
                    {
                        // Special Handling : We want this information to pass to adx code for dissociate and message schema is fixed / nothing can be added, this name/guid would have been null/empty else .
                        Name        = associateDisassociateMessage.EntityName,
                        Id          = changedItem.RemovedItem.Id,
                        LogicalName = associateDisassociateMessage.RelatedEntity1Name,
                    },
                    RelatedEntities = new List <PluginMessageEntityReference>
                    {
                        new PluginMessageEntityReference
                        {
                            Name        = null,
                            Id          = Guid.Empty,
                            LogicalName = associateDisassociateMessage.RelatedEntity2Name,
                        }
                    },
                    Relationship = new PluginMessageRelationship
                    {
                        PrimaryEntityRole = null,
                        SchemaName        = associateDisassociateMessage.RelationshipName,
                    },
                };
            }
            return(message);
        }
コード例 #20
0
ファイル: PluginHandler.cs プロジェクト: yossidev/dnx
 private void OnError(PluginMessage requestMessage, string errorMessage)
 {
     SendMessage(
         requestMessage.PluginId,
         message: new PluginResponseMessage
     {
         MessageId   = requestMessage.MessageId,
         MessageName = requestMessage.MessageName,
         Error       = errorMessage,
     });
 }
コード例 #21
0
        private PluginMessage GetLogParsePluginMessage(string message, bool isError)
        {
            var pluginMessage = new PluginMessage();
            var logType       = isError ? LogType.Error : LogType.StandardOutput;

            pluginMessage.LogParseMessage = new LogParseMessage()
            {
                LogType = logType, Message = message
            };
            return(pluginMessage);
        }
コード例 #22
0
ファイル: PluginHandler.cs プロジェクト: yossidev/dnx
        private void RegisterMessage(PluginMessage message, IAssemblyLoadContext assemblyLoadContext)
        {
            var response = RegisterPlugin(message, assemblyLoadContext);

            if (!response.Success)
            {
                _faultedRegisterPluginMessages.Add(message);
            }

            SendMessage(message.PluginId, response);
        }
        protected override async Task PostAsync(IOwinContext context, PluginMessage message)
        {
            var restartMessage = new ApplicationRestartPortalBusMessage();

            if (restartMessage.Validate(message))
            {
                ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Post: name={0}", message.Target.Name));

                await PortalBusManager <ApplicationRestartPortalBusMessage> .PostAsync(context, new ApplicationRestartPortalBusMessage()).WithCurrentCulture();
            }
        }
コード例 #24
0
        /// <summary>
        /// Implementation of handling send method defined proto
        /// It handles the request based on <see cref="PluginMessage.PayloadCase" />
        /// </summary>
        /// <param name="request"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override Task <PluginMessageResponse> Send(PluginMessage request, ServerCallContext context)
        {
            switch (request.PayloadCase)
            {
            case PluginMessage.PayloadOneofCase.LogParseMessage:
                return(HandleLogParse(request.LogParseMessage));

            default:
                return(HandleUnknown());
            }
        }
コード例 #25
0
        public PluginHandlerOnReceiveResult OnReceive([NotNull] PluginMessage message)
        {
            _messageQueue.Enqueue(message);

            if (message.MessageName == RegisterPluginMessageName)
            {
                return(PluginHandlerOnReceiveResult.RefreshDependencies);
            }

            return(PluginHandlerOnReceiveResult.Default);
        }
コード例 #26
0
        /// <inheritdoc />
        public virtual RemoteTask <object> OnMessage(PluginMessage msg, params object[] parameters)
        {
            switch (msg)
            {
            case PluginMessage.OnLoggerConfigUpdated:
                return(OnLoggerConfigUpdated());

            default:
                LogTo.Debug($"Received unknown message {msg}. Is plugin up to date ?");
                break;
            }

            return(Task.FromResult <object>(null));
        }
コード例 #27
0
        /// <nodoc />
        public virtual async Task <PluginResponseResult <List <PluginMessageType> > > GetSupportedPluginMessageType()
        {
            var requestId = GetRequestId();
            var options   = GetCallOptions(requestId);
            var request   = new PluginMessage();
            var response  = await HandleRpcExceptionWithCallAsync(
                async() => {
                var response = await PluginServiceClient.SupportedOperationAsync(request, options);

                return(response.SupportedOperationResponse.Operation.Select(op => PluginMessageTypeHelper.ToPluginMessageType(op)).ToList());
            }, requestId);

            return(response);
        }
コード例 #28
0
        public override void OnPluginMessage(BotShell bot, PluginMessage message)
        {
            try
            {
                if (message.Command != "announce")
                {
                    return;
                }
                if (message.Args.Length < 3)
                {
                    return;
                }

                string group = (string)message.Args[0];
                if (group == null || group == string.Empty)
                {
                    return;
                }
                string source = (string)message.Args[1];
                if (source == null || source == string.Empty)
                {
                    return;
                }
                string sender = (string)message.Args[2];
                if (sender == null || sender == string.Empty)
                {
                    return;
                }
                string msg = (string)message.Args[3];
                if (msg == null || msg == string.Empty)
                {
                    return;
                }

                string   formattedMessage = bot.ColorHighlight + "Message from " + HTML.CreateColorString(bot.ColorHeaderHex, sender) + " on " + HTML.CreateColorString(bot.ColorHeaderHex, source) + " »» " + bot.ColorNormal + msg;
                string[] members          = this._friendsList.GetOnlineMembers(group, true);
                bot.SendPrivateMessage(sender, bot.ColorHighlight + "Sending out an announcement to " + HTML.CreateColorString(bot.ColorHeaderHex, members.Length.ToString()) + " members");
                foreach (string member in members)
                {
                    bot.SendPrivateMessage(bot.GetUserID(member), formattedMessage, AoLib.Net.PacketQueue.Priority.Low, true);
                }
                members = this._friendsList.GetOnlineMembers(group, false);
                bot.SendReplyMessage(this.InternalName, message, (object)members);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                throw new Exception("exception", ex);
            }
        }
コード例 #29
0
        /// <nodoc />
        public virtual async Task <PluginResponseResult <bool> > StopAsync()
        {
            var requestId = GetRequestId();
            var options   = GetCallOptions(requestId);
            var request   = new PluginMessage();
            var response  = await HandleRpcExceptionWithCallAsync(
                async() =>
            {
                var response = await PluginServiceClient.StopAsync(request, options);
                return(response.Status);
            }, requestId);

            return(response);
        }
コード例 #30
0
ファイル: PluginHandler.cs プロジェクト: yossidev/dnx
 private void OnNoop(PluginMessage requestMessage, string errorMessage)
 {
     // We only want to send a no-op message if there's an associated message id on the request message.
     if (requestMessage.MessageId != null)
     {
         SendMessage(
             requestMessage.PluginId,
             message: new NoopPluginResponseMessage
         {
             MessageId   = requestMessage.MessageId,
             MessageName = requestMessage.MessageName,
             Error       = errorMessage
         });
     }
 }
コード例 #31
0
 public DefaultPlugin(IPluginInfo info, PluginOperate load, PluginOperate unload,
     PluginTestSuccessFlag isSuccessFlag, PluginMessage getMsg)
 {
     if (info == null)
         ArgumentNull.Throw("info");
     if (load == null)
         ArgumentNull.Throw("load");
     if (unload == null)
         ArgumentNull.Throw("unload");
     if (isSuccessFlag == null)
         ArgumentNull.Throw("isSuccessFlag");
     if (getMsg == null)
         ArgumentNull.Throw("getMsg");
     this.Info = info;
     this.load = load;
     this.unload = unload;
     this.isSuccessFlag = isSuccessFlag;
     this.msg = getMsg;
 }