Пример #1
0
 void Hub_RegModeUpdated(object sender, FmdcEventArgs e)
 {
     if (sender != hub && !e.Handled && hub.RegMode >= 0)
     {
         UpdateMyInfo();
     }
 }
Пример #2
0
        void hubConnection_ConnectionStatusChange(object sender, FmdcEventArgs e)
        {
            switch (e.Action)
            {
            case TcpConnection.Connecting:
                Program.WriteLine("*** Hub Connecting...");
                break;

            case TcpConnection.Connected:
                Program.WriteLine("*** Hub Connected.");
                break;

            case TcpConnection.Disconnected:
                Program.Write("*** Hub Disconnected.");
                Program.Write(e.Data);
                Program.WriteLine();
                break;

            default:
                Program.Write("*** Hub has Unknown connection status.");
                Program.Write(e.Data);
                Program.WriteLine();
                break;
            }

            Program.WriteLine();
        }
Пример #3
0
        private void m_Hub_ConnectionStatusChange(object sender, FmdcEventArgs e)
        {
            switch (e.Action)
            {
            case 0:     //connecting
            {
                m_Gui.VypisText(string.Format("Pшipojuji se k {0}...", m_Hub.HubSetting.Address));
                break;
            }

            case 1:     //connected
            {
                m_Hub.Protocol.Update += new FmdcEventHandler(Protocol_Update);
                m_Gui.VypisRadek("hotovo!");
                break;
            }

            case 2:     //disconnected
            {
                m_Hub.Protocol.Update -= new FmdcEventHandler(Protocol_Update);
                m_Gui.VypisRadek(string.Format("{0:00}:{1:00}:{2:00} {3}", DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, "Odpojen!"));

                break;
            }
            }
        }
Пример #4
0
        void Protocol_Error(object sender, FmdcEventArgs e)
        {
            Transfer trans = sender as Transfer;

            if (trans != null && trans.User != null)
            {
                switch ((TransferErrors)e.Action)
                {
                case TransferErrors.INACTIVITY:
                    //SendMessage(Actions.PrivateMessage, trans.User.ID, "Unhandled error occured: Inactivity");
                    break;

                case TransferErrors.NO_FREE_SLOTS:
                    SendMessage(Actions.PrivateMessage, trans.User.ID, "You have no free slots. Make sure to have atleast one slot free and try again.");
                    break;

                case TransferErrors.FILE_NOT_AVAILABLE:
                    SendMessage(Actions.PrivateMessage, trans.User.ID, "Unhandled error occured: I was unable to get your filelist.");
                    break;

                case TransferErrors.USERID_MISMATCH:
                    SendMessage(Actions.PrivateMessage, trans.User.ID, "Unhandled error occured: User Id missmatch");
                    break;

                case TransferErrors.UNKNOWN:
                default:
                    SendMessage(Actions.PrivateMessage, trans.User.ID, "Unhandled error occured: " + e.Data);
                    break;
                }
            }
        }
Пример #5
0
 void Share_LastModifiedChanged(object sender, FmdcEventArgs e)
 {
     if (!e.Handled)
     {
         UpdateMyInfo();
     }
 }
Пример #6
0
        /// <summary>
        /// This action retrieves the value of the external IP address on this connection instance.
        /// </summary>
        /// <returns>External IP</returns>
        public System.Net.IPAddress GetExternalIPAddress(IUPnPUpdater upnp)
        {
            UPnPFunction func = new UPnPFunction();

            func.Name    = "GetExternalIPAddress";
            func.Service = this;

            func.Arguments.Add("NewExternalIPAddress", string.Empty);

            FmdcEventArgs e = new FmdcEventArgs(Actions.UPnPFunctionCall, func);

            upnp.FireUpdateBase(e);
            if (e.Handled)
            {
                func = e.Data as UPnPFunction;
                if (func != null)
                {
                    try
                    {
                        return(System.Net.IPAddress.Parse(func.Arguments["NewExternalIPAddress"]));
                    }
                    catch { }
                }
            }
            return(null);
        }
Пример #7
0
        void hub_ConnectionStatusChange(object sender, FmdcEventArgs e)
        {
            HubStatus h;

            switch (e.Action)
            {
            case TcpConnection.Disconnected:
                if (e.Data is System.Exception)
                {
                    h = new HubStatus(HubStatus.Codes.Disconnected, (System.Exception)e.Data);
                }
                else
                {
                    h = new HubStatus(HubStatus.Codes.Disconnected);
                }
                hub.RegMode = -1;
                // Sets MyInfo Interval to 0 when connection is disconnected
                this.myInfoLastUpdated = 0;
                lastMyInfo             = null;
                break;

            case TcpConnection.Connected:
                h = new HubStatus(HubStatus.Codes.Connected);
                break;

            case TcpConnection.Connecting:
            default:
                h = new HubStatus(HubStatus.Codes.Connecting);
                break;
            }
            Update(hub, new FmdcEventArgs(Actions.StatusChange, h));
            hub.Userlist.Clear();
        }
Пример #8
0
        public void ActOnInMessage(IConMessage message)
        {
            UdpMessage msg = message as UdpMessage;

            if (msg != null)
            {
                // Device Found
                UPnPDevice    device = ParseSSDP(msg.Raw, msg.RemoteAddress);
                FmdcEventArgs e      = new FmdcEventArgs(0, device);
                Update(con, e);
                if (!e.Handled)
                {
                    string key = device.Information.Sender.ToString();
                    // Do device exist in our list?
                    if (this.con.RootDevices.ContainsKey(key))
                    {
                        // Don't add this device. It already exist in our list.
                    }
                    else
                    {
                        // We don't have this device yet. Add it.
                        con.RootDevices.Add(key, device);
                        FmdcEventArgs e2 = new FmdcEventArgs(Actions.UPnPRootDeviceFound, device);
                        Update(con, e2);
                    }
                }
            }
        }
Пример #9
0
        protected bool OnRemoteCertificateValidation(
            object sender,
            X509Certificate certificate,
            X509Chain chain,
            SslPolicyErrors sslPolicyErrors)
        {
            CertificateValidationInfo info = new CertificateValidationInfo(certificate, chain, sslPolicyErrors);
            FmdcEventArgs             args = new FmdcEventArgs(Actions.SecurityValidateRemoteCertificate, info);

            SecureUpdate(this, args);
            info = args.Data as CertificateValidationInfo;
            if (args.Handled)
            {
                if (info == null)
                {
                    return(false);
                }
                return(info.Accepted);
            }
            else
            {
                // If developer havnt added logic to support this. Assume Accepted.
                return(true);
            }
        }
Пример #10
0
        void trans_SecureUpdate(object sender, FmdcEventArgs e)
        {
            switch (e.Action)
            {
            case Actions.SecuritySelectLocalCertificate:
                LocalCertificationSelectionInfo lc = e.Data as LocalCertificationSelectionInfo;
                if (lc != null)
                {
                    //string file = System.AppDomain.CurrentDomain.BaseDirectory + "FlowLib.cer";
                    //lc.SelectedCertificate = X509Certificate.CreateFromCertFile(file);
                    //e.Data = lc;
                }

                break;

            case Actions.SecurityValidateRemoteCertificate:
                CertificateValidationInfo ct = e.Data as CertificateValidationInfo;
                if (ct != null)
                {
                    ct.Accepted = true;
                    e.Data      = ct;
                    e.Handled   = true;
                }
                break;
            }
        }
Пример #11
0
        void downloadManager_DownloadCompleted(object sender, FmdcEventArgs e)
        {
            DownloadItem item   = sender as DownloadItem;
            Source       source = e.Data as Source;

            DownloadHandler.TryHandleDownload(this, item, source);
        }
        void hubConnection_Update(object sender, FmdcEventArgs e)
        {
            switch (e.Action)
            {
            case Actions.TransferRequest:
                if (e.Data is TransferRequest)
                {
                    TransferRequest req = (TransferRequest)e.Data;
                    transferManager.AddTransferReq(req);
                }
                break;

            case Actions.TransferStarted:
                Transfer trans = e.Data as Transfer;
                if (trans != null)
                {
#if !COMPACT_FRAMEWORK
                    // Security, Windows Mobile doesnt support SSLStream so we disable this feature for it.
                    trans.SecureUpdate += new FmdcEventHandler(trans_SecureUpdate);
#endif
                    transferManager.StartTransfer(trans);
                    trans.Protocol.ChangeDownloadItem += new FmdcEventHandler(Protocol_ChangeDownloadItem);
                    trans.Protocol.RequestTransfer    += new FmdcEventHandler(Protocol_RequestTransfer);
                }
                break;
            }
        }
Пример #13
0
        void hubConnection_Update(object sender, FmdcEventArgs e)
        {
            Hub hub = (Hub)sender;

            switch (e.Action)
            {
            case Actions.TransferRequest:
                if (e.Data is TransferRequest)
                {
                    TransferRequest req = (TransferRequest)e.Data;
                    if (transferManager.GetTransferReq(req.Key) == null)
                    {
                        transferManager.AddTransferReq(req);
                    }
                }
                break;

            case Actions.TransferStarted:
                Transfer trans = e.Data as Transfer;
                if (trans != null)
                {
                    transferManager.StartTransfer(trans);
                    trans.Protocol.ChangeDownloadItem += new FmdcEventHandler(Protocol_ChangeDownloadItem);
                    trans.Protocol.RequestTransfer    += new FmdcEventHandler(Protocol_RequestTransfer);
                }
                break;

            case Actions.UserOnline:
                last = System.DateTime.Now.Ticks;
                break;
            }
        }
 void hubConnection_ProtocolChange(object sender, FmdcEventArgs e)
 {
     Hub hubConnection = sender as Hub;
     if (hubConnection != null)
     {
         hubConnection.Protocol.Update += new FmdcEventHandler(prot_Update);
     }
 }
Пример #15
0
        protected void OnProtocolUpdate(object sender, FmdcEventArgs e)
        {
            switch (e.Action)
            {
            case Actions.StatusChange:
                switch (((HubStatus)e.Data).Code)
                {
                case HubStatus.Codes.Disconnected:
                    if (socket != null && socket.Connected)
                    {
                        try
                        {
                            socket.Shutdown(SocketShutdown.Both);
                            //socket.Disconnect(true);
                            socket.Close();
                        }
                        catch (System.Net.Sockets.SocketException) { }
                        catch (System.ObjectDisposedException) { }
                    }
                    break;
                }
                break;

            case Actions.RegMode:
                RegMode = (int)e.Data;
                break;

            case Actions.UserOnline:
                UserInfo ui = (UserInfo)e.Data;
                User     u  = new User(ui.DisplayName);
                u.UserInfo = ui;
                lock (userlist)
                {
                    userlist.Add(ui.ID, u);
                }
                break;

            case Actions.UserOffline:
                UserInfo userInfo = (UserInfo)e.Data;
                if (userInfo == null)
                {
                    return;
                }
                lock (userlist)
                {
                    userlist.Remove(userInfo.ID);
                }
                break;

            case Actions.Name:
                HubName hn = (HubName)e.Data;
                if (this.hubname == null)
                {
                    this.hubname = hn;
                }
                break;
            }
        }
Пример #16
0
        void downloadManager_SegmentCompleted(object sender, FmdcEventArgs e)
        {
            //DownloadItem di = sender as DownloadItem;
            //if (di == null)
            //	return;

            //Console.WriteLine(string.Format("SEG: {0}", di.ContentInfo.Get(ContentInfo.STORAGEPATH)));
            _testTimeoutLength += 4;
        }
Пример #17
0
        private void Hub_RegModeUpdated(object sender, FmdcEventArgs e)
        {
            Hub hub = sender as Hub;

            if (!e.Handled)
            {
                UpdateRegMode();
            }
        }
Пример #18
0
        void Protocol_MessageReceived2(object sender, FmdcEventArgs e)
        {
            StrMessage msg = e.Data as StrMessage;

            if (msg != null)
            {
                System.Console.WriteLine("IN:" + msg.Raw);
            }
        }
Пример #19
0
        void hubConnection_ProtocolChange(object sender, FmdcEventArgs e)
        {
            Hub hubConnection = sender as Hub;

            if (hubConnection != null)
            {
                hubConnection.Protocol.Update += new FmdcEventHandler(prot_Update);
            }
        }
Пример #20
0
        void hubConnection_SecureUpdate(object sender, FmdcEventArgs e)
        {
            CertificateValidationInfo info = e.Data as CertificateValidationInfo;

            if (info != null)
            {
                info.Accepted = true;
            }
        }
Пример #21
0
        void Protocol_MessageReceived(object sender, FmdcEventArgs e)
        {
            StrMessage msg = e.Data as StrMessage;

            if (msg != null)
            {
                msgList.Add(string.Format("IN: {0}", msg.Raw));
                listMainchat.Show();
            }
        }
Пример #22
0
 void hubConnection_ProtocolChange(object sender, FmdcEventArgs e)
 {
     Hub hubConnection = sender as Hub;
     IProtocol prot = e.Data as IProtocol;
     if (prot != null)
     {
         prot.Update -= hubConnection_Update;
     }
     hubConnection.Protocol.Update += new FmdcEventHandler(hubConnection_Update);
 }
Пример #23
0
        void Protocol_MessageReceived(object sender, FmdcEventArgs e)
        {
            ConMessage msg = e.Data as ConMessage;

            if (msg != null)
            {
                // We are letting hub take care of incomming messages.
                hubConnection.Protocol.ParseRaw(msg.Bytes, msg.Bytes.Length);
            }
        }
Пример #24
0
        void prot_Update(object sender, FmdcEventArgs e)
        {
            Hub hubConnection = sender as Hub;

            if (hubConnection != null)
            {
                bool testFinishStatus = false;
                switch (e.Action)
                {
                case Actions.IsReady:
                    bool isReady = (bool)e.Data;
                    if (isReady)
                    {
                        // Create mainchat message.
                        MainMessage msg = new MainMessage(hubConnection.Me.ID, "Testing - MainMessage");
                        // message will here be converted to right format and then be sent.
                        UpdateBase(this, new FlowLib.Events.FmdcEventArgs(FlowLib.Events.Actions.MainMessage, msg));

                        // Create private message.
                        PrivateMessage privMsg = new PrivateMessage(hubConnection.Me.ID, hubConnection.Me.ID, "Testing - PrivateMessage");

                        // message will here be converted to right format and then be sent.
                        UpdateBase(this, new FlowLib.Events.FmdcEventArgs(FlowLib.Events.Actions.PrivateMessage, privMsg));
                    }
                    break;

                case Actions.MainMessage:
                    MainMessage msgMain = e.Data as MainMessage;
                    if (string.Equals(hubConnection.Me.ID, msgMain.From))
                    {
                        _gotMyMainMessage = true;
                    }
                    testFinishStatus = true;
                    break;

                case Actions.PrivateMessage:
                    PrivateMessage msgPriv = e.Data as PrivateMessage;
                    if (string.Equals(hubConnection.Me.ID, msgPriv.From))
                    {
                        _gotMyPrivateMessage = true;
                    }
                    testFinishStatus = true;
                    break;
                }

                if (testFinishStatus)
                {
                    if (_gotMyMainMessage && _gotMyPrivateMessage)
                    {
                        _isFinished = true;
                    }
                }
            }
        }
Пример #25
0
        protected void ParseRaw(string str, IPEndPoint point)
        {
            UdpMessage    msg = new UdpMessage(str, point);
            FmdcEventArgs e   = new FmdcEventArgs(Actions.CommandIncomming, msg);

            MessageReceived(con, e);
            if (!e.Handled)
            {
                ActOnInMessage(msg);
            }
        }
Пример #26
0
        public bool OnSend(IConMessage msg)
        {
            FmdcEventArgs e = new FmdcEventArgs(Actions.CommandOutgoing, msg);

            MessageToSend(hub, e);
            if (!e.Handled)
            {
                return(true);
            }
            return(false);
        }
Пример #27
0
        void hubConnection_ProtocolChange(object sender, FmdcEventArgs e)
        {
            Hub       hubConnection = sender as Hub;
            IProtocol prot          = e.Data as IProtocol;

            if (prot != null)
            {
                prot.Update -= hubConnection_Update;
            }
            hubConnection.Protocol.Update += new FmdcEventHandler(hubConnection_Update);
        }
Пример #28
0
        void Trans_Protocol_MessageReceived(object sender, FmdcEventArgs e)
        {
            StrMessage msg = e.Data as StrMessage;

            if (msg != null)
            {
                Program.Write(string.Format("[{0}] TRA REC: {1}\r\n",
                                            System.DateTime.Now.ToLongTimeString(),
                                            msg.Raw));
            }
        }
Пример #29
0
        void Protocol_MessageToSend(object sender, FmdcEventArgs e)
        {
            StrMessage msg = e.Data as StrMessage;

            if (msg != null)
            {
                Program.Write(string.Format("[{0}] HUB SEN: {1}\r\n",
                                            System.DateTime.Now.ToLongTimeString(),
                                            msg.Raw));
            }
        }
Пример #30
0
        void Protocol_RequestTransfer(object sender, FmdcEventArgs e)
        {
            TransferRequest req = e.Data as TransferRequest;

            req = transferManager.GetTransferReq(req.Key);
            if (req != null)
            {
                e.Handled = true;
                e.Data    = req;
                transferManager.RemoveTransferReq(req.Key);
            }
        }
Пример #31
0
        private void d_DownloadCompleted(object sender, FmdcEventArgs e)
        {
            DownloadItem dwnItm = sender as DownloadItem;

            if (dwnItm != null)
            {
                //RemoveDownload((DownloadItem)sender);
                RemoveDownload(dwnItm);
                FlowLib.Utils.FileOperations.ForceClose(dwnItm.ContentInfo.Get(ContentInfo.STORAGEPATH));
                DownloadCompleted(sender, e);
            }
        }
Пример #32
0
        /// <summary>
        /// Tries to connect to hub.
        /// </summary>
        public override void Connect()
        {
            // RegMode changed to default
            RegMode = -1;
            if (Protocol == null)
            {
                // Setting right Command Seperator.
                switch (HubSetting.Protocol)
                {
                case "Nmdc":         // NMDC
                    Protocol = new HubNmdcProtocol(this);
                    break;

                case "Zpoc":
                    Protocol = new HubZpocProtocol(this);
                    break;

                case "":            // Auto Detect
                case "Auto":        // Auto Detect
                case "Adc":         // ADC
                    Protocol = new AdcProtocol(this);
                    break;

#if !COMPACT_FRAMEWORK
// Security
                case "AdcSecure":
                    Protocol       = new AdcProtocol(this);
                    SecureProtocol = FlowLib.Enums.SecureProtocols.TLS;
                    break;

                case "NmdcSecure":
                    Protocol       = new HubNmdcProtocol(this);
                    SecureProtocol = FlowLib.Enums.SecureProtocols.TLS;
                    break;
#endif
                default:
                    FmdcEventArgs e = new FmdcEventArgs(0);
                    UnknownProtocolId(this, e);
                    if (e.Handled && e.Data is IProtocolHub)
                    {
                        Protocol = (IProtocolHub)e.Data;
                    }
                    else
                    {
                        throw new System.InvalidOperationException("Protocol is not beeing set. Protocol name is not a inbuilt protocol and has not been handled by plugin");
                    }
                    break;
                }
            }
            worker = new Thread(new ThreadStart(base.Connect));
            worker.IsBackground = true;
            worker.Start();
        }
Пример #33
0
 void hubConnection_ProtocolChange(object sender, FmdcEventArgs e)
 {
     Hub hubConnection = sender as Hub;
     IProtocol prot = e.Data as IProtocol;
     if (prot != null)
     {
         prot.MessageReceived -= Protocol_MessageReceived;
         prot.MessageToSend -= Protocol_MessageToSend;
         prot.Update -= hubConnection_Update;
     }
     hubConnection.Protocol.MessageReceived += new FlowLib.Events.FmdcEventHandler(Protocol_MessageReceived2);
     hubConnection.Protocol.MessageToSend += new FlowLib.Events.FmdcEventHandler(Protocol_MessageToSend);
     hubConnection.Protocol.Update += new FlowLib.Events.FmdcEventHandler(hubConnection_Update);
 }
Пример #34
0
 public void protRcvd(object sender, FmdcEventArgs e)
 {
     Hub hub = (sender as Hub);
     switch(e.Action)
     {
     case Actions.StatusChange:
         HubStatus status = (e.Data as HubStatus);
         if(status.Code.Equals("Connected"))
         {
             this.hublist.Add(hub.Name, hub);
         }
         else if(status.Code.Equals("Disconnected"))
         {
             this.hublist.Remove(hub.Name);
         }
         break;
     }
 }
        void prot_Update(object sender, FmdcEventArgs e)
        {
            switch (e.Action)
            {
                case Actions.MainMessage:
                    MainMessage msgMain = e.Data as MainMessage;
                    System.Console.Write(string.Format("[{0}] <{1}> {2}\r\n",
                        System.DateTime.Now.ToLongTimeString(),
                        msgMain.From,
                        msgMain.Content));
                    break;

                case Actions.PrivateMessage:
                    PrivateMessage msgPriv = e.Data as PrivateMessage;
                    System.Console.Write(string.Format("[{0}] PM:{1}\r\n",
                        System.DateTime.Now.ToLongTimeString(),
                        msgPriv.Content));
                    break;
            }
        }
Пример #36
0
 void OnMessageReceived(object sender, FmdcEventArgs e)
 {
 }
Пример #37
0
 protected void ParseRaw(string str, IPEndPoint point)
 {
     UdpMessage msg = new UdpMessage(str, point);
     FmdcEventArgs e = new FmdcEventArgs(Actions.CommandIncomming, msg);
     MessageReceived(con, e);
     if (!e.Handled)
         ActOnInMessage(msg);
 }
Пример #38
0
 void Protocol_Error(object sender, FmdcEventArgs e)
 {
     Transfer trans = sender as Transfer;
     if (trans != null && trans.User != null)
     {
         switch ((TransferErrors)e.Action)
         {
             case TransferErrors.INACTIVITY:
                 //SendMessage(Actions.PrivateMessage, trans.User.ID, "Unhandled error occured: Inactivity");
                 break;
             case TransferErrors.NO_FREE_SLOTS:
                 SendMessage(Actions.PrivateMessage, trans.User.ID, "You have no free slots. Make sure to have atleast one slot free and try again.");
                 break;
             case TransferErrors.FILE_NOT_AVAILABLE:
                 SendMessage(Actions.PrivateMessage, trans.User.ID, "Unhandled error occured: I was unable to get your filelist.");
                 break;
             case TransferErrors.USERID_MISMATCH:
                 SendMessage(Actions.PrivateMessage, trans.User.ID, "Unhandled error occured: User Id missmatch");
                 break;
             case TransferErrors.UNKNOWN:
             default:
                 SendMessage(Actions.PrivateMessage, trans.User.ID, "Unhandled error occured: " + e.Data);
                 break;
         }
     }
 }
 void Protocol_RequestTransfer(object sender, FmdcEventArgs e)
 {
     ITransfer trans = sender as ITransfer;
     TransferRequest req = e.Data as TransferRequest;
     req = transferManager.GetTransferReq(req.Key);
     if (trans != null && req != null)
     {
         e.Handled = true;
         e.Data = req;
         transferManager.RemoveTransferReq(req.Key);
     }
 }
 void PassiveConnectToUser_UpdateBase(object sender, FmdcEventArgs e)
 {
 }
 void hubConnection_Update(object sender, FmdcEventArgs e)
 {
     switch (e.Action)
     {
         case Actions.TransferRequest:
             if (e.Data is TransferRequest)
             {
                 TransferRequest req = (TransferRequest)e.Data;
                 transferManager.AddTransferReq(req);
             }
             break;
         case Actions.TransferStarted:
             Transfer trans = e.Data as Transfer;
             if (trans != null)
             {
     #if !COMPACT_FRAMEWORK
                 // Security, Windows Mobile doesnt support SSLStream so we disable this feature for it.
                 trans.SecureUpdate += new FmdcEventHandler(trans_SecureUpdate);
     #endif
                 transferManager.StartTransfer(trans);
                 trans.Protocol.ChangeDownloadItem += new FmdcEventHandler(Protocol_ChangeDownloadItem);
                 trans.Protocol.RequestTransfer += new FmdcEventHandler(Protocol_RequestTransfer);
             }
             break;
     }
 }
Пример #42
0
        void hubConnection_ConnectionStatusChange(object sender, FmdcEventArgs e)
        {
            switch (e.Action)
            {
                case TcpConnection.Connecting:
                    Program.WriteLine("*** Hub Connecting...");
                    break;
                case TcpConnection.Connected:
                    Program.WriteLine("*** Hub Connected.");
                    break;
                case TcpConnection.Disconnected:
                    Program.Write("*** Hub Disconnected.");
                    Program.Write(e.Data);
                    Program.WriteLine();
                    break;
                default:
                    Program.Write("*** Hub has Unknown connection status.");
                    Program.Write(e.Data);
                    Program.WriteLine();
                    break;
            }

            Program.WriteLine();
        }
Пример #43
0
 void hubConnection_ProtocolChange(object sender, FmdcEventArgs e)
 {
     Hub hubConnection = sender as Hub;
     if (hubConnection != null)
     {
         hubConnection.Protocol.Update += new FmdcEventHandler(prot_Update);
         if (Program.DEBUG)
         {
             hubConnection.Protocol.MessageReceived += new FmdcEventHandler(Protocol_MessageReceived);
             hubConnection.Protocol.MessageToSend += new FmdcEventHandler(Protocol_MessageToSend);
         }
     }
 }
        // Security, Windows Mobile doesnt support SSLStream so we disable this feature for it.
        void trans_SecureUpdate(object sender, FmdcEventArgs e)
        {
            switch (e.Action)
            {
                case Actions.SecuritySelectLocalCertificate:
                    LocalCertificationSelectionInfo lc = e.Data as LocalCertificationSelectionInfo;
                    if (lc != null)
                    {
                        string file = System.AppDomain.CurrentDomain.BaseDirectory + "FlowLib.cer";
                        lc.SelectedCertificate = X509Certificate.CreateFromCertFile(file);
                        e.Data = lc;
                    }

                    break;
                case Actions.SecurityValidateRemoteCertificate:
                    CertificateValidationInfo ct = e.Data as CertificateValidationInfo;
                    if (ct != null)
                    {
                        ct.Accepted = true;
                        e.Data = ct;
                        e.Handled = true;
                    }
                    break;
            }
        }
Пример #45
0
        void prot_Update(object sender, FmdcEventArgs e)
        {
            switch (e.Action)
            {
                case Actions.TransferRequest:
                    if (e.Data is TransferRequest)
                    {
                        TransferRequest req = (TransferRequest)e.Data;
                        if (transferManager.GetTransferReq(req.Key) == null)
                            transferManager.AddTransferReq(req);
                    }
                    break;
                case Actions.TransferStarted:
                    Transfer trans = e.Data as Transfer;
                    if (trans != null)
                    {
            #if !COMPACT_FRAMEWORK
                        // Security, Windows Mobile doesnt support SSLStream so we disable this feature for it.
                        trans.SecureUpdate += new FmdcEventHandler(trans_SecureUpdate);
            #endif
                        transferManager.StartTransfer(trans);
                        trans.ProtocolChange += new FmdcEventHandler(trans_ProtocolChange);
                        trans.Protocol.ChangeDownloadItem += new FmdcEventHandler(Protocol_ChangeDownloadItem);
                        trans.Protocol.RequestTransfer += new FmdcEventHandler(Protocol_RequestTransfer);
                        trans.Protocol.Error += new FmdcEventHandler(Protocol_Error);
                        if (Program.DEBUG)
                        {
                            trans.Protocol.MessageReceived += new FmdcEventHandler(Trans_Protocol_MessageReceived);
                            trans.Protocol.MessageToSend += new FmdcEventHandler(Trans_Protocol_MessageToSend);
                        }
                    }
                    break;
                case Actions.MainMessage:
                    MainMessage msgMain = e.Data as MainMessage;

                    if (CommandHandler.TryHandleMsg(this, msgMain.From, msgMain.Content, Actions.MainMessage))
                    {
                        // message will here be converted to right format and then be sent.
                        //UpdateBase(this, new FlowLib.Events.FmdcEventArgs(FlowLib.Events.Actions.MainMessage, new MainMessage(hubConnection.Me.ID, msg)));
                    }
                    else
                    {
                        if (!Program.DEBUG)
                        {
                            Program.Write(string.Format("[{0}] <{1}> {2}\r\n",
                                System.DateTime.Now.ToLongTimeString(),
                                msgMain.From,
                                msgMain.Content));
                        }
                    }
                    break;
                case Actions.PrivateMessage:
                    PrivateMessage msgPriv = e.Data as PrivateMessage;

                    if (CommandHandler.TryHandleMsg(this, msgPriv.From, msgPriv.Content.Replace("<" + msgPriv.From + "> ", string.Empty), Actions.PrivateMessage))
                    {
                        // message will here be converted to right format and then be sent.
                        //UpdateBase(this, new FlowLib.Events.FmdcEventArgs(FlowLib.Events.Actions.PrivateMessage, new PrivateMessage(msgPriv.From, hubConnection.Me.ID, msgPM)));
                    }
                    else
                    {
                        if (!Program.DEBUG)
                        {
                            Program.Write(string.Format("[{0}] PM:{1}\r\n",
                                System.DateTime.Now.ToLongTimeString(),
                                msgPriv.Content));
                        }
                    }
                    break;
            }
        }
Пример #46
0
 protected void OnUpdateSetting(object sender, FmdcEventArgs e)
 {
 }
Пример #47
0
 void hubConnection_SecureUpdate(object sender, FmdcEventArgs e)
 {
     CertificateValidationInfo info = e.Data as CertificateValidationInfo;
     if (info != null)
     {
         info.Accepted = true;
     }
 }
Пример #48
0
 void OnMessageToSend(object sender, FmdcEventArgs e)
 {
 }
Пример #49
0
 void OnUpdate(object sender, FmdcEventArgs e)
 {
 }
Пример #50
0
 void downloadManager_DownloadCompleted(object sender, FmdcEventArgs e)
 {
     DownloadItem item = sender as DownloadItem;
     Source source = e.Data as Source;
     DownloadHandler.TryHandleDownload(this, item, source);
 }
 void hubConnection_Update(object sender, FmdcEventArgs e)
 {
     Hub hub = (Hub)sender;
     switch (e.Action)
     {
         case Actions.TransferRequest:
             if (e.Data is TransferRequest)
             {
                 TransferRequest req = (TransferRequest)e.Data;
                 if (transferManager.GetTransferReq(req.Key) == null)
                     transferManager.AddTransferReq(req);
             }
             break;
         case Actions.TransferStarted:
             Transfer trans = e.Data as Transfer;
             if (trans != null)
             {
                 transferManager.StartTransfer(trans);
                 trans.Protocol.ChangeDownloadItem += new FmdcEventHandler(Protocol_ChangeDownloadItem);
                 trans.Protocol.RequestTransfer += new FmdcEventHandler(Protocol_RequestTransfer);
             }
             break;
         case  Actions.UserOnline:
             bool hasMe = (hub.GetUserById(hub.Me.ID) != null);
             if (!sentRequest && hasMe)
             {
                 User usr = null;
                 if ((usr = hub.GetUserByNick("DCpp706")) != null)
                 {
                     // Adding filelist of unknown type to download manager.
                     // to the user DCpp706
                     ContentInfo info = new ContentInfo(ContentInfo.FILELIST, BaseFilelist.UNKNOWN);
                     info.Set(ContentInfo.STORAGEPATH, currentDir + "Filelists\\" + usr.StoreID + ".filelist");
                     downloadManager.AddDownload(new DownloadItem(info), new Source(hub.RemoteAddress.ToString(), usr.StoreID));
                     // Start transfer to user
                     UpdateBase(this, new FmdcEventArgs(Actions.StartTransfer, usr));
                     sentRequest = true;
                 }
             }
             break;
     }
 }
Пример #52
0
 void Trans_Protocol_MessageToSend(object sender, FmdcEventArgs e)
 {
     StrMessage msg = e.Data as StrMessage;
     if (msg != null)
     {
         Program.Write(string.Format("[{0}] TRA SEN: {1}\r\n",
             System.DateTime.Now.ToLongTimeString(),
             msg.Raw));
     }
 }
 void Protocol_ChangeDownloadItem(object sender, FmdcEventArgs e)
 {
     Transfer trans = sender as Transfer;
     if (trans == null)
         return;
     DownloadItem dwnItem = null;
     if (downloadManager.TryGetDownload(trans.Source, out dwnItem))
     {
         e.Data = dwnItem;
         e.Handled = true;
     }
 }
Пример #54
0
        public void ActOnOutMessage(FlowLib.Events.FmdcEventArgs e)
        {
            string key = null;
            UPnPDevice device = null;
            switch (e.Action)
            {
                case Actions.UPnPDeviceDescription:
                    key = e.Data as string;
                    if (key != null)
                    {
                        try
                        {
                            if (con.RootDevices.ContainsKey(key))
                            {
                                device = con.RootDevices[key];
                                System.Net.HttpWebRequest httpRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(device.Information.DescriptionURL);
                                WebResponse webResponse = httpRequest.GetResponse();
                                System.IO.StreamReader sr = new System.IO.StreamReader(webResponse.GetResponseStream());
                                string ret = sr.ReadToEnd();
                                sr.Close();

                                FmdcEventArgs e2 = new FmdcEventArgs(Actions.UPnPDeviceDescription, ret);
                                Update(con, e2);
                                if (!e2.Handled)
                                {
                                    ParseDescription(ref device, ret);
                                    Update(con, new FmdcEventArgs(Actions.UPnPDeviceUpdated, device));
                                }
                            }
                        }
                        catch (System.Exception)
                        {
                            // TODO: Make exception handling
                        }
                    }
                    break;
                case Actions.UPnPFunctionCall:
                    UPnPFunction func = e.Data as UPnPFunction;
                    if (func != null)
                    {
                        try
                        {
                            #region Create Envelope
                            System.Text.StringBuilder sb = new System.Text.StringBuilder();
                            sb.Append("<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">");
                            sb.Append("<s:Body>");
                            sb.Append("<u:" + func.Name + " xmlns:u=\"" + func.Service.Information.serviceType + "\">");
                            foreach (KeyValuePair<string, string> argument in func.Arguments)
                            {
                                sb.AppendFormat("<{0}>{1}</{0}>", argument.Key, argument.Value);
                            }
                            sb.Append("</u:" + func.Name + ">");
                            sb.Append("</s:Body>");
                            sb.Append("</s:Envelope>");
                            #endregion
                            #region Create Request
                            byte[] body = System.Text.Encoding.UTF8.GetBytes(sb.ToString());
                            string url = null;
                            // Is ControlURL relative or absolute?
                            if (func.Service.Information.ControlURL.StartsWith("/"))
                            {
                                url = "http://" + func.Service.Device.Information.URLBase + func.Service.Information.ControlURL;
                            }
                            else
                            {
                                url = func.Service.Information.ControlURL;
                            }

                            WebRequest wr = WebRequest.Create(url);//+ controlUrl);
                            wr.Headers.Clear();
                            wr.Method = "POST";
                            wr.ContentType = "text/xml; charset=\"utf-8\"";
                            wr.Headers.Add("SOAPAction", "\"" + func.Service.Information.serviceType +
                            "#" + func.Name + "\"");
                            wr.ContentLength = body.Length;
                            #endregion
                            #region Call Service function
                            // TODO: Add error handling in this (If server returns code 500 or something)
                            System.IO.Stream stream = wr.GetRequestStream();
                            stream.Write(body, 0, body.Length);
                            stream.Flush();
                            stream.Close();
                            WebResponse wres = wr.GetResponse();
                            System.IO.StreamReader sr = new
                            System.IO.StreamReader(wres.GetResponseStream());
                            string xml = sr.ReadToEnd();
                            sr.Close();
                            #endregion
                            #region Parse returning data
                            XmlDocument document = new XmlDocument();
                            document.LoadXml(xml);
                            SortedList<string, string> tmpList = new SortedList<string, string>(func.Arguments);
                            foreach (KeyValuePair<string, string> argument in func.Arguments)
                            {
                                XmlNodeList nodes = document.GetElementsByTagName(argument.Key);
                                if (nodes.Count == 1)
                                {
                                    tmpList[argument.Key] = nodes[0].InnerText;
                                }
                            }
                            func.Arguments = tmpList;
                            #endregion
                            #region Return data
                            e.Data = func;
                            e.Handled = true;
                            #endregion
                        }
                        catch (System.Net.WebException webEx)
                        {
                            HttpWebResponse resp = webEx.Response as HttpWebResponse;
                            if (resp != null)
                            {

                                func.ErrorCode = (int)resp.StatusCode;
                            }
                            e.Data = func;
                        }
                        catch
                        {
                            // TODO: Add more specific error handling here
                        }
                    }
                    break;
            }
        }
 void trans_ProtocolChange(object sender, FmdcEventArgs e)
 {
     Transfer trans = sender as Transfer;
     if (trans == null)
         return;
     IProtocolTransfer prot = e as IProtocolTransfer;
     if (prot != null)
     {
         prot.ChangeDownloadItem -= Protocol_ChangeDownloadItem;
         prot.RequestTransfer -= Protocol_RequestTransfer;
     }
     trans.Protocol.ChangeDownloadItem += new FmdcEventHandler(Protocol_ChangeDownloadItem);
     trans.Protocol.RequestTransfer += new FmdcEventHandler(Protocol_RequestTransfer);
 }
Пример #56
0
 public bool OnSend(IConMessage msg)
 {
     FmdcEventArgs e = new FmdcEventArgs(Actions.CommandOutgoing, msg);
     MessageToSend(con, e);
     if (!e.Handled)
     {
         return true;
     }
     return false;
 }
Пример #57
0
 void d_SegmentStarted(object sender, FmdcEventArgs e)
 {
     SegmentStarted(sender, e);
 }
Пример #58
0
 void Protocol_MessageReceived(object sender, FmdcEventArgs e)
 {
     StrMessage msg = e.Data as StrMessage;
     if (msg != null)
     {
         Program.Write(string.Format("[{0}] HUB REC: {1}\r\n",
             System.DateTime.Now.ToLongTimeString(),
             msg.Raw));
     }
 }
Пример #59
0
 public void ActOnInMessage(IConMessage message)
 {
     UdpMessage msg = message as UdpMessage;
     if (msg != null)
     {
         // Device Found
         UPnPDevice device = ParseSSDP(msg.Raw, msg.RemoteAddress);
         FmdcEventArgs e = new FmdcEventArgs(0, device);
         Update(con, e);
         if (!e.Handled)
         {
             string key = device.Information.Sender.ToString();
             // Do device exist in our list?
             if (this.con.RootDevices.ContainsKey(key))
             {
                 // Don't add this device. It already exist in our list.
             }
             else
             {
                 // We don't have this device yet. Add it.
                 con.RootDevices.Add(key, device);
                 FmdcEventArgs e2 = new FmdcEventArgs(Actions.UPnPRootDeviceFound, device);
                 Update(con, e2);
             }
         }
     }
 }
Пример #60
0
 void trans_ProtocolChange(object sender, FmdcEventArgs e)
 {
     Transfer trans = sender as Transfer;
     if (trans != null)
     {
         trans.Protocol.ChangeDownloadItem += new FmdcEventHandler(Protocol_ChangeDownloadItem);
         trans.Protocol.RequestTransfer += new FmdcEventHandler(Protocol_RequestTransfer);
         trans.Protocol.Error += new FmdcEventHandler(Protocol_Error);
         if (Program.DEBUG)
         {
             trans.Protocol.MessageReceived += new FmdcEventHandler(Trans_Protocol_MessageReceived);
             trans.Protocol.MessageToSend += new FmdcEventHandler(Trans_Protocol_MessageToSend);
         }
     }
 }