protected override void WriteSelfStart(System.IO.TextWriter writer, IBootstrapContext context) { var tb = context.CreateTagBuilder("div"); tb.AddCssClass("btn-group"); tb.AddCssClass(SizeValue.ToButtonGroupCssClass()); if (VerticalValue) { tb.AddCssClass("btn-group-vertical"); } if (JustifiedValue) { tb.AddCssClass("btn-group-justified"); } if (DropUpValue) { tb.AddCssClass("dropup"); } tb.MergeAttribute("role", "group"); ApplyCss(tb); ApplyAttributes(tb); tb.WriteStartTag(writer); context.Push(this); if (content != null) { content.WriteTo(writer, context); } }
private void sizeValueToolStripMenuItem_Click(object sender, EventArgs e) { SizeValue newsv = (SizeValue)((ToolStripMenuItem)sender).Tag; sizeValue = newsv; foreach (ToolStripMenuItem mi in sizeValueMenuItems) { mi.Checked = mi == sender; } UpdateNumbers(tree.Nodes[0], true); }
public IActionResult Update([FromBody] SizeValue obj) { try { return(Ok(_logic.Update(obj))); } catch (Exception e) { return(BadRequest(e.Message)); } }
protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context) { var tb = context.CreateTagBuilder("div"); tb.AddCssClass(SizeValue.ToCssClass()); tb.AddCssClass(OffsetValue.ToOffsetCssClass()); ApplyCss(tb); ApplyAttributes(tb); tb.WriteStartTag(writer); return(tb.GetEndTag()); }
public JsonResult SaveSizeValue(SizeValueViewModel model) { Response response; try { using (var db = new KiaGalleryContext()) { if (model.id != null && model.id > 0) { var entity = db.SizeValue.Find(model.id); entity.SizeId = model.sizeId; entity.Order = model.order; entity.Value = model.value; entity.ModifyUserId = GetAuthenticatedUserId(); entity.ModifyDate = DateTime.Now; entity.Ip = Request.UserHostAddress; } else { var item = new SizeValue() { SizeId = model.sizeId, Order = model.order, Value = model.value, CreateUserId = GetAuthenticatedUserId(), ModifyUserId = GetAuthenticatedUserId(), CreateDate = DateTime.Now, ModifyDate = DateTime.Now, Ip = Request.UserHostAddress }; db.SizeValue.Add(item); } response = new Response() { status = 200, message = "اطلاعات با موفقیت ثبت شد." }; db.SaveChanges(); } } catch (Exception ex) { response = Core.GetExceptionResponse(ex); } return(Json(response, JsonRequestBehavior.AllowGet)); }
protected override string WriteSelfStartTag(System.IO.TextWriter writer, IBootstrapContext context) { var bg = context.PeekNearest <ButtonGroup>(); if (bg == null) { WriteWhitespaceSuffix = true; } else { SizeValue = bg.SizeValue; } var withHref = !string.IsNullOrEmpty(HrefValue); var tb = context.CreateTagBuilder(withHref ? "a" : "button"); tb.AddCssClass(TypeValue.ToCssClass()); tb.AddCssClass(SizeValue.ToButtonCssClass()); if (DisabledValue) { tb.AddCssClass("disabled"); } if (BlockSizeValue) { tb.AddCssClass("btn-block"); } if (withHref) { tb.MergeAttribute("href", HrefValue); } ApplyCss(tb); ApplyAttributes(tb); tb.WriteStartTag(writer); return(withHref ? "</a>" : "</button>"); }
public string GetValue(Summary summary, BenchmarkCase benchmarkCase, SummaryStyle style) { System.Reflection.MethodInfo mi = benchmarkCase.Descriptor.WorkloadMethod; if (!mi.Name.Contains("Serialize")) { return("-"); } var instance = Activator.CreateInstance(mi.DeclaringType); mi.DeclaringType.GetField("Serializer").SetValue(instance, benchmarkCase.Parameters[0].Value); mi.DeclaringType.GetMethod("Setup").Invoke(instance, null); var bytes = (byte[])mi.Invoke(instance, null); var byteSize = bytes.Length; var cultureInfo = summary.GetCultureInfo(); if (style.PrintUnitsInContent) { return(SizeValue.FromBytes(byteSize).ToString(style.SizeUnit, cultureInfo)); } return(byteSize.ToString("0.##", cultureInfo)); }
//Code is inspired by https://github.com/Microsoft/perfview/blob/master/src/PerfView/PerfViewData.cs#L5719-L5944 public IEnumerable <Metric> Parse() { using (var traceLog = new TraceLog(TraceLog.CreateFromEventTraceLogFile(etlFilePath))) { var eventSource = traceLog.Events.GetSource(); var bdnEventsParser = new EngineEventLogParser(eventSource); var start = false; var isFirstActualStartEnd = false; long totalOperation = 0; long countOfAllocatedObject = 0; bdnEventsParser.WorkloadActualStart += data => { if (!isFirstActualStartEnd) { start = true; } totalOperation = data.TotalOperations; }; bdnEventsParser.WorkloadActualStop += data => { start = false; isFirstActualStartEnd = true; }; var heapParser = new HeapTraceProviderTraceEventParser(eventSource); // We index by heap address and then within the heap we remember the allocation stack var heaps = new Dictionary <Address, Dictionary <Address, long> >(); Dictionary <Address, long> lastHeapAllocs = null; Address lastHeapHandle = 0; long nativeLeakSize = 0; long totalAllocation = 0; heapParser.HeapTraceAlloc += delegate(HeapAllocTraceData data) { if (!start) { return; } var allocs = lastHeapAllocs; if (data.HeapHandle != lastHeapHandle) { allocs = CreateHeapCache(data.HeapHandle, heaps, ref lastHeapAllocs, ref lastHeapHandle); } allocs[data.AllocAddress] = data.AllocSize; checked { countOfAllocatedObject++; nativeLeakSize += data.AllocSize; totalAllocation += data.AllocSize; } }; heapParser.HeapTraceFree += delegate(HeapFreeTraceData data) { if (!start) { return; } var allocs = lastHeapAllocs; if (data.HeapHandle != lastHeapHandle) { allocs = CreateHeapCache(data.HeapHandle, heaps, ref lastHeapAllocs, ref lastHeapHandle); } if (allocs.TryGetValue(data.FreeAddress, out long alloc)) { nativeLeakSize -= alloc; allocs.Remove(data.FreeAddress); } }; heapParser.HeapTraceReAlloc += delegate(HeapReallocTraceData data) { if (!start) { return; } // Reallocs that actually move stuff will cause a Alloc and delete event // so there is nothing to do for those events. But when the address is // the same we need to resize. if (data.OldAllocAddress != data.NewAllocAddress) { return; } var allocs = lastHeapAllocs; if (data.HeapHandle != lastHeapHandle) { allocs = CreateHeapCache(data.HeapHandle, heaps, ref lastHeapAllocs, ref lastHeapHandle); } // This is a clone of the Free code if (allocs.TryGetValue(data.OldAllocAddress, out long alloc)) { nativeLeakSize -= alloc; allocs.Remove(data.OldAllocAddress); } // This is a clone of the Alloc code (sigh don't clone code) allocs[data.NewAllocAddress] = data.NewAllocSize; checked { nativeLeakSize += data.NewAllocSize; } }; heapParser.HeapTraceDestroy += delegate(HeapTraceData data) { if (!start) { return; } // Heap is dieing, kill all objects in it. var allocs = lastHeapAllocs; if (data.HeapHandle != lastHeapHandle) { allocs = CreateHeapCache(data.HeapHandle, heaps, ref lastHeapAllocs, ref lastHeapHandle); } foreach (var alloc in allocs.Values) { nativeLeakSize -= alloc; } }; eventSource.Process(); logger.WriteLine(); logger.WriteLineHeader(LogSeparator); logger.WriteLineInfo($"{benchmarkCase.DisplayInfo}"); logger.WriteLineHeader(LogSeparator); if (totalOperation == 0) { logger.WriteLine($"Something went wrong. The trace file {etlFilePath} does not contain BenchmarkDotNet engine events."); yield break; } var memoryAllocatedPerOperation = totalAllocation / totalOperation; var memoryLeakPerOperation = nativeLeakSize / totalOperation; logger.WriteLine($"Native memory allocated per single operation: {SizeValue.FromBytes(memoryAllocatedPerOperation).ToString(SizeUnit.B, benchmarkCase.Config.CultureInfo)}"); logger.WriteLine($"Count of allocated object: {countOfAllocatedObject / totalOperation}"); if (nativeLeakSize != 0) { logger.WriteLine($"Native memory leak per single operation: {SizeValue.FromBytes(memoryLeakPerOperation).ToString(SizeUnit.B, benchmarkCase.Config.CultureInfo)}"); } var heapInfoList = heaps.Select(h => new { Address = h.Key, h.Value.Count, types = h.Value.Values }); foreach (var item in heapInfoList.Where(p => p.Count > 0)) { logger.WriteLine($"Count of not deallocated object: {item.Count / totalOperation}"); } yield return(new Metric(new AllocatedNativeMemoryDescriptor(), memoryAllocatedPerOperation)); yield return(new Metric(new NativeMemoryLeakDescriptor(), memoryLeakPerOperation)); } }
protected override void WriteSelf(System.IO.TextWriter writer, IBootstrapContext context) { var form = context.PeekNearest <IFormContext>(); var formGroup = context.PeekNearest <FormGroup>(); if (formGroup != null && ControlContextValue == null) { ControlContextValue = formGroup.ControlContextValue; } ITagBuilder div = null; if (!SizeValue.IsEmpty()) { // Inline forms does not support sized controls (we need 'some other' sizing rules?) if (form != null && form.TypeValue != FormType.Inline) { if (formGroup != null && formGroup.WithSizedControlValue) { div = context.CreateTagBuilder("div"); div.AddCssClass(SizeValue.ToCssClass()); writer.Write(div.GetStartTag()); } else { throw new InvalidOperationException("Size not allowed - call WithSizedControls() on FormGroup."); } } } var input = context.CreateTagBuilder("input"); input.AddCssClass("form-control"); var actualType = TypeValue; if (actualType != InputType.File && ControlContextValue != null) { input.MergeAttribute("id", ControlContextValue.Name); input.MergeAttribute("name", ControlContextValue.Name); if (ControlContextValue.IsRequired) { input.MergeAttribute("required", "required"); } var value = ControlContextValue.Value; if (value != null) { var valueString = value.ToString(); if (TypeValue == InputType.Date || TypeValue == InputType.Datetime || TypeValue == InputType.DatetimeLocal || TypeValue == InputType.Time) { var valueDateTime = value as DateTime?; var valueDateTimeOffset = value as DateTimeOffset?; var valueTimeSpan = value as TimeSpan?; if (valueDateTimeOffset.HasValue) { valueDateTime = valueDateTimeOffset.Value.DateTime; } if (valueDateTime.HasValue) { valueTimeSpan = valueDateTime.Value.TimeOfDay; } var asHtml5 = (DateInputMode == BootstrapMvc.DateInputMode.Html5); if (!asHtml5) { actualType = InputType.Text; } switch (TypeValue) { case InputType.Date: if (valueDateTime.HasValue) { valueString = asHtml5 ? valueDateTime.Value.ToString("yyyy-MM-dd") : valueDateTime.Value.ToString("d"); } break; case InputType.DatetimeLocal: if (valueDateTime.HasValue) { valueString = asHtml5 ? valueDateTime.Value.ToString("o") : valueDateTime.Value.ToString(); } break; case InputType.Datetime: if (valueDateTime.HasValue) { valueString = asHtml5 ? valueDateTimeOffset.Value.ToString("o") : valueDateTimeOffset.Value.ToString(); } break; case InputType.Time: if (valueDateTime.HasValue) { valueString = valueTimeSpan.ToString(); } break; } } input.MergeAttribute("value", valueString); } } if (actualType != InputType.Text) { input.MergeAttribute("type", actualType.ToType()); } if (DisabledValue) { input.MergeAttribute("disabled", "disabled"); } ApplyCss(input); ApplyAttributes(input); ////input.MergeAttributes(helper.HtmlHelper.GetUnobtrusiveValidationAttributes(context.ExpressionText, context.Metadata)); writer.Write(input.GetFullTag()); if (div != null) { writer.Write(div.GetEndTag()); } }
public bool Update(SizeValue obj) { return(_unitOfWork.ISizeValue.Update(obj)); }
public int Insert(SizeValue obj) { return(_unitOfWork.ISizeValue.Insert(obj)); }
public void SizeUnitFormattingTest(string expected, long bytes) { Assert.Equal(expected, SizeValue.FromBytes(bytes).ToString(TestCultureInfo.Instance)); }
protected override void WriteSelfStart(System.IO.TextWriter writer, IBootstrapContext context) { var form = context.PeekNearest <IFormContext>(); var formGroup = context.PeekNearest <FormGroup>(); if (ControlContextValue == null) { ControlContextValue = formGroup.ControlContextValue; } ITagBuilder div = null; if (!SizeValue.IsEmpty()) { // Inline forms does not support sized controls (we need 'some other' sizing rules?) if (form != null && form.TypeValue != FormType.Inline) { if (formGroup != null && formGroup.WithSizedControlValue) { div = context.CreateTagBuilder("div"); div.AddCssClass(SizeValue.ToCssClass()); writer.Write(div.GetStartTag()); } else { throw new InvalidOperationException("Size not allowed - call WithSizedControls() on FormGroup."); } } } object value = null; var tb = context.CreateTagBuilder("select"); tb.AddCssClass("form-control"); if (ControlContextValue != null) { tb.MergeAttribute("id", ControlContextValue.Name); tb.MergeAttribute("name", ControlContextValue.Name); if (ControlContextValue.IsRequired) { tb.MergeAttribute("required", "required"); } value = ControlContextValue.Value; } if (DisabledValue) { tb.MergeAttribute("disabled", "disabled"); } ApplyCss(tb); ApplyAttributes(tb); writer.Write(tb.GetStartTag()); context.Push(this); if (ItemsValue != null) { foreach (var item in ItemsValue) { item.WriteTo(writer, context); } } endTag = tb.GetEndTag() + (div == null ? string.Empty : div.GetEndTag()); }
protected override void WriteSelf(System.IO.TextWriter writer, IBootstrapContext context) { var form = context.PeekNearest <IFormContext>(); var formGroup = context.PeekNearest <FormGroup>(); if (formGroup != null && ControlContextValue == null) { ControlContextValue = formGroup.ControlContextValue; } ITagBuilder div = null; if (!SizeValue.IsEmpty()) { // Inline forms does not support sized controls (we need 'some other' sizing rules?) if (form != null && form.TypeValue != FormType.Inline) { if (formGroup != null && formGroup.WithSizedControlValue) { div = context.CreateTagBuilder("div"); div.AddCssClass(SizeValue.ToCssClass()); writer.Write(div.GetStartTag()); } else { throw new InvalidOperationException("Size not allowed - call WithSizedControls() on FormGroup."); } } } var tb = context.CreateTagBuilder("textarea"); tb.AddCssClass("form-control"); if (RowsValue != 0) { tb.MergeAttribute("rows", RowsValue.ToString(CultureInfo.InvariantCulture)); } if (ControlContextValue != null) { tb.MergeAttribute("id", ControlContextValue.Name); tb.MergeAttribute("name", ControlContextValue.Name); if (ControlContextValue.IsRequired) { tb.MergeAttribute("required", "required"); } } if (DisabledValue) { tb.MergeAttribute("disabled", "disabled"); } ApplyCss(tb); ApplyAttributes(tb); writer.Write(tb.GetStartTag()); if (ControlContextValue != null && ControlContextValue.Value != null) { writer.Write(context.HtmlEncode(ControlContextValue.Value.ToString())); } writer.Write(tb.GetEndTag()); if (div != null) { writer.Write(div.GetEndTag()); } }
//Code is inspired by https://github.com/Microsoft/perfview/blob/master/src/PerfView/PerfViewData.cs#L5719-L5944 private IEnumerable <Metric> Parse(TraceLog traceLog) { var stackSource = new MutableTraceEventStackSource(traceLog); var eventSource = traceLog.Events.GetSource(); var bdnEventsParser = new EngineEventLogParser(eventSource); var start = false; var isFirstActualStartEnd = false; long totalOperation = 0; long countOfAllocatedObject = 0; bdnEventsParser.WorkloadActualStart += data => { if (!isFirstActualStartEnd) { start = true; } totalOperation = data.TotalOperations; }; bdnEventsParser.WorkloadActualStop += data => { start = false; isFirstActualStartEnd = true; }; var heapParser = new HeapTraceProviderTraceEventParser(eventSource); // We index by heap address and then within the heap we remember the allocation stack var heaps = new Dictionary <Address, Dictionary <Address, long> >(); Dictionary <Address, long> lastHeapAllocs = null; Address lastHeapHandle = 0; long nativeLeakSize = 0; long totalAllocation = 0; heapParser.HeapTraceAlloc += delegate(HeapAllocTraceData data) { if (!start) { return; } var call = data.CallStackIndex(); var frameIndex = stackSource.GetCallStack(call, data); if (!IsCallStackIn(frameIndex)) { return; } var allocs = lastHeapAllocs; if (data.HeapHandle != lastHeapHandle) { allocs = CreateHeapCache(data.HeapHandle, heaps, ref lastHeapAllocs, ref lastHeapHandle); } allocs[data.AllocAddress] = data.AllocSize; checked { countOfAllocatedObject++; nativeLeakSize += data.AllocSize; totalAllocation += data.AllocSize; } bool IsCallStackIn(StackSourceCallStackIndex index) { while (index != StackSourceCallStackIndex.Invalid) { var frame = stackSource.GetFrameIndex(index); var name = stackSource.GetFrameName(frame, false); if (name.StartsWith(moduleName, StringComparison.Ordinal) && name.IndexOf(functionName, StringComparison.Ordinal) > 0) { return(true); } index = stackSource.GetCallerIndex(index); } return(false); } }; heapParser.HeapTraceFree += delegate(HeapFreeTraceData data) { if (!start) { return; } var allocs = lastHeapAllocs; if (data.HeapHandle != lastHeapHandle) { allocs = CreateHeapCache(data.HeapHandle, heaps, ref lastHeapAllocs, ref lastHeapHandle); } if (allocs.TryGetValue(data.FreeAddress, out long alloc)) { nativeLeakSize -= alloc; allocs.Remove(data.FreeAddress); } }; heapParser.HeapTraceReAlloc += delegate(HeapReallocTraceData data) { if (!start) { return; } // Reallocs that actually move stuff will cause a Alloc and delete event // so there is nothing to do for those events. But when the address is // the same we need to resize. if (data.OldAllocAddress != data.NewAllocAddress) { return; } var allocs = lastHeapAllocs; if (data.HeapHandle != lastHeapHandle) { allocs = CreateHeapCache(data.HeapHandle, heaps, ref lastHeapAllocs, ref lastHeapHandle); } if (allocs.TryGetValue(data.OldAllocAddress, out long alloc)) { // Free nativeLeakSize -= alloc; allocs.Remove(data.OldAllocAddress); // Alloc allocs[data.NewAllocAddress] = data.NewAllocSize; checked { nativeLeakSize += data.NewAllocSize; } } }; heapParser.HeapTraceDestroy += delegate(HeapTraceData data) { if (!start) { return; } // Heap is dieing, kill all objects in it. var allocs = lastHeapAllocs; if (data.HeapHandle != lastHeapHandle) { allocs = CreateHeapCache(data.HeapHandle, heaps, ref lastHeapAllocs, ref lastHeapHandle); } foreach (var alloc in allocs.Values) { nativeLeakSize -= alloc; } }; eventSource.Process(); logger.WriteLine(); logger.WriteLineHeader(LogSeparator); logger.WriteLineInfo($"{benchmarkCase.DisplayInfo}"); logger.WriteLineHeader(LogSeparator); if (totalOperation == 0) { logger.WriteLine($"Something went wrong. The trace file {etlFilePath} does not contain BenchmarkDotNet engine events."); return(Enumerable.Empty <Metric>()); } var memoryAllocatedPerOperation = totalAllocation / totalOperation; var memoryLeakPerOperation = nativeLeakSize / totalOperation; logger.WriteLine($"Native memory allocated per single operation: {SizeValue.FromBytes(memoryAllocatedPerOperation).ToString(SizeUnit.B, benchmarkCase.Config.CultureInfo)}"); logger.WriteLine($"Count of allocated object: {countOfAllocatedObject / totalOperation}"); if (nativeLeakSize != 0) { logger.WriteLine($"Native memory leak per single operation: {SizeValue.FromBytes(memoryLeakPerOperation).ToString(SizeUnit.B, benchmarkCase.Config.CultureInfo)}"); } var heapInfoList = heaps.Select(h => new { Address = h.Key, h.Value.Count, types = h.Value.Values }); foreach (var item in heapInfoList.Where(p => p.Count > 0)) { logger.WriteLine($"Count of not deallocated object: {item.Count / totalOperation}"); } return(new[] { new Metric(new AllocatedNativeMemoryDescriptor(), memoryAllocatedPerOperation), new Metric(new NativeMemoryLeakDescriptor(), memoryLeakPerOperation) }); }