Пример #1
0
        public void Rebuild(RebuildMode rebuildMode)
        {
            IBlackboardProvider blackboardProvider =
                ((VSGraphModel)Store.GetState().CurrentGraphModel).Stencil.GetBlackboardProvider();

            if (Sections == null || m_LastProvider != blackboardProvider)
            {
                m_LastProvider = blackboardProvider;
                ClearContents();
                Clear();
                Sections = blackboardProvider?.CreateSections().ToList();
                Sections?.ForEach(Add);
            }

            if (rebuildMode == RebuildMode.BlackboardAndGraphView)
            {
                Store.Dispatch(new RefreshUIAction(UpdateFlags.GraphTopology));
            }
            else
            {
                RebuildBlackboard();
            }
        }
        public string Install (string schemaGroup, SchemaObjectCollection objects, RebuildMode rebuildMode)
        {
			_scripts = new StringBuilder ();

            // validate the arguments
            if (schemaGroup == null) throw new ArgumentNullException ("schemaGroup");
            if (objects == null) throw new ArgumentNullException ("objects");

            // get the list of objects
            List<SchemaObject> schemaObjects = new List<SchemaObject> (objects);
            ValidateSchemaObjects (schemaObjects);
            for (int i = 0; i < objects.Count; i++)
                objects[i].OriginalOrder = i;

            // sort the list of objects in installation order
            schemaObjects.Sort (delegate (SchemaObject o1, SchemaObject o2) 
            { 
                int compare = o1.SchemaObjectType.CompareTo (o2.SchemaObjectType);
                if (compare == 0)
                    compare = o1.OriginalOrder.CompareTo (o2.OriginalOrder);
                if (compare == 0)
					compare = String.Compare(o1.Name, o2.Name, StringComparison.OrdinalIgnoreCase);
				return compare;
            });

			// the schema changes must be done in a transaction
            // since we don't pool the connection, we need to end the transaction before closing the connection
            try
            {
                using (TransactionScope transaction = new TransactionScope (TransactionScopeOption.Required, new TimeSpan (1, 0, 0, 0, 0)))
                {
					// open the connection
					OpenConnection ();

					 // make sure we have a schema registry
					SchemaRegistry registry = new SchemaRegistry (_connection);

                    // keep a list of all of the operations we need to perform
                    List<string> dropObjects = new List<string> ();
                    List<SchemaObject> addObjects = new List<SchemaObject> ();
                    List<SchemaObject> tableUpdates = new List<SchemaObject> ();

                    // look through all of the existing objects in the registry
                    // create a delete instruction for all of the ones that should no longer be there
                    foreach (string objectName in registry.GetObjectNames (schemaGroup))
                    {
                        SchemaObject schemaObject = schemaObjects.Find (delegate (SchemaObject o) 
						{
							return (o.Name.ToUpperInvariant() == objectName.ToUpperInvariant());
						});
                        if (schemaObject == null)
                            dropObjects.Add (objectName);
                    }

					// sort to drop in reverse dependency order 
					dropObjects.Sort (delegate (string o1, string o2)
					{
						int compare = -registry.GetObjectType (o1).CompareTo (registry.GetObjectType (o2));
						if (compare == 0)
							compare = -registry.GetOriginalOrder(o1).CompareTo(registry.GetOriginalOrder(o2)); 
						if (compare == 0)
							compare = -String.Compare(o1, o2, StringComparison.OrdinalIgnoreCase);

						return compare;
					});

                    // find out if we need to add anything
                    foreach (SchemaObject schemaObject in schemaObjects)
                    {
                        // add any objects that aren't in the registry yet
                        if (!registry.Contains (schemaObject.Name))
                            addObjects.Add (schemaObject);
                    }

					// see if there are any drops or modifications
					bool hasChanges = dropObjects.Count != 0;
					if (!hasChanges)
					{
						foreach (SchemaObject schemaObject in schemaObjects)
						{
							if (registry.Contains (schemaObject.Name) && 
								registry.GetSignature (schemaObject.Name) != schemaObject.Signature)
							{
								hasChanges = true;
								break;
							}
						}
					}

					// if there are changes, drop all of the easy items
					// drop and re-add all of the easy items
					if (hasChanges || (rebuildMode > RebuildMode.DetectChanges))
					{
						for (int i = schemaObjects.Count - 1; i >= 0; i--)
						{
							SchemaObject schemaObject = schemaObjects [i];
							if (registry.Contains (schemaObject.Name) &&
								(
									IsEasyToModify (schemaObject.SchemaObjectType) || 
									(rebuildMode >= RebuildMode.RebuildSafe && CanRebuildSafely (schemaObject.SchemaObjectType)) ||
									(rebuildMode >= RebuildMode.RebuildFull && CanRebuild (schemaObject.SchemaObjectType))
								) &&
								!dropObjects.Contains (schemaObject.Name))
							{
								dropObjects.Add (schemaObject.Name);
								addObjects.Add (schemaObject);
							}
						}
					}

					// drop and re-add everything else, using the scripting engine
					for (int i = schemaObjects.Count - 1; i >= 0; i--)
					{
						SchemaObject schemaObject = schemaObjects [i];

						if (registry.Contains (schemaObject.Name) && 
							registry.GetSignature (schemaObject.Name) != schemaObject.Signature &&
							!IsEasyToModify (schemaObject.SchemaObjectType) && 
							!dropObjects.Contains (schemaObject.Name))
                            ScheduleUpdate (dropObjects, addObjects, tableUpdates, schemaObject, true);
					}

					// sort to add in dependency order
					addObjects.Sort (delegate (SchemaObject o1, SchemaObject o2)
					{
						int compare = o1.SchemaObjectType.CompareTo (o2.SchemaObjectType);
						if (compare == 0)
							compare = o1.OriginalOrder.CompareTo (o2.OriginalOrder);
						if (compare == 0)
							compare = String.Compare (o1.Name, o2.Name, StringComparison.OrdinalIgnoreCase);
						return compare;
					});

                    // do the work
                    DropObjects (registry, dropObjects, addObjects);
                    UpdateTables (schemaGroup, registry, addObjects, tableUpdates);
                    CreateObjects (schemaGroup, registry, addObjects);
					VerifyObjects (schemaObjects);

					// update the sigs on all of the records
					foreach (SchemaObject o in schemaObjects)
						registry.UpdateObject(o, schemaGroup);

                    // commit the changes
                    registry.Update ();
                    transaction.Complete();
                }
            }
            finally
            {
                _connection.Dispose ();
            }

			return _scripts.ToString ();
        }