コード例 #1
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;
            }
        }
コード例 #2
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)
                {
                    // Here we bind transfer to our data collector
                    stats = new GeneralProtocolDataCollector(trans);
                    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;
            }
        }
コード例 #3
0
        public CollectTransferedInformationForHub()
        {
            HubSetting settings = new HubSetting();

            settings.Address     = "127.0.0.1";
            settings.Port        = 411;
            settings.DisplayName = "FlowLib";
            settings.Protocol    = "Auto"; // Here we tell it we dont care what protocol it uses (Adc or Nmdc). Just try to connect.

            Hub hubConnection = new Hub(settings);

            // Here we bind hub to our data collector
            stats = new GeneralProtocolDataCollector(hubConnection);
            hubConnection.Connect();
            General.BinaryPrefixes bp;
            Console.WriteLine("Press any key to update information");
            do
            {
                Console.ReadKey(true);
                Console.Clear();
                Console.WriteLine("Press any key to update information");
                Console.WriteLine("==================================");
                Console.WriteLine("Total data sent: " + General.FormatBytes(stats.TotalBytesSent, out bp) + bp);
                Console.WriteLine("Total data received: " + General.FormatBytes(stats.TotalBytesReceived, out bp) + bp);
                Console.WriteLine("current download speed: " + General.FormatBytes(stats.CurrentReceiveSpeed, out bp) + bp + "/s");
                Console.WriteLine("current upload speed: " + General.FormatBytes(stats.CurrentSendSpeed, out bp) + bp + "/s");
                Decimal d = new decimal(stats.MaximumReceiveSpeed);
                Console.WriteLine("Maximum download speed: " + General.FormatBytes(decimal.ToInt64(d), out bp) + bp + "/s");
                d = new decimal(stats.MaximumSendSpeed);
                Console.WriteLine("Maximum upload speed: " + General.FormatBytes(decimal.ToInt64(d), out bp) + bp + "/s");
                d = new decimal(stats.MinimumReceiveSpeed);
                Console.WriteLine("Minimum download speed: " + General.FormatBytes(decimal.ToInt64(d), out bp) + bp + "/s");
                d = new decimal(stats.MinimumSendSpeed);
                Console.WriteLine("Minimum upload speed: " + General.FormatBytes(decimal.ToInt64(d), out bp) + bp + "/s");
                Console.WriteLine("==================================");
            } while (true);
        }