Exemplo n.º 1
0
        // helpers
        private string SerializeXmlConfig(DalConfig config)
        {
            var ser = new DataContractSerializer(typeof(DalConfig));
            var settings = new XmlWriterSettings { Indent = true, Encoding = Encoding.Unicode };

            var sb = new StringBuilder();
            using (var writer = XmlWriter.Create(sb, settings))
            {
                ser.WriteObject(writer, config);
            }

            return sb.ToString();
        }
Exemplo n.º 2
0
        private static bool CompareConfigs(DalConfig xmlConfig, SimpleDataAccessLayer.Common.config.models.DalConfig newConfig)
        {
            if (xmlConfig.ApplicationConnectionString != newConfig.RuntimeConnectionStringName)
                return false;

            if (xmlConfig.Namespace != newConfig.Namespace)
                return false;

            // enums
            if (xmlConfig.Enums == null && newConfig.Enums != null)
                return false;

            if (xmlConfig.Enums != null && newConfig.Enums == null)
                return false;

            if (xmlConfig.Enums != null && newConfig.Enums != null && xmlConfig.Enums.Count != newConfig.Enums.Count)
                return false;

            if (xmlConfig.Enums != null && newConfig.Enums != null &&
                xmlConfig.Enums.Select(
                    xmlConfigEnum =>
                        newConfig.Enums.FirstOrDefault(
                            newConfigEnum =>
                                newConfigEnum.Schema == xmlConfigEnum.Schema &&
                                newConfigEnum.Alias == xmlConfigEnum.Alias &&
                                newConfigEnum.KeyColumn == xmlConfigEnum.KeyColumn &&
                                newConfigEnum.TableName == xmlConfigEnum.TableName &&
                                newConfigEnum.ValueColumn == xmlConfigEnum.ValueColumn))
                    .Any(newConfigMatchEnum => newConfigMatchEnum == null))
                return false;

            if (xmlConfig.Procedures != null && newConfig.Procedures != null &&
                xmlConfig.Procedures.Select(
                    xmlConfigProcedure =>
                        newConfig.Procedures.FirstOrDefault(
                            newConfigProcedure =>
                                newConfigProcedure.Schema == xmlConfigProcedure.Schema &&
                                newConfigProcedure.Alias == xmlConfigProcedure.Alias &&
                                newConfigProcedure.ProcedureName == xmlConfigProcedure.ProcedureName))
                    .Any(newConfigMatchProcedure => newConfigMatchProcedure == null))
                return false;

            if (xmlConfig.DesignerConnection != null && newConfig.DesignerConnection == null)
                return false;

            if (xmlConfig.DesignerConnection == null && newConfig.DesignerConnection != null &&
                newConfig.DesignerConnection.Authentication.AuthenticationType == AuthenticationType.SqlAuthentication)
                return false;

            if (xmlConfig.DesignerConnection != null && newConfig.DesignerConnection != null)
            {
                if (xmlConfig.DesignerConnection.Authentication is WindowsAuthentication &&
                    newConfig.DesignerConnection.Authentication.AuthenticationType == AuthenticationType.SqlAuthentication)
                    return false;
                if (xmlConfig.DesignerConnection.Authentication is SimpleDataAccessLayer.Common.config.models.old.SqlAuthentication &&
                    newConfig.DesignerConnection.Authentication.AuthenticationType == AuthenticationType.WindowsAuthentication)
                    return false;
                if (xmlConfig.DesignerConnection.Authentication is SimpleDataAccessLayer.Common.config.models.old.SqlAuthentication &&
                      newConfig.DesignerConnection.Authentication.AuthenticationType == AuthenticationType.SqlAuthentication
                      &&
                      !(((SimpleDataAccessLayer.Common.config.models.old.SqlAuthentication) xmlConfig.DesignerConnection.Authentication)
                          .UserName == newConfig.DesignerConnection.Authentication.UserName &&
                    ((SimpleDataAccessLayer.Common.config.models.old.SqlAuthentication) xmlConfig.DesignerConnection.Authentication)
                        .Password == newConfig.DesignerConnection.Authentication.Password))
                return false;

            }

            return true;
        }
Exemplo n.º 3
0
        private DalConfig GenerateConfig()
        {
            var rnd = new Random();

            var config = new DalConfig()
            {
                ApplicationConnectionString = rnd.Next(0, 9) < 2 ? null : Guid.NewGuid().ToString("N"),
                Namespace = rnd.Next(0, 9) < 2 ? null : Guid.NewGuid().ToString("N"),
                DesignerConnection = rnd.Next(0, 9) < 2
                    ? null
                    : new DesignerConnection()
                    {
                        Authentication =
                            rnd.Next(0, 9) < 2
                                ? null
                                : (rnd.Next(0, 9) < 5
                                    ? new WindowsAuthentication() as
                                        Authentication
                                    : new SimpleDataAccessLayer.Common.config.models.old.SqlAuthentication(
                                        rnd.Next(0, 9) < 2 ? null : Guid.NewGuid().ToString("N"),
                                        rnd.Next(0, 9) < 2 ? null : Guid.NewGuid().ToString("N")))
                    },
                Enums = GetEnums(),
                Procedures = GetProcedures()
            };

            return config;
        }
Exemplo n.º 4
0
 protected bool Equals(DalConfig other)
 {
     return Equals(DesignerConnection, other.DesignerConnection) && string.Equals(Namespace, other.Namespace) &&
            string.Equals(ApplicationConnectionString, other.ApplicationConnectionString) &&
            Equals(Enums, other.Enums) && Equals(Procedures, other.Procedures);
 }