Exemplo n.º 1
0
 public Input(string name, TypeModule module) :
     base(name, module)
 {
     if (typeof(T).IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(Reference <>))
     {
         _volume = new Volume <T>(Name, Module);
         Module.RegisterVolume(name);
     }
 }
Exemplo n.º 2
0
    public TypeModule GetOne(int id)
    {
        TypeModule dto = new TypeModule();

        using (var db = new maderaEntities())
        {
            var query = from a in db.TYPE_MODULE where a.TYPE_MODULE_ID.Equals(id) select a;
            dto.Id              = query.First().TYPE_MODULE_ID;
            dto.Nom             = query.First().TYPE_MODULE_NOM;
            dto.UniteUsage      = query.First().TYPE_MODULE_UNITE_USAGE;
            dto.Caracteristique = query.First().TYPE_MODULE_CARACTERISTIQUE;
        }

        return(dto);
    }
Exemplo n.º 3
0
        public virtual void Subscribe(TypeModule input, Func <T, Task <MessageResult> > handler)
        {
            var dereference = new Func <T, Task <MessageResult> >(t =>
            {
                if (_volume != null)
                {
                    //todo: find a typed way to do this
                    var fileName       = typeof(T).GetProperty("FileName").GetValue(t) as string;
                    var referenceCount = (int)typeof(T).GetProperty("ReferenceCount").GetValue(t);
                    var message        = _volume.Read(fileName);

                    var res = handler(message);

                    if (--referenceCount <= 0)
                    {
                        _volume.Delete(fileName);
                    }

                    return(res);
                }

                return(handler(t));
            });

            var inRouteName = $"BrokeredEndpoint(\"/modules/{input.Name}/inputs/{Name}\")";

            if (_volume != null)
            {
                input.RegisterVolume(Name);
            }

            input.SubscribeRoute(Name,
                                 RouteName,
                                 Name,
                                 inRouteName,
                                 dereference);
        }
Exemplo n.º 4
0
 public Volume(string name, TypeModule module)
     : base(name, module)
 {
     Module.RegisterVolume(Name);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Loads the module.
        /// </summary>
        /// <param name="modules">The modules.</param>
        void ITypeSystem.LoadModules(IList<IMetadataModule> modules)
        {
            foreach (IMetadataModule module in modules)
            {
                ITypeModule typeModule = new TypeModule(this, module);
                typeModules.Add(typeModule);

                if (typeModule.MetadataModule.ModuleType == ModuleType.Executable)
                    mainTypeModule = typeModule;
            }
        }
Exemplo n.º 6
0
 public Upstream(TypeModule module) :
     base("$upstream", module)
 {
 }
Exemplo n.º 7
0
 public ModuleTwin(string name, TypeModule module)
     : base(name, module)
 {
 }
Exemplo n.º 8
0
        public void SelectedPage(TypeModule type)
        {
            foreach (var frm in this.MdiChildren)
            {
                if (frm.Text == "Acceuil")
                {
                    continue;
                }
                frm.Close();
            }
            var pageFichier = rbMain.Pages.GetPageByText("Fichier");

            foreach (var p in rbMain.Pages)
            {
                var pageCnss = pageFichier.Groups.GetGroupByText("CNSS");
                if (pageCnss != null)
                {
                    pageCnss.Visible = false;
                }
                var pageBc = pageFichier.Groups.GetGroupByText("Achat en suspension");
                if (pageBc != null)
                {
                    pageBc.Visible = false;
                }
                var pageFc = pageFichier.Groups.GetGroupByText("Vente en suspension");
                if (pageFc != null)
                {
                    pageFc.Visible = false;
                }
                var pageEmp = pageFichier.Groups.GetGroupByText("Declaration employeurs");
                if (pageEmp != null)
                {
                    pageEmp.Visible = false;
                }
                var pageVir = pageFichier.Groups.GetGroupByText("Virement");
                if (pageVir != null)
                {
                    pageVir.Visible = false;
                }
                var pageLiasse = pageFichier.Groups.GetGroupByText("Liasse");
                if (pageLiasse != null)
                {
                    pageLiasse.Visible = false;
                }
            }
            switch (type)
            {
            case TypeModule.Cnss:
                var pageCnss = pageFichier.Groups.GetGroupByText("CNSS");
                if (pageCnss == null)
                {
                    return;
                }
                // pageCnss.Visible = true;
                OpenGroup(pageCnss);
                //rbMain.SelectedPage = pageCnss;
                break;

            case TypeModule.BcSuspension:
                var pageBc = pageFichier.Groups.GetGroupByText("Achat en suspension");
                if (pageBc == null)
                {
                    return;
                }
                // pageBc.Visible = true;
                OpenGroup(pageBc);
                // rbMain.SelectedPage = pageBc;
                break;

            case TypeModule.FcSuspension:
                var pageFc = pageFichier.Groups.GetGroupByText("Vente en suspension");
                if (pageFc == null)
                {
                    return;
                }
                // pageFc.Visible = true;
                OpenGroup(pageFc);
                //  rbMain.SelectedPage = pageFc;
                break;

            case TypeModule.DecEmp:
                var pageEmp = pageFichier.Groups.GetGroupByText("Declaration employeurs");
                if (pageEmp == null)
                {
                    return;
                }
                pageEmp.Visible = true;
                OpenGroup(pageEmp);
                //rbMain.SelectedPage = pageEmp;
                break;

            case TypeModule.VirementBancaire:
                var pageVir = pageFichier.Groups.GetGroupByText("Virement");
                if (pageVir == null)
                {
                    return;
                }
                //   pageVir.Visible = true;
                OpenGroup(pageVir);
                //rbMain.SelectedPage = pageVir;
                break;

            case TypeModule.Liasse:
                var pageLiass = pageFichier.Groups.GetGroupByText("Liasse");
                if (pageLiass == null)
                {
                    return;
                }
                pageLiass.Visible = true;
                OpenGroup(pageLiass);
                //rbMain.SelectedPage = pageVir;
                break;

            //Covis
            case TypeModule.Covis:
                var pageCovis = pageFichier.Groups.GetGroupByText("CNSS");
                if (pageCovis == null)
                {
                    return;
                }
                pageCovis.Visible = true;
                OpenGroup(pageCovis);
                //rbMain.SelectedPage = pageVir;
                break;

            default: break;
            }
        }
Exemplo n.º 9
0
 protected TypeProperty(string name, TypeModule module)
 {
     Name   = name;
     Module = module;
 }
Exemplo n.º 10
0
 protected Endpoint(string name, TypeModule module)
     : base(name, module)
 {
 }
Exemplo n.º 11
0
        public static async Task DockerEntryPoint(string[] args)
        {
            var cancellationTokenSource = new CancellationTokenSource();

            AssemblyLoadContext.Default.Unloading += ctx => cancellationTokenSource.Cancel();
            Console.CancelKeyPress += (sender, cpe) => cancellationTokenSource.Cancel();

            var services         = new ServiceCollection().AddLogging();
            var containerBuilder = new ContainerBuilder();

            containerBuilder.Populate(services);
            containerBuilder.RegisterBuildCallback(c => { });

            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appSettings.json", true)
                                .AddEnvironmentVariables()
                                .AddCommandLine(args)
                                .Build();

            var moduleName = configuration.GetValue <string>(Constants.ModuleNameConfigName);

            if (IsNullOrEmpty(moduleName))
            {
                moduleName = DiscoverModuleName();
                if (IsNullOrEmpty(moduleName))
                {
                    Console.WriteLine($"WARN:No {Constants.ModuleNameConfigName} in configuration. ");
                    Console.WriteLine("Exiting...");
                    return;
                }
            }

            configuration = new ConfigurationBuilder()
                            .AddJsonFile("appSettings.json", true)
                            .AddJsonFile($"{moduleName}Settings.json", true)
                            .AddEnvironmentVariables()
                            .AddCommandLine(args)
                            .Build();

            var(moduleType, _) = GetModuleTypes(moduleName);

            if (moduleType == null)
            {
                throw new ArgumentException($"No module called {moduleName} in calling assembly");
            }

            if (configuration.GetValue("metadata", false))
            {
                var description = ServiceDescriptor.Describe(moduleType);
                Console.WriteLine(JsonConvert.SerializeObject(description, Formatting.Indented));
                return;
            }


            var _inContainer       = File.Exists(@"/.dockerenv");
            var _in_Docker_Compose = Directory.Exists(Constants.ComposeConfigurationPath);

            if (_inContainer && _in_Docker_Compose)
            {
                //check the file system, we are in docker-compose mode
                var fileName         = Path.Combine(Constants.ComposeConfigurationPath, $"{moduleName}.env");
                var remainingSeconds = 100;
                while (remainingSeconds-- > 0)
                {
                    if (File.Exists(fileName))
                    {
                        configuration = new ConfigurationBuilder()
                                        .AddJsonFile("appSettings.json", true)
                                        .AddJsonFile($"{moduleName}Settings.json", true)
                                        .AddEnvironmentVariables()
                                        .AddCommandLine(args)
                                        .AddDotΕnv(fileName)
                                        .Build();
                        File.Delete(fileName);
                        break;
                    }

                    Console.WriteLine($"{moduleName}:{fileName} does not exist. Retrying in 1 sec.");
                    Thread.Sleep(1000);
                }

                if (remainingSeconds < 0)
                {
                    Console.WriteLine($"{moduleName}:No {moduleName}.env found.");
                    Console.WriteLine($"{moduleName}:Exiting...");
                    return;
                }
            }

            containerBuilder.RegisterType(moduleType);
            containerBuilder.RegisterInstance(configuration);

            var moduleDependencies    = moduleType.GetConstructors().First().GetParameters();
            var moduleDependencyTypes = moduleDependencies.Where(i => i.ParameterType.IsInterface &&
                                                                 i.ParameterType.GetCustomAttribute(
                                                                     typeof(TypeModuleAttribute),
                                                                     true) != null).Select(e => e.ParameterType);

            var proxyGenerator = new ProxyGenerator();

            foreach (var dependency in moduleDependencyTypes)
            {
                containerBuilder.RegisterInstance(
                    proxyGenerator.CreateInterfaceProxyWithoutTarget(dependency, new ModuleProxyBase(dependency)))
                .As(dependency);
            }

            var container = containerBuilder.Build();

            Module = container.Resolve(moduleType) as TypeModule;
            if (Module != null)
            {
                Module._Init(configuration, container);
                await Module._RunAsync(cancellationTokenSource.Token).ConfigureAwait(false);
            }

            await cancellationTokenSource.Token.WhenCanceled().ConfigureAwait(false);
        }