Exemplo n.º 1
0
        //method that receives a callback when the results are available
        void ResultsReady(IAsyncResult result)
        {
            List <string> keys_matched = new List <string>();

            // Extract the delegate from the
            // System.Runtime.Remoting.Messaging.AsyncResult.
            GetResultsDelegate getResultDelegate = (GetResultsDelegate)((AsyncResult)result).AsyncDelegate;
            int g = (int)result.AsyncState;

            // Obtain the result
            bool return_val = getResultDelegate.EndInvoke(ref keys_matched, result);

            waiter.Set();
        }
        public ResultsPage(string answer, GetResultsDelegate getResultsDelegate)
        {
            this.IsWellFormed = false;

            try {
                var jsonObject = JsonObject.FromString(answer);

                JsonObject resultsPage = null;
                try {
                    resultsPage = jsonObject.Get <JsonObject> ("resultsPage");
                    this.status = resultsPage.Get <String> ("status");
                    if (IsStatusOk)
                    {
                        // TODO: refactor
                        var hasAnyResults = resultsPage.Get <int> ("totalEntries") != 0;
                        if (hasAnyResults)
                        {
                            JsonObject resultsJson = resultsPage.Get <JsonObject> ("results");
                            if (resultsJson != null)
                            {
                                this.results = getResultsDelegate(resultsJson);
                            }
                            else
                            {
                                Hyena.Log.Error("SongKick: Server returned 'ok' status without 'results'");
                            }
                        }
                        else
                        {
                            this.results = new Results <T> ();
                        }
                    }

                    var errorJson = resultsPage.Get <JsonObject> ("error");
                    if (errorJson != null)
                    {
                        this.error = new ResultsError(errorJson);
                    }

                    this.IsWellFormed = true;
                } catch (ArgumentNullException e) {
                    Hyena.Log.DebugException(e);
                }
            } catch (ApplicationException e) {
                Hyena.Log.DebugException(e);
            }
        }
Exemplo n.º 3
0
        protected void load_Results(string path, ref string[] results, GetResultsDelegate defaultResults)
        {
            var list = new List <string>();

            try
            {
                loadResults(path, ref list);

                for (var i = 0; i < list.Count; i++)
                {
                    results[i] = list[i];
                }
            }
            catch
            {
                defaultResults();
            }
        }
Exemplo n.º 4
0
        //Method2: asynchronous pattern using a BeginInvoke, followed by waiting with a time-out
        public void GetResultsAndWait(string key, ref List <string> keys_matched, int waitTime = 10000)
        {
            //declare instance of delegate
            GetResultsDelegate getResultDelegate = new GetResultsDelegate(ResultsGetter.GetResults);

            //asynchonously invoke the GetResult method
            IAsyncResult result = getResultDelegate.BeginInvoke(key, ref keys_matched, null, null);

            while (!result.IsCompleted)
            {
                //do any work that can done before waiting
                result.AsyncWaitHandle.WaitOne(waitTime, false);
            }
            result.AsyncWaitHandle.Close();

            //the asynchronous operation has completed
            bool return_val = getResultDelegate.EndInvoke(ref keys_matched, result);
        }
Exemplo n.º 5
0
        //Method1: asynchronous pattern using a callback method
        public void GetResultUsingCallback(string key, ref List <string> keys_matched)
        {
            //declare instance of delegate
            GetResultsDelegate getResultDelegte = new GetResultsDelegate(ResultsGetter.GetResults);

            // Waiter will keep the main application thread from
            // ending before the callback completes because
            // the main thread blocks until the waiter is signaled
            // in the callback
            waiter = new ManualResetEvent(false);

            //define the AsyncCallback delegate
            AsyncCallback callback = new AsyncCallback(this.ResultsReady);

            // Asynchronously invoke the GetRsults method
            IAsyncResult result = getResultDelegte.BeginInvoke(key, ref keys_matched, callback, key);

            // Do some other useful work while
            // waiting for the asynchronous operation to complete.

            // When no more work can be done, wait.
            waiter.WaitOne();
        }
Exemplo n.º 6
0
		public Initializer(EventHandler<EventArgs> configChangedHandler)
		{
			var configuration = SipServerConfigurationSection.GetSection();

			var adUsers = (configuration.IsActiveDirectoryEnabled == false) ? null : new AdUsers(configuration.ActiveDirectoryGroup);

			Func<Userz> CreateUserz = () =>
			{
				var result = new Userz(configuration.CustomUsersPath);

				result.Add(new CsvUsers(configuration.UsersCsvFilePathName));
				if (adUsers != null)
					result.Add(adUsers);

				result.LoadCustomUsers();

				return result;
			};


			var serversManager = new ServersManager<Connection>(new ServersManagerConfig());
			var transportLayer = new TransportLayer(serversManager, configuration.WebSocketResponseFrame);
			var authorization = new SipAuthorizationManager();
			var transactionLayer = new TransactionLayer(authorization);
			var userz = CreateUserz();
			var locationService = new LocationService();
			var mras = new Mras.Mras1();
			var trunkManager = new TrunkManager();
			var accounts = new Accountx(configuration.AccountConfigFilePathName);
			var msPresTu = new MsPresTU(accounts, userz, locationService);
			var wcfService = new WCFService(configuration, msPresTu.EnhancedPresence, trunkManager, accounts, userz);
			var httpAuthorization = new HttpAuthorizationManager();
			var httpServer = new HttpServer(httpAuthorization, configuration.AdminUri);
			//var httpServerAgentRegistrar = new Func<IHttpServerAgent, IHttpServer>((agent) => { return httpServer.Register(agent); });
			var restapi = new RestapiService(accounts, userz) { AdministratorPassword = configuration.AdministratorPassword, };
			var httpFileServer = new HttpFileServer(configuration.WwwPath, string.Empty);
			var xcapServer = new XcapServer();
			var configurationMonitor = new ConfigurationMonitor();
			var simpleModule = new SimpleModule(EqualityComparer<string>.Default);
            var proxyServerTU = new ProxyServerTU(locationService, trunkManager, accounts);

			GetResults = (
				out TransportLayer transportLayer1,
				out TransactionLayer transactionLayer1,
				out LocationService locationService1,
				out WCFService wcfService1,
				out ConfigurationMonitor configurationMonitor1,
				out TrunkManager trunkManager1,
				out SipAuthorizationManager authorization1,
				out Userz userz1,
				out AdUsers adUsers1,
				out Mras.Mras1 mras1,
				out HttpFileServer httpFileServer1,
				out Accountx accounts1,
				out RestapiService restapi1,
                out ProxyServerTU proxyServerTU1
				) =>
			{
				transportLayer1 = transportLayer;
				transactionLayer1 = transactionLayer;
				locationService1 = locationService;
				wcfService1 = wcfService;
				configurationMonitor1 = configurationMonitor;
				trunkManager1 = trunkManager;
				authorization1 = authorization;
				userz1 = userz;
				adUsers1 = adUsers;
				mras1 = mras;
				httpFileServer1 = httpFileServer;
				accounts1 = accounts;
				restapi1 = restapi;
                proxyServerTU1 = proxyServerTU;
			};


			Action InitializeTracer = () =>
			{
				Tracer.Initialize(serversManager.Logger);
                Tracer.Configure(configuration.TracingPath, configuration.IsTracingEnabled);
			};


			Action InitializeConfigurationMonitor = () =>
			{
				configurationMonitor.Changed += configChangedHandler;
				configurationMonitor.StartMonitoring(configuration);
			};

			Action InitializeHttpModules = () =>
			{
				httpServer.SendAsync = transportLayer.SendAsyncHttp;
				transportLayer.IncomingHttpRequest = httpServer.ProcessIncomingRequest;

				httpServer.Register(restapi, 0, true);
				httpServer.Register(xcapServer, 0, true);
				httpServer.Register(new HttpFileServer(configuration.WwwAdminPath, configuration.AdminUri), 254, true);
				httpServer.Register(httpFileServer, 255, true);

				xcapServer.AddHandler(new ResourceListsHandler(accounts, userz));
				xcapServer.AddHandler(new PidfManipulationHandler(simpleModule));
			};

			Action InitializeWcfService = () =>
			{
				wcfService.Start();
			};


            Action InitializeProxyServerTU = () =>
            {
                proxyServerTU.IsOfficeSIPFiletransferEnabled = configuration.IsOfficeSIPFiletransferEnabled;
            };


            Action InitializeTransactionLayer = () =>
			{
                InitializeProxyServerTU();

				transportLayer.IncomingMessage += transactionLayer.IncomingMessage;
				transportLayer.SendErrorSip += transactionLayer.TransportError;
				transactionLayer.SendAsync = transportLayer.SendAsyncSip;
				transactionLayer.IsLocalAddress = transportLayer.IsLocalAddress;

				serversManager.EndConnection += (s, c) => { locationService.RemoveBindingsWhenConnectionEnd(c.Id); };
				transactionLayer.RegisterTransactionUser(new RegistrarTU(locationService, accounts));

				transactionLayer.RegisterTransactionUser(msPresTu);

				transactionLayer.RegisterTransactionUser(new SimpleTU(simpleModule));
				transactionLayer.RegisterTransactionUser(new OptionsTU());
				transactionLayer.RegisterTransactionUser(new MessageSummaryTU());

				transactionLayer.RegisterTransactionUser(new MrasTU(mras));

				transactionLayer.RegisterTransactionUser(new DirectorySearchTU(accounts, new ServiceSoap.ServiceSoap1(), userz));

                transactionLayer.RegisterTransactionUser(proxyServerTU);

				transactionLayer.RegisterTransactionUser(new TrunkTU(trunkManager));
				transactionLayer.RegisterTransactionUser(new ErrorTU());
			};


			Action InitializeAuthorization = () =>
			{
				authorization.IsEnabled = configuration.IsAuthorizationEnabled;

				if (configuration.IsActiveDirectoryEnabled)
				{
					var kerberosAuth = new SipMicrosoftAuthentication(SipAuthSchemes.Kerberos, accounts, userz);
					var ntlmAuth = new SipMicrosoftAuthentication(SipAuthSchemes.Ntlm, accounts, userz);

					authorization.RegisterAgent(kerberosAuth, SipAuthSchemes.Kerberos);
					authorization.RegisterAgent(ntlmAuth, SipAuthSchemes.Ntlm);
				}

				var digestAuth = new SipDigestAuthentication(accounts, userz, configuration.IsAuthIntEnabled);
				authorization.RegisterAgent(digestAuth, SipAuthSchemes.Digest);



				httpAuthorization.IsEnabled = configuration.IsAuthorizationEnabled;
				httpAuthorization.RegisterAgent(new HttpDigestAuthentication(accounts, userz, false), HttpAuthSchemes.Digest);
			};


			Action InitializeServersManager = () =>
			{
				serversManager.FakeAddressAction = (ServerEndPoint localEndpoint) =>
				{
					foreach (var portForwarding in configuration.PortForwardings)
					{
						if (localEndpoint.Equals(portForwarding.Protocol, portForwarding.LocalEndpoint))
							return portForwarding.ExternalEndpoint;
					}

					return null;
				};

				Action<ServerProtocol, int> bind = (protocol, port) =>
				{
					if (port > 0)
					{
						var error = serversManager.Bind(new ProtocolPort()
						{
							Protocol = protocol,
							Port = port,
						});

						if (error != SocketError.Success)
							Tracer.WriteError("Can't open " + protocol + " port " + port + ".\r\n" + error.ToString());
					}
				};

				if (configuration.UdpPort > 0)
					bind(ServerProtocol.Udp, configuration.UdpPort);
				if (configuration.TcpPort > 0)
					bind(ServerProtocol.Tcp, configuration.TcpPort);
				if (configuration.TcpPort2 > 0)
					bind(ServerProtocol.Tcp, configuration.TcpPort2);
			};

			ConfigureMras(mras, configuration);
			InitializeConfigurationMonitor();
			InitializeTracer();
			InitializeTransactionLayer();
			InitializeAuthorization();
			InitializeWcfService();
			InitializeHttpModules();
			InitializeServersManager();
		}
Exemplo n.º 7
0
        public Initializer(EventHandler <EventArgs> configChangedHandler)
        {
            var configuration = SipServerConfigurationSection.GetSection();

            var adUsers = (configuration.IsActiveDirectoryEnabled == false) ? null : new AdUsers(configuration.ActiveDirectoryGroup);

            Func <Userz> CreateUserz = () =>
            {
                var result = new Userz(configuration.CustomUsersPath);

                result.Add(new CsvUsers(configuration.UsersCsvFilePathName));
                if (adUsers != null)
                {
                    result.Add(adUsers);
                }

                result.LoadCustomUsers();

                return(result);
            };


            var serversManager    = new ServersManager <Connection>(new ServersManagerConfig());
            var transportLayer    = new TransportLayer(serversManager, configuration.WebSocketResponseFrame);
            var authorization     = new SipAuthorizationManager();
            var transactionLayer  = new TransactionLayer(authorization);
            var userz             = CreateUserz();
            var locationService   = new LocationService();
            var mras              = new Mras.Mras1();
            var trunkManager      = new TrunkManager();
            var accounts          = new Accountx(configuration.AccountConfigFilePathName);
            var msPresTu          = new MsPresTU(accounts, userz, locationService);
            var wcfService        = new WCFService(configuration, msPresTu.EnhancedPresence, trunkManager, accounts, userz);
            var httpAuthorization = new HttpAuthorizationManager();
            var httpServer        = new HttpServer(httpAuthorization, configuration.AdminUri);
            //var httpServerAgentRegistrar = new Func<IHttpServerAgent, IHttpServer>((agent) => { return httpServer.Register(agent); });
            var restapi = new RestapiService(accounts, userz)
            {
                AdministratorPassword = configuration.AdministratorPassword,
            };
            var httpFileServer       = new HttpFileServer(configuration.WwwPath, string.Empty);
            var xcapServer           = new XcapServer();
            var configurationMonitor = new ConfigurationMonitor();
            var simpleModule         = new SimpleModule(EqualityComparer <string> .Default);
            var proxyServerTU        = new ProxyServerTU(locationService, trunkManager, accounts);

            GetResults = (
                out TransportLayer transportLayer1,
                out TransactionLayer transactionLayer1,
                out LocationService locationService1,
                out WCFService wcfService1,
                out ConfigurationMonitor configurationMonitor1,
                out TrunkManager trunkManager1,
                out SipAuthorizationManager authorization1,
                out Userz userz1,
                out AdUsers adUsers1,
                out Mras.Mras1 mras1,
                out HttpFileServer httpFileServer1,
                out Accountx accounts1,
                out RestapiService restapi1,
                out ProxyServerTU proxyServerTU1
                ) =>
            {
                transportLayer1       = transportLayer;
                transactionLayer1     = transactionLayer;
                locationService1      = locationService;
                wcfService1           = wcfService;
                configurationMonitor1 = configurationMonitor;
                trunkManager1         = trunkManager;
                authorization1        = authorization;
                userz1          = userz;
                adUsers1        = adUsers;
                mras1           = mras;
                httpFileServer1 = httpFileServer;
                accounts1       = accounts;
                restapi1        = restapi;
                proxyServerTU1  = proxyServerTU;
            };


            Action InitializeTracer = () =>
            {
                Tracer.Initialize(serversManager.Logger);
                Tracer.Configure(configuration.TracingPath, configuration.IsTracingEnabled);
            };


            Action InitializeConfigurationMonitor = () =>
            {
                configurationMonitor.Changed += configChangedHandler;
                configurationMonitor.StartMonitoring(configuration);
            };

            Action InitializeHttpModules = () =>
            {
                httpServer.SendAsync = transportLayer.SendAsyncHttp;
                transportLayer.IncomingHttpRequest = httpServer.ProcessIncomingRequest;

                httpServer.Register(restapi, 0, true);
                httpServer.Register(xcapServer, 0, true);
                httpServer.Register(new HttpFileServer(configuration.WwwAdminPath, configuration.AdminUri), 254, true);
                httpServer.Register(httpFileServer, 255, true);

                xcapServer.AddHandler(new ResourceListsHandler(accounts, userz));
                xcapServer.AddHandler(new PidfManipulationHandler(simpleModule));
            };

            Action InitializeWcfService = () =>
            {
                wcfService.Start();
            };


            Action InitializeProxyServerTU = () =>
            {
                proxyServerTU.IsOfficeSIPFiletransferEnabled = configuration.IsOfficeSIPFiletransferEnabled;
            };


            Action InitializeTransactionLayer = () =>
            {
                InitializeProxyServerTU();

                transportLayer.IncomingMessage += transactionLayer.IncomingMessage;
                transportLayer.SendErrorSip    += transactionLayer.TransportError;
                transactionLayer.SendAsync      = transportLayer.SendAsyncSip;
                transactionLayer.IsLocalAddress = transportLayer.IsLocalAddress;

                serversManager.EndConnection += (s, c) => { locationService.RemoveBindingsWhenConnectionEnd(c.Id); };
                transactionLayer.RegisterTransactionUser(new RegistrarTU(locationService, accounts));

                transactionLayer.RegisterTransactionUser(msPresTu);

                transactionLayer.RegisterTransactionUser(new SimpleTU(simpleModule));
                transactionLayer.RegisterTransactionUser(new OptionsTU());
                transactionLayer.RegisterTransactionUser(new MessageSummaryTU());

                transactionLayer.RegisterTransactionUser(new MrasTU(mras));

                transactionLayer.RegisterTransactionUser(new DirectorySearchTU(accounts, new ServiceSoap.ServiceSoap1(), userz));

                transactionLayer.RegisterTransactionUser(proxyServerTU);

                transactionLayer.RegisterTransactionUser(new TrunkTU(trunkManager));
                transactionLayer.RegisterTransactionUser(new ErrorTU());
            };


            Action InitializeAuthorization = () =>
            {
                authorization.IsEnabled = configuration.IsAuthorizationEnabled;

                if (configuration.IsActiveDirectoryEnabled)
                {
                    var kerberosAuth = new SipMicrosoftAuthentication(SipAuthSchemes.Kerberos, accounts, userz);
                    var ntlmAuth     = new SipMicrosoftAuthentication(SipAuthSchemes.Ntlm, accounts, userz);

                    authorization.RegisterAgent(kerberosAuth, SipAuthSchemes.Kerberos);
                    authorization.RegisterAgent(ntlmAuth, SipAuthSchemes.Ntlm);
                }

                var digestAuth = new SipDigestAuthentication(accounts, userz, configuration.IsAuthIntEnabled);
                authorization.RegisterAgent(digestAuth, SipAuthSchemes.Digest);



                httpAuthorization.IsEnabled = configuration.IsAuthorizationEnabled;
                httpAuthorization.RegisterAgent(new HttpDigestAuthentication(accounts, userz, false), HttpAuthSchemes.Digest);
            };


            Action InitializeServersManager = () =>
            {
                serversManager.FakeAddressAction = (ServerEndPoint localEndpoint) =>
                {
                    foreach (var portForwarding in configuration.PortForwardings)
                    {
                        if (localEndpoint.Equals(portForwarding.Protocol, portForwarding.LocalEndpoint))
                        {
                            return(portForwarding.ExternalEndpoint);
                        }
                    }

                    return(null);
                };

                Action <ServerProtocol, int> bind = (protocol, port) =>
                {
                    if (port > 0)
                    {
                        var error = serversManager.Bind(new ProtocolPort()
                        {
                            Protocol = protocol,
                            Port     = port,
                        });

                        if (error != SocketError.Success)
                        {
                            Tracer.WriteError("Can't open " + protocol + " port " + port + ".\r\n" + error.ToString());
                        }
                    }
                };

                if (configuration.UdpPort > 0)
                {
                    bind(ServerProtocol.Udp, configuration.UdpPort);
                }
                if (configuration.TcpPort > 0)
                {
                    bind(ServerProtocol.Tcp, configuration.TcpPort);
                }
                if (configuration.TcpPort2 > 0)
                {
                    bind(ServerProtocol.Tcp, configuration.TcpPort2);
                }
            };

            ConfigureMras(mras, configuration);
            InitializeConfigurationMonitor();
            InitializeTracer();
            InitializeTransactionLayer();
            InitializeAuthorization();
            InitializeWcfService();
            InitializeHttpModules();
            InitializeServersManager();
        }