/// <summary> /// Recalculates the group lengths for all groups in the <paramref name="dataset"/>. Removes any group lengths for groups with out elements. /// </summary> /// <remarks>For most use cases, this method will be called by the library as needed and will not need to be called by the user.</remarks> /// <param name="dataset">DICOM dataset</param> /// <param name="createIfMissing">If set to <c>true</c>, group length elements will be created if missing. If set to <c>false</c>, only groups with existing group lengths will be recalculated.</param> public static void RecalculateGroupLengths(this DicomDataset dataset, bool createIfMissing = true) { // recalculate group lengths for sequences first foreach (var sq in dataset.Where(x => x.ValueRepresentation == DicomVR.SQ).Cast<DicomSequence>()) { foreach (var item in sq.Items) { item.RecalculateGroupLengths(createIfMissing); } } var calculator = new DicomWriteLengthCalculator(dataset.InternalTransferSyntax, DicomWriteOptions.Default); IEnumerable<ushort> groups = null; if (createIfMissing) groups = dataset.Select(x => x.Tag.Group).Distinct(); else groups = dataset.Where(x => x.Tag.Element == 0x0000).Select(x => x.Tag.Group); foreach (var group in groups.ToList()) { var items = dataset.EnumerateGroup(group).ToList(); if (items.Count == 0) { // no items exist for the specified group; remove dataset.Remove(new DicomTag(group, 0x0000)); return; } uint length = calculator.Calculate(items); dataset.AddOrUpdate(new DicomTag(group, 0x0000), length); } }
/// <summary> /// Recalculates the group length element for the specified group. Removes the group length element if no elements exist for the specified group. /// </summary> /// <remarks>For most use cases, this method will be called by the library as needed and will not need to be called by the user.</remarks> /// <param name="dataset">DICOM dataset</param> /// <param name="group">DICOM tag group</param> /// <param name="createIfMissing">If set to <c>true</c>, the group length element will be created if missing. If set to <c>false</c>, the group length will only be calculated if the group length element exists.</param> public static void RecalculateGroupLength(this DicomDataset dataset, ushort group, bool createIfMissing = true) { var items = dataset.EnumerateGroup(group).ToList(); if (items.Count == 0) { // no items exist for the specified group; remove dataset.Remove(new DicomTag(group, 0x0000)); return; } var calculator = new DicomWriteLengthCalculator(dataset.InternalTransferSyntax, DicomWriteOptions.Default); uint length = calculator.Calculate(items); dataset.AddOrUpdate(new DicomTag(group, 0x0000), length); }
public static Author AddSeed(this DbSet<Author> authors, BlogContext context, string name, string email, Action<Author> configItem = null) { var item = new Author { Name = name, Email = email }; if (configItem != null) { configItem(item); } authors.AddOrUpdate(x => x.Name, item); context.SaveChanges(); return authors.First(x => x.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)); }
internal static void CreateExecutionSteps(this _ExecutionStepFactory factory) { using (ILogMethod method = Log.LogMethod(DYN_MODULE_NAME, "CreateExecutionSteps")) { try { ExecutionStepDictionary execSteps = factory.ExecutionSteps; ExecutionStepDeviceTypes deviceType = ExecutionStepFactory.Current.DeviceType; IDictionary<string, ExecutionStepCollection> messageWiseSteps = factory.MessageWiseSteps; IDictionary<int, ExecutionStepCollection> groupedSteps = factory.GroupedSteps; var mappings = (from m in _mappings from j in m.Attributes where j.DeviceType == deviceType select m).ToArray(); foreach (var mapping in mappings)//.AsParallel()) { Type classType = mapping.Type; IExecutionStep step = factory.AddOrUpdate(classType, classType.Name); foreach (var mappingAttribute in mapping.Attributes .Where(d => d.DeviceType == deviceType)) { if (mappingAttribute.IsStart && (execSteps.Start == null)) execSteps.Start = step; if (mappingAttribute.IsEnd && (execSteps.End == null)) execSteps.End = step; step.PostTypeG2H = mappingAttribute.PostTypeG2H; step.PostTypeH2G = mappingAttribute.PostTypeH2G; step.MoveToNextStep = mappingAttribute.MoveToNextStep; //if (mappingAttribute.Dependencies != null) //{ // foreach (var dependency in mappingAttribute.Dependencies) // { // IExecutionStep parentStep = execSteps.AddOrUpdate(dependency, dependency.Name); // if (!parentStep.NextSteps.Contains(step)) // parentStep.NextSteps.Add(step); // } //} //if (mappingAttribute.NextDependency != null) //{ // var dependency = mappingAttribute.NextDependency; // IExecutionStep nextStep = execSteps.AddOrUpdate(dependency, dependency.Name); // if (!step.NextSteps.Contains(nextStep)) // step.NextSteps.Add(nextStep); // step.NextStep = nextStep; // step.SetNextStep = mappingAttribute.SetNextStep; // nextStep.PrevStep = step; //} if (mappingAttribute.NextSteps != null) { foreach (var dependency in mappingAttribute.NextSteps) { IExecutionStep nextStep = factory.AddOrUpdate(dependency, dependency.Name); //nextStep.Level = step.Level + 1; bool resetNextStep = false; if (!step.NextSteps.Contains(nextStep)) { step.NextSteps.Add(nextStep); resetNextStep = (step.NextSteps.Count > 1); } step.NextStep = (resetNextStep ? null : nextStep); if (!nextStep.PrevSteps.Contains(step)) { nextStep.PrevSteps.Add(step); } //step.SetNextStep = mappingAttribute.SetNextStep; //nextStep.PrevStep = step; } } if (messageWiseSteps != null && mappingAttribute.AllowedMessages != null) { var direction = mappingAttribute.AllowedMessageDirectionAll; int length = mappingAttribute.AllowedMessages.Length; for (int i = 0; i < mappingAttribute.AllowedMessages.Length; i++) { if (mappingAttribute.AllowedMessageDirections != null) { direction = mappingAttribute.AllowedMessageDirections[i]; } ExecutionStepKeyValue pair = new ExecutionStepKeyValue(mappingAttribute.AllowedMessages[i].Name, direction); string pairKey = pair.FullKey; if (!step.AllowedMessages.ContainsKey(pair)) { step.AllowedMessages.Add(pair, 1); } ExecutionStepCollection execSteps2 = null; if (messageWiseSteps.ContainsKey(pairKey)) { execSteps2 = messageWiseSteps[pairKey]; } else { messageWiseSteps.Add(pairKey, (execSteps2 = new ExecutionStepCollection())); } execSteps2.Add(step); } if (mappingAttribute.AllowedReplyMessages != null && mappingAttribute.AllowedReplyMessages.Length == length) { for (int j = 0; j < length; j++) { Type type1 = mappingAttribute.AllowedMessages[j]; Type type2 = mappingAttribute.AllowedReplyMessages[j]; if (type1 != null && type2 != null) { factory.RequestResponseMappings.Add(type1.Name, type2.Name, new RequestResponseMapItem()); } } } } } } // execution step grouping if (messageWiseSteps != null && groupedSteps != null) { execSteps.ArrangeExecutionSteps(messageWiseSteps, groupedSteps); } } catch (Exception ex) { method.Exception(ex); } } }
// Adds to or update an entry in Objects dictionary for SMSG_CHAR_ENUM player data public static void AddOrUpdate(this ConcurrentDictionary<Guid, WoWObject> dict, Guid guid, Player playerInfo) { dict.AddOrUpdate(guid, playerInfo, (guid1, wowObject) => Player.UpdatePlayerInfo((Player)wowObject, playerInfo)); }