/// <summary> /// Convert expression to code. /// </summary> /// <param name="expression">Expression.</param> /// <param name="converter">Expression converter.</param> /// <returns>Parts.</returns> public override ICode Convert(MethodCallExpression expression, ExpressionConverter converter) { //TODO これちょっとおかしい var startIndex = expression.SkipMethodChain(0); var table = FromConverterAttribute.ConvertTable(converter, expression.Arguments[startIndex]); if (table.IsEmpty) { return(string.Empty.ToCode()); } var condition = ((startIndex + 1) < expression.Arguments.Count) ? converter.ConvertToCode(expression.Arguments[startIndex + 1]) : null; var join = new HCode() { AddIndentNewLine = true, Separator = " ", Indent = 1 }; join.Add(_nameCode); join.Add(table); if (condition != null) { join.Add("ON".ToCode()); join.Add(condition); } return(join); }
internal static HCode Clause(ICode clause, params ICode[] args) { var code = new HCode() { AddIndentNewLine = true, Separator = " " }; code.Add(clause); code.AddRange(args); return code; }
public void EwcCodeNull_Throws() { Assert.Throws <ArgumentNullException>(() => new WasteType(ImportNotificationId, "WasteTypeName", BaselOecdCode.CreateNotListed(), null, YCode.CreateNotApplicable(), HCode.CreateNotApplicable(), UnClass.CreateNotApplicable(), ChemicalComposition.Other)); }
internal static HCode Clause(ICode clause, params ICode[] args) { var code = new HCode() { AddIndentNewLine = true, Separator = " " }; code.Add(clause); code.AddRange(args); return(code); }
public WasteType(Guid importNotificationId, string name, BaselOecdCode baselOecdCode, EwcCode ewcCode, YCode yCode, HCode hCode, UnClass unClass, ChemicalComposition chemicalComposition) { Guard.ArgumentNotDefaultValue(() => importNotificationId, importNotificationId); Guard.ArgumentNotNullOrEmpty(() => name, name); Guard.ArgumentNotNull(() => baselOecdCode, baselOecdCode); Guard.ArgumentNotNull(() => ewcCode, ewcCode); Guard.ArgumentNotNull(() => yCode, yCode); Guard.ArgumentNotNull(() => hCode, hCode); Guard.ArgumentNotNull(() => unClass, unClass); Guard.ArgumentNotDefaultValue(() => chemicalComposition, chemicalComposition); ImportNotificationId = importNotificationId; Name = name; var wasteCodes = new List <WasteTypeWasteCode>(); WasteCodesCollection = new List <WasteTypeWasteCode>(); BaselOecdCodeNotListed = baselOecdCode.NotListed; YCodeNotApplicable = yCode.NotApplicable; HCodeNotApplicable = hCode.NotApplicable; UnClassNotApplicable = unClass.NotApplicable; ChemicalCompositionType = chemicalComposition; wasteCodes.AddRange(ewcCode.Codes); if (!BaselOecdCodeNotListed) { wasteCodes.Add(baselOecdCode.Code); } if (!YCodeNotApplicable) { wasteCodes.AddRange(yCode.Codes); } if (!HCodeNotApplicable) { wasteCodes.AddRange(hCode.Codes); } if (!UnClassNotApplicable) { wasteCodes.AddRange(unClass.Codes); } WasteCodesCollection = wasteCodes; }
ICode[] ConvertExpandArrayArgument(ExpressionConverter converter, ArgumentInfo argumentInfo, Expression argExp) { ICode[] code; var newArrayExp = argExp as NewArrayExpression; if (newArrayExp != null) { code = new ICode[newArrayExp.Expressions.Count]; for (int i = 0; i < newArrayExp.Expressions.Count; i++) { code[i] = converter.ConvertToCode(newArrayExp.Expressions[i]); } } else { var obj = converter.ConvertToObject(argExp); var list = new List <ICode>(); foreach (var e in (IEnumerable)obj) { list.Add(converter.ConvertToCode(e)); } code = list.ToArray(); } if (!string.IsNullOrEmpty(argumentInfo.ArrayExpandSeparator)) { var isEmpty = true; for (int i = code.Length - 1; 0 <= i; i--) { var currentIsEmpty = code[i].IsEmpty; if (!isEmpty && !currentIsEmpty) { code[i] = new HCode(code[i], argumentInfo.ArrayExpandSeparator.ToCode()) { EnableChangeLine = false }; } if (isEmpty) { isEmpty = currentIsEmpty; } } } if (0 < code.Length && argumentInfo.Separator != null) { code[code.Length - 1] = new HCode(code[code.Length - 1], argumentInfo.Separator) { EnableChangeLine = false }; } return(code); }
private HCode CreateHCode(bool notApplicable, IEnumerable <Guid> codeIds) { if (notApplicable) { return(HCode.CreateNotApplicable()); } var wasteCodes = Task.Run(() => wasteCodeRepository.GetWasteCodesByIds(codeIds)).Result; return(HCode.CreateFor(wasteCodes)); }
public WasteType(Guid importNotificationId, string name, BaselOecdCode baselOecdCode, EwcCode ewcCode, YCode yCode, HCode hCode, UnClass unClass, ChemicalComposition chemicalComposition) { Guard.ArgumentNotDefaultValue(() => importNotificationId, importNotificationId); Guard.ArgumentNotNullOrEmpty(() => name, name); Guard.ArgumentNotNull(() => baselOecdCode, baselOecdCode); Guard.ArgumentNotNull(() => ewcCode, ewcCode); Guard.ArgumentNotNull(() => yCode, yCode); Guard.ArgumentNotNull(() => hCode, hCode); Guard.ArgumentNotNull(() => unClass, unClass); Guard.ArgumentNotDefaultValue(() => chemicalComposition, chemicalComposition); ImportNotificationId = importNotificationId; Name = name; var wasteCodes = new List<WasteTypeWasteCode>(); WasteCodesCollection = new List<WasteTypeWasteCode>(); BaselOecdCodeNotListed = baselOecdCode.NotListed; YCodeNotApplicable = yCode.NotApplicable; HCodeNotApplicable = hCode.NotApplicable; UnClassNotApplicable = unClass.NotApplicable; ChemicalCompositionType = chemicalComposition; wasteCodes.AddRange(ewcCode.Codes); if (!BaselOecdCodeNotListed) { wasteCodes.Add(baselOecdCode.Code); } if (!YCodeNotApplicable) { wasteCodes.AddRange(yCode.Codes); } if (!HCodeNotApplicable) { wasteCodes.AddRange(hCode.Codes); } if (!UnClassNotApplicable) { wasteCodes.AddRange(unClass.Codes); } WasteCodesCollection = wasteCodes; }
/// <summary> /// Convert expression to code. /// </summary> /// <param name="expression">Expression.</param> /// <param name="converter">Expression converter.</param> /// <returns>Parts.</returns> public override ICode Convert(NewExpression expression, ExpressionConverter converter) { var arg0 = new HCode(new SingleTextCode("["), converter.ConvertToCode(expression.Arguments[0]), new SingleTextCode("]")) { Separator = string.Empty }; return(new HCode(arg0, converter.ConvertToCode(expression.Arguments[1]), new SingleTextCode("AS JSON")) { Separator = " " }); }
public void Update(string name, BaselOecdCode baselOecdCode, EwcCode ewcCode, YCode yCode, HCode hCode, UnClass unClass) { Guard.ArgumentNotNullOrEmpty(() => name, name); Guard.ArgumentNotNull(() => baselOecdCode, baselOecdCode); Guard.ArgumentNotNull(() => ewcCode, ewcCode); Guard.ArgumentNotNull(() => yCode, yCode); Guard.ArgumentNotNull(() => hCode, hCode); Guard.ArgumentNotNull(() => unClass, unClass); Name = name; var wasteCodes = new List <WasteTypeWasteCode>(); var existingCodes = WasteCodes.ToList(); BaselOecdCodeNotListed = baselOecdCode.NotListed; YCodeNotApplicable = yCode.NotApplicable; HCodeNotApplicable = hCode.NotApplicable; UnClassNotApplicable = unClass.NotApplicable; foreach (var code in existingCodes) { WasteCodesCollection.Remove(code); } wasteCodes.AddRange(ewcCode.Codes); if (!BaselOecdCodeNotListed) { wasteCodes.Add(baselOecdCode.Code); } if (!YCodeNotApplicable) { wasteCodes.AddRange(yCode.Codes); } if (!HCodeNotApplicable) { wasteCodes.AddRange(hCode.Codes); } if (!UnClassNotApplicable) { wasteCodes.AddRange(unClass.Codes); } WasteCodesCollection = wasteCodes; }
public void CanCreateWasteType() { var wasteType = new WasteType(ImportNotificationId, "WasteTypeName", BaselOecdCode.CreateFor(AnyWasteCode(CodeType.Basel)), EwcCode.CreateFor(new[] { AnyWasteCode(CodeType.Ewc) }), YCode.CreateFor(new[] { AnyWasteCode(CodeType.Y) }), HCode.CreateFor(new[] { AnyWasteCode(CodeType.H) }), UnClass.CreateFor(new[] { AnyWasteCode(CodeType.Un) }), ChemicalComposition.Other); Assert.IsType <WasteType>(wasteType); }
public void UnClassNotApplicable_NotApplicableTrue() { var wasteType = new WasteType(ImportNotificationId, "WasteTypeName", BaselOecdCode.CreateNotListed(), EwcCode.CreateFor(new[] { AnyWasteCode(CodeType.Ewc) }), YCode.CreateNotApplicable(), HCode.CreateNotApplicable(), UnClass.CreateNotApplicable(), ChemicalComposition.Other); Assert.True(wasteType.UnClassNotApplicable); }
public void ImportNotificationIdDefaultValue_Throws() { Assert.Throws <ArgumentException>(() => new WasteType(Guid.Empty, "WasteTypeName", BaselOecdCode.CreateNotListed(), EwcCode.CreateFor(new[] { AnyWasteCode(CodeType.Ewc) }), YCode.CreateNotApplicable(), HCode.CreateNotApplicable(), UnClass.CreateNotApplicable(), ChemicalComposition.Other)); }
public void UnsetChemicalComposition_Throws() { Assert.Throws <ArgumentException>(() => new WasteType(ImportNotificationId, "Name", BaselOecdCode.CreateNotListed(), EwcCode.CreateFor(new[] { AnyWasteCode(CodeType.Ewc) }), YCode.CreateNotApplicable(), HCode.CreateNotApplicable(), UnClass.CreateNotApplicable(), default(ChemicalComposition))); }
public void UnClassNull_Throws() { Assert.Throws <ArgumentNullException>(() => new WasteType(ImportNotificationId, "WasteTypeName", BaselOecdCode.CreateNotListed(), EwcCode.CreateFor(new[] { AnyWasteCode(CodeType.Ewc) }), YCode.CreateNotApplicable(), HCode.CreateNotApplicable(), null, ChemicalComposition.Other)); }
public void UnClassesAreSet() { var unCode = AnyWasteCode(CodeType.Un); var unCodeId = new Guid("4B50E7AA-0136-444A-9185-FE31BE6CF98E"); ObjectInstantiator <WasteCode> .SetProperty(x => x.Id, unCodeId, unCode); var wasteType = new WasteType(ImportNotificationId, "WateTypeName", BaselOecdCode.CreateNotListed(), EwcCode.CreateFor(new[] { AnyWasteCode(CodeType.Ewc) }), YCode.CreateNotApplicable(), HCode.CreateNotApplicable(), UnClass.CreateFor(new[] { unCode }), ChemicalComposition.Other); Assert.Equal(1, wasteType.WasteCodes.Count(wc => wc.WasteCodeId == unCodeId)); }
public void HCodesAreSet() { var hCode = AnyWasteCode(CodeType.H); var hCodeId = new Guid("B21D8610-EBB0-436F-BD26-D2F40B42B866"); ObjectInstantiator <WasteCode> .SetProperty(x => x.Id, hCodeId, hCode); var wasteType = new WasteType(ImportNotificationId, "WateTypeName", BaselOecdCode.CreateNotListed(), EwcCode.CreateFor(new[] { AnyWasteCode(CodeType.Ewc) }), YCode.CreateNotApplicable(), HCode.CreateFor(new[] { hCode }), UnClass.CreateNotApplicable(), ChemicalComposition.Other); Assert.Equal(1, wasteType.WasteCodes.Count(wc => wc.WasteCodeId == hCodeId)); }
public void YCodesAreSet() { var yCode = AnyWasteCode(CodeType.Y); var yCodeId = new Guid("F416BD1D-56E9-45D8-9A4E-7476DF201AB2"); ObjectInstantiator <WasteCode> .SetProperty(x => x.Id, yCodeId, yCode); var wasteType = new WasteType(ImportNotificationId, "WateTypeName", BaselOecdCode.CreateNotListed(), EwcCode.CreateFor(new[] { AnyWasteCode(CodeType.Ewc) }), YCode.CreateFor(new[] { yCode }), HCode.CreateNotApplicable(), UnClass.CreateNotApplicable(), ChemicalComposition.Other); Assert.Equal(1, wasteType.WasteCodes.Count(wc => wc.WasteCodeId == yCodeId)); }
public void EwcCodesAreSet() { var ewcCode = AnyWasteCode(CodeType.Ewc); var ewcCodeId = new Guid("A4DA3323-B6BD-4245-B144-B9E05661BEC6"); ObjectInstantiator <WasteCode> .SetProperty(x => x.Id, ewcCodeId, ewcCode); var wasteType = new WasteType(ImportNotificationId, "WateTypeName", BaselOecdCode.CreateNotListed(), EwcCode.CreateFor(new[] { ewcCode }), YCode.CreateNotApplicable(), HCode.CreateNotApplicable(), UnClass.CreateNotApplicable(), ChemicalComposition.Other); Assert.Equal(1, wasteType.WasteCodes.Count(wc => wc.WasteCodeId == ewcCodeId)); }
public void BaselCodeIsSet() { var baselCode = AnyWasteCode(CodeType.Basel); var baselCodeId = new Guid("72669DEE-1126-47B3-8C45-2395F54C82D8"); ObjectInstantiator <WasteCode> .SetProperty(x => x.Id, baselCodeId, baselCode); var wasteType = new WasteType(ImportNotificationId, "WasteTypeName", BaselOecdCode.CreateFor(baselCode), EwcCode.CreateFor(new[] { AnyWasteCode(CodeType.Ewc) }), YCode.CreateNotApplicable(), HCode.CreateNotApplicable(), UnClass.CreateNotApplicable(), ChemicalComposition.Other); Assert.Equal(1, wasteType.WasteCodes.Count(wc => wc.WasteCodeId == baselCodeId)); }
public void OecdCodeIsSet() { var oecdCode = AnyWasteCode(CodeType.Oecd); var oecdCodeId = new Guid("A58E7CE8-FA46-4E35-A3ED-26E395678CA0"); ObjectInstantiator <WasteCode> .SetProperty(x => x.Id, oecdCodeId, oecdCode); var wasteType = new WasteType(ImportNotificationId, "WasteTypeName", BaselOecdCode.CreateFor(oecdCode), EwcCode.CreateFor(new[] { AnyWasteCode(CodeType.Ewc) }), YCode.CreateNotApplicable(), HCode.CreateNotApplicable(), UnClass.CreateNotApplicable(), ChemicalComposition.Other); Assert.Equal(1, wasteType.WasteCodes.Count(wc => wc.WasteCodeId == oecdCodeId)); }
/// <summary> /// Assert.AreEqual(16, data1.Length); /// Assert.AreEqual(data2.Length, data1.Sum(b => b)); /// Assert.IsTrue(data2.Length <= 256); /// </summary> public static ReadOnlyDictionary <int, HCode> BuildTree(IList <byte> data1, IList <byte> data2) { var tree = new Dictionary <int, HCode>(); var offset = 0; var bits = 0; for (var i = 0; i < 16; i++) { bits = bits << 1; for (var j = 0; j < data1[i]; j++) { var value = new HCode(data2[offset], (byte)(i + 1)); tree.Add(bits, value); bits++; offset++; } } return(new ReadOnlyDictionary <int, HCode>(tree)); }
ICode Layout(ICode[] code) { ICode[] front, back; TakeAndSkip(code, _firstLineElemetCount, out front, out back); if (FormatDirection == FormatDirection.Vertical) { var mustFirstLine = new HCode(front) { EnableChangeLine = false }; var layout = new VCode(mustFirstLine) { Indent = Indent }; //after line, add indent. for (int i = 0; i < back.Length; i++) { layout.Add(new HCode(back[i]) { Indent = 1 }); } return(layout); } else { var mustFirstLine = new HCode(front) { EnableChangeLine = false }; var layout = new HCode(mustFirstLine) { AddIndentNewLine = true, Indent = Indent }; layout.AddRange(back); return(layout); } }
public void HCode_CreateFor_Null_Throws() { Assert.Throws <ArgumentNullException>(() => HCode.CreateFor(null)); }
public void AnyHCodesWrongType_Throws(CodeType codeType) { Assert.Throws <ArgumentException>(() => HCode.CreateFor(new[] { AnyWasteCode(codeType) })); }