Exemplo n.º 1
0
        private static IEnumerable <IEdmModel> BuildAnnotations(IEdmModel model)
        {
            IEdmEntityContainer edmEntityContainer = ExtensionMethods.EntityContainers(model).SingleOrDefault((IEdmEntityContainer ec) => ec.Name == "TenantReportingWebService");
            EdmModel            edmModel           = new EdmModel();

            edmModel.AddReferencedModel(model);
            ReportingSchema reportingSchema = ReportingService.GetReportingSchema();

            foreach (IEntity entity in reportingSchema.Entities.Values)
            {
                IEdmEntitySet edmEntitySet = edmEntityContainer.FindEntitySet(entity.Name);
                if (edmEntitySet != null)
                {
                    ReportingService.AddAnnotation(edmModel, edmEntitySet, "ReportTitle", entity.Annotation.ReportTitle);
                    if (entity.Annotation.Xaxis != null)
                    {
                        string value = string.Join(",", entity.Annotation.Xaxis);
                        if (!string.IsNullOrEmpty(value))
                        {
                            ReportingService.AddAnnotation(edmModel, edmEntitySet, "X-Axis", value);
                        }
                    }
                    ReportingService.AddAnnotation(edmModel, edmEntitySet, "Y-Axis", string.Join(",", entity.Annotation.Yaxis));
                }
            }
            return(new IEdmModel[]
            {
                edmModel
            });
        }
Exemplo n.º 2
0
        private Dictionary <string, ReportingSchema.ReportPropertyCmdletParamMapping[]> LoadRbacMapping(SafeXmlDocument doc)
        {
            Dictionary <string, ReportingSchema.ReportPropertyCmdletParamMapping[]> result;

            using (XmlNodeList xmlNodeList = doc.SelectNodes("/Configuration/CmdletParameterMappings/CmdletParameterMapping"))
            {
                Dictionary <string, ReportingSchema.ReportPropertyCmdletParamMapping[]> dictionary = new Dictionary <string, ReportingSchema.ReportPropertyCmdletParamMapping[]>(xmlNodeList.Count);
                foreach (object obj in xmlNodeList)
                {
                    XmlNode xmlNode = (XmlNode)obj;
                    using (XmlNodeList xmlNodeList2 = xmlNode.SelectNodes("Cmdlet"))
                    {
                        using (XmlNodeList xmlNodeList3 = xmlNode.SelectNodes("Mappings/Mapping"))
                        {
                            ReportingSchema.CheckCondition(xmlNodeList2.Count == 1, "There must be one and only one Cmdlet node under Rbac node.");
                            string key = xmlNodeList2[0].Attributes["Name"].Value.Trim();
                            ReportingSchema.CheckCondition(!dictionary.ContainsKey(key), "There shouldn't be duplicate Cmdlet under Rbac node.");
                            ReportingSchema.CheckCondition(xmlNodeList3.Count > 0, "The mapping shouldn't be empty.");
                            ReportingSchema.ReportPropertyCmdletParamMapping[] array = new ReportingSchema.ReportPropertyCmdletParamMapping[xmlNodeList3.Count];
                            int num = 0;
                            foreach (object obj2 in xmlNodeList3)
                            {
                                XmlNode xmlNode2 = (XmlNode)obj2;
                                array[num++] = new ReportingSchema.ReportPropertyCmdletParamMapping(xmlNode2.Attributes["CmdletParameter"].Value.Trim(), xmlNode2.Attributes["ReportObjectProperty"].Value.Trim());
                            }
                            dictionary.Add(key, array);
                        }
                    }
                }
                result = dictionary;
            }
            return(result);
        }
Exemplo n.º 3
0
        private static ReportingSchema GetReportingSchema()
        {
            HttpContext httpContext             = HttpContext.Current;
            string      currentReportingVersion = ReportingVersion.GetCurrentReportingVersion(httpContext);

            return(ReportingSchema.GetReportingSchema(currentReportingVersion));
        }
Exemplo n.º 4
0
 private void LoadEntityNodes(SafeXmlDocument doc, Dictionary <string, ReportingSchema.ReportPropertyCmdletParamMapping[]> reportPropertyCmdletParamMapping)
 {
     using (XmlNodeList xmlNodeList = doc.SelectNodes("/Configuration/Reports/Report"))
     {
         HashSet <string> hashSet = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase);
         foreach (object obj in xmlNodeList)
         {
             XmlNode xmlNode = (XmlNode)obj;
             ReportingSchema.CheckCondition(!string.IsNullOrWhiteSpace(xmlNode.Attributes["Name"].Value) && !string.IsNullOrWhiteSpace(xmlNode.Attributes["Snapin"].Value) && !string.IsNullOrWhiteSpace(xmlNode.Attributes["Cmdlet"].Value), string.Format("Attributes {0}, {1}, {2} of entity should not be empty.", "Name", "Cmdlet", "Snapin"));
             hashSet.Add(xmlNode.Attributes["Snapin"].Value.Trim());
         }
         using (IPSCommandResolver ipscommandResolver = DependencyFactory.CreatePSCommandResolver(hashSet))
         {
             foreach (object obj2 in xmlNodeList)
             {
                 XmlNode xmlNode2   = (XmlNode)obj2;
                 string  text       = xmlNode2.Attributes["Name"].Value.Trim();
                 string  text2      = xmlNode2.Attributes["Cmdlet"].Value.Trim();
                 string  snapinName = xmlNode2.Attributes["Snapin"].Value.Trim();
                 ReportingSchema.CheckCondition(!this.entities.ContainsKey(text), "Duplicate entity in the config file");
                 Dictionary <string, string> dictionary = null;
                 using (XmlNodeList xmlNodeList2 = xmlNode2.SelectNodes("CmdletParameters/CmdletParameter"))
                 {
                     if (xmlNodeList2.Count > 0)
                     {
                         dictionary = new Dictionary <string, string>(xmlNodeList2.Count);
                         foreach (object obj3 in xmlNodeList2)
                         {
                             XmlNode xmlNode3 = (XmlNode)obj3;
                             ReportingSchema.CheckCondition(!string.IsNullOrWhiteSpace(xmlNode3.Attributes["Name"].Value) && !string.IsNullOrWhiteSpace(xmlNode3.Attributes["Value"].Value), "cmdlet parameter name and value should not be empty.");
                             string key   = xmlNode3.Attributes["Name"].Value.Trim();
                             string value = xmlNode3.Attributes["Value"].Value.Trim();
                             dictionary.Add(key, value);
                         }
                     }
                 }
                 Dictionary <string, List <string> > dictionary2 = null;
                 if (reportPropertyCmdletParamMapping.ContainsKey(text2))
                 {
                     dictionary2 = new Dictionary <string, List <string> >(reportPropertyCmdletParamMapping[text2].Length);
                     foreach (ReportingSchema.ReportPropertyCmdletParamMapping reportPropertyCmdletParamMapping2 in reportPropertyCmdletParamMapping[text2])
                     {
                         if (!dictionary2.ContainsKey(reportPropertyCmdletParamMapping2.ReportObjectProperty))
                         {
                             dictionary2.Add(reportPropertyCmdletParamMapping2.ReportObjectProperty, new List <string>());
                         }
                         dictionary2[reportPropertyCmdletParamMapping2.ReportObjectProperty].Add(reportPropertyCmdletParamMapping2.CmdletParameter);
                     }
                 }
                 XmlNode           annotationNode = ReportingSchema.SelectSingleNode(xmlNode2, "Annotation");
                 IReportAnnotation annotation     = DependencyFactory.CreateReportAnnotation(annotationNode);
                 IEntity           entity         = DependencyFactory.CreateEntity(text, new TaskInvocationInfo(text2, snapinName, dictionary), dictionary2, annotation);
                 entity.Initialize(ipscommandResolver);
                 this.entities.Add(text, entity);
             }
         }
     }
 }
Exemplo n.º 5
0
 private IDataServiceQueryProvider GetQueryProvider(IDataServiceMetadataProvider metadata)
 {
     if (this.queryProvider == null)
     {
         ReportingSchema reportingSchema = ReportingService.GetReportingSchema();
         this.queryProvider = new ReportingQueryProvider(metadata, reportingSchema);
     }
     return(this.queryProvider);
 }
Exemplo n.º 6
0
        public static IReportAnnotation Load(XmlNode annotationNode)
        {
            ReportAnnotation reportAnnotation = new ReportAnnotation();

            reportAnnotation.reportTitle = ReportAnnotation.GetStringInfo(ReportingSchema.SelectSingleNode(annotationNode, "ReportTitle"));
            ReportingSchema.CheckCondition(reportAnnotation.reportTitle != null && !string.IsNullOrEmpty(reportAnnotation.reportTitle.StringId), "Report title isn't present.");
            reportAnnotation.xaxises = ReportAnnotation.LoadSeries(annotationNode, "XAxis");
            reportAnnotation.yaxises = ReportAnnotation.LoadSeries(annotationNode, "YAxis");
            ReportingSchema.CheckCondition(reportAnnotation.yaxises != null && reportAnnotation.yaxises.Count > 0, "Report Y-Axis doesn't present.");
            return(reportAnnotation);
        }
Exemplo n.º 7
0
        public static ReportingSchema GetCurrentReportingSchema(HttpContext httpContext)
        {
            ReportingSchema schema = null;

            ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.GetReportingSchemaLatency, delegate
            {
                string currentReportingVersion = ReportingVersion.GetCurrentReportingVersion(httpContext);
                schema = ReportingSchema.GetReportingSchema(currentReportingVersion);
            });
            return(schema);
        }
Exemplo n.º 8
0
        public static XmlNode SelectSingleNode(XmlNode node, string xpath)
        {
            XmlNode result;

            using (XmlNodeList xmlNodeList = node.SelectNodes(xpath))
            {
                ReportingSchema.CheckCondition(xmlNodeList.Count == 1, string.Format("expect only one {0}.", xpath));
                result = xmlNodeList[0];
            }
            return(result);
        }
Exemplo n.º 9
0
        private IDataServiceMetadataProvider GetMetadataProvider()
        {
            this.metadataProvider = (ReportingMetadataProvider)HttpRuntime.Cache[this.GetCacheKey()];
            if (this.metadataProvider != null)
            {
                return(this.metadataProvider);
            }
            ReportingSchema reportingSchema = ReportingService.GetReportingSchema();

            this.metadataProvider = new ReportingMetadataProvider(reportingSchema);
            HttpRuntime.Cache.Insert(this.GetCacheKey(), this.metadataProvider, null, (DateTime)ExDateTime.UtcNow.Add(ReportingService.MetadataProviderCacheMaxAge), Cache.NoSlidingExpiration, CacheItemPriority.High, null);
            return(this.metadataProvider);
        }
Exemplo n.º 10
0
        private ResourceType GenerateComplexTypeSchema(Type clrType, ResourceTypeKind resourceTypeKind)
        {
            if (this.complexTypeResourceTypes.ContainsKey(clrType.FullName))
            {
                return(this.complexTypeResourceTypes[clrType.FullName]);
            }
            ResourceType resourceType = new ResourceType(clrType, resourceTypeKind, null, "TenantReporting", clrType.Name, false);

            foreach (PropertyInfo propertyInfo in clrType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy))
            {
                Type type = propertyInfo.PropertyType;
                Type type2;
                if (ReportingSchema.IsNullableType(type, out type2))
                {
                    type = type2;
                }
                ResourcePropertyKind resourcePropertyKind = 1;
                ResourceType         resourceType2        = ResourceType.GetPrimitiveResourceType(type);
                if (resourceType2 == null)
                {
                    if (type.IsEnum || type.IsValueType)
                    {
                        throw new NotSupportedException("struct and enum are not supported. For struct, try to change it to class. For enum, try to change it to integer or string.");
                    }
                    if (type.Equals(clrType))
                    {
                        resourceType2 = resourceType;
                    }
                    else
                    {
                        resourceType2 = this.GenerateComplexTypeSchema(type, 1);
                    }
                    resourcePropertyKind = 4;
                }
                resourceType.AddProperty(new ResourceProperty(propertyInfo.Name, resourcePropertyKind, resourceType2));
            }
            if (resourceTypeKind == 1)
            {
                this.complexTypeResourceTypes.Add(clrType.FullName, resourceType);
            }
            return(resourceType);
        }
Exemplo n.º 11
0
        public static ReportingSchema GetReportingSchema(string version)
        {
            ReportingSchema schema = null;

            ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.GetReportingSchemaLatency, delegate
            {
                if (!ReportingSchema.SchemaDictionary.TryGetValue(version, out schema))
                {
                    lock (ReportingSchema.SyncRoot)
                    {
                        if (!ReportingSchema.SchemaDictionary.TryGetValue(version, out schema))
                        {
                            schema = new ReportingSchema(version);
                            ReportingSchema.SchemaDictionary[version] = schema;
                        }
                    }
                }
            });
            return(schema);
        }
Exemplo n.º 12
0
 private void BuildResourceType(IEntity entity, ResourceType resourceType, Dictionary <string, ResourceType> complexTypeResourceTypes)
 {
     if (ResourceType.GetPrimitiveResourceType(entity.ClrType) == null)
     {
         foreach (PropertyInfo propertyInfo in entity.ClrType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy))
         {
             if (entity.ReportPropertyCmdletParamsMap == null || !entity.ReportPropertyCmdletParamsMap.ContainsKey(propertyInfo.Name) || this.IsEntityPropertyVisibleForCurrentUser(entity, propertyInfo.Name))
             {
                 Type type = propertyInfo.PropertyType;
                 Type type2;
                 if (ReportingSchema.IsNullableType(type, out type2))
                 {
                     type = type2;
                 }
                 ResourcePropertyKind resourcePropertyKind = 1;
                 ResourceType         resourceType2        = ResourceType.GetPrimitiveResourceType(type);
                 if (resourceType2 == null)
                 {
                     if (type.IsEnum || type.IsValueType)
                     {
                         throw new NotSupportedException("struct and enum are not supported. For struct, try to change it to class. For enum, try to change it to integer or string.");
                     }
                     if (type.Equals(entity.ClrType))
                     {
                         resourceType2 = resourceType;
                     }
                     else
                     {
                         resourceType2 = complexTypeResourceTypes[type.FullName];
                     }
                     resourcePropertyKind = 4;
                 }
                 resourceType.AddProperty(new ResourceProperty(propertyInfo.Name, resourcePropertyKind | (entity.KeyMembers.Contains(propertyInfo.Name) ? 2 : 0), resourceType2));
             }
         }
     }
     resourceType.SetReadOnly();
 }
Exemplo n.º 13
0
 public ReportingQueryProvider(IDataServiceMetadataProvider metadataProvider, ReportingSchema schema)
 {
     this.metadataProvider = metadataProvider;
     this.schema           = schema;
     this.dataSource       = DependencyFactory.CreateReportingDataSource(RbacPrincipal.Current);
 }
Exemplo n.º 14
0
        private RbacPrincipal CreateRbacPrincipal(IIdentity identity, string tenantDomain, string cacheKey, HttpContext httpContext)
        {
            ExTraceGlobals.ReportingWebServiceTracer.TraceDebug <string, string, string>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] Create RbacPrincipal. Identity: {0}; tenantDomain: {1}; cacheKey: '{2}'", identity.GetSafeName(true), tenantDomain ?? string.Empty, cacheKey);
            ExchangeRunspaceConfigurationSettings rbacSettings = null;

            ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.NewExchangeRunspaceConfigurationSettingsLatency, delegate
            {
                rbacSettings = new ExchangeRunspaceConfigurationSettings(ExchangeRunspaceConfigurationSettings.ExchangeApplication.ReportingWebService, tenantDomain, ExchangeRunspaceConfigurationSettings.SerializationLevel.None);
            });
            ReportingSchema schema = ReportingSchema.GetCurrentReportingSchema(httpContext);

            try
            {
                RequestStatistics requestStatistics = HttpContext.Current.Items[RequestStatistics.RequestStatsKey] as RequestStatistics;
                if (requestStatistics != null)
                {
                    requestStatistics.AddExtendedStatisticsDataPoint("AuthType", identity.AuthenticationType);
                }
                using (new AverageTimePerfCounter(RwsPerfCounters.AverageRbacPrincipalCreation, RwsPerfCounters.AverageRbacPrincipalCreationBase, true))
                {
                    RwsExchangeRunspaceConfiguration rbacConfiguration = null;
                    ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.NewRwsExchangeRunspaceConfigurationLatency, delegate
                    {
                        rbacConfiguration = RwsExchangeRunspaceConfiguration.NewInstance(identity, rbacSettings, schema.CmdletFilter, this.GetSnapinSet());
                    });
                    RbacPrincipal rbacPrincipal = null;
                    ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.NewRbacPrincipalLatency, delegate
                    {
                        rbacPrincipal = new RbacPrincipal(rbacConfiguration, cacheKey);
                    });
                    return(rbacPrincipal);
                }
            }
            catch (CmdletAccessDeniedException ex)
            {
                HttpRuntime.Cache.Remove(cacheKey);
                ExTraceGlobals.ReportingWebServiceTracer.TraceError <CmdletAccessDeniedException>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] CmdletAccessDeniedException: {0}", ex);
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ErrorTenantNotInOrgScope, Strings.ErrorTenantNotInOrgScope(tenantDomain), ex);
            }
            catch (CannotResolveTenantNameException ex2)
            {
                HttpRuntime.Cache.Remove(cacheKey);
                ExTraceGlobals.ReportingWebServiceTracer.TraceError <CannotResolveTenantNameException>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] CannotResolveTenantNameException: {0}", ex2);
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ErrorTenantNotResolved, Strings.ErrorTenantNotResolved(tenantDomain), ex2);
            }
            catch (ADTransientException ex3)
            {
                HttpRuntime.Cache.Remove(cacheKey);
                ExTraceGlobals.ReportingWebServiceTracer.TraceError <ADTransientException>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] ADTransientException: {0}", ex3);
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ADTransientError, Strings.ADTransientError, ex3);
            }
            catch (DataSourceOperationException ex4)
            {
                HttpRuntime.Cache.Remove(cacheKey);
                ExTraceGlobals.ReportingWebServiceTracer.TraceError <DataSourceOperationException>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] DataSourceOperationException: {0}", ex4);
                ServiceDiagnostics.ThrowError(ReportingErrorCode.ADOperationError, Strings.ADOperationError, ex4);
            }
            catch (TimeoutException ex5)
            {
                HttpRuntime.Cache.Remove(cacheKey);
                ExTraceGlobals.ReportingWebServiceTracer.TraceError <TimeoutException>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] TimeoutException: {0}", ex5);
                ServiceDiagnostics.ThrowError(ReportingErrorCode.CreateRunspaceConfigTimeoutError, Strings.CreateRunspaceConfigTimeoutError, ex5);
            }
            catch (Exception ex6)
            {
                HttpRuntime.Cache.Remove(cacheKey);
                ExTraceGlobals.ReportingWebServiceTracer.TraceError <Exception>((long)this.GetHashCode(), "[RbacPrincipalManager::CreateRbacPrincipal] Exception: {0}", ex6);
                ServiceDiagnostics.ThrowError(ReportingErrorCode.UnknownError, Strings.UnknownError, ex6);
            }
            return(null);
        }
 public ReportingMetadataProvider(ReportingSchema schema)
 {
     this.metadata = new Metadata(RbacPrincipal.Current, schema.Entities.Values, schema.ComplexTypeResourceTypes);
 }