public override void Execute() { base.Execute(); if (string.IsNullOrWhiteSpace(column) && !askAtRuntime) { aggregate.PivotOnDimensionID = null; aggregate.SaveToDatabase(); } else { var opts = new AggregateBuilderOptionsFactory().Create(aggregate); AggregateDimension match = null; if (askAtRuntime) { var possible = aggregate.AggregateDimensions.Where(d => !d.IsDate()).ToArray(); if (!possible.Any()) { throw new Exception($"There are no AggregateDimensions in {aggregate} that can be used as a Pivot"); } match = (AggregateDimension)BasicActivator.SelectOne("Choose pivot dimension", possible); if (match == null) { return; } } else { match = aggregate.AggregateDimensions.FirstOrDefault(a => string.Equals(column, a.ToString())); if (match == null) { throw new Exception($"Could not find AggregateDimension {column} in Aggregate {aggregate} so could not set it as a pivot dimension. Try adding the column to the aggregate first"); } } if (match.IsDate()) { throw new Exception($"AggregateDimension {match} is a Date so cannot set it as a Pivot for Aggregate {aggregate}"); } var enable = opts.ShouldBeEnabled(AggregateEditorSection.PIVOT, aggregate); if (!enable) { throw new Exception($"Current state of Aggregate {aggregate} does not support having a Pivot Dimension"); } aggregate.PivotOnDimensionID = match.ID; aggregate.SaveToDatabase(); } Publish(aggregate); }
private void PopulateAxis(AggregateDimension axisIfAny, AggregateDimension pivotIfAny) { var allDimensions = _aggregate.AggregateDimensions.ToArray(); //if there's a pivot then don't advertise that as an axis if (pivotIfAny != null && !pivotIfAny.Equals(axisIfAny)) { allDimensions = allDimensions.Except(new[] { pivotIfAny }).ToArray(); } ddAxisDimension.Items.Clear(); ddAxisDimension.Items.AddRange(allDimensions.Where(d => d.IsDate()).ToArray()); //should only be one var axisDimensions = allDimensions.Where(d => d.AggregateContinuousDateAxis != null).ToArray(); if (axisDimensions.Length > 1) { if (Activator.YesNo( "Aggregate " + _aggregate + " has more than 1 dimension, this is highly illegal, shall I delete all the axis configurations for you?", "Delete all axis?")) { foreach (AggregateDimension a in axisDimensions) { a.AggregateContinuousDateAxis.DeleteInDatabase(); } } else { return; } } if (axisIfAny == null) { aggregateContinuousDateAxisUI1.Dimension = null; return; } ddAxisDimension.SelectedItem = axisIfAny; aggregateContinuousDateAxisUI1.Dimension = axisIfAny; if (!axisIfAny.IsDate()) { _errorProviderAxis.SetError(ddAxisDimension, "Column is not a DateTime"); } else { _errorProviderAxis.Clear(); } }
public override void Execute() { base.Execute(); if (string.IsNullOrWhiteSpace(column) && !askAtRuntime) { aggregate.GetAxisIfAny()?.DeleteInDatabase(); } else { if (aggregate.GetAxisIfAny() != null) { throw new Exception($"Aggregate {aggregate} already has an axis"); } var opts = new AggregateBuilderOptionsFactory().Create(aggregate); AggregateDimension match = null; if (askAtRuntime) { var possible = aggregate.AggregateDimensions.Where(d => d.IsDate()).ToArray(); if (!possible.Any()) { throw new Exception($"There are no AggregateDimensions in {aggregate} that can be used as an axis (Dimensions must be Date Type)"); } match = (AggregateDimension)BasicActivator.SelectOne("Choose axis dimension", possible); if (match == null) { return; } } else { match = aggregate.AggregateDimensions.FirstOrDefault(a => string.Equals(column, a.ToString())); if (match == null) { throw new Exception($"Could not find AggregateDimension {column} in Aggregate {aggregate} so could not set it as an axis dimension. Try adding the column to the aggregate first"); } } if (!match.IsDate()) { throw new Exception($"AggregateDimension {match} is not a Date so cannot set it as an axis for Aggregate {aggregate}"); } var enable = opts.ShouldBeEnabled(AggregateEditorSection.AXIS, aggregate); if (!enable) { throw new Exception($"Current state of Aggregate {aggregate} does not support having an axis Dimension"); } var axis = new AggregateContinuousDateAxis(BasicActivator.RepositoryLocator.CatalogueRepository, match); axis.SaveToDatabase(); } Publish(aggregate); }