Example #1
0
        public virtual ServiceRegistryDescriptor GetServiceRegistryDescriptor(string name)
        {
            Dictionary <string, Func <FileInfo, ServiceRegistryDescriptor> > deserializers = new Dictionary <string, Func <FileInfo, ServiceRegistryDescriptor> >
            {
                { ".json", (fi) => fi.FromJsonFile <ServiceRegistryDescriptor>() },
                { ".yml", (fi) => fi.FromYamlFile <ServiceRegistryDescriptor>() }
            };
            DirectoryInfo             systemServiceRegistryDir = DataSettings.GetSysDataDirectory(nameof(ServiceRegistry).Pluralize());
            ServiceRegistryDescriptor fromFile = new ServiceRegistryDescriptor {
                Name = name
            };

            ServiceDescriptor[] descriptors = new ServiceDescriptor[] { };
            FileInfo            file        = new FileInfo(Path.Combine(systemServiceRegistryDir.FullName, $"{name}.json"));

            foreach (string extension in new[] { ".yml", ".json" })
            {
                string path = Path.Combine(systemServiceRegistryDir.FullName, $"{name}{extension}");
                if (File.Exists(path))
                {
                    file     = new FileInfo(path);
                    fromFile = deserializers[extension](file);
                    break;
                }
            }

            Dictionary <string, Action <ServiceRegistryDescriptor, FileInfo> > serializers = new Dictionary <string, Action <ServiceRegistryDescriptor, FileInfo> >
            {
                { ".json", (sr, fi) => sr.ToJsonFile(fi) },
                { ".yml", (sr, fi) => sr.ToYamlFile(fi) }
            };
            ServiceRegistryDescriptor fromRepo = ServiceRegistryRepository.ServiceRegistryDescriptorsWhere(c => c.Name == name).FirstOrDefault();

            if (fromRepo != null)
            {
                HashSet <ServiceDescriptor> svcs = new HashSet <ServiceDescriptor>();
                if (fromFile != null)
                {
                    fromFile.Services?.Each(svc => svcs.Add(svc));
                }
                fromRepo.Services?.Each(svc => svcs.Add(svc));
                fromRepo.Services = svcs.ToList();
                serializers[Path.GetExtension(file.FullName)](fromRepo, file);
            }

            ServiceRegistryDescriptor toSave = fromRepo ?? fromFile;

            if (toSave != null)
            {
                ServiceRegistryRepository.Save(toSave);
            }
            return(fromRepo ?? fromFile);
        }
Example #2
0
        public CompositeRepository(DaoRepository sourceRepository, DataSettings dataSettings = null)
        {
            DataSettings               = dataSettings ?? DataSettings.Current;
            SourceRepository           = sourceRepository;
            ReadRepository             = new CachingRepository(sourceRepository);
            WriteRepositories          = new HashSet <IRepository>();
            WorkspacePath              = DataSettings.GetWorkspaceDirectory(this.GetType()).FullName;
            BackupRepository           = new ObjectRepository(DataSettings.GetSysDataDirectory("BackupObjectRepo").FullName);
            TypeSchemaTempPathProvider = (sd, ts) => Path.Combine(WorkspacePath, sd.Name, ts.Hash);

            WireBackup();

            sourceRepository.StorableTypes.Each(type => AddType(type));
        }