Esempio n. 1
0
		/// <summary>
		/// This method supports the infrastructure and is not intended to be used directly from your code.
		/// </summary>
		/// <param name="configFolderPaths">Possible configuration file locations.</param>
		/// <param name="serviceBrowserAvailable">Indicates whether the service browser is avaliable.</param>
		public void Init(string[] configFolderPaths, bool serviceBrowserAvailable) {
			_messageBroker = new MessageBroker(this);

			string servicesConfigFile = null;
			for (int i = 0; i < configFolderPaths.Length; i++) {
				servicesConfigFile = Path.Combine(configFolderPaths[i], "services-config.xml");
				if (log.IsDebugEnabled)
					log.Debug(__Res.GetString(__Res.MessageServer_TryingServiceConfig, servicesConfigFile));
				if (File.Exists(servicesConfigFile))
					break;
			}
			if (servicesConfigFile != null && File.Exists(servicesConfigFile)) {
				if (log.IsDebugEnabled)
					log.Debug(__Res.GetString(__Res.MessageServer_LoadingServiceConfig, servicesConfigFile));
				_servicesConfiguration = ServicesConfiguration.Load(servicesConfigFile);
			} else {
				if (log.IsDebugEnabled)
					log.Debug(__Res.GetString(__Res.MessageServer_LoadingConfigDefault));
				_servicesConfiguration = ServicesConfiguration.CreateDefault();
			}

			foreach (ChannelDefinition channelDefinition in _servicesConfiguration.Channels) {
				Type type = ObjectFactory.Locate(FluorineConfiguration.Instance.ClassMappings.GetType(channelDefinition.Endpoint.Class));
				if (type != null) {
					IEndpoint endpoint = ObjectFactory.CreateInstance(type, new object[] { _messageBroker, channelDefinition }) as IEndpoint;
					if (endpoint != null)
						_messageBroker.AddEndpoint(endpoint);
				} else
					log.Error(__Res.GetString(__Res.Type_InitError, channelDefinition.Class));
			}
			ChannelDefinition rtmptChannelDefinition = new ChannelDefinition();
			rtmptChannelDefinition.Id = RtmptEndpoint.FluorineRtmptEndpointId;
			IEndpoint rtmptEndpoint = new RtmptEndpoint(_messageBroker, rtmptChannelDefinition);
			_messageBroker.AddEndpoint(rtmptEndpoint);

			if (_servicesConfiguration.Factories != null) {
				foreach (Factory factory in _servicesConfiguration.Factories) {
					Type type = ObjectFactory.Locate(FluorineConfiguration.Instance.ClassMappings.GetType(factory.Class));
					if (type != null) {
						IFlexFactory flexFactory = ObjectFactory.CreateInstance(type, new object[0]) as IFlexFactory;
						if (flexFactory != null)
							_messageBroker.AddFactory(factory.Id, flexFactory);
					} else
						log.Error(__Res.GetString(__Res.Type_InitError, factory.Class));
				}
			}
			//Add the dotnet Factory
			_messageBroker.AddFactory(DotNetFactory.Id, new DotNetFactory());

			if (serviceBrowserAvailable) {
				ServiceDefinition serviceConfiguration = _servicesConfiguration.GetServiceByClass("flex.messaging.services.RemotingService");
				if (serviceConfiguration != null) {
					AdapterDefinition adapter = serviceConfiguration.GetAdapterByClass(typeof(Remoting.RemotingAdapter).FullName);
					if (adapter != null)
						InstallServiceBrowserDestinations(serviceConfiguration, adapter);
					else {
						adapter = serviceConfiguration.GetDefaultAdapter();
						if (adapter != null)
							InstallServiceBrowserDestinations(serviceConfiguration, adapter);
					}
				}
			}
			if (_servicesConfiguration.Services.ServiceDefinitions != null) {
				foreach (ServiceDefinition serviceDefinition in _servicesConfiguration.Services.ServiceDefinitions) {
					Type type = ObjectFactory.Locate(FluorineConfiguration.Instance.ClassMappings.GetType(serviceDefinition.Class));//current assembly only
					if (type != null) {
						IService service = ObjectFactory.CreateInstance(type, new object[] { _messageBroker, serviceDefinition }) as IService;
						if (service != null)
							_messageBroker.AddService(service);
					} else
						log.Error(__Res.GetString(__Res.Type_InitError, serviceDefinition.Class));
				}
			}
			if (_servicesConfiguration.Services.Includes != null) {
				foreach (ServiceInclude include in _servicesConfiguration.Services.Includes) {
					ServiceDefinition serviceDefinition = include.ServiceDefinition;
					Type type = ObjectFactory.Locate(FluorineConfiguration.Instance.ClassMappings.GetType(serviceDefinition.Class));//current assembly only
					if (type != null) {
						IService service = ObjectFactory.CreateInstance(type, new object[] { _messageBroker, serviceDefinition }) as IService;
						if (service != null)
							_messageBroker.AddService(service);
					} else
						log.Error(__Res.GetString(__Res.Type_InitError, serviceDefinition.Class));
				}
			}
			if (_servicesConfiguration.Security != null) {
				if (_servicesConfiguration.Security.LoginCommands != null && _servicesConfiguration.Security.LoginCommands.Length > 0) {
					LoginCommand loginCommand = _servicesConfiguration.Security.GetLoginCommand(LoginCommand.FluorineLoginCommand);
					if (loginCommand != null) {
						Type type = ObjectFactory.Locate(FluorineConfiguration.Instance.ClassMappings.GetType(loginCommand.Class));
						if (type != null) {
							ILoginCommand loginCommandObj = ObjectFactory.CreateInstance(type, new object[] { }) as ILoginCommand;
							_messageBroker.LoginManager.LoginCommand = loginCommandObj;
							_messageBroker.LoginManager.IsPerClientAuthentication = loginCommand.IsPerClientAuthentication;
						} else
							log.Error(__Res.GetString(__Res.Type_InitError, loginCommand.Class));
					} else
						log.Error(__Res.GetString(__Res.Type_InitError, "<<LoginCommand class>>"));
				}
			}
			InitAuthenticationService();

			try {
				if (FluorineConfiguration.Instance.FluorineSettings.Silverlight.PolicyServerSettings != null &&
					FluorineConfiguration.Instance.FluorineSettings.Silverlight.PolicyServerSettings.Enable) {
					IResource resource;
					if (FluorineContext.Current != null)
						resource = FluorineContext.Current.GetResource(FluorineConfiguration.Instance.FluorineSettings.Silverlight.PolicyServerSettings.PolicyFile);
					else
						resource = new FileSystemResource(FluorineConfiguration.Instance.FluorineSettings.Silverlight.PolicyServerSettings.PolicyFile);
					if (resource.Exists) {
						log.Info(__Res.GetString(__Res.Silverlight_StartPS, resource.File.FullName));
						_policyServer = new PolicyServer(resource.File.FullName);
					} else
						throw new FileNotFoundException("Policy file not found", FluorineConfiguration.Instance.FluorineSettings.Silverlight.PolicyServerSettings.PolicyFile);
				}
			} catch (Exception ex) {
				log.Error(__Res.GetString(__Res.Silverlight_PSError), ex);
			}
		}
Esempio n. 2
0
		internal static ServiceDefinition Load(ServicesConfiguration parent, string path) {
			if (!File.Exists(path))
				return null;
			using (StreamReader streamReader = new StreamReader(path)) {
				XmlSerializer serializer = new XmlSerializer(typeof(ServiceDefinition));
				ServiceDefinition serviceDefinition = serializer.Deserialize(streamReader) as ServiceDefinition;
				serviceDefinition.Parent = parent;
				streamReader.Close();
				if (serviceDefinition.Destinations != null) {
					foreach (DestinationDefinition destinationDefinition in serviceDefinition.Destinations)
						destinationDefinition.Service = serviceDefinition;
				}
				return serviceDefinition;
			}
		}
Esempio n. 3
0
		internal void Load(ServicesConfiguration parent, string rootPath) {
			_serviceDefinition = ServiceDefinition.Load(parent, Path.Combine(rootPath, this.FilePath));
		}
Esempio n. 4
0
		internal ServiceDefinition(ServicesConfiguration parent) {
			_parent = parent;
		}
Esempio n. 5
0
		/// <summary>
		/// Creates a default services configuration instance.
		/// </summary>
		/// <returns>Services configuration instance.</returns>
		public static ServicesConfiguration CreateDefault() {
			ServicesConfiguration sc = new ServicesConfiguration();

			LoginCommandCollection loginCommandCollection = FluorineConfiguration.Instance.LoginCommands;
			if (loginCommandCollection != null) {
				LoginCommand loginCommand = new LoginCommand();
				loginCommand.Class = loginCommandCollection.GetLoginCommand(LoginCommandSettings.FluorineLoginCommand);
				loginCommand.Server = LoginCommandSettings.FluorineLoginCommand;
				SecurityConfiguration securityConfiguration = new SecurityConfiguration();
				securityConfiguration.LoginCommands = new LoginCommand[] { loginCommand };
				sc.Security = securityConfiguration;
			}

			//Create a default amf channel
			ChannelDefinition channelDefinition = new ChannelDefinition();
			channelDefinition.Class = "flex.messaging.endpoints.AMFEndpoint";
			channelDefinition.Id = "my-amf";
			Endpoint endpoint = new Endpoint();
			endpoint.Url = @"http://{server.name}:{server.port}/{context.root}/Gateway.aspx";
			endpoint.Class = "flex.messaging.endpoints.AMFEndpoint";
			channelDefinition.Endpoint = endpoint;
			sc.Channels = new ChannelDefinition[] { channelDefinition };

			ServiceDefinition serviceDefinition = new ServiceDefinition(sc);
			serviceDefinition.Id = GodLesZ.Library.Amf.Messaging.Services.RemotingService.RemotingServiceId;
			serviceDefinition.Class = typeof(GodLesZ.Library.Amf.Messaging.Services.RemotingService).FullName;
			serviceDefinition.MessageTypes = "flex.messaging.messages.RemotingMessage";

			AdapterDefinition adapter = new AdapterDefinition();
			adapter.Id = "dotnet";
			adapter.Class = typeof(GodLesZ.Library.Amf.Remoting.RemotingAdapter).FullName;
			adapter.Default = true;
			serviceDefinition.AddAdapter(adapter);
			serviceDefinition.Adapters = new AdapterDefinition[] { adapter };
			AdapterRef adapterRef = new AdapterRef();
			adapterRef.Ref = "dotnet";

			DestinationDefinition destination = new DestinationDefinition(serviceDefinition);
			destination.Id = DestinationDefinition.FluorineDestination;
			destination.AdapterRef = adapterRef;
			DestinationProperties properties = new DestinationProperties();
			properties.Source = "*";
			destination.Properties = properties;
			serviceDefinition.AddDestination(destination);

			Services services = new Services();
			services.ServiceDefinitions = new ServiceDefinition[] { serviceDefinition };
			sc.Services = services;

			FlexClient flexClient = new FlexClient();
			sc.FlexClient = flexClient;
			return sc;
		}