Esempio n. 1
0
        // -------- отправка пакета плагину ------

        private void SendPacketToManaged(Managed item)
        {
            if (item.Packets.Count > 0)
            {
                Packet packet = item.Packets[0];
                item.iAsync = item.InvokeAsync.BeginInvoke(packet, null, null);

                item.sendPackets += 1;

                if (item.iAsync.CompletedSynchronously)
                {
                    item.processedPackets += 1;
                    item.State             = ManagedState.Wait;
                }
                else
                if (item.iAsync.AsyncWaitHandle.WaitOne(waitTime))
                {
                    item.processedPackets += 1;
                    item.State             = ManagedState.Wait;
                }
                else
                {
                    item.State = ManagedState.Processed;
                }

                item.Packets.RemoveAt(0);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Загрузка плагина
        /// </summary>
        /// <param name="path">URI к плагину</param>
        /// <returns></returns>
        public static List <Managed> LoadPlugins(string path)
        {
            List <Managed> managed = new List <Managed>();

            foreach (string dllName in Directory.GetFiles(path, "*.dll"))
            {
                AssemblyName assemblyName = AssemblyName.GetAssemblyName(dllName);
                if (assemblyName != null)
                {
                    Managed m = GetManaged(assemblyName);
                    if (m != null)
                    {
                        managed.Add(m);
                    }
                }
            }
            return(managed);
        }
Esempio n. 3
0
        // ---- удаление из интерфейса ------

        void Deleter(Managed item)
        {
            foreach (ToolStripItem mitem in services.DropDownItems)
            {
                if (mitem.Tag.Equals(item.key))
                {
                    services.DropDownItems.Remove(mitem);
                    break;
                }
            }

            foreach (ToolStripItem mitem in contextServices.DropDownItems)
            {
                if (mitem.Tag.Equals(item.key))
                {
                    contextServices.DropDownItems.Remove(mitem);
                    break;
                }
            }

            foreach (ListViewItem mitem in listView.Items)
            {
                if (mitem.Tag.Equals(item.key))
                {
                    listView.Items.Remove(mitem);
                }
            }

            string message = "Компонент: " + item.plugin.Name + " удален из системы. Так как его статус равен: ";

            switch (item.State)
            {
            case ManagedState.Overflow:

                message += "переполнен";
                break;

            case ManagedState.NotResponding:

                message += "не отвечает";
                break;
            }
            MessageBox.Show(message);
        }
Esempio n. 4
0
        // ------------------
        private static Managed GetManaged(AssemblyName assemblyName)
        {
            AppDomain Domain = AppDomain.CreateDomain(Generator.GenerateDomainName());
            if (Domain != null)
            {
                Assembly assembly = Domain.Load(assemblyName);
                if (assembly != null)
                {
                    IPlugin plugin = GetPlugin(assembly);
                    if (plugin != null)
                    {
                        Managed m = new Managed(plugin);

                        m.domain = Domain;
                        m.plugin = plugin;

                        return m;
                    }
                }
            }
            AppDomain.Unload(Domain);
            return null;
        }
Esempio n. 5
0
        // ------------------

        private static Managed GetManaged(AssemblyName assemblyName)
        {
            AppDomain Domain = AppDomain.CreateDomain(Generator.GenerateDomainName());

            if (Domain != null)
            {
                Assembly assembly = Domain.Load(assemblyName);
                if (assembly != null)
                {
                    IPlugin plugin = GetPlugin(assembly);
                    if (plugin != null)
                    {
                        Managed m = new Managed(plugin);

                        m.domain = Domain;
                        m.plugin = plugin;

                        return(m);
                    }
                }
            }
            AppDomain.Unload(Domain);
            return(null);
        }
Esempio n. 6
0
        // ------ удаляем информацтю о плагине ------

        void m_PluginUnload(Managed item)
        {
            Invoke(remover, item);
        }
Esempio n. 7
0
        // -------- отправка пакета плагину ------
        private void SendPacketToManaged(Managed item)
        {
            if (item.Packets.Count > 0)
            {
                Packet packet = item.Packets[0];
                item.iAsync = item.InvokeAsync.BeginInvoke(packet, null, null);

                item.sendPackets += 1;

                if (item.iAsync.CompletedSynchronously)
                {
                    item.processedPackets += 1;
                    item.State = ManagedState.Wait;
                }
                else
                    if (item.iAsync.AsyncWaitHandle.WaitOne(waitTime))
                    {
                        item.processedPackets += 1;
                        item.State = ManagedState.Wait;
                    }
                    else
                        item.State = ManagedState.Processed;

                item.Packets.RemoveAt(0);
            }
        }
Esempio n. 8
0
 // ------ удаляем информацтю о плагине ------
 void m_PluginUnload(Managed item)
 {
     Invoke(remover, item);
 }
Esempio n. 9
0
        // ---- удаление из интерфейса ------
        void Deleter(Managed item)
        {
            foreach (ToolStripItem mitem in services.DropDownItems)
            {
                if (mitem.Tag.Equals(item.key))
                {
                    services.DropDownItems.Remove(mitem);
                    break;
                }
            }

            foreach (ToolStripItem mitem in contextServices.DropDownItems)
            {
                if (mitem.Tag.Equals(item.key))
                {
                    contextServices.DropDownItems.Remove(mitem);
                    break;
                }
            }

            foreach (ListViewItem mitem in listView.Items)
            {
                if (mitem.Tag.Equals(item.key))
                {
                    listView.Items.Remove(mitem);
                }
            }

            string message = "Компонент: " + item.plugin.Name + " удален из системы. Так как его статус равен: ";
            switch (item.State)
            {
                case ManagedState.Overflow:

                    message += "переполнен";
                    break;

                case ManagedState.NotResponding:

                    message += "не отвечает";
                    break;
            }
            MessageBox.Show(message);
        }