void Connection_UpdateTLS(object sender, FlowLib.Events.FmdcEventArgs e)
        {
            switch (e.Action)
            {
            case Actions.TransferStarted:
                Transfer trans = e.Data as Transfer;
                if (trans != null)
                {
                    if (trans.Protocol == null)
                    {
                        trans.Protocol       = new FlowLib.Protocols.AdcProtocol(trans);
                        trans.SecureUpdate  += new FmdcEventHandler(trans_SecureUpdate);
                        trans.SecureProtocol = FlowLib.Enums.SecureProtocols.TLS;
                        trans.Listen();
                        transferManager.AddTransfer(trans);
                    }

                    trans.Protocol.ChangeDownloadItem += new FmdcEventHandler(Protocol_ChangeDownloadItem);
                    trans.Protocol.RequestTransfer    += new FmdcEventHandler(Protocol_RequestTransfer);
                    trans.ProtocolChange += new FmdcEventHandler(trans_ProtocolChange);
                    e.Handled             = true;
                }
                break;
            }
        }
Exemple #2
0
 protected virtual void DoUPnPIGD()
 {
     try
     {
         // Wait 20 seconds before continue
         int i = 0;
         do
         {
             Thread.Sleep(1 * 1000);
         } while (((Functions.UPnPIGD & Success) != Functions.UPnPIGD) && i++ > 20);
         System.Collections.Generic.SortedList <string, UPnPDevice> tmpDevices = new System.Collections.Generic.SortedList <string, UPnPDevice>(upnp.RootDevices);
         foreach (System.Collections.Generic.KeyValuePair <string, UPnPDevice> devicePair in tmpDevices)
         {
             FlowLib.Events.FmdcEventArgs e = new FlowLib.Events.FmdcEventArgs(Actions.UPnPDeviceDescription, devicePair.Key);
             UpdateBase(this, e);
         }
     }
     finally
     {
         //if ((Functions.UPnPIGD & Success) == Functions.UPnPIGD)
         //{
         Progress = Functions.UPnPExternalRecieveAccess;
         //}
         //else
         //{
         //    Progress = Functions.End;
         //}
     }
 }
Exemple #3
0
        void Connection_Update(object sender, FlowLib.Events.FmdcEventArgs e)
        {
            switch (e.Action)
            {
            case Actions.TransferStarted:
                Transfer trans = e.Data as Transfer;
                if (trans != null)
                {
                    // Here we bind transfer to our data collector
                    stats = new GeneralProtocolDataCollector(trans);
                    if (trans.Protocol == null)
                    {
                        trans.Protocol = new FlowLib.Protocols.AdcProtocol(trans);
                        trans.Listen();
                        transferManager.AddTransfer(trans);
                    }

                    trans.Protocol.ChangeDownloadItem += new FmdcEventHandler(Protocol_ChangeDownloadItem);
                    trans.Protocol.RequestTransfer    += new FmdcEventHandler(Protocol_RequestTransfer);
                    trans.ProtocolChange += new FmdcEventHandler(trans_ProtocolChange);
                    e.Handled             = true;
                }
                break;
            }
        }
Exemple #4
0
 void OnConnectionStatusChange(object sender, FlowLib.Events.FmdcEventArgs e)
 {
     switch (e.Action)
     {
     case TcpConnection.Connected:
         _isConnected = true;
         break;
     }
 }
Exemple #5
0
 void hubConnection_Update(object sender, FlowLib.Events.FmdcEventArgs e)
 {
     switch (e.Action)
     {
     case Actions.SearchResult:
         if (e.Data is SearchResultInfo)
         {
             SearchResultInfo srInfo = (SearchResultInfo)e.Data;
         }
         break;
     }
 }
Exemple #6
0
        void hubConnection_Update(object sender, FlowLib.Events.FmdcEventArgs e)
        {
            Hub hub = sender as Hub;

            if (hub == null)
            {
                return;
            }
            switch (e.Action)
            {
            case Actions.SearchResult:
                if (e.Data is SearchResultInfo)
                {
                    SearchResultInfo srInfo = (SearchResultInfo)e.Data;
                    // This is if we want to enable auto adding of sources to a downloaditem.
                    //FlowLib.Managers.DownloadManager dm = new FlowLib.Managers.DownloadManager();
                    //DownloadItem tmpDownloadItem = new DownloadItem(srInfo.Info);
                    //// Do downloadItem exist?
                    //if (dm.ContainsDownload(tmpDownloadItem))
                    //{
                    //    // Add Source to the existing downloaditem. Note that we first check if it exist.
                    //    dm.AddDownload(tmpDownloadItem, srInfo.Source);
                    //}
                }
                break;

            case Actions.UserOnline:
                bool hasMe = (hub.GetUserById(hub.Me.ID) != null);
                if (!sentRequest && hasMe)
                {
                    // Send Search
                    SearchInfo searchInfo = new SearchInfo();
                    searchInfo.Set(SearchInfo.SEARCH, "Ubuntu");
                    //searchInfo.Set(SearchInfo.SIZE, "1000");
                    //searchInfo.Set(SearchInfo.SIZETYPE, "1");
                    UpdateBase(this, new FlowLib.Events.FmdcEventArgs(Actions.Search, searchInfo));
                    sentRequest = true;
                }
                break;
            }
        }
Exemple #7
0
        protected virtual void DoInternalListenAccess_Update(object sender, FlowLib.Events.FmdcEventArgs e)
        {
            switch (e.Action)
            {
            case Actions.TransferStarted:
                Transfer trans = e.Data as Transfer;
                if (trans != null)
                {
                    if (trans.Protocol == null)
                    {
                        trans.Protocol = new FlowLib.Protocols.TransferNmdcProtocol(trans);
                        trans.Listen();
                        transferManager.AddTransfer(trans);
                    }

                    trans.Protocol.RequestTransfer += new FmdcEventHandler(DoInternalListenAccess_RequestTransfer);
                    e.Handled = true;
                }
                break;
            }
        }
 void DcBot_UpdateBase(object sender, FlowLib.Events.FmdcEventArgs e)
 {
 }
Exemple #9
0
 void Downloading_In_PassiveMode_UpdateBase(object sender, FlowLib.Events.FmdcEventArgs e)
 {
 }
Exemple #10
0
 void PassiveSearch_UpdateBase(object sender, FlowLib.Events.FmdcEventArgs e)
 {
 }
        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;
            }
        }
Exemple #12
0
 void SendMainChatOrPMToHub_UpdateBase(object sender, FlowLib.Events.FmdcEventArgs e)
 {
 }
Exemple #13
0
 protected virtual void DoUPnPIGD()
 {
     try
     {
         // Wait 20 seconds before continue
         int i = 0;
         do
         {
             Thread.Sleep(1 * 1000);
         } while (((Functions.UPnPIGD & Success) != Functions.UPnPIGD) && i++ > 20);
         System.Collections.Generic.SortedList<string, UPnPDevice> tmpDevices = new System.Collections.Generic.SortedList<string, UPnPDevice>(upnp.RootDevices);
         foreach (System.Collections.Generic.KeyValuePair<string, UPnPDevice> devicePair in tmpDevices)
         {
             FlowLib.Events.FmdcEventArgs e = new FlowLib.Events.FmdcEventArgs(Actions.UPnPDeviceDescription, devicePair.Key);
             UpdateBase(this, e);
         }
     }
     finally
     {
         //if ((Functions.UPnPIGD & Success) == Functions.UPnPIGD)
         //{
             Progress = Functions.UPnPExternalRecieveAccess;
         //}
         //else
         //{
         //    Progress = Functions.End;
         //}
     }
 }
Exemple #14
0
        public void Hub_Update(object sender, FlowLib.Events.FmdcEventArgs e)
        {
            Hub hub = (Hub)sender;

            this.hub = hub;
            string str = string.Empty;

            switch (e.Action)
            {
            case Actions.TransferStarted:
                if (e.Data is ITransfer)
                {
                    ITransfer trans = (ITransfer)e.Data;
                    transferManager.StartTransfer(trans);
                }
                break;

            case Actions.TransferRequest:
                if (e.Data is TransferRequest)
                {
                    TransferRequest req = (TransferRequest)e.Data;
                    transferManager.AddTransferReq(req);
                }
                break;

                #region MainMessage
            case Actions.MainMessage:
                if (e.Data is MainMessage)
                {
                    MainMessage mainchat = (MainMessage)e.Data;
                    if (mainchat.From == null)
                    {
                        str = mainchat.Content;
                    }
                    else
                    {
                        User u = hub.GetUserById(mainchat.From);
                        if (u == null)
                        {
                            str = "<" + mainchat.From + "> " + mainchat.Content;
                        }
                        else
                        {
                            str = "<" + u.DisplayName + "> " + mainchat.Content;
                        }
                    }
                    // Test : Start
                    user = hub.GetUserById("DC++0.699");
                    //User user = hub.GetUserById("DCDM++0.0495");
                    if (user != null && hub.Share != null)
                    {
                        ContentInfo ci = new ContentInfo(ContentInfo.FILELIST, FlowLib.Utils.FileLists.BaseFilelist.UNKNOWN);
                        ci.Set(ContentInfo.STORAGEPATH, @"C:\Private\FMDC\PiP\FlowLibDemo\ConsoleDemo\bin\Debug\FileLists\" + user.ID + ".xml.bz2");
                        DownloadItem di = new DownloadItem(ci);
                        downloadManager.AddDownload(di, new Source(null, user.ID));
                        downloadManager.DownloadCompleted += new FmdcEventHandler(DownloadManager_DownloadCompleted);
                        this.Hub_Update(null, new FmdcEventArgs(Actions.TransferRequest, new TransferRequest(user.ID, hub, user.UserInfo)));
                        //TransferManager.AddTransferReq(user.ID, hub, user.UserInfo);
                        hub.Send(new FlowLib.Protocols.HubNmdc.ConnectToMe(user.ID, hub.Share.Port, hub));
                    }
                    // Test : End
                }
                else
                {
                    str = e.Data.ToString();
                }
                Console.WriteLine(str);
                break;

                #endregion
                #region PrivateMessage
            case Actions.PrivateMessage:
                PrivateMessage to = (PrivateMessage)e.Data;
                Console.WriteLine("*** PM From: " + to.From + ", To: " + to.To + " " + to.Content);
                break;

                #endregion
                #region RegMode
            case Actions.RegMode:
                break;

                #endregion
                #region Status
            case Actions.StatusChange:
                HubStatus status = (HubStatus)e.Data;
                switch (status.Code)
                {
                case HubStatus.Codes.Disconnected:
                    Console.WriteLine("*** Hub Disconnected");
                    if (status.Exception != null)
                    {
#if DEBUG
                        if (status.Exception is System.Net.Sockets.SocketException)
                        {
                            System.Net.Sockets.SocketException se = (System.Net.Sockets.SocketException)status.Exception;
                            StringBuilder sb = new StringBuilder();
                            sb.Append("\r\n");
                            sb.Append("\tErrorCode: " + se.ErrorCode + "\r\n");
                            sb.Append("\tMessage: " + se.Message + "\r\n");
                            sb.Append("\tStackTrace: " + se.StackTrace);
                            Console.WriteLine(sb.ToString());
                        }
#else
                        Console.WriteLine(" : " + status.Exception.Message);
                        //richTextBox1.AppendText(status.Exception.StackTrace);
#endif
                    }
                    Console.WriteLine("\r\n");
                    break;

                case HubStatus.Codes.Connected:
                    Console.WriteLine("*** Hub Connected");
                    break;

                case HubStatus.Codes.Connecting:
                    Console.WriteLine("*** Hub Connecting");
                    break;
                }
                break;

                #endregion
            default:
                Console.WriteLine(e.Data);
                break;
            }
        }