public ColumnMetadata(string name, DType schema, DataFormat?dataFormat, string displayName, bool isReadOnly, bool isKey, bool isRequired, ColumnCreationKind creationKind, ColumnVisibility visibility, string titleColumnName, string subtitleColumnName, string thumbnailColumnName, ColumnLookupMetadata?lookupMetadata, ColumnAttachmentMetadata?attachmentMetadata) { Contracts.AssertNonEmpty(name); Contracts.AssertValid(schema); Contracts.AssertOneOfValueTypeOrNull(dataFormat, DataTypeInfo.GetValidDataFormats(schema.Kind)); Contracts.AssertNonEmpty(displayName); Contracts.AssertNonEmptyOrNull(titleColumnName); Contracts.AssertNonEmptyOrNull(subtitleColumnName); Contracts.AssertNonEmptyOrNull(thumbnailColumnName); Contracts.AssertValueOrNull(lookupMetadata); Contracts.AssertValueOrNull(attachmentMetadata); Name = name; Type = schema; DataFormat = dataFormat; DisplayName = displayName; IsReadOnly = isReadOnly; IsKey = isKey; IsRequired = isRequired; _kind = creationKind; _visibility = visibility; TitleColumnName = titleColumnName; SubtitleColumnName = subtitleColumnName; ThumbnailColumnName = thumbnailColumnName; LookupMetadata = lookupMetadata; AttachmentMetadata = attachmentMetadata; if (dataFormat == PowerFx.Core.App.DataFormat.AllowedValues) { AllowedValues = AllowedValuesMetadata.CreateForValue(schema); } }
/// <summary> /// Formats data byte(s) to human readable format appending the appropriate <see cref="DataFormat"/> /// if not specified. /// </summary> /// <param name="value">Bytes length/count.</param> /// <param name="format">Data format type to convert to.</param> /// <param name="precision">Number of decimal places.</param> /// <returns>Formatted data string.</returns> public static string HumanizeData(this long value, DataFormat?format = null, int precision = 2) { if (!format.HasValue) { format = value >= OneTb ? DataFormat.TB : value >= OneGb ? DataFormat.GB : value >= OneMb ? DataFormat.MB : DataFormat.KB; } return(string.Format("{0} {1}", value.ConvertData(format.Value, precision).ToCommaSeparated(precision), format.Value.GetName())); }
public void HumanizeDataSize(long dataSize, DataFormat?format) { // Arrange format = format.HasValue ? format : DataFormat.Bytes; // Act string result = dataSize.HumanizeData(format); // Assert Assert.IsNotNull(result); Log(result); Assert.IsTrue(result.EndsWith(format.ToString())); }
/// <summary> /// Creates REST request. /// </summary> /// <param name="restClient">REST client to setup.</param> /// <param name="resource">URI of the request.</param> /// <param name="method">HTTP method to use.</param> /// <param name="dataFormat">The data format.</param> /// <returns> /// REST request. /// </returns> public static IRestRequest CreateRequest(this IRestClient restClient, string resource, Method method = Method.POST, DataFormat?dataFormat = null) { var restRequest = new RestRequest { Resource = resource, Method = method }; if (dataFormat.HasValue) { restRequest.RequestFormat = dataFormat.Value; } return(restRequest); }
/// <summary> /// Create read command /// 创建读取命令 /// </summary> /// <param name="id">Entity id</param> /// <param name="range">View range</param> /// <param name="format">Date format</param> /// <returns>Command</returns> protected virtual CommandDefinition NewReadCommand(T id, string range, DataFormat?format = null) { var name = GetReadCommand(range, format); var parameters = new DynamicParameters(); parameters.Add("id", id); if (range != PublicRange) { // Deserve for public acess AddSystemParameters(parameters); } return(CreateCommand(name, parameters)); }
/// <summary> /// Get read command name /// </summary> /// <param name="range">Range</param> /// <param name="format">Format</param> /// <returns>Command name</returns> protected virtual string GetReadCommand(string range, DataFormat?format = null) { // Avoid possible SQL injection attack FilterRange(range); // Keys var keys = new List <string> { "read", "for", range }; if (format != null) { keys.Add(format.Name.ToLower()); } return(GetCommandNameBase(keys)); }
/// <summary> /// Used to get data produced by a specific report /// </summary> /// <param name="reportId">Report id of the desired report</param> /// <param name="dataType">"ReportData" or "ChartData" (if not provided, ReportData is used)</param> /// <param name="dataFormat">"Raw" or "Formatted" (if not provided, Raw is used)</param> public Uri GetReportDataUri(int reportId, ReportDataType?dataType = null, DataFormat?dataFormat = null) { var builder = new UriBuilder(BaseUri); builder.Path += $"reports/{reportId}"; var queryBuilder = new QueryBuilder(); if (dataType != null) { queryBuilder.Add("dataType", dataType); } if (dataFormat != null) { queryBuilder.Add("dataFormat", dataFormat); } builder.Query = queryBuilder.ToString(); return(builder.Uri); }
private unsafe DataFormat GetDataFormat <TRaw>() where TRaw : unmanaged { if (_dataFormat == null) { // Build DataFormat from IDataFormatProvider if (typeof(IDataFormatProvider).IsAssignableFrom(typeof(TRaw))) { var provider = (IDataFormatProvider)(new TRaw()); _dataFormat = new DataFormat(provider.Flags) { DataSize = sizeof(TRaw), ObjectsFormat = provider.ObjectsFormat }; } else { // Build DataFormat from DataFormat and DataObjectFormat attributes IEnumerable <DataFormatAttribute> dataFormatAttributes = typeof(TRaw).GetCustomAttributes <DataFormatAttribute>(false); if (dataFormatAttributes.Count() != 1) { throw new InvalidOperationException( string.Format(System.Globalization.CultureInfo.InvariantCulture, "The structure [{0}] must be marked with DataFormatAttribute or provide a IDataFormatProvider", typeof(TRaw).FullName)); } _dataFormat = new DataFormat(((DataFormatAttribute)dataFormatAttributes.First()).Flags) { DataSize = sizeof(TRaw) }; var dataObjects = new List <ObjectDataFormat>(); IEnumerable <FieldInfo> fields = typeof(TRaw).GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); // Iterates on fields foreach (var field in fields) { IEnumerable <DataObjectFormatAttribute> dataObjectAttributes = field.GetCustomAttributes <DataObjectFormatAttribute>(false); if (dataObjectAttributes.Count() > 0) { int fieldOffset = Marshal.OffsetOf(typeof(TRaw), field.Name).ToInt32(); int totalSizeOfField = Marshal.SizeOf(field.FieldType); int offset = fieldOffset; int numberOfDataObjects = 0; // Count the number of effective sub-field for a field // A field that contains a fixed array should have sub-field for (int i = 0; i < dataObjectAttributes.Count(); i++) { var attr = dataObjectAttributes.ElementAt(i); numberOfDataObjects += attr.ArrayCount == 0 ? 1 : attr.ArrayCount; } // Check that the size of the field is compatible with the number of sub-field // For a simple field without any array element, sub-field = field int sizeOfField = totalSizeOfField / numberOfDataObjects; if ((sizeOfField * numberOfDataObjects) != totalSizeOfField) { throw new InvalidOperationException(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Field [{0}] has incompatible size [{1}] and number of DataObjectAttributes [{2}]", field.Name, (double)totalSizeOfField / numberOfDataObjects, numberOfDataObjects)); } int subFieldIndex = 0; // Iterates on attributes for (int i = 0; i < dataObjectAttributes.Count(); i++) { var attr = dataObjectAttributes.ElementAt(i); numberOfDataObjects = attr.ArrayCount == 0 ? 1 : attr.ArrayCount; // Add DataObjectFormat for (int j = 0; j < numberOfDataObjects; j++) { var dataObject = new ObjectDataFormat( string.IsNullOrEmpty(attr.Guid) ? Guid.Empty : new Guid(attr.Guid), offset, attr.TypeFlags, attr.Flags, attr.InstanceNumber); // Use attribute name or fallback to field's name string name = (string.IsNullOrEmpty(attr.Name)) ? field.Name : attr.Name; name = numberOfDataObjects == 1 ? name : name + subFieldIndex; dataObject.Name = name; dataObjects.Add(dataObject); offset += sizeOfField; subFieldIndex++; } } } } _dataFormat.ObjectsFormat = dataObjects.ToArray(); } for (int i = 0; i < _dataFormat.ObjectsFormat.Length; i++) { var dataObject = _dataFormat.ObjectsFormat[i]; // Map field name to object if (_mapNameToObjectFormat.ContainsKey(dataObject.Name)) { throw new InvalidOperationException(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Incorrect field name [{0}]. Field name must be unique", dataObject.Name)); } _mapNameToObjectFormat.Add(dataObject.Name, dataObject); } // DumpDataFormat(_dataFormat); } return(_dataFormat); }
/// <summary> /// Used to get data for multiple records /// </summary> /// <param name="appId">App id of the desired records</param> /// <param name="filter">e.g., "not (38 gt 10 or 38 lt 5) and 37 gt datetime'2014-03-01T00:00:00.0000000'" (intersected with recordIds - if not provided, all records (or those matching recordIds) are returned)</param> /// <param name="recordIds">List of recordIds (intersected with filter - if not provided, all records (or those matching the filter) are returned)</param> /// <param name="fieldIds">List of fieldIds to include in the output (if not provided, all fields are returned)</param> /// <param name="dataFormat">"Raw" or "Formatted" (if not provided, Raw is used)</param> public Uri GetAppRecordsUri(int appId, string filter = null, IReadOnlyList <int> recordIds = null, IReadOnlyList <int> fieldIds = null, DataFormat?dataFormat = null) { var builder = new UriBuilder(BaseUri); builder.Path += "records/" + appId; var queryBuilder = new QueryBuilder(); if (!string.IsNullOrEmpty(filter)) { queryBuilder.Add("$filter", filter); } if (recordIds != null && recordIds.Any()) { queryBuilder.Add("recordIds", string.Join(",", recordIds)); } if (fieldIds != null && fieldIds.Any()) { queryBuilder.Add("fieldIds", string.Join(",", fieldIds)); } if (dataFormat != null) { queryBuilder.Add("dataFormat", dataFormat); } builder.Query = queryBuilder.ToString(); return(builder.Uri); }
/// <summary> /// Create report command /// 创建报表命令 /// </summary> /// <param name="range">Report range</param> /// <param name="model">Condition model</param> /// <param name="format">Date format</param> /// <returns>Command</returns> protected virtual CommandDefinition NewReportCommand(string range, object?model = null, DataFormat?format = null) { // Avoid possible SQL injection attack FilterRange(range); var parameters = FormatParameters(model ?? new DynamicParameters()); AddSystemParameters(parameters); // Keys var keys = new List <string> { "report", "for", range }; if (format != null) { keys.Add("as"); keys.Add(format.Name.ToLower()); } var name = GetCommandNameBase(keys); return(CreateCommand(name, parameters)); }
/// <summary> /// Formats data byte(s) to human readable format appending the appropriate <see cref="DataFormat"/> /// based on the bytes size. /// </summary> /// <param name="value">Bytes length/count.</param> /// <param name="precision">Number of decimal places.</param> /// <returns>Formatted data string.</returns> public static string HumanizeBytes(this long value, DataFormat?format = null, int precision = 2) => value.HumanizeData(format, precision);
public async Task <ResultRecord> GetAppRecordAsync(int appId, int recordId, IReadOnlyList <int> fieldIds = null, DataFormat?dataFormat = null) { var uri = _urlHelper.GetAppRecordUri(appId, recordId, fieldIds, dataFormat); using (var response = await MakeGetRequestAsync(uri).ConfigureAwait(false)) { using (var rs = response.GetResponseStream()) { return(JsonHelper.LoadRecord(rs)); } } }
public ResultRecord GetAppRecord(int appId, int recordId, IReadOnlyList <int> fieldIds = null, DataFormat?dataFormat = null) { var uri = _urlHelper.GetAppRecordUri(appId, recordId, fieldIds, dataFormat); using (var response = MakeGetRequest(uri)) { using (var rs = response.GetResponseStream()) { return(JsonHelper.LoadRecord(rs)); } } }
public async Task <ReportData> GetReportDataAsync(int reportId, ReportDataType?dataType = null, DataFormat?dataFormat = null) { var uri = _urlHelper.GetReportDataUri(reportId, dataType, dataFormat); using (var response = await MakeGetRequestAsync(uri).ConfigureAwait(false)) { using (var rs = response.GetResponseStream()) { return(JsonHelper.LoadReportData(rs)); } } }
public ReportData GetReportData(int reportId, ReportDataType?dataType = null, DataFormat?dataFormat = null) { var uri = _urlHelper.GetReportDataUri(reportId, dataType, dataFormat); using (var response = MakeGetRequest(uri)) { using (var rs = response.GetResponseStream()) { return(JsonHelper.LoadReportData(rs)); } } }
/// <summary> /// View entity to PipeWriter /// 浏览实体数据到PipeWriter /// </summary> /// <param name="writer">PipeWriter</param> /// <param name="id">Entity id</param> /// <param name="format">Data format</param> /// <param name="multipleResults">Multiple results</param> /// <returns>Task</returns> public virtual async Task ReadAsync(PipeWriter writer, T id, string range = "default", DataFormat?format = null, bool multipleResults = false) { format ??= DataFormat.Json; var command = NewReadCommand(id, range, format); await ReadToStreamAsync(command, writer, format, multipleResults); }
/// <summary> /// Used to get data for a specific record /// </summary> /// <param name="appId">App id of the desired record</param> /// <param name="recordId">Record id of the desired record</param> /// <param name="fieldIds">List of fieldIds to include in the output (if not provided, all fields are returned)</param> /// <param name="dataFormat">"Raw" or "Formatted" (if not provided, Raw is used)</param> public Uri GetAppRecordUri(int appId, int recordId, IReadOnlyList <int> fieldIds = null, DataFormat?dataFormat = null) { var builder = new UriBuilder(BaseUri); builder.Path += $"records/{appId}/{recordId}"; var queryBuilder = new QueryBuilder(); if (fieldIds != null && fieldIds.Any()) { queryBuilder.Add("fieldIds", string.Join(",", fieldIds)); } if (dataFormat != null) { queryBuilder.Add("dataFormat", dataFormat); } builder.Query = queryBuilder.ToString(); return(builder.Uri); }
/// <summary> /// Entity report to PipeWriter /// 实体报告数据到PipeWriter /// </summary> /// <param name="writer">PipeWriter</param> /// <param name="range">View range</param> /// <param name="modal">Condition modal</param> /// <param name="format">Data format</param> /// <returns>Task</returns> public virtual async Task ReportAsync(PipeWriter writer, string range, object?modal = null, DataFormat?format = null, bool multipleResults = false) { format ??= DataFormat.Json; var command = NewReportCommand(range, modal, format); await ReadToStreamAsync(command, writer, format, multipleResults); }
/// <param name="endpoint">A <see cref="PlatformEndpoint"/> or null. On null <see cref="PlatformEndpoint.SMITE"/> will be used.</param> /// <param name="dataFormat">If not specified <see cref="DataFormat.JSON"/> will be used</param> public RequestClient(PlatformEndpoint?endpoint = null, DataFormat?dataFormat = null) { _endpoint = endpoint ?? PlatformEndpoint.SMITE; _dataFormat = dataFormat ?? DataFormat.JSON; }