public static void Add(IMapsDirectlyToDatabaseTable toCreate) { lock (currentScopeLock) { CurrentScope?.Objects.Add(toCreate); } }
public ExecuteCommandCreateNewCohortFromCatalogue(IBasicActivateItems activator, [DemandsInitialization("Either a Catalogue with a single IsExtractionIdentifier column or a specific ExtractionInformation to query")] IMapsDirectlyToDatabaseTable toQuery, [DemandsInitialization(Desc_ExternalCohortTableParameter)] ExternalCohortTable ect, [DemandsInitialization(Desc_CohortNameParameter)] string cohortName, [DemandsInitialization(Desc_ProjectParameter)] Project project, [DemandsInitialization("Pipeline for executing the query, performing any required transforms on the output list and allocating release identifiers")] IPipeline pipeline) : base(activator, ect, cohortName, project, pipeline) { UseTripleDotSuffix = true; if (toQuery != null) { if (toQuery is Catalogue c) SetExtractionIdentifierColumn(GetExtractionInformationFromCatalogue(c)); else if (toQuery is ExtractionInformation ei) SetExtractionIdentifierColumn(ei); else throw new ArgumentException($"{nameof(toQuery)} must be a Catalogue or an ExtractionInformation but it was a {toQuery.GetType().Name}", nameof(toQuery)); } }
public ExecuteCommandShow(IActivateItems activator, IMapsDirectlyToDatabaseTable objectToShow, int expansionDepth, bool useIconAndTypeName = false) : base(activator) { _objectToShow = objectToShow; _objectType = _objectToShow.GetType(); _expansionDepth = expansionDepth; _useIconAndTypeName = useIconAndTypeName; }
/// <inheritdoc/> public void RevertToDatabaseState(IMapsDirectlyToDatabaseTable localCopy) { //get new copy out of database IMapsDirectlyToDatabaseTable databaseState = GetObjectByID(localCopy.GetType(), localCopy.ID); Debug.Assert(localCopy.GetType() == databaseState.GetType()); //set all properties on the passed in one to the database state foreach (var propertyInfo in GetPropertyInfos(localCopy.GetType())) { if (!propertyInfo.CanWrite) { throw new InvalidOperationException("The property " + propertyInfo.Name + " has no setter for type " + databaseState.GetType().Name); } propertyInfo.SetValue(localCopy, propertyInfo.GetValue(databaseState)); } //Mark any cached data as out of date var inject = localCopy as IInjectKnown; if (inject != null) { inject.ClearAllInjections(); } }
public void ThrowIfDeleteDisallowed(IMapsDirectlyToDatabaseTable oTableWrapperObject) { if (_shareManager.IsExportedObject(oTableWrapperObject)) { throw new Exception("You cannot Delete '" + oTableWrapperObject + "' because it is an Exported object declared in the ObjectExport table"); } }
public static void SetValue(PropertyInfo prop, object value, IMapsDirectlyToDatabaseTable onObject) { //sometimes json decided to swap types on you e.g. int64 for int32 var propertyType = prop.PropertyType; //if it is a nullable int etc if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable <>)) { propertyType = propertyType.GetGenericArguments()[0]; //lets pretend it's just int / whatever } if (value != null && value != DBNull.Value && !propertyType.IsInstanceOfType(value)) { if (propertyType == typeof(CatalogueFolder)) { //will be passed as a string value = value is string?new CatalogueFolder((Catalogue)onObject, (string)value) : (CatalogueFolder)value; } else if (propertyType == typeof(Uri)) { value = value is string?new Uri((string)value) : (Uri)value; } else if (typeof(Enum).IsAssignableFrom(propertyType)) { value = Enum.ToObject(propertyType, value);//if the property is an enum } else { value = UsefulStuff.ChangeType(value, propertyType); //the property is not an enum } } prop.SetValue(onObject, value); //if it's a shared property (most properties) use the new shared value being imported }
public static string Describe(IMapsDirectlyToDatabaseTable o) { var sb = new StringBuilder(); BuildDescribe(o, sb); return(sb.ToString()); }
public ExecuteCommandViewData(IBasicActivateItems activator, [DemandsInitialization("The ColumnInfo, TableInfo or ExtractionInformation you want to view a sample of")] IMapsDirectlyToDatabaseTable obj, [DemandsInitialization("Optional. The view mode you want to see. Options include 'TOP_100', 'Aggregate' and 'Distribution'", DefaultValue = ViewType.TOP_100)] ViewType viewType = ViewType.TOP_100, [DemandsInitialization("Optional. A file to write the records to instead of the console")] FileInfo toFile = null) : base(activator) { _viewType = viewType; ToFile = toFile; if (obj is TableInfo ti) { _collection = new ViewTableInfoExtractUICollection(ti, _viewType); if (_viewType != ViewType.TOP_100) { throw new ArgumentException($"Only '{nameof(ViewType.TOP_100)}' can be used for TableInfos"); } } else if (obj is ColumnInfo col) { _collection = CreateCollection(col); } else if (obj is ExtractionInformation ei) { _collection = CreateCollection(ei); } else { throw new ArgumentException($"Object '{obj}' was not a table or column compatible with this command"); } }
public DbCommand this[IMapsDirectlyToDatabaseTable o] { get { return(UpdateCommands[o.GetType()]); } }
/// <summary> /// Returns the text drawn for the object e.g. ToString() + (UsefulProperty) /// </summary> /// <param name="m"></param> /// <returns></returns> private string GetUsefulProperties(IMapsDirectlyToDatabaseTable m) { StringBuilder sb = new StringBuilder(); var p = _usefulPropertyFinder.GetProperties(m).ToArray(); if (p.Length == 0) { return(null); } sb.Append("("); foreach (var propertyInfo in p) { var attr = _usefulPropertyFinder.GetAttribute(propertyInfo); var key = string.IsNullOrWhiteSpace(attr.DisplayName) ? propertyInfo.Name : attr.DisplayName; var val = propertyInfo.GetValue(m); sb.Append(key + "='" + val + "' "); } sb.Append(")"); return(sb.ToString()); }
public ExecuteCommandSet(IBasicActivateItems activator, [DemandsInitialization("A single object on which you want to change a given property")] IMapsDirectlyToDatabaseTable setOn, [DemandsInitialization("Name of a property you want to change e.g. Description")] string property, [DemandsInitialization("New value to assign, this will be parsed into a valid Type if property is not a string")] string value) : base(activator) { _setOn = setOn; _property = _setOn.GetType().GetProperty(property); if (_property == null) { SetImpossible($"Unknown Property '{property}'"); } else { var picker = new CommandLineObjectPicker(new string[] { value ?? "NULL" }, activator.RepositoryLocator); if (!picker.HasArgumentOfType(0, _property.PropertyType)) { SetImpossible($"Provided value could not be converted to '{_property.PropertyType}'"); } else { NewValue = picker[0].GetValueForParameterOfType(_property.PropertyType); } } }
private void Emphasise(IMapsDirectlyToDatabaseTable o) { Activator.RequestItemEmphasis(this, new EmphasiseRequest(o, 1) { Pin = UserSettings.FindShouldPin }); }
public override void Publish(IMapsDirectlyToDatabaseTable databaseEntity) { if (databaseEntity is DatabaseEntity de) { RefreshBus.Publish(this, new RefreshObjectEventArgs(de)); } }
/// <inheritdoc/> /// <remarks>Consults each <see cref="OtherDependencyFinders"/> to see if deleting is disallowed</remarks> /// <param name="oTableWrapperObject"></param> public void ThrowIfDeleteDisallowed(IMapsDirectlyToDatabaseTable oTableWrapperObject) { foreach (IObscureDependencyFinder obscureDependencyFinder in OtherDependencyFinders) { obscureDependencyFinder.ThrowIfDeleteDisallowed(oTableWrapperObject); } }
public ExecuteCommandShow(IActivateItems activator, IEnumerable <IMapsDirectlyToDatabaseTable> objectsToPickFrom, int expansionDepth, bool useIconAndTypeName = false) : base(activator) { if (objectsToPickFrom == null) { SetImpossible("No objects found"); return; } var obs = objectsToPickFrom.ToArray(); //no objects! if (obs.Length == 0) { SetImpossible("No objects found"); } else if (obs.Length == 1) { //one object only _objectToShow = objectsToPickFrom.Single(); _objectType = _objectToShow.GetType(); } else { //many objects, lets assume they are of the same type for display purposes _objectType = objectsToPickFrom.First().GetType(); _objectsToPickFrom = obs; } _expansionDepth = expansionDepth; _useIconAndTypeName = useIconAndTypeName; }
private void btnSelectNULL_Click(object sender, EventArgs e) { Selected = null; MultiSelected = null; DialogResult = DialogResult.OK; this.Close(); }
private void listBox1_CellClick(object sender, CellClickEventArgs e) { if (e.ClickCount >= 2) { Selected = olvObjects.SelectedObject as IMapsDirectlyToDatabaseTable; if (Selected == null) { return; } //double clicking on a row when several others are selected should not make it the only selected item if (AllowMultiSelect) { //instead it should just add it to the multi selection MultiSelected.Add(Selected); buildGroupsRequired = true; UpdateButtonEnabledness(); return; } MultiSelected = new HashSet <IMapsDirectlyToDatabaseTable>(new[] { Selected }); DialogResult = DialogResult.OK; this.Close(); } }
public void SetupEditAnything(object sender, IMapsDirectlyToDatabaseTable o) { _windowManager.CloseAllToolboxes(); _windowManager.CloseAllWindows(); if (o is LoadMetadata lmd) { SetupEditLoadMetadata(sender, lmd); } else { _activator.RequestItemEmphasis(this, new EmphasiseRequest(o, int.MaxValue)); var activate = new ExecuteCommandActivate(_activator, o); //activate it if possible if (!activate.IsImpossible) { activate.Execute(); } else { _activator.RequestItemEmphasis(this, new EmphasiseRequest(o, 1)); //otherwise just show it } } }
protected void AddGoTo(IMapsDirectlyToDatabaseTable o, string title) { Add(new ExecuteCommandShow(_activator, o, 1) { OverrideCommandName = title }, Keys.None, GoTo); }
public PersistableSingleDatabaseObjectDockContent(IRDMPSingleDatabaseObjectControl control, IMapsDirectlyToDatabaseTable databaseObject, RefreshBus refreshBus) : base(refreshBus) { _control = (Control)control; DatabaseObject = databaseObject; TabText = "Loading..."; }
public RevertableObjectReport HasLocalChanges(IMapsDirectlyToDatabaseTable mapsDirectlyToDatabaseTable) { //if we don't know about it then it was deleted if (!Objects.Contains(mapsDirectlyToDatabaseTable)) { return new RevertableObjectReport() { Evaluation = ChangeDescription.DatabaseCopyWasDeleted } } ; //if it has no changes (since a save) if (!_propertyChanges.ContainsKey(mapsDirectlyToDatabaseTable)) { return new RevertableObjectReport { Evaluation = ChangeDescription.NoChanges } } ; //we have local 'unsaved' changes var type = mapsDirectlyToDatabaseTable.GetType(); var differences = _propertyChanges[mapsDirectlyToDatabaseTable].Select( d => new RevertablePropertyDifference(type.GetProperty(d.PropertyName), d.NewValue, d.OldValue)) .ToList(); return(new RevertableObjectReport(differences) { Evaluation = ChangeDescription.DatabaseCopyDifferent }); }
protected void AddGoTo(ToolStripMenuItem menu, IMapsDirectlyToDatabaseTable o, string title) { Add(menu, new ExecuteCommandShow(_activator, o, 1) { OverrideCommandName = title }); }
public override bool CustomActivate(IMapsDirectlyToDatabaseTable o) { // we only care about responding to opening AggregateConfiguration objects // and then only if the aggregate being edited is one of the ones that our API handles if (o is not AggregateConfiguration ac || !compiler.ShouldRun(ac)) { return(false); } // Look at the Description property for a number (your API could use a complex XML or YAML syntax if you want) // You could also store some info at the Catalogue level for reuse in other Aggregates if (!int.TryParse(ac.Description, out var number)) { number = 5; } // Launch a UI that prompts a new value to be entered if (BasicActivator.TypeText("Generate random CHIs", "Number of Chis:", 100, number.ToString(), out string result, false)) { if (int.TryParse(result, out int newCount)) { ac.Description = newCount.ToString(); ac.SaveToDatabase(); } } // we handled this, don't launch the default user interface return(true); }
public void RevertToDatabaseState(IMapsDirectlyToDatabaseTable mapsDirectlyToDatabaseTable) { //Mark any cached data as out of date var inject = mapsDirectlyToDatabaseTable as IInjectKnown; if (inject != null) { inject.ClearAllInjections(); } if (!_propertyChanges.ContainsKey(mapsDirectlyToDatabaseTable)) { return; } var type = mapsDirectlyToDatabaseTable.GetType(); foreach (var e in _propertyChanges[mapsDirectlyToDatabaseTable].ToArray()) //call ToArray to avoid cyclical events on SetValue { var prop = type.GetProperty(e.PropertyName); prop.SetValue(mapsDirectlyToDatabaseTable, e.OldValue);//reset the old values } //forget about all changes now _propertyChanges.Remove(mapsDirectlyToDatabaseTable); }
/// <inheritdoc/> public void DeleteFromDatabase(IMapsDirectlyToDatabaseTable oTableWrapperObject) { //do not log information about access credentials if (!(oTableWrapperObject is IDataAccessCredentials)) { _logger.Debug("Deleted," + oTableWrapperObject.GetType().Name + "," + oTableWrapperObject.ID + "," + oTableWrapperObject); } lock (_oLockUpdateCommands) { //if the repository has obscure dependencies if (ObscureDependencyFinder != null) { ObscureDependencyFinder.ThrowIfDeleteDisallowed(oTableWrapperObject);//confirm that deleting the object is allowed by the dependencies } using (var con = GetConnection()) { using (DbCommand cmd = DatabaseCommandHelper.GetCommand( "DELETE FROM " + oTableWrapperObject.GetType().Name + " WHERE ID =@ID", con.Connection, con.Transaction)) { DatabaseCommandHelper.AddParameterWithValueToCommand("@ID", cmd, oTableWrapperObject.ID); cmd.ExecuteNonQuery(); } //likewise if there are obscure depenedency handlers let them handle cascading this delete into the mists of their obscure functionality (e.g. deleting a Catalogue in CatalogueRepository would delete all Evaluations of that Catalogue in the DQE repository because they would then be orphans) if (ObscureDependencyFinder != null) { ObscureDependencyFinder.HandleCascadeDeletesForDeletedObject(oTableWrapperObject); } } } }
/// <inheritdoc/> public void DeleteFromDatabase(IMapsDirectlyToDatabaseTable oTableWrapperObject) { _logger.Debug("Deleted," + oTableWrapperObject.GetType().Name + "," + oTableWrapperObject.ID + "," + oTableWrapperObject); lock (_oLockUpdateCommands) { //if the repository has obscure dependencies if (ObscureDependencyFinder != null) { ObscureDependencyFinder.ThrowIfDeleteDisallowed(oTableWrapperObject);//confirm that deleting the object is allowed by the dependencies } using (var con = GetConnection()) { DbCommand cmd = DatabaseCommandHelper.GetCommand("DELETE FROM " + oTableWrapperObject.GetType().Name + " WHERE ID =@ID", con.Connection, con.Transaction); DatabaseCommandHelper.AddParameterWithValueToCommand("@ID", cmd, oTableWrapperObject.ID); int affectedRows = cmd.ExecuteNonQuery(); if (affectedRows != 1) { throw new Exception("Attempted to delete object of type " + oTableWrapperObject.GetType().Name + " from table " + oTableWrapperObject.GetType().Name + " with ID " + oTableWrapperObject.ID + " but the DELETE command resulted in " + affectedRows + " affected rows"); } //likewise if there are obscure depenedency handlers let them handle cascading this delete into the mists of their obscure functionality (e.g. deleting a Catalogue in CatalogueRepository would delete all Evaluations of that Catalogue in the DQE repository because they would then be orphans) if (ObscureDependencyFinder != null) { ObscureDependencyFinder.HandleCascadeDeletesForDeletedObject(oTableWrapperObject); } } } }
private void btnCancel_Click(object sender, EventArgs e) { Selected = null; MultiSelected = null; DialogResult = DialogResult.Cancel; this.Close(); }
public FindAndReplaceNode(IMapsDirectlyToDatabaseTable instance, PropertyInfo property) { Instance = instance; Property = property; PropertyName = instance.GetType().Name + "." + property.Name; _currentValue = Property.GetValue(Instance); }
public void SaveToDatabase(IMapsDirectlyToDatabaseTable oTableWrapperObject) { //forget about property changes (since it's 'saved' now) if (_propertyChanges.ContainsKey(oTableWrapperObject)) { _propertyChanges.Remove(oTableWrapperObject); } }
/// <summary> /// True if the <paramref name="o"/> is the object that is explicitly referenced by this class instance /// </summary> /// <param name="o"></param> /// <returns></returns> public bool IsReferenceTo(IMapsDirectlyToDatabaseTable o) { return(o.ID == ReferencedObjectID && AreProbablySameType(ReferencedObjectType, o.GetType()) && AreProbablySameType(ReferencedObjectRepositoryType, o.Repository.GetType())); }