Ejemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();

            DataContext = new MainWindowViewModel();

            var startupMinimized = DePeuterRegistry.Get("Timesheets", "StartupMinimized") as string;

            if (!string.IsNullOrEmpty(startupMinimized))
            {
                try
                {
                    if (bool.Parse(startupMinimized))
                    {
                        WindowState = WindowState.Minimized;
                        _maximizeOnNextStateChanged = true;
                    }
                }
                catch (Exception ex)
                {
                    ViewModel.HandleException(ex);
                }
            }
        }
Ejemplo n.º 2
0
 public static List <string> GetDefaultTaskNumbers()
 {
     return((DePeuterRegistry.Get("Timesheets", "DefaultTaskNumbers") as string ?? string.Empty).Split(';').Select(x => x.Trim()).Where(x => !string.IsNullOrEmpty(x)).ToList());
 }
Ejemplo n.º 3
0
    public static Type FindImplementationType(ResolveData data, ValidateImplementationTypesHandler validateImplementationTypes = null, ResolveImplementationTypeHandler resolveImplementationType = null)
    {
        var wantedType = data.WantedType;

        if (!wantedType.IsAbstract)
        {
            return(wantedType);
        }

        lock (Lock)
        {
            if (WantedTypeToImplementationType.ContainsKey(wantedType))
            {
                return(WantedTypeToImplementationType[wantedType]);
            }

            Type   type = null;
            Type[] types;

            if (ImplementationTypes.ContainsKey(wantedType))
            {
                types = ImplementationTypes[wantedType];
            }
            else
            {
                types = AllImplementationTypes.Where(wantedType.IsAssignableFrom).ToArray();

                if (!types.Any())
                {
                    types = wantedType.Assembly.GetTypes().Where(x => !x.IsAbstract && wantedType.IsAssignableFrom(x)).ToArray();
                }

                if (!types.Any())
                {
                    throw new MissingTypesException(wantedType);
                }

                if (validateImplementationTypes != null)
                {
                    validateImplementationTypes(wantedType, types);
                }
                else if (ValidateImplementationTypes != null)
                {
                    ValidateImplementationTypes(wantedType, types);
                }

                ImplementationTypes.Set(wantedType, types);
            }

            if (resolveImplementationType != null)
            {
                type = resolveImplementationType(data, types.AreNotNull().ToArray());
            }
            else if (ResolveImplementationType != null)
            {
                type = ResolveImplementationType(data, types.AreNotNull().ToArray());
            }

            if (type == null)
            {
                if (types.Length == 1)
                {
                    type = types[0];
                }
                else if (typeof(IBaseDatabaseService).IsAssignableFrom(wantedType))
                {
                    //basic logica voor implementatie van inherited interface van IBaseDatabaseService
                    //dan moet hij obv providername van connectionstring de juiste databaseprovider vinden
                    foreach (var x in types.AreNotNull())
                    {
                        string connectionStringProvider = null;

                        var connectionStringNameAttr = x.GetCustomAttribute <ConnectionStringNameAttribute>() ?? x.GetCustomAttribute <ConnectionStringNameAttribute>(true);
                        if (connectionStringNameAttr != null)
                        {
                            var connectionString = ConfigurationManager.ConnectionStrings[connectionStringNameAttr.Name];
                            if (connectionString == null)
                            {
                                throw new MissingConnectionStringException(connectionStringNameAttr.Name);
                            }

                            connectionStringProvider = connectionString.ProviderName;
                        }

                        if (connectionStringProvider == null)
                        {
                            var registryKeyAttribute = x.GetCustomAttribute <RegistryKeyAttribute>() ?? x.GetCustomAttribute <RegistryKeyAttribute>(true);
                            if (registryKeyAttribute != null)
                            {
                                connectionStringProvider = DePeuterRegistry.Get(registryKeyAttribute.Key + "ProviderName") as string;
                            }
                        }

                        if (connectionStringProvider == null)
                        {
                            continue;
                        }

                        var databaseProviderAttrs = x.GetCustomAttributes <BaseDatabaseProviderAttribute>();
                        if (databaseProviderAttrs == null || !databaseProviderAttrs.Any())
                        {
                            databaseProviderAttrs = x.GetCustomAttributes <BaseDatabaseProviderAttribute>(true);
                        }

                        if (databaseProviderAttrs != null)
                        {
                            foreach (var databaseProviderAttr in databaseProviderAttrs)
                            {
                                if (type != null)
                                {
                                    break;
                                }

                                var provider = DatabaseProviders.GetDatabaseProvider(connectionStringProvider);
                                if (databaseProviderAttr.ProviderType == provider.GetType())
                                {
                                    type = x;
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            if (type == null)
            {
                type = types.SingleOrDefault(x => "I" + x.Name == wantedType.Name && x.Namespace == wantedType.Namespace && x.Assembly.FullName == wantedType.Assembly.FullName);

                if (type == null)
                {
                    throw new MultipleTypesException(wantedType, types);
                }
            }

            if (resolveImplementationType == null || ResolveImplementationType == null)
            {
                WantedTypeToImplementationType.Set(wantedType, type);
            }

            return(type);
        }
    }
Ejemplo n.º 4
0
 protected override void ResolveProviderAndConnectionString(out string providerInvariantName, out string connectionString)
 {
     connectionString      = DePeuterRegistry.Get("Timesheets", "ConnectionString") as string ?? @"Data Source=localhost\SQLEXPRESS;Initial Catalog=depeuter;Integrated Security=SSPI";
     providerInvariantName = DatabaseProviderName;
 }