コード例 #1
0
        /// <summary>
        /// Answers Genuine Channels URI and Transport Context via which access to the remote
        /// MarshalByRefObject object is performed.
        /// </summary>
        /// <param name="marshalByRefObject">MarshalByRefObject instance to fetch the URI from.</param>
        /// <param name="uri">The uri.</param>
        /// <param name="iTransportContext">The transport context.</param>
        public static void FetchChannelUriFromMbr(MarshalByRefObject marshalByRefObject, out string uri, out ITransportContext iTransportContext)
        {
            IDictionary iDictionary = ChannelServices.GetChannelSinkProperties(marshalByRefObject);

            uri = iDictionary["GC_URI"] as string;
            iTransportContext = iDictionary["GC_TC"] as ITransportContext;
        }
コード例 #2
0
        static void Main(string[] args)
        {
            try
            {
                String filename = "client.exe.config";
                RemotingConfiguration.Configure(filename);

                CustomerManager mgr = new CustomerManager();

                Console.WriteLine("Client.Main(): Reference to CustomerManager " +
                                  " acquired");

                IDictionary props = ChannelServices.GetChannelSinkProperties(mgr);
                props["username"] = "******";
                props["password"] = "******";

                Customer cust = mgr.getCustomer(4711);
                cust = mgr.getCustomer(4711);
                cust = mgr.getCustomer(4711);
                cust = mgr.getCustomer(4711);
                int age = cust.getAge();
                Console.WriteLine("Client.Main(): Customer {0} {1} is {2} " +
                                  "years old.",
                                  cust.FirstName,
                                  cust.LastName,
                                  age);
            }
            catch (Exception e)
            {
                Console.WriteLine("EX: {0}", e.Message);
            }

            Console.ReadLine();
        }
コード例 #3
0
        private void ActivateObjects()
        {
            DeactivateObjects();
            remotingObject = (ObjectType)Activator.GetObject(typeof(ObjectType), "tcp://" + server + ":" + port + "/" + serviceUri);
            IDictionary di = ChannelServices.GetChannelSinkProperties(remotingObject);

            di["customerid"]      = sProps["customerid"];
            di["extensionnumber"] = sProps["extensionnumber"];
            di["password"]        = sProps["password"];
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: anaska/WhisperChat
        private static void Init()
        {
            RemotingConfiguration.Configure("ChatClient.exe.config", false);

            Server = (IChatServer)Activator.GetObject(
                typeof(IChatServer),
                "tcp://192.168.175.1:8001/chat");

            IDictionary props = ChannelServices.GetChannelSinkProperties(Server);

            props["username"] = "******";
            props["password"] = "******";
        }
コード例 #5
0
        public static void Main()
        {
            ListDictionary myProperties = new ListDictionary();

            myProperties.Add("port", 8085);
            myProperties.Add("name", "MyHttpChannel");
// <Snippet1>
            HttpChannel myClientChannel = new HttpChannel(myProperties,
                                                          new SoapClientFormatterSinkProvider(),
                                                          new SoapServerFormatterSinkProvider());

            ChannelServices.RegisterChannel(myClientChannel);
            // Get the registered channel.
            Console.WriteLine("Channel Name : " + ChannelServices.GetChannel(
                                  myClientChannel.ChannelName).ChannelName);
            Console.WriteLine("Channel Priorty : " + ChannelServices.GetChannel(
                                  myClientChannel.ChannelName).ChannelPriority);
// </Snippet1>
            HelloServer myProxy = (HelloServer)Activator.GetObject(typeof(
                                                                       RemotingSamples.HelloServer), "http://localhost:8086/SayHello");
// <Snippet2>
            // Get an IDictionary of properties for a given proxy.
            IDictionary myDictionary = ChannelServices.
                                       GetChannelSinkProperties(myProxy);
            ICollection myKeysCollection = myDictionary.Keys;

            object[]    myKeysArray        = new object[myKeysCollection.Count];
            ICollection myValuesCollection = myDictionary.Values;

            object[] myValuesArray = new object[myValuesCollection.Count];
            myKeysCollection.CopyTo(myKeysArray, 0);
            myValuesCollection.CopyTo(myValuesArray, 0);
            for (int iIndex = 0; iIndex < myKeysArray.Length; iIndex++)
            {
                Console.WriteLine("Property Name : " + myKeysArray[iIndex] +
                                  " value : " + myValuesArray[iIndex]);
            }
// </Snippet2>
            if (myProxy == null)
            {
                System.Console.WriteLine("Could not locate server");
            }
            else
            {
                Console.WriteLine(myProxy.HelloMethod("Caveman"));
            }
        }
コード例 #6
0
        public void print(string username, string password, string profileName)
        {
            var         ps    = (IPrintingService)Activator.GetObject(typeof(IPrintingService), "tcp://" + Properties.Settings.Default.PSHost + ":5555/PrintingService");
            IDictionary props = ChannelServices.GetChannelSinkProperties(ps);

            props["timeout"]           = 5000;
            props["connectionTimeout"] = 3000;

            var txtDoc = new TextDocument();

            txtDoc.Description = "WiFi";
            txtDoc.User        = "******";

            // koristim za boldovani text kod komandi
            txtDoc.LineFormats.Add("{\\Ac}");       // index 0
            txtDoc.LineFormats.Add("{\\sbhw\\Ac}"); // index 1

            string[] str = Properties.Settings.Default.Header.Split('\\');

            // stampam zaglavlje
            foreach (string line in str)
            {
                txtDoc.Commands.Add(new PrintLineCommand(0, new string[] { line }));
            }

            txtDoc.Commands.Add(new PrintLineCommand(0, new string[] { "================================" }));

            txtDoc.Commands.Add(new PrintLineCommand(1, new string[] { "Password: "******"Password: "******"================================" }));
            txtDoc.Commands.Add(new PrintLineCommand(0, new string[] { profileName + "" }));

            //txtDoc.LineFormats.Add("{\\sbh\\Ac}");
            //txtDoc.LineFormats.Add("{\\Ac}");
            //foreach (string s in str)
            //{
            //    txtDoc.Commands.Add(new PrintLineCommand(0,new string[] {s}));
            //}

            //txtDoc.Commands.Add(new PrintLineCommand(0, new string[] { "Test 1" }));
            txtDoc.Commands.Add(new LineFeedCommand(3));
            txtDoc.Commands.Add(new CutCommand(true));
            ps.QueueTextDocument(Properties.Settings.Default.PSName, txtDoc);
        }
コード例 #7
0
        /// <summary>
        /// Gets a Transport Context servicing the specified transparent proxy.
        /// </summary>
        /// <param name="marshalByRefObject">The transparent proxy.</param>
        /// <returns>The Transport Context.</returns>
        public static ITransportContext FetchTransportContextFromMbr(MarshalByRefObject marshalByRefObject)
        {
            IDictionary iDictionary = ChannelServices.GetChannelSinkProperties(marshalByRefObject);

            return(iDictionary["GC_TC"] as ITransportContext);
        }
コード例 #8
0
        /// <summary>
        /// Registers the receiver and associate the provided object with it.
        /// Returns false if the receiver has already been registered.
        /// WARNING: does not check whether the receiver supports the required interface (via Reflection)
        /// because this check requires client's dll.
        /// </summary>
        /// <param name="obj">The receiver being registered.</param>
        /// <param name="tag">The object associated with the receiver. This object is accessible when receiver is being unregistered or during filtering.</param>
        /// <param name="remoteGenuineUri">The uri of the remote host provided by any of Genuine Channels.</param>
        /// <param name="transportContext">The transport context of the remote host.</param>
        /// <returns>False if the receiver has been already registered.</returns>
        public bool Add(MarshalByRefObject obj, object tag, string remoteGenuineUri, ITransportContext transportContext)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            BinaryLogWriter binaryLogWriter = GenuineLoggingServices.BinaryLogWriter;

            // check if it is in the list
            string uri = RemotingServices.GetObjectUri(obj);

            if (uri == null && !RemotingServices.IsObjectOutOfAppDomain(obj))
            {
                // it was not marshalled
                RemotingServices.Marshal(obj);
                uri = RemotingServices.GetObjectUri(obj);
            }

            using (ReaderAutoLocker reader = new ReaderAutoLocker(this._readerWriterLock))
            {
                if (this._receivers.ContainsKey(uri))
                {
                    return(false);
                }
            }

            // this check can not be performed because client's dll is required
//			// check on the interface
//			bool supportInterface = false;
//			foreach(Type interfaceType in obj.GetType().GetInterfaces())
//				if (interfaceType == this._interfaceToSupport)
//				{
//					supportInterface = true;
//					break;
//				}
//			if (! supportInterface)
//				throw GenuineExceptions.Get_Broadcast_ObjectDoesNotSupportDestinationInterface();

            // adds the object to the receiver list
            ReceiverInfo receiverInfo = new ReceiverInfo();

            receiverInfo.MbrObject = obj;
            receiverInfo.MbrUri    = uri;
            receiverInfo.Tag       = tag;

            if (binaryLogWriter != null)
            {
                try
                {
                    if (receiverInfo.MbrObject != null)
                    {
                        receiverInfo.DbgRemoteHost = GenuineUtility.FetchHostInformationFromMbr(receiverInfo.MbrObject);
                    }
                }
                catch (Exception ex)
                {
                    binaryLogWriter.WriteImplementationWarningEvent("Dispatcher.Add",
                                                                    LogMessageType.Error, ex, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name,
                                                                    "Can't get HostInformation from MbrObject.");
                }
            }

            ObjRef objRef = receiverInfo.MbrObject.CreateObjRef(typeof(MarshalByRefObject));

            receiverInfo.Local = objRef.IsFromThisAppDomain();

            // cache object's info to speed up sending thru Genuine Channels
            if (!receiverInfo.Local)
            {
                if (remoteGenuineUri != null)
                {
                    receiverInfo.IClientChannelSink = new GenuineTcpClientTransportSink(remoteGenuineUri, transportContext);
                }
                else
                {
                    // check whether the client sink has registered itself on this MBR
                    receiverInfo.IClientChannelSink = ChannelServices.GetChannelSinkProperties(obj)["GC_TS"] as IClientChannelSink;
                    if (receiverInfo.IClientChannelSink == null)
                    {
                        throw GenuineExceptions.Get_Broadcast_ClientSinkIsUnknown();
                    }
                }

                // object uri
                receiverInfo.SerializedObjRef = objRef;

//				// and shell's uri
//				string shellUri;
//				ITransportContext iTransportContext;
//				GenuineUtility.FetchChannelUriFromMbr(obj, out shellUri, out iTransportContext);
//				if (shellUri == null)
//					throw GenuineExceptions.Get_Send_NoSender(objRef.URI);
//
//				receiverInfo.ReceiverUri = shellUri;
            }

            // LOG:
            if (binaryLogWriter != null && binaryLogWriter[LogCategory.BroadcastEngine] > 0)
            {
                binaryLogWriter.WriteBroadcastEngineEvent(LogCategory.BroadcastEngine, "Dispatcher.Add",
                                                          LogMessageType.BroadcastRecipientAdded, null, null, receiverInfo.DbgRemoteHost, null,
                                                          GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name,
                                                          null, null, false, this, null, true, receiverInfo,
                                                          null, null,
                                                          "The broadcast recipient is added.");
            }

            // register the sponsor to prevent unexpected reclaiming
            ILease lease = (ILease)RemotingServices.GetLifetimeService(obj);

            if (lease != null)
            {
                lease.Register(this.GlobalSponsor);
            }

            // and register it
            using (WriterAutoLocker writer = new WriterAutoLocker(this._readerWriterLock))
            {
                this._cachedReceiversInfoArray = null;
                this._receivers[uri]           = receiverInfo;
            }
            return(true);
        }