public static void AddTabularEditorTag(this TOM.Database database)
 {
     if (!database.Model.Annotations.Contains(TabularEditorTag))
     {
         var annotation = new TOM.Annotation()
         {
             Name = TabularEditorTag, Value = "1"
         };
         database.Model.Annotations.Add(annotation);
     }
 }
        public static void AddTabularEditorTag(this TOM.Database database)
        {
            const string annotationName = "__TEdtr";

            if (!database.Model.Annotations.Contains(annotationName))
            {
                var annotation = new TOM.Annotation()
                {
                    Name = annotationName, Value = "1"
                };
                database.Model.Annotations.Add(annotation);
            }
        }
        public void ToJsonMeasure(ref Measure measure)
        {
            measure.IsHidden = Measure.IsHidden;

            if (Format != FormatType.General)
            {
                var annotation = new Annotation();
                annotation.Name  = "Format";
                annotation.Value = produceFormatXmlString();
                measure.Annotations.Add(annotation);
            }

            measure.FormatString  = Measure.FormatString;
            measure.DisplayFolder = !string.IsNullOrWhiteSpace(Measure.DisplayFolder) ?
                                    Measure.DisplayFolder.Trim('\'').Replace("`", "'") :
                                    measure.DisplayFolder;
            measure.Description = !string.IsNullOrWhiteSpace(Measure.Description) ?
                                  Measure.Description.Trim('\'').Replace("`", "'") :
                                  measure.Description;
            measure.KPI = KPI?.Clone();
        }
        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);
        }