public UnknownFeatureIonInstanceSpectrumChartDataProvider(IEntityDataService entityDataService, IEnumerable <EntityItemData> entityItemData) { ArgumentHelper.AssertNotNull(entityItemData, "entityItemData"); m_entityDataService = entityDataService; var entityReader = entityDataService.CreateEntityItemReader(); var compoundIonInstanceItem = entityReader.Read <UnknownFeatureIonInstanceItem>(entityItemData.First().GetEntityIds()); // make spectrum header m_extraHeaderLine = String.Format( "Ion: {0}, m/z: {1:F5}, Area: {2:F0}", compoundIonInstanceItem.IonDescription, compoundIonInstanceItem.Mass, compoundIonInstanceItem.Area); // set ion m_unknownFeatureIonInstanceItems = new[] { compoundIonInstanceItem }; // get reader entityReader = entityDataService.CreateEntityItemReader(); m_fileNames = entityReader.ReadAll <WorkflowInputFile>().ToDictionary(file => file.FileID, file => Path.GetFileNameWithoutExtension(file.FileName)); // load related chromatographic peak items var peakItems = entityReader.ReadFlat <UnknownFeatureIonInstanceItem, ChromatogramPeakItem>(compoundIonInstanceItem).Item2; m_chromatogramPeakItemsMap = new Dictionary <object[], IList <ChromatogramPeakItem> >(IdArrayComparer.Instance) { { compoundIonInstanceItem.GetIDs(), peakItems } }; // load related spectrum tree SpectralTreeNodes = LoadSpectralTree(); }
public EventDispatcher(Type serviceType, Type baseType) { ArgumentHelper.AssertNotNull <Type>(serviceType, "service"); ArgumentHelper.AssertNotNull <Type>(baseType, "baseType"); subject = EventSubject.GetObject(baseType, serviceType); }
/// <summary> /// One of the connected nodes sent all of its data. /// </summary> public override void OnParentNodeFinished(IProcessingNode sender, ResultsArguments eventArgs) { ArgumentHelper.AssertNotNull(eventArgs, "eventArgs"); try { SendAndLogTemporaryMessage("⇒ {0} started...", DisplayName); var timer = Stopwatch.StartNew(); // generate expected lipids var lipids = GenerateLipids(); // send lipids to child nodes SendResults(lipids); timer.Stop(); SendAndLogMessage("✓ {0} finished after {1}.", DisplayName, StringHelper.GetDisplayString(timer.Elapsed)); } catch (Exception ex) { SendAndLogErrorMessage("Error: " + ex.Message); throw; } // inform child nodes that processing has finished FireProcessingFinishedEvent(new ResultsArguments(LipidSearchDataTypes.LipidCompounds)); }
public async Task SetMetadata(ImageMetadata metadata, CancellationToken cancellationToken) { ArgumentHelper.AssertNotNull(nameof(metadata), metadata); ArgumentHelper.AssertNotNullOrEmpty(nameof(metadata.Id), metadata.Id); ArgumentHelper.AssertNotNullOrEmpty(nameof(metadata.PartitionKey), metadata.PartitionKey); ArgumentHelper.AssertNotNullOrEmpty(nameof(metadata.MimeType), metadata.MimeType); ArgumentHelper.AssertNotNullOrEmpty(nameof(metadata.MD5Hash), metadata.MD5Hash); if (metadata.SizeBytes <= 0) { throw new ArgumentOutOfRangeException(nameof(metadata.SizeBytes)); } if (metadata.Width <= 0) { throw new ArgumentOutOfRangeException(nameof(metadata.Width)); } if (metadata.Height <= 0) { throw new ArgumentOutOfRangeException(nameof(metadata.Height)); } var container = await GetContainer(); await container.UpsertItemAsync(metadata, new PartitionKey(metadata.PartitionKey), cancellationToken : cancellationToken) .ConfigureAwait(false); }
/// <summary> /// 获取指定路径的节点的值 /// </summary> /// <param name="path">路径名称</param> /// <returns>如果存在的话返回指定路径节点下的值,否则返回空字符串</returns> public string GetItemValue(string path) { ArgumentHelper.AssertNotNull <string>(path, "path"); path = EncodePath(path); XmlNode node = xml.SelectSingleNode(RootPath + path); return(node == null ? string.Empty : node.InnerText); }
public int Add(TemplateMappingInfo info) { ArgumentHelper.AssertNotNull(info, "TemplateMappingInfo is null"); ArgumentHelper.AssertNotNullOrEmpty(info.AppId, "TemplateMappingInfo.appId is null"); ArgumentHelper.AssertNotNullOrEmpty(info.TemplateIdShort, "TemplateMappingInfo.TemplateIdShort is null"); ArgumentHelper.AssertNotNullOrEmpty(info.TemplateId, "TemplateMappingInfo.TemplateId is null"); return(TemplateMappingDao.Insert(info)); }
/// <summary> /// Sums the intensity of trace points, if the <see cref="TracePoint.SpectrumID"/> is the same. /// This method can be used to sum traces having the same raster. /// </summary> /// <param name="items">An enumeration of trace points.</param> public static IEnumerable <TracePoint> SumPoints(this IEnumerable <TracePoint> items) { // ReSharper disable PossibleMultipleEnumeration ArgumentHelper.AssertNotNull(items, "items"); return(items .GroupBy(g => g.SpectrumID) .Select(s => new TracePoint(s.Key, s.First().Time, s.Sum(sum => sum.Intensity), s.Max(m => m.MaxNoise)))); // ReSharper restore PossibleMultipleEnumeration }
public void assert_not_null_does_not_throw_if_enumerable_contains_null_but_checking_for_null_items_is_disabled() { var list = new List <string> { string.Empty, null }; ArgumentHelper.AssertNotNull(list, "test", false); }
/// <summary> /// 获取指定路径、指定节点名称的节点 /// </summary> /// <param name="path">路径名称</param> /// <param name="item">属性名称</param> /// <returns>如果存在的话返回指定路径下的节点,否则返回null</returns> public XmlNode GetItem(string path, KeyValuePair <string, string> item) { ArgumentHelper.AssertNotNull <string>(path, "path"); ArgumentHelper.AssertNotNull <string>(item.Key, "item.Key"); ArgumentHelper.AssertNotNull <string>(item.Value, "item.Value"); path = EncodePath(path); XmlNode node = xml.SelectSingleNode(RootPath + path); return(node == null ? null : node.SelectSingleNode("[" + item.Key + "='" + item.Value + "']")); }
/// <summary> /// 增加绑定批次 /// </summary> /// <param name="tenantId"></param> /// <param name="info"></param> /// <returns></returns> public int Add(int tenantId, BindBatchInfo info) { ArgumentHelper.AssertIsTrue(tenantId > 0, "tenantId is 0"); ArgumentHelper.AssertNotNull(info, "info is null"); ArgumentHelper.AssertIsTrue(info.TenantId > 0, "info.TenantId is 0"); ArgumentHelper.AssertIsTrue(info.AppUserAccountId > 0, "info.AppUserAccountId is 0"); ArgumentHelper.AssertNotNullOrEmpty(info.BeisenAccount, "info.BeisenAccount is null"); return(BindBatchDao.Insert(tenantId, info)); }
/// <summary> /// 判断路径是否存在 /// </summary> /// <param name="path">路径名称</param> /// <returns>如果存在的话返回true,否则返回false</returns> public bool Exists(string path) { ArgumentHelper.AssertNotNull <string>(path, "path"); path = path.Trim(); string nodepath = EncodePath(path); XmlNode node = xml.SelectSingleNode(RootPath + nodepath); return(node != null); }
public ImageBlobAzureStorage(ImageAzureStorageConfiguration configuration) { ArgumentHelper.AssertNotNull(nameof(configuration), configuration); var storageAccount = CloudStorageAccount.Parse(configuration.ConnectionString); _cloudBlobClient = storageAccount.CreateCloudBlobClient(); _imagesContainer = new Lazy <CloudBlobContainer>(() => CreateCloudBlobContainer(configuration.ImagesContainerName.ToLowerInvariant())); _thumbnailsContainer = new Lazy <CloudBlobContainer>(() => CreateCloudBlobContainer(configuration.ThumbnailsContainerName.ToLowerInvariant())); }
public ImageResizingResult Resize(Stream imageStream, ImageType imageType, int targetWidth) { ArgumentHelper.AssertNotNull(nameof(imageStream), imageStream); imageStream.Position = 0; IImageFormat imageFormat = PngFormat.Instance; switch (imageType) { case ImageType.PNG: imageFormat = PngFormat.Instance; break; case ImageType.JPEG: imageFormat = JpegFormat.Instance; break; case ImageType.BMP: imageFormat = BmpFormat.Instance; break; case ImageType.GIF: imageFormat = GifFormat.Instance; break; } using var image = Image.Load(imageStream); decimal divisor = (decimal)image.Width / targetWidth; var targetHeight = Convert.ToInt32(Math.Round(image.Height / divisor)); image.Mutate(x => x .Resize(new ResizeOptions { Size = new Size(targetWidth, targetHeight), Mode = ResizeMode.Max })); MemoryStream resultStream = new MemoryStream(); image.Save(resultStream, imageFormat); return(new ImageResizingResult { Image = resultStream, Size = new ImageSize { Bytes = resultStream.Length, Width = image.Width, Height = image.Height } }); }
/// <summary> /// 获取指定节点名称的路径信息 /// </summary> /// <param name="item">节点名称</param> /// <returns>如果找到节点返回节点的路径,否则返回null</returns> public string SearchNode(string item) { ArgumentHelper.AssertNotNull <string>(item, "item"); item = EncodeNodeName(item.Trim()); XmlNode node = xml.SelectSingleNode("//" + item); if (node == null) { return(null); } return(GetXPath(node)); }
/// <summary> /// 获取指定路径下所有的子节点 /// </summary> /// <param name="path">路径名称</param> /// <returns>如果存在的话返回指定路径下的所有节点列表,否则返回null</returns> public XmlNodeList GetChildren(string path) { ArgumentHelper.AssertNotNull <string>(path, "path"); path = EncodePath(path); XmlNode node = xml.SelectSingleNode(RootPath + path); if (node == null) { return(null); } return(node.SelectNodes("*")); }
/// <summary> /// 增加用户账户 /// </summary> /// <param name="tenantId"></param> /// <param name="appUserAccountInfo"></param> public int AddOrUpdate(int tenantId, AppUserAccountInfo appUserAccountInfo) { ArgumentHelper.AssertIsTrue(tenantId > 0, "tenantId is 0"); ArgumentHelper.AssertNotNull(appUserAccountInfo, "appUserAccountInfo is null"); ArgumentHelper.AssertNotNullOrEmpty(appUserAccountInfo.AppId, "appUserAccountInfo.appId is null"); ArgumentHelper.AssertNotNullOrEmpty(appUserAccountInfo.OpenId, "appUserAccountInfo.openId is null"); ArgumentHelper.AssertIsTrue(appUserAccountInfo.TenantId > 0, "appUserAccountInfo.TenantId is 0"); ArgumentHelper.AssertIsTrue(appUserAccountInfo.UserId > 0, "appUserAccountInfo.UserId is 0"); var sqlId = AppUserAccountDao.InsertOrUpdate(tenantId, appUserAccountInfo); AppUserAccountDao.AddOrUpdateCLoud(tenantId, sqlId, appUserAccountInfo); return(sqlId); }
public static string LowerCaseFirstLetter(this string input) { ArgumentHelper.AssertNotNull(input, nameof(input)); if (input.Length == 0) { return(input); } var arr = input.ToCharArray(); arr[0] = char.ToLowerInvariant(arr[0]); return(new string(arr)); }
private string GetDingTalkPCUrl(int tenantId, string appaccount_id, string app_id, string return_url) { ArgumentHelper.AssertPositive(tenantId, "GetDingTalkPCUrl tenantId is not positive"); ArgumentHelper.AssertNotNull(appaccount_id, "GetDingTalkPCUrl appaccount_id is null"); ArgumentHelper.AssertNotNull(app_id, "GetDingTalkPCUrl app_id is null"); if (string.IsNullOrEmpty(return_url)) { return(null); } var encodeRedirectUrl = HttpUtility.UrlEncode(string.Format("{0}?return_url={1}", AppConnectHostConfig.Cache[2], HttpUtility.UrlEncode(return_url))); string redirectUrl = string.Format("{0}/user/authorizeformsg?tenant_id={1}&appaccount_id={2}&app_id={3}&login_type=0&redirect_url={4}", AppConnectHostConfig.Cache[0], tenantId, appaccount_id, app_id, encodeRedirectUrl); AppConnectLogHelper.DebugFormat("PC端拼接后详情页RedirectUrl:{0}", redirectUrl); return(redirectUrl); }
public override SpectrumChartData CreateSpectrumDetails(MassSpectrumItem massSpectrumItem, MassSpectrum referenceSpectrum = null) { ArgumentHelper.AssertNotNull(massSpectrumItem, "massSpectrumItem"); // clone given spectrum var spectrum = massSpectrumItem.Spectrum.Clone(); if (spectrum == null) { return(null); } //// get ions for respective polarity //var ions = spectrum.ScanEvent.Polarity == PolarityType.Negative // ? m_unknownFeatureIonInstanceItems.Where(w => w.Charge < 0) // : m_unknownFeatureIonInstanceItems.Where(w => w.Charge > 0); // annotate nearest centroids foreach (var ion in m_unknownFeatureIonInstanceItems) { // annotate isotopes foreach (var peak in m_chromatogramPeakItemsMap[ion.GetIDs()]) { var centroid = spectrum.PeakCentroids.FindClosestPeak(peak.Mass); if (centroid != null) { centroid.DisplayPriority = 2; } } } // create spectrum chart data var massRange = Range.Create(spectrum.Header.LowPosition, spectrum.Header.HighPosition); if (spectrum.ScanEvent.MSOrder == MSOrderType.MS1) { var peaks = m_chromatogramPeakItemsMap.SelectMany(s => s.Value).ToList(); massRange = Range.Create(Math.Max(0, peaks.Min(m => m.Mass)) - 4, peaks.Max(m => m.Mass) + 5); } return(new SpectrumChartData { MassRange = massRange, SpectrumDistanceDetails = null, Spectrum = spectrum, SpectrumHeaderText = CreateSpectrumChartHeader(spectrum, m_extraHeaderLine, m_fileNames[spectrum.Header.FileID]) }); }
/// <summary> /// 检查指定路径下是否含有子节点 /// </summary> /// <param name="path">路径名称</param> /// <returns>如果存在的话返回true,否则返回false</returns> public bool HasChildren(string path) { ArgumentHelper.AssertNotNull <string>(path, "path"); path = path.Trim(); string nodepath = EncodePath(path); XmlNode node = xml.SelectSingleNode(RootPath + nodepath); if (node == null) { throw new ArgumentException("无法在配置树中找到节点" + path, "path"); } XmlNodeList subItems = node.SelectNodes("*"); return(subItems.Count > 0); }
public static bool TryRead <T>(XmlNode parentNode, string attributeName, Converter <string, T> converter, ref T value) { ArgumentHelper.AssertNotNull <XmlNode>(parentNode, "parentNode"); ArgumentHelper.AssertNotEmpty(attributeName, "attributeName"); ArgumentHelper.AssertNotNull <Converter <string, T> >(converter, "converter"); XmlAttribute attr = parentNode.Attributes[attributeName]; if (null == attr) { return(false); } else { value = converter(attr.Value); return(true); } }
/// <summary> /// 检查指定路径的节点是否存在 /// </summary> /// <param name="path">路径名称</param> /// <param name="item">节点名称</param> /// <returns>如果存在的话返回true,否则返回false</returns> public bool Exists(string path, string item) { ArgumentHelper.AssertNotNull <string>(path, "path"); path = path.Trim(); string nodepath = EncodePath(path); ArgumentHelper.AssertNotNull <string>(item, "item"); item = item.Trim(); XmlNode node = xml.SelectSingleNode(RootPath + nodepath); if (node == null) { return(false); } XmlNode subItem = node.SelectSingleNode("*[name()='" + item + "']"); return(subItem != null); }
public ImageSize ReadSize(Stream imageStream) { ArgumentHelper.AssertNotNull(nameof(imageStream), imageStream); imageStream.Position = 0; var identify = Image.Identify(imageStream); if (identify == null) { return(null); } return(new ImageSize { Bytes = imageStream.Length, Width = identify.Width, Height = identify.Height }); }
public async Task <UploadImageResult> UploadImage(string imageName, Stream imageStream, ImageSizeType imageSizeType, string imageContentType, CancellationToken cancellationToken) { ArgumentHelper.AssertNotNullOrEmpty(nameof(imageName), imageName); ArgumentHelper.AssertNotNull(nameof(imageStream), imageStream); var blockBlob = GetBlockBlob(imageName, imageSizeType); blockBlob.Properties.ContentType = imageContentType; imageStream.Position = 0; await blockBlob.UploadFromStreamAsync(imageStream, cancellationToken).ConfigureAwait(false); return(new UploadImageResult { MD5Hash = blockBlob.Properties.ContentMD5, DateAdded = blockBlob.Properties.Created ?? DateTimeOffset.Now, Url = blockBlob.Uri }); }
public void assert_not_null_throws_if_enumerable_contains_null_and_checking_for_null_items_is_enabled() { var listOfClassType = new List <string> { string.Empty, null }; var ex = Assert.Throws <ArgumentException>(() => ArgumentHelper.AssertNotNull(listOfClassType, "test", true)); Assert.Equal("An item inside the enumeration was null." + Environment.NewLine + "Parameter name: test", ex.Message); var listOfInterfaceType = new List <IDisposable> { new StringReader(""), null }; ex = Assert.Throws <ArgumentException>(() => ArgumentHelper.AssertNotNull(listOfInterfaceType, "test", true)); Assert.Equal("An item inside the enumeration was null." + Environment.NewLine + "Parameter name: test", ex.Message); }
/// <summary> /// 获取指定路径的节点的属性信息 /// </summary> /// <param name="path">路径名称</param> /// <param name="attribute">属性名称</param> /// <returns>如果存在的话返回指定属性的值,否则返回空字符串</returns> public string GetItemAttribute(string path, string attribute) { ArgumentHelper.AssertNotNull <string>(path, "path"); ArgumentHelper.AssertNotNull <string>(attribute, "attribute"); path = EncodePath(path); XmlNode node = xml.SelectSingleNode(RootPath + path); if (node == null) { return(string.Empty); } for (int i = 0; i < node.Attributes.Count; i++) { if (node.Attributes.Item(i).Name.ToLower() == attribute.ToLower()) { return(node.Attributes.Item(i).Value); } } return(string.Empty); }
private static void SendMessage(int tenantId, AddMessageModel model) { ArgumentHelper.AssertNotNull(model); ArgumentHelper.AssertPositive(tenantId); ArgumentHelper.AssertPositive(model.FromUserId); string url = string.Format(TitaApiUrl + "/api/v1/{0}/{1}/message", tenantId, model.FromUserId); try { var resultStr = HttpClientHelper.HttpPost(url, model); var result = JsonConvert.DeserializeObject <ApiResult <object> >(resultStr); if (result.code != 0) { AppConnectLogHelper.ErrorFormat("Tita发送消息接口出错!租户:{0},发送人:{1}", tenantId, model.FromUserId); } } catch (Exception ex) { AppConnectLogHelper.ErrorFormat("发送消息出错!接口Url:{0},租户:{1},发送人:{2},异常信息:{3}", url, tenantId, model.FromUserId, JsonConvert.SerializeObject(ex)); } }
/* * Using of partitions make search requests more efficient * https://docs.microsoft.com/en-us/azure/cosmos-db/partitioning-overview */ public async Task <List <ImageMetadata> > GetMetadata(ICollection <string> imageIds, string partitionKey, CancellationToken cancellationToken) { ArgumentHelper.AssertNotNull(nameof(imageIds), imageIds); if (imageIds.Count < 1) { throw new ArgumentException("Please provide at least one image id"); } var container = await GetContainer(); QueryRequestOptions queryRequestOptions = null; if (!string.IsNullOrEmpty(partitionKey)) { queryRequestOptions = new QueryRequestOptions { PartitionKey = new PartitionKey(partitionKey) } } ; var queryIterator = container .GetItemLinqQueryable <ImageMetadata>(requestOptions: queryRequestOptions) .Where(x => imageIds.Contains(x.Id)) .ToFeedIterator(); List <ImageMetadata> result = new List <ImageMetadata>(); while (queryIterator.HasMoreResults) { FeedResponse <ImageMetadata> response = await queryIterator.ReadNextAsync(cancellationToken); result.AddRange(response); } return(result); }
public ImageFormat DetectFormat(Stream imageStream) { ArgumentHelper.AssertNotNull(nameof(imageStream), imageStream); imageStream.Position = 0; var imageFormat = Image.DetectFormat(imageStream); if (imageFormat == null) { return(null); } ImageType imageType; if (imageFormat is PngFormat) { imageType = ImageType.PNG; } else if (imageFormat is JpegFormat) { imageType = ImageType.JPEG; } else if (imageFormat is GifFormat) { imageType = ImageType.GIF; } else if (imageFormat is BmpFormat) { imageType = ImageType.BMP; } else { throw new NotSupportedException($"Image format {imageFormat.Name} is not supported"); } return(new ImageFormat(imageFormat.DefaultMimeType, imageFormat.FileExtensions.First(), imageType)); }
public static T Read <T>(XmlNode parentNode, string attributeName, Converter <string, T> converter, T defaultValue, bool throwExceptionIfMissing) { ArgumentHelper.AssertNotNull <XmlNode>(parentNode, "parentNode"); ArgumentHelper.AssertNotEmpty(attributeName, "attributeName"); ArgumentHelper.AssertNotNull <Converter <string, T> >(converter, "converter"); XmlAttribute attr = parentNode.Attributes[attributeName]; if (null == attr) { if (throwExceptionIfMissing) { throw new ConfigurationErrorsException("Missing @" + attributeName + " attribute. This value should is required.", parentNode); } else { return(defaultValue); } } else { return(converter(attr.Value)); } }