Ejemplo n.º 1
0
        static void Main()
        {
            try {
                Console.WriteLine("Starting...");
                ValueManager.ValueManagerType = typeof(MultiThreadValueManager <>).GetGenericTypeDefinition();
                XpoTypesInfoHelper.GetXpoTypeInfoSource();
                XafTypesInfo.Instance.RegisterEntity(typeof(Employee));
                XafTypesInfo.Instance.RegisterEntity(typeof(PermissionPolicyUser));
                XafTypesInfo.Instance.RegisterEntity(typeof(PermissionPolicyRole));
                string connectionString = @"Integrated Security=SSPI;Pooling=false;Data Source=(localdb)\mssqllocaldb;Initial Catalog=ClientServer";
                Console.WriteLine("Creating default objects...");
                XPObjectSpaceProvider objectSpaceProvider = new XPObjectSpaceProvider(connectionString);
                objectSpaceProvider.CheckCompatibilityType = CheckCompatibilityType.DatabaseSchema;
                objectSpaceProvider.SchemaUpdateMode       = SchemaUpdateMode.DatabaseAndSchema;
                IObjectSpace objectSpace = objectSpaceProvider.CreateUpdatingObjectSpace(true);
                CreateUsers(objectSpace);
                CreateObjects(objectSpace);
                objectSpace.CommitChanges();

                Console.WriteLine("Starting server...");
                Func <IDataServerSecurity> securityProviderHandler = () => new SecurityStrategyComplex(typeof(PermissionPolicyUser), typeof(PermissionPolicyRole), new AuthenticationStandard());

                ServiceHost serviceHost = new WcfXafServiceHost(connectionString, securityProviderHandler);
                serviceHost.AddServiceEndpoint(typeof(IWcfXafDataServer), WcfDataServerHelper.CreateNetTcpBinding(), "net.tcp://localhost:1424/DataServer");
                serviceHost.Open();

                Console.WriteLine("Server is started. Press Enter to stop.");
                Console.ReadLine();
                Console.WriteLine("Stopping...");
                serviceHost.Close();
                Console.WriteLine("Server is stopped.");
            }
            catch (Exception e) {
                Console.WriteLine("Exception occurs: " + e.Message);
                Console.WriteLine("Press Enter to close.");
                Console.ReadLine();
            }
        }