private void RunProfilingTypes()
        {
            ProfilingTypeSettingsCollection profilingTypesSettings = _configurationSettings.ProfilingTypesSettings;
            List <IProfilingTypeAdapter>    adapters = new List <IProfilingTypeAdapter>();

            foreach (ProfilingTypeSettings profilingTypeSettings in profilingTypesSettings)
            {
                IProfilingType        profilingType = ProfilingTypes[profilingTypeSettings.Uid];
                IProfilingTypeAdapter adapter       = profilingType.GetWinAdapter();
                adapters.Add(adapter);
            }
            foreach (IProfilingTypeAdapter adapter in adapters)
            {
                IServiceConsumer serviceConsumer = adapter as IServiceConsumer;
                if (serviceConsumer != null)
                {
                    serviceConsumer.ExportServices(_session.ServiceContainer);
                }
            }
            foreach (IProfilingTypeAdapter adapter in adapters)
            {
                IServiceConsumer serviceConsumer = adapter as IServiceConsumer;
                if (serviceConsumer != null)
                {
                    serviceConsumer.ImportServices(_session.ServiceContainer);
                }
            }
        }
예제 #2
0
        public BotInstance(IServiceConsumer <ISteamBotCoordinator> coordinator, ILogProvider logProvider,
                           BotCookieManager cookieManager, MqClientProvider mqClientProvider)
        {
            _coordinator      = coordinator;
            _logger           = logProvider.Logger;
            _mqClientProvider = mqClientProvider;
            CookieManager     = cookieManager;

            _callbackManager = new CallbackManager(SteamClient);

            _callbackManager.Subscribe <SteamClient.ConnectedCallback>(OnConnected);
            _callbackManager.Subscribe <SteamClient.DisconnectedCallback>(OnDisconnected);

            _callbackManager.Subscribe <SteamUser.LoggedOnCallback>(OnLoggedOn);
            _callbackManager.Subscribe <SteamUser.UpdateMachineAuthCallback>(OnUpdateMachineAuth);
            _callbackManager.Subscribe <SteamUser.LoginKeyCallback>(OnLoginKeyReceived);

            _callbackManager.Subscribe <SteamFriends.PersonaStateCallback>(OnPersonaStateChanged);
            _callbackManager.Subscribe <SteamFriends.FriendsListCallback>(OnFriendListUpdated);
            _callbackManager.Subscribe <SteamFriends.FriendMsgCallback>(OnFriendMessageReceived);

            _steamUser   = SteamClient.GetHandler <SteamUser>();
            SteamFriends = SteamClient.GetHandler <SteamFriends>();
            SteamApps    = SteamClient.GetHandler <SteamApps>();
        }
        private void RunProductivities()
        {
            List <IProductivityAdapter> adapters = new List <IProductivityAdapter>();

            foreach (IProductivity productivity in Productivities)
            {
                IProductivityAdapter adapter = productivity.GetWinAdapter();
                adapters.Add(adapter);
            }
            foreach (IProductivityAdapter adapter in adapters)
            {
                IServiceConsumer serviceConsumer = adapter as IServiceConsumer;
                if (serviceConsumer != null)
                {
                    serviceConsumer.ExportServices(_session.ServiceContainer);
                }
            }
            foreach (IProductivityAdapter adapter in adapters)
            {
                IServiceConsumer serviceConsumer = adapter as IServiceConsumer;
                if (serviceConsumer != null)
                {
                    serviceConsumer.ImportServices(_session.ServiceContainer);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Load a consumer object into its own app domain
        /// </summary>
        /// <param name="assemblyName"></param>
        /// <param name="typeName"></param>
        /// <param name="name"></param>
        private void LoadConsumer(String assemblyName, String typeName, String name)
        {
            Assembly assembly     = Assembly.Load(assemblyName);
            Type     consumerType = assembly.GetType(typeName);

            if (consumerType == null)
            {
                Log.Error("Consumer type could not be loaded: '" + name + "'");
                return;
            }
            IServiceConsumer consumer = Activator.CreateInstance(assembly.GetType(typeName)) as IServiceConsumer;

            if (consumer == null)
            {
                Log.Error("Consumer instance could not be created or does not derive from IServiceConsumer: '" + name + "'");
                return;
            }

            Object[] attributes = consumer.GetType().GetCustomAttributes(typeof(GuidAttribute), true);
            Guid     consumerId = (attributes.Length == 0 ? Guid.Empty : new Guid(((GuidAttribute)attributes[0]).Value));

            if (consumerId == Guid.Empty)
            {
                Log.Error("Consumer '" + typeName + "' has no Guid assigned");
                return;
            }

            ServiceConsumerInfo info = new ServiceConsumerInfo();

            info.Id = consumerId;
            info.ServiceConsumer         = consumer;
            ServiceConsumers[consumerId] = info;
        }
 public void Initialize()
 {
     serviceAMock = new Mock <IServiceA>();
     serviceBMock = new Mock <IServiceB>();
     sut          = new ServiceConsumer(
         serviceAMock.Object,
         serviceBMock.Object);
 }
예제 #6
0
        /// <summary>
        /// Get pre-connection information for a service
        /// </summary>
        /// <param name="appId">The id of the service</param>
        /// <returns>Returns connection information like the config datatype</returns>
        public ServiceConnectData GetConnectData(Guid appId)
        {
            // find the service consumer
            ServiceConsumerInfo consumerInfo;

            if (!ServiceConsumers.TryGetValue(appId, out consumerInfo))
            {
                return(new ServiceConnectData());
            }

            IServiceConsumer consumer = consumerInfo.ServiceConsumer;

            return(new ServiceConnectData(consumer.ConfigData));
        }
예제 #7
0
    /// <summary>
    /// Registers a Service Consumer if the service exists
    /// </summary>
    /// <param name="consumer"></param>
    /// <param name="consumedServiceName"></param>
    /// <param name="stackIfServiceDoesNotExist">if true, the consumer will be stacked and registered, as soon as the correct service registeres</param>
    /// <returns></returns>
    public bool RegisterServiceConsumer(IServiceConsumer <IServiceMessage> consumer, string consumedServiceName, bool stackIfServiceDoesNotExist = true)
    {
        //Check if service exists
        if (serviceNameTable.ContainsKey(consumedServiceName))
        {
            var service = serviceNameTable[consumedServiceName];
            serviceTable[service].Add(consumer);

            if (service.SendMessageToNewSubscribers)
            {
                consumer.ConsumeServiceItem(service.RetrieveServiceItem(), service.GetServiceName());
            }

            return(true);
        }
        else
        {
            if (stackIfServiceDoesNotExist)
            {
                //Add consumer to stack
                if (consumerStack.ContainsKey(consumedServiceName))
                {
                    consumerStack[consumedServiceName].Add(consumer);
                }
                else
                {
                    consumerStack[consumedServiceName] = new List <IServiceConsumer <IServiceMessage> >()
                    {
                        consumer
                    };
                }
                //Debug.Log($"Service with the name {consumedServiceName} does not exist, consumer was stacked");
                return(true);
            }

            //Debug.Log($"Service with the name {consumedServiceName} does not exist");
            return(false);
        }
    }
예제 #8
0
    /// <summary>
    /// Unregisters a service consumer if exists
    /// </summary>
    /// <param name="consumer"></param>
    /// <param name="consumedServiceName"></param>
    /// <returns></returns>
    public bool UnregisterServiceConsumer(IServiceConsumer <IServiceMessage> consumer, string consumedServiceName)
    {
        //Remove consumer from stack if it exists
        if (consumerStack.ContainsKey(consumedServiceName))
        {
            consumerStack[consumedServiceName].Remove(consumer);
            if (consumerStack[consumedServiceName].Count == 0)
            {
                consumerStack.Remove(consumedServiceName);
            }
        }

        if (serviceNameTable.ContainsKey(consumedServiceName))
        {
            serviceTable[serviceNameTable[consumedServiceName]].Remove(consumer);
            return(true);
        }
        else
        {
            //Debug.Log($"Service with the name {consumedServiceName} does not exist");
            return(false);
        }
    }
예제 #9
0
        public SteamBot(ILogProvider logProvider, IServiceConsumer <ISteamBotCoordinator> coordinator,
                        SteamBotCoordinatorCallback callback)
        {
            ServiceName = "Keylol.SteamBot";

            _logger           = logProvider.Logger;
            Coordinator       = coordinator;
            callback.SteamBot = this;

            _heartbeatTimer.Elapsed += (sender, args) =>
            {
                try
                {
                    Coordinator.Operations.Ping();
                }
                catch (Exception e)
                {
                    _logger.Warn("Ping failed.", e);
                    Coordinator.Close();
                }
                _heartbeatTimer.Start();
            };
        }
예제 #10
0
        public ImageGarage(ILogProvider logProvider, MqClientProvider mqClientProvider,
                           IServiceConsumer <IImageGarageCoordinator> coordinator)
        {
            ServiceName = "Keylol.ImageGarage";

            _logger            = logProvider.Logger;
            _mqChannel         = mqClientProvider.CreateModel();
            _coordinator       = coordinator;
            Config.HtmlEncoder = new HtmlEncoderNone();

            _heartbeatTimer.Elapsed += (sender, args) =>
            {
                try
                {
                    _coordinator.Operations.Ping();
                }
                catch (Exception e)
                {
                    _logger.Warn("Ping failed.", e);
                    _coordinator.Close();
                }
                _heartbeatTimer.Start();
            };
        }
예제 #11
0
 /// <summary>
 /// Sets the retry policy.
 /// </summary>
 /// <typeparam name="TServiceInterface">The type of the service interface.</typeparam>
 /// <param name="serviceConsumer">The service consumer.</param>
 /// <param name="retryPolicy">The retry policy.</param>
 public static void SetRetryPolicy <TServiceInterface>(this IServiceConsumer <TServiceInterface> serviceConsumer, RetryPolicy retryPolicy)
 {
     serviceConsumer.RetryPolicy = new RetryPolicyAdapter(retryPolicy);
 }
 public AgenteAdministracion()
 {
     proxy = ServiceConsumerFactory.Create <IServicioAdministracion>(() => new ServicioAdministracionClient());
 }
예제 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConstructorInjectedController"/> class.
 /// </summary>
 /// <param name="fakeService">The fake service.</param>
 public ConstructorInjectedController(IServiceConsumer <IFakeService> fakeService)
 {
     this.FakeService = fakeService;
 }
예제 #14
0
        /// <summary>
        /// Find all available services in all assemblies
        /// </summary>
        public void FindServices()
        {
            serviceConsumers = new Dictionary <Guid, ServiceConsumerInfo>();

            AppDomainSetup setup = new AppDomainSetup();

            setup.ApplicationName     = "TempDomain";
            setup.ApplicationBase     = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            setup.ConfigurationFile   = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
            setup.PrivateBinPath      = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath;
            setup.PrivateBinPathProbe = AppDomain.CurrentDomain.SetupInformation.PrivateBinPathProbe;
            AppDomain tempDomain = AppDomain.CreateDomain("TempDomain", AppDomain.CurrentDomain.Evidence, setup, AppDomain.CurrentDomain.PermissionSet, new StrongName[0]);
            var       proxy      = tempDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(LoadServiceTypesProxy).FullName) as LoadServiceTypesProxy;

            if (proxy == null)
            {
                Log.Error("Proxy is null!");
                return;
            }

            // find all types which implement IServiceConsumer
            String        path   = (AppDomain.CurrentDomain.SetupInformation.PrivateBinPath ?? AppDomain.CurrentDomain.SetupInformation.ApplicationBase);
            DirectoryInfo binDir = new DirectoryInfo(path);

            Log.Debug("Scanning for service consumers in '" + binDir.FullName + "'.");
            foreach (FileInfo assemblyFile in binDir.GetFiles("*.dll"))
            {
                try
                {
                    String   assemblyName;
                    String[] consumerTypes = proxy.LoadServiceTypes(assemblyFile.FullName, out assemblyName);

                    foreach (String consumerType in consumerTypes)
                    {
                        IServiceConsumer consumer = tempDomain.CreateInstanceAndUnwrap(assemblyName, consumerType) as IServiceConsumer;
                        if (consumer == null || String.IsNullOrEmpty(consumer.Name))
                        {
                            Log.Error("Error instantiating type or consumer of type " + consumerType + " has an invalid name.");
                            continue;
                        }

                        LoadConsumer(assemblyName, consumerType, consumer.Name);
                    }
                }
                catch (BadImageFormatException)
                {
                    // don't log those errors
                }
                catch (Exception ex)
                {
                    Log.Error("ServiceManager.FindServices", ex);
                }
            }
            AppDomain.Unload(tempDomain);

            // create the apps for the services
            // store the service settings in the database
            SettingsManager            settingsManager = new SettingsManager();
            List <ServiceConsumerInfo> tempConsumers   = new List <ServiceConsumerInfo>(ServiceConsumers.Values);

            foreach (ServiceConsumerInfo consumerInfo in tempConsumers)
            {
                IServiceConsumer consumer = consumerInfo.ServiceConsumer;

                try
                {
                    // save default authentication settings if they don't exist
                    AuthSettingsBase authSettings = settingsManager.GetServiceSettings(consumerInfo.Id);
                    if (authSettings == null || authSettings.GetType().Name != consumer.Settings.GetType().Name)
                    {
                        settingsManager.SaveServiceSettings(consumerInfo.Id, consumer.Settings);
                    }
                    else
                    {
                        consumer.Settings = authSettings;
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("ServiceManager.FindServices.InitializeConsumer", ex);
                    UnloadConsumer(consumerInfo);
                }
            }
        }
 public TestController(ILogger <TestController> logger, IServiceConsumer serviceConsumer)
 {
     _logger      = logger;
     _svcConsumer = serviceConsumer;
 }