Example #1
0
 /// <summary>
 /// Merges two service collections
 /// </summary>
 /// <param name="svc">Target service</param>
 /// <param name="other">Service to merge with (will override services if exist)</param>
 public static void Merge(this IXServiceCollection svc, IXServiceCollection other)
 {
     foreach (var dep in other.Services)
     {
         svc.AddOrReplace(dep.Key, dep.Value);
     }
 }
Example #2
0
        internal void Init(IXServiceCollection customServices)
        {
            if (!m_IsInitialized)
            {
                m_CustomServices = customServices;

                m_IsInitialized = true;

                var services = new ServiceCollection();
                ConfigureServices(services);

                if (customServices != null)
                {
                    services.Merge(customServices);
                }

                m_Provider = services.CreateProvider();
                m_Logger   = m_Provider.GetService <IXLogger>();

                Documents = new SwDocumentCollection(this, m_Logger);

                var geomBuilderDocsProvider = m_Provider.GetService <IMemoryGeometryBuilderDocumentProvider>();

                MemoryGeometryBuilder = new SwMemoryGeometryBuilder(this, geomBuilderDocsProvider);
            }
            else
            {
                Debug.Assert(false, "App has been already initialized. Must be only once");
            }
        }
Example #3
0
 public static void Populate(this ContainerBuilder builder, IXServiceCollection svcColl)
 {
     foreach (var svc in svcColl.Services)
     {
         builder.Register <object>(x => svc.Value.Invoke())
         .As(svc.Key);
     }
 }
 public static void Populate(this IXServiceCollection svcColl, IComponentContext context)
 {
     foreach (var reg in context.ComponentRegistry.Registrations)
     {
         var svcType = (reg.Services.First() as Autofac.Core.TypedService).ServiceType;
         svcColl.AddOrReplace(svcType, () => context.Resolve(svcType));
     }
 }
Example #5
0
        public SwApplicationProvider(IXLogger logger, IMacroExecutor svc, ICadDescriptor entDesc)
        {
            m_Logger = logger;

            MacroRunnerService = svc;
            Descriptor         = entDesc;
            m_CustomServices   = new ServiceCollection();
            m_CustomServices.AddOrReplace <IXLogger>(() => m_Logger);

            m_ForceDisabledAddIns = new Dictionary <Process, List <string> >();
        }
Example #6
0
        public static ISwApplication FromProcess(Process process, IXServiceCollection services)
        {
            var app = RotHelper.TryGetComObjectByMonikerName <ISldWorks>(GetMonikerName(process));

            if (app != null)
            {
                return(FromPointer(app, services));
            }
            else
            {
                throw new Exception($"Cannot access SOLIDWORKS application at process {process.Id}");
            }
        }
Example #7
0
        private void OnConfigureExtensionServices(IXServiceConsumer sender, IXServiceCollection svcColl)
        {
            var builder = new ContainerBuilder();

            builder.Populate(svcColl);

            ConfigureHostServices(builder);

            ConfigureServices?.Invoke(new ContainerBuilderWrapper(builder));

            m_SvcProvider = new ServiceProvider(builder.Build());

            svcColl.Populate(m_SvcProvider.Container);

            m_PageCreator = m_SvcProvider.Container.Resolve <IPropertyPageCreator>();
        }
Example #8
0
        private void OnConfigureExtensionServices(IXServiceConsumer sender, IXServiceCollection svcColl)
        {
            var builder = new ContainerBuilder();

            builder.Populate(svcColl);

            ConfigureHostServices(builder);

            ConfigureServices?.Invoke(new ContainerBuilderWrapper(builder));

            m_SvcProvider = new ServiceProvider(builder.Build());

            svcColl.Populate(m_SvcProvider.Context);

            Initialized?.Invoke(m_App, m_SvcProvider, m_Modules);
        }
Example #9
0
        public SwApplicationProvider(IXLogger logger)
        {
            InputFilesFilter = new FileFilter[]
            {
                new FileFilter("SOLIDWORKS Parts", "*.sldprt"),
                new FileFilter("SOLIDWORKS Assemblies", "*.sldasm"),
                new FileFilter("SOLIDWORKS Drawings", "*.slddrw"),
                new FileFilter("SOLIDWORKS Files", "*.sldprt", "*.sldasm", "*.slddrw"),
                FileFilter.AllFiles
            };

            m_Logger = logger;

            m_CustomServices = new ServiceCollection();
            m_CustomServices.AddOrReplace <IXLogger>(() => m_Logger);

            m_ForceDisabledAddIns = new Dictionary <Process, List <string> >();
        }
Example #10
0
 public static ISwApplication FromPointer(ISldWorks app, IXServiceCollection services)
 {
     return(new SwApplication(app, services));
 }
Example #11
0
 /// <inheritdoc cref="AddOrReplace(IXServiceCollection, Type, Type)"/>
 /// <param name="factory">Service creation factory</param>
 public static void AddOrReplace(this IXServiceCollection coll, Type svcType, Func <object> factory)
 {
     coll.AddOrReplace(svcType, factory);
 }
Example #12
0
 /// <inheritdoc cref="IXServiceCollection.AddOrReplace(Type, Func{object})"/>
 /// <param name="svcType">Type of service</param>
 /// <param name="impType">Service implementation</param>
 public static void AddOrReplace(this IXServiceCollection coll, Type svcType, Type impType)
 => AddOrReplace(coll, svcType, () => Activator.CreateInstance(impType));
Example #13
0
 /// <inheritdoc cref="AddOrReplace{TService, TImplementation}(IXServiceCollection)"/>
 /// <param name="factory">Service creation factory</param>
 public static void AddOrReplace <TService>(this IXServiceCollection coll, Func <TService> factory)
 => AddOrReplace(coll, typeof(TService), new Func <object>(() => factory.Invoke()));
Example #14
0
 public void ConfigureServices(IXServiceCollection collection)
 {
     collection.AddOrReplace((Func <IXLogger>)(() => new TraceLogger("xCAD.SwApplication")));
     collection.AddOrReplace((Func <IMemoryGeometryBuilderDocumentProvider>)(() => new DefaultMemoryGeometryBuilderDocumentProvider(this)));
 }
Example #15
0
 internal SwApplication(ISldWorks app, IXServiceCollection customServices)
     : this(app)
 {
     Init(customServices);
 }
 public virtual void OnConfigureServices(IXServiceCollection collection)
 {
 }
 public override void OnConfigureServices(IXServiceCollection collection)
 {
     collection.AddOrReplace <IMemoryGeometryBuilderDocumentProvider>(
         () => new LazyNewDocumentGeometryBuilderDocumentProvider(Application));
 }
Example #18
0
 /// <inheritdoc cref="IXServiceCollection.AddOrReplace(Type, Func{object})"/>
 /// <param name="coll">Services collection</param>
 /// <typeparam name="TService">Service interface</typeparam>
 /// <typeparam name="TImplementation">Service implementation</typeparam>
 public static void AddOrReplace <TService, TImplementation>(this IXServiceCollection coll)
     where TImplementation : TService => AddOrReplace(coll, typeof(TService), typeof(TImplementation));