示例#1
0
        /// <summary>
        /// Standard run-method. Call this for the 'search'-action.
        /// </summary>
        /// <param name="args">The commandline-parameters.</param>
        public override void Run(string[] args)
        {
            String peerID = null;
            String attr   = "Name";
            String val    = @"*";
            //String query = null;
            //String infile = null;
            Int32 num = 10;

            try
            {
                if (args.Length == 1)
                {
                    operation = operations.local;
                }
                else
                {
                    for (int i = 1; i < args.Length; i++)
                    {
                        switch (args[i])
                        {
                        case "-p":
                            operation = operations.remote;
                            peerID    = args[++i].Trim();
                            break;

                        case "-r":
                            operation = operations.remote;
                            break;

                        case "-f":
                            operation = operations.flush;
                            break;

                        case "-a":
                            operation = operations.local;
                            attr      = args[++i].Trim();
                            break;

                        case "-n":
                            operation = operations.local;
                            num       = Convert.ToInt32(args[++i].Trim());
                            break;

                        case "-v":
                            operation = operations.local;
                            val       = args[++i].Trim();
                            break;

                        /*case "-q":
                         *  operation = operations.remote;
                         *  query = args[++i].Trim();
                         *  break;*/
                        /*case "-i":
                         *  operation = operations.remote;
                         *  infile = args[++i].Trim();
                         *  query = ReadQueryFile(infile);
                         *  break;*/
                        case "-h":
                            operation = operations.help;
                            break;

                        default:
                            textWriter.WriteLine("Error: invalid parameter");
                            return;
                        }
                    }
                }
            }
            catch
            {
                textWriter.WriteLine("Error: invalid parameter");
                return;
            }

            switch (operation)
            {
            case operations.remote:
                PeerSearch(peerID, attr, val, num /*, query*/);
                break;

            case operations.local:
                PeerSearch(peerID, attr, val, num /*, query*/);
                break;

            case operations.flush:
                textWriter.WriteLine("Flushing...");
                discovery.FlushAdvertisements(null, DiscoveryService.DISC_ADV);
                break;

            case operations.help:
                Help();
                return;
            }
        }
示例#2
0
        /// <summary>
        /// Standard run-method. Call this for the 'peers'-action.
        /// </summary>
        /// <param name="args">The commandline-parameters.</param>
        public override void Run(string[] args)
        {
            DiscoveryService dis = netPeerGroup.DiscoveryService;

            bool remote = false;
            bool flush  = false;

            string attr = "";
            string val  = "";
            //			string peer = "";

            int responses = 10;

            try
            {
                for (int i = 1; i < args.Length; i++)
                {
                    switch (args[i])
                    {
                    case "-r":
                        remote = true;
                        break;

                    case "-f":
                        flush = true;
                        break;

                    case "-h":
                        Help();
                        return;

                    case "-a":
                        attr = args[++i].Trim();
                        break;

                    case "-v":
                        val = args[++i].Trim();
                        break;

                    case "-n":
                        responses = Int32.Parse(args[++i].Trim());
                        break;

                    /*case "p":
                    * peer = args[++i].Trim();
                    * break; */
                    default:
                        textWriter.WriteLine("Error: invalid parameter");
                        return;
                    }
                }
            }
            catch
            {
                textWriter.WriteLine("Error: invalid parameter");
                return;
            }

            if (flush)
            {
                dis.FlushAdvertisements(null, DiscoveryService.DISC_PEER);
                return;
            }

            if (remote)
            {
                dis.GetRemoteAdvertisements(null, DiscoveryService.DISC_PEER, attr, val, responses);

                textWriter.WriteLine("peer discovery message send");
                return;
            }

            List <Advertisement> vec = dis.GetLocalAdvertisements(DiscoveryService.DISC_PEER, attr, val);

            for (int i = 0; i < vec.Count; i++)
            {
                textWriter.WriteLine("peer" + i + ": " + ((PeerAdvertisement)vec[i]).Name);
            }

            if (vec.Count == 0)
            {
                textWriter.WriteLine("No peer advertisements retrieved");
            }
        }