Ejemplo n.º 1
0
        public virtual bool IsConnectionOpen(SmoObjectBase smoObj)
        {
            SqlSmoObject sqlObj = smoObj as SqlSmoObject;

            return(sqlObj != null &&
                   sqlObj.ExecutionManager != null &&
                   sqlObj.ExecutionManager.ConnectionContext != null &&
                   sqlObj.ExecutionManager.ConnectionContext.IsOpen);
        }
Ejemplo n.º 2
0
 public MySmoObjectBase(MySmoObjectBase mySmoObject)
 {
     SourceSmoObject           = mySmoObject.SourceSmoObject;
     Name                      = mySmoObject.Name;
     ParentName                = mySmoObject.ParentName;
     this.mProductionSmoObject = mySmoObject.mProductionSmoObject;
     ExtraParams               = new string[mySmoObject.ExtraParams.Length];
     mySmoObject.ExtraParams.CopyTo(ExtraParams, 0);
 }
 /// <summary>
 /// Ensures the server objects connection context is open. This is used by all child objects, and
 /// the only way to easily access is via the server object. This should be called during access of
 /// any of the object properties
 /// </summary>
 public void EnsureConnectionOpen(SmoObjectBase smoObj)
 {
     if (!smoWrapper.IsConnectionOpen(smoObj))
     {
         // We have a closed server connection. Reopen this
         // Note: not currently catching connection exceptions. Expect this to bubble
         // up to calling methods and be logged there as this would be happening there in any case
         smoWrapper.OpenConnection(smoObj);
     }
 }
Ejemplo n.º 4
0
        public virtual void OpenConnection(SmoObjectBase smoObj)
        {
            SqlSmoObject sqlObj = smoObj as SqlSmoObject;

            if (sqlObj != null &&
                sqlObj.ExecutionManager != null &&
                sqlObj.ExecutionManager.ConnectionContext != null)
            {
                sqlObj.ExecutionManager.ConnectionContext.Connect();
            }
        }
        /// <summary>
        /// Copies the context for use by another node
        /// </summary>
        /// <param name="parent">New Parent to set</param>
        /// <returns>new <see cref="SmoQueryContext"/> with all fields except <see cref="Parent"/> the same</returns>
        public SmoQueryContext CopyWithParent(SmoObjectBase parent)
        {
            SmoQueryContext context = new SmoQueryContext(this.Server, this.ServiceProvider, this.smoWrapper)
            {
                database      = this.Database,
                Parent        = parent,
                SqlServerType = this.SqlServerType,
                ValidFor      = ValidFor
            };

            return(context);
        }
Ejemplo n.º 6
0
 protected virtual void EnsureContextInitialized()
 {
     if (context == null)
     {
         SmoObjectBase   smoParent     = GetParentSmoObject();
         SmoQueryContext parentContext = Parent?.GetContextAs <SmoQueryContext>();
         if (smoParent != null && parentContext != null)
         {
             context = parentContext.CopyWithParent(smoParent);
         }
     }
 }
Ejemplo n.º 7
0
 public MySmoObjectBase(SmoObjectBase smoObject,
                        string name,
                        string parentName,
                        params string[] extraParams)
 {
     SourceSmoObject = smoObject;
     Name            = name;
     ParentName      = parentName;
     ExtraParams     = new string[extraParams.Length];
     for (int i = 0; i < extraParams.Length; i++)
     {
         ExtraParams[i] = UpgradeScriptGenerator.TrimSymbols(extraParams[i]);
     }
 }
Ejemplo n.º 8
0
        public void QueryContextShouldReopenClosedConnectionWhenGettingParent()
        {
            // given a server connection that will state its connection is closed
            Server            smoServer = new Server(new ServerConnection(new SqlConnection(fakeConnectionString)));
            Mock <SmoWrapper> wrapper   = SetupSmoWrapperForIsOpenTest(smoServer, isOpen: false);

            SmoQueryContext context = new SmoQueryContext(smoServer, ServiceProvider, wrapper.Object);

            context.Parent = smoServer;
            // when I access the Parent property
            SmoObjectBase actualParent = context.Parent;

            // Then I expect to have open called
            Assert.NotNull(actualParent);
            wrapper.Verify(c => c.OpenConnection(It.IsAny <Server>()), Times.Once);
        }
Ejemplo n.º 9
0
 public MyIndex(SmoObjectBase smoObject, string name, string parentName) :
     base(smoObject, ChangeName(name), parentName)
 {
 }
Ejemplo n.º 10
0
 public MyColumn(SmoObjectBase smoObject, string name, string parentName) :
     base(smoObject, name, parentName)
 {
 }
Ejemplo n.º 11
0
 public MyForeignKey(SmoObjectBase smoObject, string name, string parentName) :
     base(smoObject, name, parentName)
 {
 }
Ejemplo n.º 12
0
 private bool IncludeSysObject(SmoObjectBase o)
 {
     return(arguments.IncludeSystemObjects || (o is Table ? ((Table)o).Name == "sysdiagrams" : false) || (arguments.IncludeSystemTables && o is Table));
 }
Ejemplo n.º 13
0
 private bool OutputAtEnd(SmoObjectBase o, string s)
 {
     return(o is Table && s.Contains("\nALTER") && !s.StartsWith("INSERT"));
 }
Ejemplo n.º 14
0
 public MyStoredProcedure(SmoObjectBase smoObject, string name, string parentName, string textBody) :
     base(smoObject, name, parentName, textBody)
 {
 }
Ejemplo n.º 15
0
 public MyTrigger(SmoObjectBase smoObject, string name, string parentName, string textBody) :
     base(smoObject, name, parentName, textBody)
 {
 }