コード例 #1
0
 static EducationDataContext()
 {
     EFTracingProviderConfiguration.DefaultWrappedProvider = WrappedProvider;
     EFTracingProviderConfiguration.RegisterProvider();
     EFCachingProviderConfiguration.DefaultWrappedProvider = WrappedProvider;
     EFCachingProviderConfiguration.RegisterProvider();
 }
コード例 #2
0
        static void Main(string[] args)
        {
            //tracing
            EFTracingProviderConfiguration.RegisterProvider();
            EFCachingProviderConfiguration.RegisterProvider();
            EFTracingProviderConfiguration.LogToConsole = false;

            //execution order
            //BuildingsAndContactInfoPass (buildings, contact infos, users
            //AffiliateUsersPass (apiKeys, affiliateUsers)
            //PhotosPass (takes a really long f*****g time)
            //PrimaryPhotosPass
            //AmenitiesPass (basic, withOptions, custom)
            //BuildingAmenitiesPass (probably gonna take a while, 330,000 of them in there.)
            //BuildingAmenitiesWithOptionsPass

            var first = new BuildingsAndContactInfoPass();

            first.LetsDoThis();
            first = null;

            var second = new AffiliateUsersPass();

            second.LetsDoThis();
            second = null;

            Console.WriteLine("Now would be a good time to import the applications, dude.");
            Console.ReadLine();

            var third = new PhotosPass();

            third.LetsDoThis();
            third = null;

            var fourth = new PrimaryPhotosPass();

            fourth.LetsDoThis();
            fourth = null;

            //stop here and run the amenities import.sql script
            Console.WriteLine("Pause here and run the amenities import.sql script");
            Console.ReadLine();

            var fifth = new CustomAmenitiesPass();

            fifth.LetsDoThis();
            fifth = null;

            var sixth = new BuildingAmenitiesPass();

            sixth.LetsDoThis();
            sixth = null;

            var seventh = new BuildingAmenitiesWithOptions();

            seventh.LetsDoThis();
            seventh = null;
        }
コード例 #3
0
 public static void InitSqlTracing(ILogger logger)
 {
     _logger = logger;
     EFTracingProviderConfiguration.RegisterProvider();
     if (logger.IsLoggingEnabled())              // Don't add logging hooks if logging isn't enabled
     {
         EFTracingProviderConfiguration.LogAction = new Action <CommandExecutionEventArgs>(AppendSqlLog);
     }
 }
コード例 #4
0
        public void Init()
        {
            EFTracingProviderConfiguration.RegisterProvider();
            EFCachingProviderConfiguration.RegisterProvider();
#if LOGGING
            EFTracingProviderConfiguration.LogToConsole = true; //Optional: for sending tracing to console
#endif
            // 初始化Log4net,配置在独立的"log4net.config"中配置
            log4net.Config.XmlConfigurator.Configure(new FileInfo("log4net.config"));
            // 初始化一个logger
            logger = log4net.LogManager.GetLogger("EFLog4net");
        }
コード例 #5
0
        static void Main(string[] args)
        {
            EFTracingProviderConfiguration.RegisterProvider();
            EFCachingProviderConfiguration.RegisterProvider();

            // tracing + caching demos
            SimpleCachingDemo();
            CacheInvalidationDemo();
            NonDeterministicQueryCachingDemo();

            // tracing demos
            SimpleTracingDemo();
            AdvancedTracingDemo();
        }
コード例 #6
0
    private static DbConnection CreateConnection(string connectionString,
                                                 string providerInvariantName)
    {
        DbConnection connection = null;

        if (TraceEnabled)
        {
            EFTracingProviderConfiguration.RegisterProvider();
            EFTracingProviderConfiguration.LogToConsole = true;
            string wrapperConnectionString = String.Format(@"wrappedProvider={0};{1}",
                                                           providerInvariantName, connectionString);
            connection = new EFTracingConnection()
            {
                ConnectionString = wrapperConnectionString
            };
        }
        else
        {
            DbProviderFactory factory = DbProviderFactories.GetFactory(providerInvariantName);
            connection = factory.CreateConnection();
            connection.ConnectionString = connectionString;
        }
        return(connection);
    }
コード例 #7
0
        //private void AppendToLog(object sender, CommandExecutionEventArgs e)
        //{
        //    if (this.logOutput != null)
        //    {
        //        this.logOutput.WriteLine(e.ToTraceString().TrimEnd());
        //        this.logOutput.WriteLine();
        //    }
        //}

        //public TextWriter Log
        //{
        //    get { return this.logOutput; }
        //    set
        //    {
        //        if ((this.logOutput != null) != (value != null))
        //        {
        //            if (value == null)
        //            {
        //                CommandExecuting -= AppendToLog;
        //            }
        //            else
        //            {
        //                CommandExecuting += AppendToLog;
        //            }
        //        }

        //        this.logOutput = value;
        //    }
        //}


        #endregion

        /// <summary>
        /// Create warpped connection.
        /// </summary>
        /// <param name="nameOrConnectionString">The connection string name in the config file or actual value.</param>
        /// <param name="enableTracing">Enable entities tracing.</param>
        /// <param name="enableCaching">Enable entities caching.</param>
        /// <returns>The wrapped connection.</returns>
        protected static DbConnection CreateWrappedConnection(string nameOrConnectionString, bool enableTracing, bool enableCaching)
        {
            //-------------------------------------------------------
            //  Init
            //-------------------------------------------------------

            /* Setup variables */
            DbConnection connection            = null;
            string       providerInvariantName = "System.Data.SqlClient";
            string       connectionString      = nameOrConnectionString;

            if (enableTracing && !initializedTracingWrapper)
            {
                EFTracingProviderConfiguration.RegisterProvider();
#if DEBUG
                EFTracingProviderConfiguration.LogToConsole = true;
#endif

                initializedTracingWrapper = true;
            }

            if (enableCaching && !initializedCachingWrapper)
            {
                EFCachingProviderConfiguration.RegisterProvider();
                initializedCachingWrapper = true;
            }

            //-------------------------------------------------------
            //  Do we got a "name={DbConnectionNameInConfigFile} format?
            //-------------------------------------------------------
            int index = nameOrConnectionString.IndexOf('=');
            if (index > -1 &&
                nameOrConnectionString.Substring(0, index).Trim().Equals("name", StringComparison.OrdinalIgnoreCase))
            {
                /* Get the actual connection name */
                nameOrConnectionString = nameOrConnectionString.Substring(index + 1).Trim();
            }

            //-------------------------------------------------------
            //  Parse the connection string and provider invariant name
            //-------------------------------------------------------
            var connectionStringSetting = ConfigurationManager.ConnectionStrings[nameOrConnectionString];
            if (connectionStringSetting != null)
            {
                providerInvariantName = connectionStringSetting.ProviderName;
                connectionString      = connectionStringSetting.ConnectionString;
            }

            //-------------------------------------------------------
            //  Construct the basic underlaying connection
            //-------------------------------------------------------
            DbProviderFactory factory = DbProviderFactories.GetFactory(providerInvariantName);
            connection = factory.CreateConnection();
            try
            {
                connection.ConnectionString = connectionString;
            }
            catch { }

            //-------------------------------------------------------
            //  Should we use tracking
            //-------------------------------------------------------
            if (enableTracing)
            {
                connection = new EFTracingConnection(connection, "System.Data.SqlClient");
            }

            //-------------------------------------------------------
            //  Should we use caching
            //  NOTE: Caching test and wrapping MUST COME AFTER Tracing OTHERWISE IT'LL WON'T WORK!
            //-------------------------------------------------------

            if (enableCaching)
            {
                if (enableTracing)
                {
                    connection = new EFCachingConnection(connection, "EFTracingProvider");
                }
                else
                {
                    connection = new EFCachingConnection(connection, "System.Data.SqlClient");
                }
            }

            return(connection);
        }