Beispiel #1
0
        public static void GetInstance(string uniqueName = "OpenRPAService")
        {
            if (RemoteInstance != null)
            {
                try
                {
                    RemoteInstance.Ping();
                    return;
                }
                catch (Exception)
                {
                }
            }
            //if (secondInstanceChannel == null)
            //{
            //    secondInstanceChannel = new IpcClientChannel();
            //    ChannelServices.RegisterChannel(secondInstanceChannel, true);
            //}
            try
            {
                IpcClientChannel secondInstanceChannel = new IpcClientChannel();
                ChannelServices.RegisterChannel(secondInstanceChannel, true);
            }
            catch (Exception ex)
            {
                Log.Debug(ex.ToString());
            }
            string applicationIdentifier = uniqueName + Environment.UserName;
            string channelName           = String.Concat(applicationIdentifier, Delimiter, ChannelNameSuffix);
            string remotingServiceUrl    = IpcProtocol + channelName + "/" + RemoteServiceName;

            // Obtain a reference to the remoting service exposed by the server i.e the first instance of the application
            RemoteInstance = (OpenRPAService)RemotingServices.Connect(typeof(OpenRPAService), remotingServiceUrl);
            RemoteInstance.Ping();
        }
Beispiel #2
0
 public static bool GetInstance(string uniqueName = "OpenRPAService", bool ChildSession = false)
 {
     try
     {
         if (RemoteInstance != null && _ChildSession == ChildSession)
         {
             try
             {
                 RemoteInstance.Ping();
                 return(true);
             }
             catch (Exception)
             {
             }
         }
         _ChildSession = ChildSession;
         try
         {
             if (ChannelServices.RegisteredChannels.Length > 0 && secondInstanceChannel != null)
             {
                 try
                 {
                     ChannelServices.UnregisterChannel(secondInstanceChannel);
                 }
                 catch (Exception)
                 {
                 }
             }
             secondInstanceChannel = new IpcClientChannel();
             ChannelServices.RegisterChannel(secondInstanceChannel, true);
         }
         catch (Exception ex)
         {
             Log.Debug(ex.ToString());
         }
         string channelName        = String.Concat(ApplicationIdentifier(uniqueName, ChildSession), Delimiter, ChannelNameSuffix);
         string remotingServiceUrl = IpcProtocol + channelName + "/" + RemoteServiceName;
         // Obtain a reference to the remoting service exposed by the server i.e the first instance of the application
         RemoteInstance = (OpenRPAService)RemotingServices.Connect(typeof(OpenRPAService), remotingServiceUrl);
         RemoteInstance.Ping();
     }
     catch (Exception)
     {
         return(false);
     }
     return(true);
 }
Beispiel #3
0
        private static void CreateRemoteService(string channelName)
        {
            BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();

            serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
            IDictionary props = new Dictionary <string, string>();

            props["authorizedGroup"]     = GetUsersGroupName();
            props["name"]                = channelName;
            props["portName"]            = channelName;
            props["exclusiveAddressUse"] = "false";

            // Create the IPC Server channel with the channel properties
            channel = new IpcServerChannel(props, serverProvider);

            // Register the channel with the channel services
            ChannelServices.RegisterChannel(channel, true);

            // Expose the remote service with the REMOTE_SERVICE_NAME
            RemoteInstance = new OpenRPAService();
            RemotingServices.Marshal(RemoteInstance, RemoteServiceName);
            RemoteInstance.Ping();
        }