コード例 #1
0
        /// <summary>
        /// Здесь запускается аддон
        /// </summary>
        /// <param name="mainWindow">Главное окно Цирцеи</param>
        public override void Run(IMainWindow mainWindow)
        {
            this.mainWindow = mainWindow;
            this.data       = Data.Load();

            IBaseWindow activeWindow = mainWindow.ActiveIRCWindow;

            if (activeWindow is IServerWindow)
            {
                IServerWindow server = activeWindow as IServerWindow;
                this.data.Info.Server.Name = server.Server.Name;
                this.data.Info.Nick        = new NickName(server.Nick);
            }
            else if (activeWindow is IChannelWindow)
            {
                IChannelWindow channelWindow2 = activeWindow as IChannelWindow;
                this.data.Info.Server.Name = channelWindow2.OwnerServerWindow.Server.Name;
                this.data.Info.Nick        = new NickName(channelWindow2.OwnerServerWindow.Nick);
                this.data.Channel          = channelWindow2.WindowName;
            }
            else if (activeWindow is IPrivateWindow)
            {
                IPrivateWindow privateWindow = activeWindow as IPrivateWindow;
                this.data.Info.Server.Name = privateWindow.OwnerServerWindow.Server.Name;
                this.data.Info.Nick        = new NickName(privateWindow.OwnerServerWindow.Nick);
            }
            else
            {
                this.data.Info.Nick = new NickName(mainWindow.DefaultNick);
            }

            this.connectionForm = (ConnectionForm)this.mainWindow.CreateObject(AppDomain.CurrentDomain, typeof(ConnectionForm), this.data);

            if (this.connectionForm == null)
            {
                ManualClose();
                return;
            }

            if (this.mainWindow.ShowDialog(connectionForm) == DialogResult.OK)
            {
                this.data                   = this.connectionForm.Data;
                this.serverWindow           = mainWindow.OpenConnection(this.data.Info);
                this.serverWindow.Disposed += (sender, e) => ManualClose();
                if (this.serverWindow.IsConnected)
                {
                    this.mainWindow.RunCallback(new Special.Action(Futher));
                }
                else
                {
                    this.serverWindow.OnConnected += new EventHandler(serverWindow_OnConnected);
                    this.serverWindow.Connect();
                }
            }
            else
            {
                ManualClose();
            }
        }
コード例 #2
0
        /// <summary>
        /// Здесь запускается дополнение
        /// </summary>
        /// <param name="application">Ссылка на Цирцею</param>
        public override void Run(ICIRCeApplication application)
        {
            this.application = application;
            this.data        = Data.Load();

            var activeItem = application.ActiveItem;

            if (activeItem is ICIRCeServer)
            {
                var server = activeItem as ICIRCeServer;
                this.data.Info.Server.Name = server.Info.Server.Name;
                this.data.Info.Nick        = server.Info.Nick;
            }
            else if (activeItem is ICIRCeChannel)
            {
                var channel = activeItem as ICIRCeChannel;
                this.data.Info.Server.Name = channel.OwnerServer.Info.Server.Name;
                this.data.Info.Nick        = channel.OwnerServer.Info.Nick;
                this.data.Channel          = channel.Name;
            }
            else if (activeItem is ICIRCePrivateSession)
            {
                var privateSession = activeItem as ICIRCePrivateSession;
                this.data.Info.Server.Name = privateSession.OwnerServer.Info.Server.Name;
                this.data.Info.Nick        = privateSession.OwnerServer.Info.Nick;
            }
            else
            {
                this.data.Info.Nick = application.DefaultNickName;
            }

            this.connectionForm = new ConnectionForm(this.data);
            this.application.AddOwnedWindow(this.connectionForm.Handle);

            if (this.connectionForm.ShowDialog() == DialogResult.OK)
            {
                this.data   = this.connectionForm.Data;
                this.server = application.CreateConnection(this.data.Info);

                if (!this.server.IsConnected && !this.server.Connect())
                {
                    Stop();
                    return;
                }

                this.channel = this.server.JoinChannel(this.data.Channel);

                if (channel == null)
                {
                    Stop();
                    return;
                }

                this.channel.Closed += Wrap(Stop);

                Init();
            }
            else
            {
                Stop();
            }
        }