当前位置: 首页>>代码示例>>C#>>正文


C# DataContext.UserIsInRole方法代码示例

本文整理汇总了C#中DataContext.UserIsInRole方法的典型用法代码示例。如果您正苦于以下问题:C# DataContext.UserIsInRole方法的具体用法?C# DataContext.UserIsInRole怎么用?C# DataContext.UserIsInRole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataContext的用法示例。


在下文中一共展示了DataContext.UserIsInRole方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CopyModelAsCsvToStreamAsync

        private async Task CopyModelAsCsvToStreamAsync(NameValueCollection requestParameters, Stream responseStream, CancellationToken cancellationToken)
        {
            const int DefaultFrameRate = 30;

            SecurityProviderCache.ValidateCurrentProvider();
            string dateTimeFormat = Program.Host.Model.Global.DateTimeFormat;

            // TODO: Improve operation for large point lists:
            // Pick-up "POST"ed parameters with a "genurl" param, then cache parameters
            // in a memory cache and return the unique URL (a string instead of a file)
            // with a "download" param and unique ID associated with cached parameters.
            // Then extract params based on unique ID and follow normal steps...

            string pointIDsParam = requestParameters["PointIDs"];
            string startTimeParam = requestParameters["StartTime"];
            string endTimeParam = requestParameters["EndTime"];
            string frameRateParam = requestParameters["FrameRate"];
            string alignTimestampsParam = requestParameters["AlignTimestamps"];
            string missingAsNaNParam = requestParameters["MissingAsNaN"];
            string fillMissingTimestampsParam = requestParameters["FillMissingTimestamps"];
            string instanceName = requestParameters["InstanceName"];
            ulong[] pointIDs;
            string headers;

            if (string.IsNullOrEmpty(pointIDsParam))
                throw new ArgumentNullException("PointIDs", "Cannot export data: no values were provided in \"PointIDs\" parameter.");

            try
            {
                pointIDs = pointIDsParam.Split(',').Select(ulong.Parse).ToArray();
                Array.Sort(pointIDs);
            }
            catch (Exception ex)
            {
                throw new ArgumentNullException("PointIDs", $"Cannot export data: failed to parse \"PointIDs\" parameter value \"{pointIDsParam}\": {ex.Message}");
            }

            if (string.IsNullOrEmpty(startTimeParam))
                throw new ArgumentNullException("StartTime", "Cannot export data: no \"StartTime\" parameter value was specified.");

            if (string.IsNullOrEmpty(pointIDsParam))
                throw new ArgumentNullException("EndTime", "Cannot export data: no \"EndTime\" parameter value was specified.");

            DateTime startTime, endTime;

            try
            {
                startTime = DateTime.ParseExact(startTimeParam, dateTimeFormat, null, DateTimeStyles.AdjustToUniversal);
            }
            catch (Exception ex)
            {
                throw new ArgumentException($"Cannot export data: failed to parse \"StartTime\" parameter value \"{startTimeParam}\". Expected format is \"{dateTimeFormat}\". Error message: {ex.Message}", "StartTime", ex);
            }

            try
            {
                endTime = DateTime.ParseExact(endTimeParam, dateTimeFormat, null, DateTimeStyles.AdjustToUniversal);
            }
            catch (Exception ex)
            {
                throw new ArgumentException($"Cannot export data: failed to parse \"EndTime\" parameter value \"{endTimeParam}\". Expected format is \"{dateTimeFormat}\". Error message: {ex.Message}", "EndTime", ex);
            }

            if (startTime > endTime)
                throw new ArgumentOutOfRangeException("StartTime", "Cannot export data: start time exceeds end time.");

            using (DataContext dataContext = new DataContext())
            {
                // Validate current user has access to requested data
                if (!dataContext.UserIsInRole(s_minimumRequiredRoles))
                    throw new SecurityException($"Cannot export data: access is denied for user \"{Thread.CurrentPrincipal.Identity?.Name ?? "Undefined"}\", minimum required roles = {s_minimumRequiredRoles.ToDelimitedString(", ")}.");

                headers = GetHeaders(dataContext, pointIDs.Select(id => (int)id));
            }

            int frameRate;

            if (!int.TryParse(frameRateParam, out frameRate))
                frameRate = DefaultFrameRate;

            bool alignTimestamps = alignTimestampsParam?.ParseBoolean() ?? true;
            bool missingAsNaN = missingAsNaNParam?.ParseBoolean() ?? true;
            bool fillMissingTimestamps = alignTimestamps && (fillMissingTimestampsParam?.ParseBoolean() ?? false);

            if (string.IsNullOrEmpty(instanceName))
                instanceName = TrendValueAPI.DefaultInstanceName;
        
            LocalOutputAdapter adapter;
            LocalOutputAdapter.Instances.TryGetValue(instanceName, out adapter);
            HistorianServer serverInstance = adapter?.Server;

            if ((object)serverInstance == null)
                throw new InvalidOperationException($"Cannot export data: failed to access internal historian server instance \"{instanceName}\".");

            const int TargetBufferSize = 524288;

            StringBuilder readBuffer = new StringBuilder(TargetBufferSize * 2);
            ManualResetEventSlim bufferReady = new ManualResetEventSlim(false);
            List<string> writeBuffer = new List<string>();
            object writeBufferLock = new object();
//.........这里部分代码省略.........
开发者ID:GridProtectionAlliance,项目名称:openHistorian,代码行数:101,代码来源:ExportDataHandler.ashx.cs


注:本文中的DataContext.UserIsInRole方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。