Example #1
0
        // this routine clones the permissions for the various major permission types
        private void ClonePermissions(MajorObject mo, Role r)
        {
            DimensionPermission  dimPerm  = mo as DimensionPermission;
            CubePermission       cubePerm = mo as CubePermission;
            DatabasePermission   dbPerm   = mo as DatabasePermission;
            DataSourcePermission dsPerm   = mo as DataSourcePermission;

            if (dimPerm != null)
            {
                ClonePermissions(dimPerm, r);
            }
            else if (cubePerm != null)
            {
                ClonePermissions(cubePerm, r);
            }
            else if (dbPerm != null)
            {
                ClonePermissions(dbPerm, r);
            }
            else if (dsPerm != null)
            {
                ClonePermissions(dsPerm, r);
            }
            else
            {
                throw new System.Exception("BIDSHelper: unhandled permission type");
            }
        }
        public static void SaveXmlAnnotation(MajorObject obj, string annotationName, object annotationValue)
        {
            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(annotationValue.GetType());
            StringBuilder sb = new StringBuilder();

            System.IO.StringWriter writer = new System.IO.StringWriter(sb);
            serializer.Serialize(writer, annotationValue);
            System.Xml.XmlDocument xml = new XmlDocument();
            xml.LoadXml(sb.ToString());
            if (obj.Annotations.Contains(annotationName))
            {
                obj.Annotations.Remove(annotationName);
            }
            if (AreAnnotationsStringStyle(obj))
            {
                //this is just a workaround to this bug: https://connect.microsoft.com/SQLServer/feedback/details/776444/tabular-model-error-during-opening-bim-after-sp1-readelementcontentas-methods-cannot-be-called-on-an-element-that-has-child-elements
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent             = true;
                settings.OmitXmlDeclaration = true;
                StringBuilder sb2           = new StringBuilder();
                XmlWriter     wr            = XmlWriter.Create(sb2, settings);
                XmlDocument   annotationDoc = new XmlDocument();
                annotationDoc.LoadXml(xml.InnerXml);
                annotationDoc.Save(wr);
                wr.Close();

                Annotation annotation = new Annotation(annotationName, sb2.ToString());
                obj.Annotations.Add(annotation);
            }
            else
            {
                Annotation annotation = annotation = new Annotation(annotationName, xml.DocumentElement);
                obj.Annotations.Add(annotation);
            }
        }
 public static string GetAnnotationXml(MajorObject obj, string annotationName)
 {
     if (AreAnnotationsStringStyle(obj))
     {
         return(obj.Annotations[annotationName].Value.InnerText);
     }
     else
     {
         return(obj.Annotations[annotationName].Value.OuterXml);
     }
 }
        public static bool AreAnnotationsStringStyle(MajorObject obj)
        {
            while (obj != null && !(obj is Database))
            {
                obj = (MajorObject)obj.Parent;
            }
            if (obj == null)
            {
                throw new Exception("Can't find Database object!");
            }
            Database db = (Database)obj;

            if (db.Annotations.Contains(ANNOTATION_STYLE_ANNOTATION))
            {
                if (db.Annotations[ANNOTATION_STYLE_ANNOTATION].Value.InnerText == ANNOTATION_STYLE_STRING)
                {
                    return(true);
                }
            }
            return(false);
        }
Example #5
0
        // Helper Functions
        // ================

        // returns a new id with a GUID so that it is guaranteed to be unique
        private string NewId(MajorObject mo)
        {
            return(mo.GetType().Name + " " + System.Guid.NewGuid().ToString());
        }
Example #6
0
 public static string GetAnnotationXml(MajorObject obj, string annotationName)
 {
     if (TabularAnnotationWorkaroundPlugin.AreAnnotationsStringStyle(obj))
     {
         return obj.Annotations[annotationName].Value.InnerText;
     }
     else
     {
         return obj.Annotations[annotationName].Value.OuterXml;
     }
 }
Example #7
0
        public static void SaveXmlAnnotation(MajorObject obj, string annotationName, object annotationValue)
        {
            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(annotationValue.GetType());
            StringBuilder sb = new StringBuilder();
            System.IO.StringWriter writer = new System.IO.StringWriter(sb);
            serializer.Serialize(writer, annotationValue);
            System.Xml.XmlDocument xml = new XmlDocument();
            xml.LoadXml(sb.ToString());
            if (obj.Annotations.Contains(annotationName)) obj.Annotations.Remove(annotationName);
            if (TabularAnnotationWorkaroundPlugin.AreAnnotationsStringStyle(obj))
            {
                //this is just a workaround to this bug: https://connect.microsoft.com/SQLServer/feedback/details/776444/tabular-model-error-during-opening-bim-after-sp1-readelementcontentas-methods-cannot-be-called-on-an-element-that-has-child-elements
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;
                settings.OmitXmlDeclaration = true;
                StringBuilder sb2 = new StringBuilder();
                XmlWriter wr = XmlWriter.Create(sb2, settings);
                XmlDocument annotationDoc = new XmlDocument();
                annotationDoc.LoadXml(xml.InnerXml);
                annotationDoc.Save(wr);
                wr.Close();

                Annotation annotation = new Annotation(annotationName, sb2.ToString());
                obj.Annotations.Add(annotation);
            }
            else
            {
                Annotation annotation = annotation = new Annotation(annotationName, xml.DocumentElement);
                obj.Annotations.Add(annotation);
            }
        }
Example #8
0
        // this routine clones the permissions for the various major permission types
        private void ClonePermissions(MajorObject mo, Role r)
        {
            DimensionPermission dimPerm = mo as DimensionPermission;
            CubePermission cubePerm = mo as CubePermission;
            DatabasePermission dbPerm = mo as DatabasePermission;
            DataSourcePermission dsPerm = mo as DataSourcePermission;

            if (dimPerm != null)
                ClonePermissions(dimPerm, r);
            else if (cubePerm != null)
                ClonePermissions(cubePerm, r);
            else if (dbPerm != null)
                ClonePermissions(dbPerm, r);
            else if (dsPerm != null)
                ClonePermissions(dsPerm, r);
            else throw new System.Exception("BIDSHelper: unhandled permission type");            

        }
Example #9
0
        // Helper Functions
        // ================

        // returns a new id with a GUID so that it is guaranteed to be unique
        private string NewId(MajorObject mo)
        {
            return mo.GetType().Name + " " + System.Guid.NewGuid().ToString();
        }
 public static bool AreAnnotationsStringStyle(MajorObject obj)
 {
     while (obj != null && !(obj is Database))
     {
         obj = (MajorObject)obj.Parent;
     }
     if (obj == null) throw new Exception("Can't find Database object!");
     Database db = (Database)obj;
     if (db.Annotations.Contains(ANNOTATION_STYLE_ANNOTATION))
     {
         if (db.Annotations[ANNOTATION_STYLE_ANNOTATION].Value.InnerText == ANNOTATION_STYLE_STRING)
         {
             return true;
         }
     }
     return false;
 }