public void GivenICreateCalculationPropertyWithUnathorizedApiKey() { var _header = new Dictionary <string, string>(); _header.Add("ApiKey", "99"); _property = new CalculationProperty() { Principal = 1000, PercentageRate = 2, Years = 5 }; var _request = new HttpRequestWrapper() .AddHeaders(_header) .SetMethod(Method.POST) .SetResourse("/api/calculations/calculateTotalAmount") .AddJsonContent(_property); _restResponse = new RestResponse(); _restResponse = _request.Execute(); _statusCode = _restResponse.StatusCode; ScenarioContext.Current.Add("StatusCode", _statusCode); }
public void GivenICreateANewProperty(int principal, int percentageRate, int years) { var _header = new Dictionary <string, string>(); _header.Add("ApiKey", "100"); _property = new CalculationProperty() { Principal = principal, PercentageRate = percentageRate, Years = years }; var _request = new HttpRequestWrapper() .AddHeaders(_header) .SetMethod(Method.POST) .SetResourse("/api/calculations/calculateTotalAmount") .AddJsonContent(_property); _restResponse = new RestResponse(); _restResponse = _request.Execute(); _statusCode = _restResponse.StatusCode; ScenarioContext.Current.Add("StatusCode", _statusCode); ScenarioContext.Current.Add("Content", _restResponse.Content); ScenarioContext.Current.Add("Prop", _property); }
// Use this for initialization void Start() { calculationController = GameObject.Find("CalculationController"); calculationProperty = calculationController.GetComponent <CalculationProperty>(); judgeContainFunc = calculationController.GetComponent <JudgeBoxBContainBoxA>(); judgeBiggerFunc = calculationController.GetComponent <JudgeBiggerBoxCollider>(); controller = transform.parent.GetComponent <EnemyController>(); }
public IList <CalculationProperty> GetKpiProperties(string measureName) { var properties = new List <CalculationProperty>(); if (!string.IsNullOrWhiteSpace(Measure.KPI?.TargetExpression)) { var property = new CalculationProperty(); property.Annotations.Insert(0, "Type", "SupportMdx"); property.Annotations.Insert(1, "MainObjectType", "Measure"); property.Annotations.Insert(2, "MainObjectName", measureName); property.CalculationReference = "[_" + measureName + " Goal]"; property.CalculationType = CalculationType.Member; property.Visible = false; properties.Add(property); } if (!string.IsNullOrWhiteSpace(Measure.KPI?.StatusExpression)) { var property = new CalculationProperty(); property.Annotations.Insert(0, "Type", "SupportMdx"); property.Annotations.Insert(1, "MainObjectType", "Measure"); property.Annotations.Insert(2, "MainObjectName", measureName); property.CalculationReference = "[_" + measureName + " Status]"; property.CalculationType = CalculationType.Member; property.Visible = false; properties.Add(property); } if (!string.IsNullOrWhiteSpace(Measure.KPI?.TrendExpression)) { var property = new CalculationProperty(); property.Annotations.Insert(0, "Type", "SupportMdx"); property.Annotations.Insert(1, "MainObjectType", "Measure"); property.Annotations.Insert(2, "MainObjectName", measureName); property.CalculationReference = "[_" + measureName + " Trend]"; property.CalculationType = CalculationType.Member; property.Visible = false; properties.Add(property); } var lastProperty = new CalculationProperty(); lastProperty.Annotations.Insert(0, "Type", "SupportKpi"); lastProperty.Annotations.Insert(1, "MainObjectType", "Measure"); lastProperty.Annotations.Insert(2, "MainObjectName", measureName); lastProperty.CalculationReference = "KPIs.[" + measureName + "]"; lastProperty.CalculationType = CalculationType.Member; properties.Add(lastProperty); return(properties); }
public void GivenICreateEmptyProperty() { var _header = new Dictionary <string, string>(); _header.Add("ApiKey", "100"); _property = null; var _request = new HttpRequestWrapper() .AddHeaders(_header) .SetMethod(Method.POST) .SetResourse("/api/calculations/calculateTotalAmount") .AddJsonContent(_property); _restResponse = new RestResponse(); _restResponse = _request.Execute(); _statusCode = _restResponse.StatusCode; ScenarioContext.Current.Add("StatusCode", _statusCode); }
public CalculationProperty ToXmlCalculationProperty(string measureName) { var property = new CalculationProperty(); property.Annotations.Insert(0, "Type", Measure.KPI != null ? "Kpi" : "User"); property.Annotations.Insert(1, "IsPrivate", Measure.IsHidden ? "True" : "False"); property.Annotations.Insert(2, "Format", ""); var document = new XmlDocument(); document.LoadXml(produceFormatXmlString()); property.Annotations["Format"].Value = document; if (Measure.KPI != null) { var i = 3; foreach (var annotation in Measure.KPI.Annotations) { property.Annotations.Insert(i, annotation.Name, annotation.Value); ++i; } //property.Annotations.Insert(i, "ValueDescription", Measure.KPI.Description ?? ""); //property.Annotations.Insert(i + 1, "GoalDescription", Measure.KPI.TargetDescription ?? ""); //property.Annotations.Insert(i + 2, "StatusDescription", Measure.KPI.StatusDescription ?? ""); //property.Annotations.Insert(i + 3, "TrendDescription", Measure.KPI.TrendDescription ?? ""); } property.CalculationReference = measureName; property.CalculationType = CalculationType.Member; property.FormatString = $"\'{Measure.FormatString}\'"; property.Visible = !Measure.IsHidden; property.DisplayFolder = !string.IsNullOrWhiteSpace(Measure.DisplayFolder) ? Measure.DisplayFolder.Trim('\'').Replace("`", "'") : property.DisplayFolder; property.Description = !string.IsNullOrWhiteSpace(Measure.Description) ? Measure.Description.Trim('\'').Replace("`", "'") : property.Description; return(property); }
public void Save(List <SSAS.TabularTranslationObjectAnnotation> annotationsList) { if (_Property != TabularTranslatedItemProperty.Caption) { return; //every object will have a caption, so only perform the save on the caption } Dictionary <int, string> DisplayFolderLanguages = new Dictionary <int, string>(); Dictionary <int, string> DescriptionLanguages = new Dictionary <int, string>(); bool bDependentPropertyDirty = false; foreach (TabularTranslatedItem dependent in DependentProperties) { bDependentPropertyDirty = bDependentPropertyDirty || dependent.Dirty; if (dependent.Property == TabularTranslatedItemProperty.DisplayFolder) { DisplayFolderLanguages = dependent.Languages; } else if (dependent.Property == TabularTranslatedItemProperty.Description) { DescriptionLanguages = dependent.Languages; } } //if (!Dirty && !bDependentPropertyDirty) return; //would be nice if we could short-circuit here, but we need to build the annotation SSAS.TabularTranslationObjectAnnotation annotation = new TabularTranslationObjectAnnotation(); annotation.ObjectType = _ObjectType; if (_object is DimensionAttribute) { DimensionAttribute da = (DimensionAttribute)_object; annotation.ObjectID = da.ID; annotation.TableID = da.Parent.ID; SaveInternal(da.Translations, DisplayFolderLanguages, DescriptionLanguages, annotation); } else if (_object is Hierarchy) { Hierarchy h = (Hierarchy)_object; annotation.ObjectID = h.ID; annotation.TableID = h.Parent.ID; SaveInternal(h.Translations, DisplayFolderLanguages, DescriptionLanguages, annotation); } else if (_object is Level) { Level l = (Level)_object; annotation.ObjectID = l.ID; annotation.HierarchyID = l.Parent.ID; annotation.TableID = l.ParentDimension.ID; SaveInternal(l.Translations, DisplayFolderLanguages, DescriptionLanguages, annotation); } else if (_object is CalculationProperty) { CalculationProperty calc = (CalculationProperty)_object; annotation.ObjectID = _ObjectName; //no need to save table SaveInternal(calc.Translations, DisplayFolderLanguages, DescriptionLanguages, annotation); } else if (_object is Database) { Database db = (Database)_object; annotation.ObjectID = db.ID; SaveInternal(db.Translations, DisplayFolderLanguages, DescriptionLanguages, annotation); } else if (_object is Cube) { Cube cube = (Cube)_object; annotation.ObjectID = cube.ID; SaveInternal(cube.Translations, DisplayFolderLanguages, DescriptionLanguages, annotation); } else if (_object is Perspective) { Perspective p = (Perspective)_object; annotation.ObjectID = p.ID; SaveInternal(p.Translations, DisplayFolderLanguages, DescriptionLanguages, annotation); } else if (_object is Dimension) { Dimension dim = (Dimension)_object; annotation.ObjectID = dim.ID; SaveInternal(dim.Translations, DisplayFolderLanguages, DescriptionLanguages, annotation); foreach (Cube cube in dim.Parent.Cubes) { foreach (CubeDimension cd in cube.Dimensions) { if (cd.DimensionID == dim.ID) { SaveInternal(cd.Translations, DisplayFolderLanguages, DescriptionLanguages, null); } } foreach (MeasureGroup mg in cube.MeasureGroups) { if (mg.ID == dim.ID) { SaveInternal(mg.Translations, DisplayFolderLanguages, DescriptionLanguages, null); } } } } else if (_object is Microsoft.AnalysisServices.Action) { Microsoft.AnalysisServices.Action actionMaster = (Microsoft.AnalysisServices.Action)_object; foreach (Microsoft.AnalysisServices.Action action in actionMaster.Parent.Actions) { if (action.ID.StartsWith(actionMaster.ID)) { annotation.ObjectID = action.ID; SaveInternal(action.Translations, DisplayFolderLanguages, DescriptionLanguages, annotation); } } } else { throw new Exception("Unexpected object type: " + _object.GetType().Name); } if (annotation.TabularTranslations.Length > 0) { annotationsList.Add(annotation); } }
public TabularTranslatedItem(string table, IModelComponent obj, TabularTranslatedItemProperty property, TabularTranslatedItem caption, SSAS.TabularTranslationsAnnotation annotations) { _Table = table; _object = obj; _Property = property; TranslationCollection translations; string sCaption; string sDescription; string sDisplayFolder = null; if (obj is DimensionAttribute) { _ObjectType = TabularTranslatedItemType.Column; DimensionAttribute typedobj = (DimensionAttribute)obj; translations = typedobj.Translations; sDisplayFolder = typedobj.AttributeHierarchyDisplayFolder; sCaption = typedobj.Name; sDescription = typedobj.Description; } else if (obj is Hierarchy) { _ObjectType = TabularTranslatedItemType.Hierarchy; Hierarchy typedobj = (Hierarchy)obj; translations = typedobj.Translations; sDisplayFolder = typedobj.DisplayFolder; sCaption = typedobj.Name; sDescription = typedobj.Description; } else if (obj is Level) { _ObjectType = TabularTranslatedItemType.Level; Level typedobj = (Level)obj; translations = typedobj.Translations; sCaption = typedobj.Name; sDescription = typedobj.Description; } else if (obj is CalculationProperty) { _ObjectType = TabularTranslatedItemType.Measure; CalculationProperty typedobj = (CalculationProperty)obj; translations = typedobj.Translations; sDisplayFolder = typedobj.DisplayFolder; sCaption = typedobj.CalculationReference; sDescription = typedobj.Description; if (sCaption.StartsWith("[") && sCaption.EndsWith("]")) { sCaption = sCaption.Substring(1, sCaption.Length - 2); } } else if (obj is Database) { _ObjectType = TabularTranslatedItemType.Database; Database typedobj = (Database)obj; translations = typedobj.Translations; sCaption = typedobj.Name; sDescription = typedobj.Description; } else if (obj is Cube) { _ObjectType = TabularTranslatedItemType.Cube; Cube typedobj = (Cube)obj; translations = typedobj.Translations; sCaption = typedobj.Name; sDescription = typedobj.Description; } else if (obj is Perspective) { _ObjectType = TabularTranslatedItemType.Perspective; Perspective typedobj = (Perspective)obj; translations = typedobj.Translations; sCaption = typedobj.Name; sDescription = typedobj.Description; } else if (obj is Dimension) { _ObjectType = TabularTranslatedItemType.Table; Dimension typedobj = (Dimension)obj; translations = typedobj.Translations; sCaption = typedobj.Name; sDescription = typedobj.Description; } else if (obj is Microsoft.AnalysisServices.Action) { _ObjectType = TabularTranslatedItemType.Action; Microsoft.AnalysisServices.Action typedobj = (Microsoft.AnalysisServices.Action)obj; translations = typedobj.Translations; sCaption = typedobj.Name; sDescription = typedobj.Description; } else { throw new Exception("Unexpected object type: " + obj.GetType().Name); } _ObjectName = sCaption; if (property == TabularTranslatedItemProperty.Caption) { _DefaultLanguage = sCaption; SSAS.TabularTranslationObjectAnnotation annotation = annotations.Find(obj); if (annotation != null && translations.Count == 0) { foreach (SSAS.TabularTranslationAnnotation tranAnnotation in annotation.TabularTranslations) { Translation t = new Translation(tranAnnotation.Language); if (obj is DimensionAttribute) { t = new AttributeTranslation(tranAnnotation.Language); } t.Caption = tranAnnotation.Caption; t.Description = tranAnnotation.Description; t.DisplayFolder = tranAnnotation.DisplayFolder; translations.Add(t); } _restoredTranslations = true; } } else if (property == TabularTranslatedItemProperty.Description) { _DefaultLanguage = sDescription; } else if (property == TabularTranslatedItemProperty.DisplayFolder) { _DefaultLanguage = sDisplayFolder; } Languages = new Core.DirtyMonitoredDictionary <int, string>(); foreach (Translation t in translations) { if (property == TabularTranslatedItemProperty.Caption) { Languages.Add(t.Language, t.Caption); } else if (property == TabularTranslatedItemProperty.Description) { Languages.Add(t.Language, t.Description); } else if (property == TabularTranslatedItemProperty.DisplayFolder) { Languages.Add(t.Language, t.DisplayFolder); } } if (caption != null) { caption.DependentProperties.Add(this); } }
public static DaxCalcProperty CreateFromXmlProperty(CalculationProperty property) { if (property == null) { throw new ArgumentNullException(nameof(property)); } var rv = CreateDefaultCalculationProperty(); rv.Measure.FormatString = property.FormatString?.Trim('\''); rv.Measure.DisplayFolder = property.DisplayFolder; rv.Measure.IsHidden = !property.Visible; rv.Measure.Description = property.Description; var annotations = property.Annotations; if (annotations["Type"].Value.Value == "Kpi") { rv.KPI = rv.KPI ?? new KPI(); foreach (Microsoft.AnalysisServices.Annotation annotation in annotations) { if (annotation.Name != "Type" && annotation.Name != "IsPrivate" && annotation.Name != "Format") { var newAnnotation = new Annotation(); newAnnotation.Name = annotation.Name; newAnnotation.Value = annotation.Value?.Value; rv.KPI.Annotations.Add(newAnnotation); } } } if (!annotations.Contains("Format")) { return(rv); } var formatValueElement = annotations["Format"].Value; Debug.Assert(formatValueElement != null); Debug.Assert(formatValueElement.Attributes != null); var formatString = formatValueElement?.Attributes["Format"]?.Value; Debug.Assert(formatString != null); rv.Format = (FormatType)Enum.Parse(typeof(FormatType), formatString); switch (rv.Format) { case FormatType.General: case FormatType.NumberWhole: case FormatType.NumberDecimal: case FormatType.Percentage: case FormatType.Scientific: case FormatType.Currency: case FormatType.DateTimeCustom: case FormatType.DateTimeShortDatePattern: case FormatType.DateTimeGeneral: var accuracyAttribute = formatValueElement?.Attributes["Accuracy"]; if (accuracyAttribute != null) { rv.Accuracy = int.Parse(accuracyAttribute.Value); } var thousandSeparatorAttribute = formatValueElement?.Attributes["ThousandSeparator"]; if (thousandSeparatorAttribute != null) { rv.ThousandSeparator = bool.Parse(thousandSeparatorAttribute.Value); } if (formatValueElement?.FirstChild != null) { rv.CustomFormat = InitCustomFormatString(XElement.Parse(formatValueElement.FirstChild.OuterXml)); } break; case FormatType.Text: break; default: Debug.Assert(false, "Not reachable"); break; } return(rv); }
void OpenCalcPropertiesDialog() { Form form1 = null; //should be a CalcPropertiesEditorForm which is private Cube cube = (Cube)this.ApplicationObject.ActiveWindow.ProjectItem.Object; System.IServiceProvider provider = (System.IServiceProvider) this.ApplicationObject.ActiveWindow.ProjectItem.ContainingProject; using (WaitCursor cursor1 = new WaitCursor()) { IUserPromptService oService = (IUserPromptService)provider.GetService(typeof(IUserPromptService)); foreach (Type t in System.Reflection.Assembly.GetAssembly(typeof(Microsoft.AnalysisServices.Design.Scripts)).GetTypes()) { if (t.FullName == "Microsoft.AnalysisServices.Design.Calculations.CalcPropertiesEditorForm") { form1 = (Form)t.GetConstructor(new Type[] { typeof(IUserPromptService) }).Invoke(new object[] { oService }); break; } } if (form1 == null) { throw new Exception("Couldn't create instance of CalcPropertiesEditorForm"); } object script1 = null; //should be a Microsoft.AnalysisServices.MdxCodeDom.MdxCodeScript object try { //validate the script because deploying an invalid script makes cube unusable Microsoft.AnalysisServices.Design.Scripts scripts = new Microsoft.AnalysisServices.Design.Scripts(cube); System.Reflection.BindingFlags getflags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance; script1 = scripts.GetType().InvokeMember("mdxCodeScript", getflags, null, scripts, null); } catch (Microsoft.AnalysisServices.Design.ScriptParsingFailed ex) { string throwaway = ex.Message; //prevents a warning during compile MessageBox.Show("MDX Script in " + cube.Name + " is not valid.", "Problem Deploying MDX Script"); return; } if (cube.MdxScripts.Count == 0) { MessageBox.Show("There is no MDX script defined in this cube yet."); return; } System.Reflection.BindingFlags getmethodflags = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance; form1.GetType().InvokeMember("Initialize", getmethodflags, null, form1, new object[] { cube.MdxScripts[0], script1, cube, null }); //now make custom changes to the form Button okButton = (Button)form1.Controls.Find("okButton", true)[0]; Panel panel = (Panel)form1.Controls.Find("gridPanel", true)[0]; Button descButton = new Button(); descButton.Text = "Edit Description"; descButton.Anchor = AnchorStyles.Left | AnchorStyles.Bottom; descButton.Left = panel.Left; descButton.Top = okButton.Top; descButton.Width += 40; descButton.Click += new EventHandler(descButton_Click); form1.Controls.Add(descButton); } if (Microsoft.DataWarehouse.DataWarehouseUtilities.ShowDialog(form1, provider) == DialogResult.OK) { using (WaitCursor cursor2 = new WaitCursor()) { System.Reflection.BindingFlags getflags = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance; CalculationPropertyCollection collection1 = (CalculationPropertyCollection)form1.GetType().InvokeMember("GetResultProperties", getflags, null, form1, new object[] { }); DesignerTransaction transaction1 = null; try { IDesignerHost host1 = (IDesignerHost)ApplicationObject.ActiveWindow.Object; transaction1 = host1.CreateTransaction("BidsHelperCalcPropertiesUndoBatchDesc"); IComponentChangeService service1 = (IComponentChangeService)ApplicationObject.ActiveWindow.Object; service1.OnComponentChanging(cube.MdxScripts[0].CalculationProperties, null); cube.MdxScripts[0].CalculationProperties.Clear(); for (int num1 = collection1.Count - 1; num1 >= 0; num1--) { CalculationProperty property1 = collection1[num1]; collection1.RemoveAt(num1); cube.MdxScripts[0].CalculationProperties.Insert(0, property1); } service1.OnComponentChanged(cube.MdxScripts[0].CalculationProperties, null, null, null); } catch (CheckoutException exception1) { if (transaction1 != null) { transaction1.Cancel(); } if (exception1 != CheckoutException.Canceled) { throw exception1; } } finally { if (transaction1 != null) { transaction1.Commit(); } } } } }
public MdxScript ToMdxScript(int compatibilityLevel) { var script = new MdxScript(); script.ID = "MdxScript"; script.Name = "MdxScript"; var firstCommand = new Command(); firstCommand.Text = compatibilityLevel < 1103 ? ServerCommandProducer.CommonCommandText1100 : ServerCommandProducer.CommonCommandText1103; script.Commands.Add(firstCommand); if (compatibilityLevel < 1103) { //Add all measures full text in one command var command = new Command(); command.Text = ServerCommandProducer.DoNotModify1100 + string.Concat( Measures.Select(i => i.FullText + ";" + Environment.NewLine) ); script.Commands.Add(command); } else { foreach (var measure in Measures) { var command = new Command(); command.Text = ServerCommandProducer.DoNotModify1103; if (!string.IsNullOrWhiteSpace(measure.Scope)) { command.Text = command.Text.TrimEnd('\r', '\n', ' '); command.Text += $@" -- MDX SCRIPT -- {measure.Scope} -- MDX SCRIPT -- "; } command.Text += measure.FullText + ";" + Environment.NewLine; if (measure.CalcProperty?.KPI != null) { var goalName = "_" + measure.Name + " Goal"; var goalMeasure = GetSupportMeasure(goalName); if (goalMeasure != null) { command.Text += goalMeasure.FullText + "; " + Environment.NewLine; } var statusName = "_" + measure.Name + " Status"; var statusMeasure = GetSupportMeasure(statusName); if (statusMeasure != null) { command.Text += statusMeasure.FullText + Environment.NewLine + "; " + Environment.NewLine; } var trendName = "_" + measure.Name + " Trend"; var trendMeasure = GetSupportMeasure(trendName); if (trendMeasure != null) { command.Text += trendMeasure.FullText + Environment.NewLine + "; " + Environment.NewLine; } //ASSOCIATED_MEASURE_GROUP = 'DimCurrency' command.Text += "CREATE KPI CURRENTCUBE." + measure.NameInBrackets + " AS Measures." + measure.NameInBrackets; command.Text += ", ASSOCIATED_MEASURE_GROUP = '" + measure.TableName + "'"; if (goalMeasure != null) { command.Text += ", GOAL = Measures." + goalMeasure.NameInBrackets; } if (statusMeasure != null) { command.Text += ", STATUS = Measures." + statusMeasure.NameInBrackets; } if (!string.IsNullOrWhiteSpace(measure.CalcProperty.KPI.StatusGraphic)) { command.Text += ", STATUS_GRAPHIC = " + measure.CalcProperty.KPI.StatusGraphic; } if (trendMeasure != null) { command.Text += ", TREND = Measures." + trendMeasure.NameInBrackets; } if (!string.IsNullOrWhiteSpace(measure.CalcProperty.KPI.TrendGraphic)) { command.Text += ", TREND_GRAPHIC = " + measure.CalcProperty.KPI.TrendGraphic; } command.Text += ";" + Environment.NewLine; } command.Annotations.Insert(0, "FullName", measure.Name); command.Annotations.Insert(1, "Table", measure.TableName); script.Commands.Add(command); } } foreach (var measure in Measures) { var property = measure.CalcProperty != null? measure.CalcProperty.ToXmlCalculationProperty(measure.NameInBrackets) : DaxCalcProperty.CreateDefaultCalculationProperty().ToXmlCalculationProperty(measure.NameInBrackets); script.CalculationProperties.Add(property); if (measure.CalcProperty?.KPI != null) { var kpiProperties = measure.CalcProperty.GetKpiProperties(measure.Name); foreach (var kpiProperty in kpiProperties) { script.CalculationProperties.Add(kpiProperty); } } } var lastProperty = new CalculationProperty(); lastProperty.CalculationReference = compatibilityLevel < 1103 ? "Measures.[__No measures defined]" : "[__XL_Count of Models]"; lastProperty.CalculationType = CalculationType.Member; lastProperty.Visible = false; script.CalculationProperties.Add(lastProperty); return(script); }