public void GetServiceImplementationData_DataResolvesTypeThroughProxy()
 {
     var builder = new ContainerBuilder();
     var implementation = new ServiceImplementation();
     builder.RegisterInstance(implementation).As<IServiceContract>();
     var container = builder.Build();
     var provider = new MultitenantServiceImplementationDataProvider();
     var data = provider.GetServiceImplementationData(typeof(IServiceContract).AssemblyQualifiedName);
     var resolved = data.ImplementationResolver(container.BeginLifetimeScope());
     Assert.IsNotNull(resolved, "The proxy object resolved should not be null.");
     ((IServiceContract)resolved).MethodToProxy();
     Assert.IsTrue(implementation.ProxyMethodCalled, "The proxy object should proxy the methods on the implementation.");
 }
Esempio n. 2
0
        public void CreateWcfProxy_InterfaceToProxyIsGeneric()
        {
            var    generator        = new ServiceHostProxyGenerator();
            object target           = new ServiceImplementation();
            Type   interfaceToProxy = typeof(IServiceContractGeneric <>);

            Assert.Throws <ArgumentException>(() => generator.CreateWcfProxy(interfaceToProxy, target));
        }
Esempio n. 3
0
        public void CreateWcfProxy_NullInterface()
        {
            var    generator        = new ServiceHostProxyGenerator();
            object target           = new ServiceImplementation();
            Type   interfaceToProxy = null;

            Assert.Throws <ArgumentNullException>(() => generator.CreateWcfProxy(interfaceToProxy, target));
        }
Esempio n. 4
0
        public void CreateWcfProxy_CustomProxyTypeCanBeHosted()
        {
            var    generator        = new ServiceHostProxyGenerator();
            object target           = new ServiceImplementation();
            Type   interfaceToProxy = typeof(IServiceContract);
            var    proxy            = generator.CreateWcfProxy(interfaceToProxy, target);

            // XUnit does not have "Assert.DoesNotThrow".
            new ServiceHost(proxy.GetType(), new Uri("http://localhost:22111/Foo.svc"));
        }
Esempio n. 5
0
        internal override void Start()
        {
            foreach (var item in dataList)
            {
                Data = item;
                var codeDom = Render();

                var filePath = $"{Path}/{item.Class}{FileExtension}";

                if (!WriteToFile(filePath, codeDom))
                {
                    Console.WriteLine("It can be not write to file!");
                }
            }
        }
        public void GetServiceImplementationData_DataResolvesTypeThroughProxy()
        {
            var builder        = new ContainerBuilder();
            var implementation = new ServiceImplementation();

            builder.RegisterInstance(implementation).As <IServiceContract>();
            var container = builder.Build();
            var provider  = new MultitenantServiceImplementationDataProvider();
            var data      = provider.GetServiceImplementationData(typeof(IServiceContract).AssemblyQualifiedName);
            var resolved  = data.ImplementationResolver(container.BeginLifetimeScope());

            Assert.NotNull(resolved);
            ((IServiceContract)resolved).MethodToProxy();
            Assert.True(implementation.ProxyMethodCalled);
        }
        /// <summary>
        /// Constructs a LocalServerImpl object.
        /// </summary>
        public LocalServerImpl()
        {
            dor = new EmptyDoR();
            doi = new EmptyDoI();
            syncID = Guid.NewGuid();

            server = new KIARAServer(KIARAServerManager.Instance.ServerURI,
                KIARAServerManager.Instance.ServerPort,
                "/serversync/",
                "serverSync.kiara");

            Configuration serverSyncConfig = ConfigurationManager.OpenExeConfiguration(this.GetType().Assembly.Location);
            int syncPort = int.Parse(serverSyncConfig.AppSettings.Settings["serverSyncPort"].Value);
            service = server.StartService(KIARAServerManager.Instance.ServerURI, syncPort, "/", "ws", "fives-json");
            service.OnNewClient += ServerSyncTools.ConfigureJsonSerializer;

            RegisterSyncIDAPI(service);
        }
Esempio n. 8
0
        // The main entry point for the windows service application.
        static void Main(string[] args)
        {
            try
            {
                // If install was a command line flag, then run the installer at runtime.
                if (args.Contains("-install", StringComparer.InvariantCultureIgnoreCase))
                {
                    WindowsServiceInstaller.RuntimeInstall <ServiceImplementation>();
                }

                // If uninstall was a command line flag, run uninstaller at runtime.
                else if (args.Contains("-uninstall", StringComparer.InvariantCultureIgnoreCase))
                {
                    WindowsServiceInstaller.RuntimeUnInstall <ServiceImplementation>();
                }

                // Otherwise, fire up the service as either console or windows service based on UserInteractive property.
                else
                {
                    var implementation = new ServiceImplementation();

                    // If started from console, file explorer, etc, run as console app.
                    if (Environment.UserInteractive)
                    {
                        ConsoleHarness.Run(args, implementation);
                    }

                    // Otherwise run as a windows service
                    else
                    {
                        ServiceBase.Run(new WindowsServiceHarness(implementation));
                    }
                }
            }

            catch (Exception ex)
            {
                ConsoleHarness.WriteToConsole(ConsoleColor.Red, "An exception occurred in Main(): {0}", ex);
            }
        }
        // The main entry point for the windows service application.
        static void Main(string[] args)
        {
            try
            {
                // If install was a command line flag, then run the installer at runtime.
                if (args.Contains("-install", StringComparer.InvariantCultureIgnoreCase))
                {
                    WindowsServiceInstaller.RuntimeInstall<ServiceImplementation>();
                }

                // If uninstall was a command line flag, run uninstaller at runtime.
                else if (args.Contains("-uninstall", StringComparer.InvariantCultureIgnoreCase))
                {
                    WindowsServiceInstaller.RuntimeUnInstall<ServiceImplementation>();
                }

                // Otherwise, fire up the service as either console or windows service based on UserInteractive property.
                else
                {
                    var implementation = new ServiceImplementation();

                    // If started from console, file explorer, etc, run as console app.
                    if (Environment.UserInteractive)
                    {
                        ConsoleHarness.Run(args, implementation);
                    }

                    // Otherwise run as a windows service
                    else
                    {
                        ServiceBase.Run(new WindowsServiceHarness(implementation));
                    }
                }
            }

            catch (Exception ex)
            {
                ConsoleHarness.WriteToConsole(ConsoleColor.Red, "An exception occurred in Main(): {0}", ex);
            }
        }
        /// <summary>
        /// Create the template output
        /// </summary>
        public virtual string TransformText()
        {
            this.Write("\r\n");
            this.Write("\r\n");
            this.Write("\r\n");
            this.Write("\r\n");
            this.Write("\r\n\r\n\r\n");

            #line 19 "C:\workgit\oyasar.codegenerator\OYASAR.CodeGenerator.Lib\TextTemplate\ServiceImplementationTemplate.tt"
            ServiceImplementation model = ServiceImplementationManager.Data;

            #line default
            #line hidden
            this.Write("\r\n\r\nusing System;\r\nusing System.Collections.Generic;\r\n\r\nnamespace ");

            #line 25 "C:\workgit\oyasar.codegenerator\OYASAR.CodeGenerator.Lib\TextTemplate\ServiceImplementationTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(model.NameSpace));

            #line default
            #line hidden
            this.Write("\r\n{\r\n    public partial class ");

            #line 27 "C:\workgit\oyasar.codegenerator\OYASAR.CodeGenerator.Lib\TextTemplate\ServiceImplementationTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(model.Class));

            #line default
            #line hidden
            this.Write("Service : I");

            #line 27 "C:\workgit\oyasar.codegenerator\OYASAR.CodeGenerator.Lib\TextTemplate\ServiceImplementationTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(model.Class));

            #line default
            #line hidden
            this.Write("Service\r\n    {\r\n        \r\n    }\r\n}\r\n");
            return(this.GenerationEnvironment.ToString());
        }
Esempio n. 11
0
        private object Resolve(Type dependencyType, ServiceImplementation implementationVariant = ServiceImplementation.None)
        {
            if (dependencyType.IsGenericType && (dependencyType.GetGenericTypeDefinition() == typeof(IEnumerable <>)))
            {
                return(GetAllImplementations(dependencyType.GetGenericArguments()[0]));
            }

            if (dependencyType.IsGenericType && _dependencies.ContainsKey(dependencyType.GetGenericTypeDefinition()))
            {
                var implementationType = _dependencies[dependencyType.GetGenericTypeDefinition()][0].ImplementationType;
                implementationType = implementationType.MakeGenericType(dependencyType.GetGenericArguments());

                if (dependencyType.IsAssignableFrom(implementationType))
                {
                    return(CreateInstance(implementationType));
                }
            }

            if (!_dependencies.ContainsKey(dependencyType))
            {
                return(null);
            }

            var implementationInfo = GetImplementationInfo(dependencyType, implementationVariant);

            if (!dependencyType.IsAssignableFrom(implementationInfo.ImplementationType))
            {
                return(null);
            }

            return(implementationInfo.Lifetime switch
            {
                Lifetime.Transient => CreateInstance(implementationInfo.ImplementationType),
                Lifetime.Singleton => Singleton.GetInstance(implementationInfo.ImplementationType, CreateInstance),
                _ => null
            });
Esempio n. 12
0
        private InstancesController NewInstanceController(Mock <HttpContext> context)
        {
            Instance createdInstance = new Instance()
            {
                Id = $"{instanceOwnerId}/878761d7-06d0-43ee-98c7-c85f7997d696",
                InstanceOwnerId = $"{instanceOwnerId}",
                AppId           = $"{org}/{app}",
                Org             = $"{org}",
            };

            Instance instanceWithData = new Instance()
            {
                Id = createdInstance.Id,
                InstanceOwnerId = createdInstance.InstanceOwnerId,
                AppId           = createdInstance.AppId,
                Org             = createdInstance.Org,
                Data            = new List <DataElement>()
                {
                    new DataElement()
                    {
                        Id          = dataGuid.ToString(),
                        ElementType = "default",
                    }
                }
            };

            Mock <IAuthorization> authorizationService             = new Mock <IAuthorization>();
            Mock <ILogger <InstancesController> > logger           = new Mock <ILogger <InstancesController> >();
            Mock <IOptions <PlatformSettings> >   platformSettings = new Mock <IOptions <PlatformSettings> >();

            Mock <IInstance> instanceServiceMock = new Mock <IInstance>();

            instanceServiceMock
            .Setup(i => i.CreateInstance(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Instance>()))
            .Returns(Task.FromResult(createdInstance));

            Mock <IRegister> registerServiceMock = new Mock <IRegister>();

            registerServiceMock
            .Setup(x => x.GetParty(It.IsAny <int>()))
            .Returns(Task.FromResult(new Party()
            {
                PartyId = int.Parse(instanceOwnerId)
            }));

            Mock <IProfile> profileServiceMock = new Mock <IProfile>();

            profileServiceMock
            .Setup(x => x.GetUserProfile(It.IsAny <int>()))
            .Returns(Task.FromResult(new UserProfile()
            {
                UserId = int.Parse(userId)
            }));

            Mock <IOptions <GeneralSettings> > generalSettingsMock = new Mock <IOptions <GeneralSettings> >();

            generalSettingsMock.Setup(s => s.Value).Returns(new GeneralSettings()
            {
                AltinnPartyCookieName = "AltinnPartyId",
            });

            Mock <ServiceContext> serviceContextMock   = new Mock <ServiceContext>();
            Mock <IExecution>     executionServiceMock = new Mock <IExecution>();

            executionServiceMock
            .Setup(e => e.GetServiceContext(org, app, It.IsAny <bool>()))
            .Returns(serviceContextMock.Object);

            ServiceImplementation serviceImplementation = new ServiceImplementation();

            executionServiceMock
            .Setup(e => e.GetServiceImplementation(org, app, It.IsAny <bool>()))
            .Returns(serviceImplementation);

            Mock <IRepository> repositoryServiceMock = new Mock <IRepository>();
            Application        application           = JsonConvert.DeserializeObject <Application>(File.ReadAllText("Runtime/ServiceModels/default/Metadata/applicationmetadata.json"));

            repositoryServiceMock.Setup(r => r.GetApplication(org, app)).Returns(application);

            Mock <IData> dataServiceMock = new Mock <IData>();

            dataServiceMock
            .Setup(d => d.InsertFormData(It.IsAny <object>(), It.IsAny <Guid>(), It.IsAny <Type>(), org, app, It.IsAny <int>()))
            .Returns(Task.FromResult(instanceWithData));

            return(new InstancesController(
                       generalSettingsMock.Object,
                       logger.Object,
                       registerServiceMock.Object,
                       instanceServiceMock.Object,
                       dataServiceMock.Object,
                       executionServiceMock.Object,
                       profileServiceMock.Object,
                       new Mock <IPlatformServices>().Object,
                       repositoryServiceMock.Object)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = context.Object,
                },
            });
        }
        private void InitializeKIARA()
        {
            clientService = KIARAServerManager.Instance.KiaraService;

            string clientManagerIDL = File.ReadAllText("clientManager.kiara");
            KIARAPlugin.KIARAServerManager.Instance.KiaraServer.AmendIDL(clientManagerIDL);
        }
Esempio n. 14
0
 private void StartKiaraServer()
 {
     KiaraServer  = new KIARAServer(ServerURI, ServerPort, ServerPath, "fives.kiara");
     KiaraService = KiaraServer.StartService(ServerURI, ServicePort, "/service/", ServiceTransport, ServiceProtocol);
 }
        public void Register <TDependency, TImplementation>(Lifetime lifetime = Lifetime.Transient, ServiceImplementation variant = ServiceImplementation.None)
            where TDependency : class
            where TImplementation : TDependency
        {
            var implementationInfo = new ImplementationInfo(typeof(TImplementation), lifetime, variant);

            if (Dependencies.ContainsKey(typeof(TDependency)))
            {
                Dependencies[typeof(TDependency)].Add(implementationInfo);
            }
            else
            {
                Dependencies.Add(typeof(TDependency), new List <ImplementationInfo>());
                Dependencies[typeof(TDependency)].Add(implementationInfo);
            }
        }
Esempio n. 16
0
 private void StartSinfoniServer()
 {
     SinfoniServer  = new SINFONIServer(ServerURI, ServerPort, ServerPath, "fives.kiara");
     SinfoniService = SinfoniServer.StartService(ServiceHost, ServicePort, "/service/", ServiceTransport, ServiceProtocol);
 }
Esempio n. 17
0
 public ImplementationInfo(Type type, Lifetime lifetime, ServiceImplementation variant)
 {
     Lifetime           = lifetime;
     ImplementationType = type;
     Variant            = variant;
 }
Esempio n. 18
0
        public T Resolve <T>(ServiceImplementation implementationVariant = ServiceImplementation.None) where T : class
        {
            Type dependencyType = typeof(T);

            return((T)Resolve(dependencyType, implementationVariant));
        }
 internal bool OnCanWatch(BaseWoopsaSubscriptionServiceSubscription subscription, IWoopsaProperty itemProperty)
 {
     return(ServiceImplementation.OnCanWatch(subscription, itemProperty));
 }
Esempio n. 20
0
 public DependencyKeyAttribute(ServiceImplementation variant)
 {
     ImplementationVariant = variant;
 }
        private ValidateController NewValidateController(Mock <HttpContext> context, Mock <IInstance> instanceServiceMock, Mock <IData> dataServiceMock, Mock <IApplication> appServiceMock)
        {
            Mock <IRegister> registerServiceMock = new Mock <IRegister>();

            registerServiceMock
            .Setup(x => x.GetParty(It.IsAny <int>()))
            .Returns(Task.FromResult(new Party()
            {
                PartyId = partyId
            }));

            Mock <IProfile> profileServiceMock = new Mock <IProfile>();

            profileServiceMock
            .Setup(x => x.GetUserProfile(It.IsAny <int>()))
            .Returns(Task.FromResult(new UserProfile()
            {
                UserId = userId
            }));

            Mock <IOptions <GeneralSettings> > generalSettingsMock = new Mock <IOptions <GeneralSettings> >();

            generalSettingsMock.Setup(s => s.Value).Returns(new GeneralSettings()
            {
                AltinnPartyCookieName = "AltinnPartyId",
            });

            ServiceRepositorySettings serviceRepositorySettings = new ServiceRepositorySettings()
            {
                RepositoryLocation = repoPath,
            };

            Mock <ServiceContext> serviceContextMock   = new Mock <ServiceContext>();
            Mock <IExecution>     executionServiceMock = new Mock <IExecution>();

            executionServiceMock
            .Setup(e => e.GetServiceContext(org, app, It.IsAny <bool>()))
            .Returns(serviceContextMock.Object);

            ServiceImplementation serviceImplementation = new ServiceImplementation();

            executionServiceMock
            .Setup(e => e.GetServiceImplementation(org, app, It.IsAny <bool>()))
            .Returns(serviceImplementation);

            Mock <IPlatformServices> platformServicesMock = new Mock <IPlatformServices>();

            Mock <IObjectModelValidator> objectValidator = new Mock <IObjectModelValidator>();

            objectValidator.Setup(o => o.Validate(
                                      It.IsAny <ActionContext>(),
                                      It.IsAny <ValidationStateDictionary>(),
                                      It.IsAny <string>(),
                                      It.IsAny <object>()));

            ValidateController validateController = new ValidateController(
                generalSettingsMock.Object,
                registerServiceMock.Object,
                instanceServiceMock.Object,
                dataServiceMock.Object,
                executionServiceMock.Object,
                profileServiceMock.Object,
                platformServicesMock.Object,
                new Mock <IInstanceEvent>().Object,
                appServiceMock.Object)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = context.Object,
                },

                ObjectValidator = objectValidator.Object,
            };

            return(validateController);
        }