Exemple #1
0
        public static void SetName(this NamedMetadataObject obj, string newName, Culture culture = null)
        {
            if (culture != null)
            {
                culture.ObjectTranslations.SetTranslation(obj, TranslatedProperty.Caption, newName);
            }
            else
            {
                if (obj.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase))
                {
                    obj.Name = newName;
                    return;
                }

                // Automatically apply name change to translations (but only if the translation is identical to the old name):
                var cultures = obj.Model?.Cultures;

                if (cultures != null && obj.IsTranslatable())
                {
                    foreach (var c in cultures)
                    {
                        var translatedName = obj.GetNameTranslation(c);
                        if (!string.IsNullOrEmpty(translatedName) && translatedName.Equals(obj.Name, StringComparison.InvariantCultureIgnoreCase))
                        {
                            obj.SetName(newName, c);
                        }
                    }
                }

                if (!obj.IsRemoved)
                {
                    obj.Name = newName;
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the TabularObject class.
        /// </summary>
        /// <param name="namedMetaDataObject">The Tabular Object Model supertype of the class being abstracted.</param>
        public TabularObject(NamedMetadataObject namedMetaDataObject)
        {
            _name = namedMetaDataObject.Name;
            if (namedMetaDataObject is Tom.Model)
            {
                return;                                   //Model has custom JSON string
            }
            //Serialize json
            SerializeOptions options = new SerializeOptions();

            options.IgnoreInferredProperties = true;
            options.IgnoreInferredObjects    = true;
            options.IgnoreTimestamps         = true;
            options.SplitMultilineStrings    = true;
            _objectDefinition = Tom.JsonSerializer.SerializeObject(namedMetaDataObject, options);

            //Remove annotations
            {
                JToken token = JToken.Parse(_objectDefinition);
                RemovePropertyFromObjectDefinition(token, "annotations");
                _objectDefinition = token.ToString(Formatting.Indented);
            }

            ////todo: remove with Giri's fix
            ////Remove return characters
            //if (namedMetaDataObject is Tom.NamedExpression || namedMetaDataObject is Tom.Table)
            //{
            //    _objectDefinition = _objectDefinition.Replace("\\r", "");
            //}

            //Order table columns
            if (namedMetaDataObject is Tom.Table)
            {
                if (((Tom.Table)namedMetaDataObject).CalculationGroup != null)
                {
                    JToken token = JToken.Parse(_objectDefinition);
                    RemovePropertyFromObjectDefinition(token, "calculationItems");
                    _objectDefinition = token.ToString(Formatting.Indented);
                }

                _objectDefinition = SortArray(_objectDefinition, "columns");
                _objectDefinition = SortArray(_objectDefinition, "partitions");
            }

            //Order role members
            if (namedMetaDataObject is Tom.ModelRole)
            {
                _objectDefinition = SortArray(_objectDefinition, "members");
            }

            //Hide privacy setting on structured data sources
            if (namedMetaDataObject is Tom.StructuredDataSource)
            {
                JToken token = JToken.Parse(_objectDefinition);
                RemovePropertyFromObjectDefinition(token, "PrivacySetting");
                _objectDefinition = token.ToString(Formatting.Indented);
            }
        }
Exemple #3
0
 public TabularNamedObject this[NamedMetadataObject obj]
 {
     get
     {
         TabularNamedObject result;
         if (!cache.TryGetValue(obj, out result))
         {
             result = TabularNamedObject.CreateFromMetadata(obj, handler);
             cache.Add(obj, result);
         }
         return(result);
     }
 }
Exemple #4
0
 public static string GetNameTranslation(this NamedMetadataObject obj, Culture culture = null)
 {
     if (obj == null)
     {
         return(null);
     }
     if (culture != null)
     {
         var tran = culture.ObjectTranslations[obj, TranslatedProperty.Caption];
         if (tran != null)
         {
             return(tran.Value);
         }
     }
     return(null);
 }
        private static bool IsTranslatable(this NamedMetadataObject obj)
        {
            switch (obj.ObjectType)
            {
            case ObjectType.Table:
            case ObjectType.Measure:
            case ObjectType.Hierarchy:
            case ObjectType.Level:
            case ObjectType.Column:
            case ObjectType.Model:
            case ObjectType.Perspective:
                return(true);

            default:
                return(false);
            }
        }
Exemple #6
0
        /// <summary>
        /// Initializes a new instance of the TabularObject class.
        /// </summary>
        /// <param name="namedMetaDataObject">The Tabular Object Model supertype of the class being abstracted.</param>
        public TabularObject(NamedMetadataObject namedMetaDataObject)
        {
            _name = namedMetaDataObject.Name;

            //Serialize json
            SerializeOptions options = new SerializeOptions();

            options.IgnoreInferredProperties = true;
            options.IgnoreInferredObjects    = true;
            options.IgnoreTimestamps         = true;
            options.SplitMultilineStrings    = true;
            _objectDefinition = Tom.JsonSerializer.SerializeObject(namedMetaDataObject, options);

            //Remove annotations
            {
                JToken token = JToken.Parse(_objectDefinition);
                RemovePropertyFromObjectDefinition(token, "annotations");
                _objectDefinition = token.ToString(Formatting.Indented);
            }

            //Order table columns
            if (namedMetaDataObject is Tom.Table)
            {
                _objectDefinition = SortArray(_objectDefinition, "columns");
                _objectDefinition = SortArray(_objectDefinition, "partitions");
            }

            //Order role members
            if (namedMetaDataObject is Tom.ModelRole)
            {
                _objectDefinition = SortArray(_objectDefinition, "members");
            }

            //Hide privacy setting on structured data sources
            if (namedMetaDataObject is Tom.StructuredDataSource)
            {
                JToken token = JToken.Parse(_objectDefinition);
                RemovePropertyFromObjectDefinition(token, "PrivacySetting");
                _objectDefinition = token.ToString(Formatting.Indented);
            }
        }
        /// <summary>
        /// Throws an exception of the provided new name is invalid for the specified object.
        /// </summary>
        public static void ValidateName(this NamedMetadataObject obj, string newName)
        {
            if (obj.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }

            if (obj is Measure)
            {
                var measure = obj as Measure;

                // Do not allow multiple measures with the same name:
                if (measure.Model.Tables.Any(t => t.Measures.Any(m => m != obj && m.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase))))
                {
                    throw new ArgumentException(string.Format(Messages.DuplicateMeasureName, newName));
                }

                // Do not allow a measure with the same name as a column in the table:
                if (measure.Table.Columns.Any(c => c.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase)))
                {
                    throw new ArgumentException(string.Format(Messages.DuplicateColumnName, newName));
                }
            }
            else if (obj is Column)
            {
                var column = obj as Column;

                // Do not allow a column with the same name as a measure in the table:
                if (column.Table.Measures.Any(m => m.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase)))
                {
                    throw new ArgumentException(string.Format(Messages.DuplicateMeasureName, newName));
                }

                // Do not allow a column with the same name as another column in the table:
                if (column.Table.Columns.Any(c => c != obj && c.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase)))
                {
                    throw new ArgumentException(string.Format(Messages.DuplicateColumnName, newName));
                }
            }
        }
        public static void SetName(this NamedMetadataObject obj, string newName, Culture culture = null)
        {
            if (culture != null)
            {
                culture.ObjectTranslations.SetTranslation(obj, TranslatedProperty.Caption, newName);
            }
            else
            {
                if (obj.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase))
                {
                    obj.Name = newName;
                    return;
                }

                if (obj is Measure)
                {
                    var measure = obj as Measure;

                    // Do not allow multiple measures with the same name:
                    if (measure.Model.Tables.Any(t => t.Measures.Any(m => m != obj && m.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase))))
                    {
                        throw new ArgumentException(string.Format(Messages.DuplicateMeasureName, newName));
                    }

                    // Do not allow a measure with the same name as a column in the table:
                    if (measure.Table.Columns.Any(c => c.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        throw new ArgumentException(string.Format(Messages.DuplicateColumnName, newName));
                    }
                }
                else if (obj is Column)
                {
                    var column = obj as Column;

                    // Do not allow a column with the same name as a measure in the table:
                    if (column.Table.Measures.Any(m => m.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        throw new ArgumentException(string.Format(Messages.DuplicateMeasureName, newName));
                    }

                    // Do not allow a column with the same name as another column in the table:
                    if (column.Table.Columns.Any(c => c != obj && c.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        throw new ArgumentException(string.Format(Messages.DuplicateColumnName, newName));
                    }
                }

                // Automatically apply name change to translations (but only if the translation is identical to the old name):
                var cultures = obj.Model?.Cultures;

                if (cultures != null && obj.IsTranslatable())
                {
                    foreach (var c in cultures)
                    {
                        var translatedName = obj.GetName(c);
                        if (!string.IsNullOrEmpty(translatedName) && translatedName.Equals(obj.Name, StringComparison.InvariantCultureIgnoreCase))
                        {
                            obj.SetName(newName, c);
                        }
                    }
                }

                if (!obj.IsRemoved)
                {
                    obj.Name = newName;
                }
            }
        }
Exemple #9
0
 public MetadataObjectContainer(NamedMetadataObject metadataObject, TranslatedProperty translatedProperty)
 {
     TabularObject      = metadataObject;
     TranslatedProperty = translatedProperty;
     TemporaryObjectId  = Guid.NewGuid();
 }
Exemple #10
0
 protected TabularNamedObject(NamedMetadataObject metadataObject) : base(metadataObject)
 {
 }
Exemple #11
0
 public MetadataObjectContainer(NamedMetadataObject metadataObject, TranslatedProperty translatedProperty)
 {
     TabularObject      = metadataObject;
     TranslatedProperty = translatedProperty;
 }
Exemple #12
0
 public void Add(NamedMetadataObject metadataObject, TabularNamedObject tabularObject)
 {
     cache.Add(metadataObject, tabularObject);
 }
Exemple #13
0
        public static void AddDisplayFolder(this ObservableCollection <ExpandoObject> collection, NamedMetadataObject metadataObject, string displayString, string defaultCulture, CultureCollection cultures)
        {
            if (collection == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(displayString))
            {
                foreach (ExpandoObject item in collection)
                {
                    if (((IDictionary <String, Object>)item)[defaultCulture] is string displayName && displayName.Equals(displayString))
                    {
                        var existingDisplayFolderContainer = ((IDictionary <String, Object>)item)["Object"] as DisplayFolderContainer;
                        existingDisplayFolderContainer.TabularObjects.Add(metadataObject);
                        return;
                    }
                }
            }

            dynamic row = new ExpandoObject();
            var     displayFolderContainer = new DisplayFolderContainer(metadataObject, TranslatedProperty.DisplayFolder);

            ((IDictionary <String, Object>)row)["Object"] = displayFolderContainer;
            foreach (var culture in cultures)
            {
                ((IDictionary <String, Object>)row)[culture.Name] = culture.Name.Equals(defaultCulture) ? displayString :
                                                                    culture.ObjectTranslations[displayFolderContainer.TabularObject, displayFolderContainer.TranslatedProperty]?.Value;
            }

            collection.Add(row);
        }