// todo: 将类型声明尾部的 1组或多组 [???] 分离并返回 public static KeyValuePair <string, string> SplitTypeKeyword(string k, Declare d) { int n = 0; while (d.DataType == DataTypes.Array) { n += 2 + d.MinLen.ToString().Length; d = d.Childs[0]; } return(new KeyValuePair <string, string>(k.Substring(0, k.Length - n), k.Substring(k.Length - n, n))); }
public void Given() { var branchPoint = Declare.Step(); wf = new Workflow <IObject>() .Do(x => x.Feedback("beginning"), If.IsTrue(() => counter < 1, branchPoint)) .Do(x => x.Feedback("middle")) .Do(x => x.Feedback("end"), branchPoint); mock = new Mock <IObject>(); mock.Setup(x => x.Feedback(It.IsAny <string>())).Returns(mock.Object); }
public void Add(string symbol, Declare decl) { if (symbol_table.ContainsKey(symbol)) { throw new Exception("Name is already used"); } else { symbol_table[symbol] = decl; } }
public override void ResolveNames(LexicalScope scope) { if (scope != null) { decl = scope.ResolveName(assName); } if (decl == null) { Console.WriteLine("Undeclared Identifier"); throw new Exception("Resolve Name Error"); } }
/// <summary> /// /// </summary> /// <param name="element"></param> /// <param name="evp"></param> public override void Visit(Declare element, EvaluationParam evp) { result = new Result(); if (evp.IsPropertyExist(element.Name)) { result.Value = evp.GetValue(element.Name); } else { result.Value = element.Value; } }
public void OneBranchHasOneTransition() { var branch1 = Declare.Step(); var wf = new StatefulWorkflow <StatefulObject>(2, gateway.Object) .Define(branch1) .Do(x => x) .When(x => true).BranchTo(branch1); var transitions = wf.PossibleTransitions.ToList(); transitions.Count.ShouldBe(1); transitions.Where(x => x.From == null && x.To == null).Count().ShouldBe(1); }
/// <summary> /// Processes the all global declarations in program. /// This method creates objects (ILGlobal) for global variables, /// and adds it the global context /// </summary> /// <param name="declare">The declare.</param> private void ProcessGlobalDeclare(Declare declare) { TypeEntity type = new TypeEntity(declare.Type); int index = 0; foreach (Variable var in declare) { new ILGlobal(type, var.Name, this); if (declare.GetInitExpression(index++) != null) { throw new AnalizeException("Can't initialize global variable", declare); } } }
protected virtual CodeMemberProperty GenerateProperty(ResourceMapping mapping) { var resource = mapping.Resource; var resourceType = resource.Type != null?Code.Type(resource.Type.Type).Local( ) : Code.Type <object> ( ); var summary = resource.Type == TypeNames.String ? Format(StringPropertySummary, GeneratePreview((string)resource.Value)) : Format(NonStringPropertySummary, resource.Name); return(Declare.Property(resourceType, mapping.Property) .Modifiers(settings.AccessModifiers) .Get(get => get.Return(GenerateResourceGetter(resource))) .AddSummary(summary + FormatResourceComment(resource.Comment))); }
public static string AssCon(string predelcode) { IsoDateTimeConverter iso = new IsoDateTimeConverter();//序列化JSON对象时,日期的处理格式 iso.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; DataTable dt = Declare.AssCon(predelcode); var json = "[]"; if (dt != null) { json = JsonConvert.SerializeObject(dt, iso); } return(json); }
private Syntax.Value ParseValue(Declare assignTo) { try { // var _strval = getValue(Syntax.Value.ValueExpression, _current.Value); var val = new Syntax.Value(assignTo, _current.Span, _current.Value); return(val); } catch (Exception e) { AddError(Source.Severity.Error, e.Message, _current.Span); var val = new Syntax.Value(assignTo, _current.Span, ""); return(val); } }
public void StartsAndEndsWithDefines() { var start = Declare.Step(); var end = Declare.Step(); var wf = new StatefulWorkflow <StatefulObject>(2, gateway.Object) .Define(start) .Yield(1) .Define(end) ; var transitions = wf.PossibleTransitions.ToList(); transitions.Count.ShouldBe(2); transitions.Where(x => x.From == null && (int?)x.To == 1).Count().ShouldBe(1); transitions.Where(x => (int?)x.From == 1 && x.To == null).Count().ShouldBe(1); }
public void failed_branches_work_with_parameters() { var jump = Declare.Step(); var wf = new StatefulWorkflow <ITest>("wf") .Unless((x, opts) => (bool)opts["flag"]).BranchTo(jump) .Yield("it didn't jump") .Define(jump) .Yield("it jumped"); var test = Mock.Of <ITest>(); wf.StartWithParams(test, new { flag = true }); Mock.Get(test).Verify(x => x.SetStateId("wf", "it jumped"), Times.Never()); Mock.Get(test).Verify(x => x.SetStateId("wf", "it didn't jump")); }
public Declare ResolveName(string symbol) { Declare decl = ResoveNameHere(symbol); if (decl != null) { return(decl); } else if (parent != null) { return(parent.ResolveName(symbol)); } else { return(null); } }
public static string ModifySave(string predelcode, int modifyflag) { WGUserEn user = (WGUserEn)HttpContext.Current.Session["user"]; if (user == null || string.IsNullOrEmpty(user.CustomerCode)) { return("[]"); } bool bf = Declare.saveModifyFlag(predelcode, modifyflag, user); var jsonstr = "false"; if (bf) { jsonstr = "success"; } return(jsonstr); }
public override void Apply() { Declare.Exchange("EvolvedAI") .OnVirtualHost("/") .AsType(EasyNetQ.Migrations.ExchangeType.Topic) .Durable(); Declare.Queue("FileSystem") .OnVirtualHost("/") .Durable(); Declare.Binding() .OnVirtualHost("/") .FromExchange("EvolvedAI") .ToQueue("FileSystem") .RoutingKey("#"); }
public override void Apply() { Declare.Exchange("myExchange") .OnVirtualHost("Test") .AsType(ExchangeType.Topic) .Durable(); Declare.Queue("myQueue") .OnVirtualHost("Test") .Durable(); Declare.Binding() .OnVirtualHost("Test") .FromExchange("myExchange") .ToQueue("myQueue") .RoutingKey("#"); }
public static string GetBufferString(Declare d) { string rtv = " "; if (d.DataType == DataTypes.BuiltIn) { switch (d.Name) { case "Byte": rtv = "byte"; break; case "SByte": rtv = "sbyte"; break; case "UInt16": rtv = "ushort"; break; case "Int16": rtv = "short"; break; case "UInt32": rtv = "uint"; break; case "Int32": rtv = "int"; break; case "UInt64": rtv = "uint64"; break; case "Int64": rtv = "int64"; break; case "Double": rtv = "double"; break; case "Single": rtv = "float"; break; case "Boolean": rtv = "bool"; break; case "String": rtv = "string"; break; // case "List<int>": rtv = "xxx::List<int>"; break; default: rtv = (d.Namespace != "" ? (d.Namespace + ".") : "") + d.Name; break; } } else if (d.DataType == DataTypes.Custom) { rtv = (d.Namespace != "" ? d.Namespace : ("" + _pn + "PkgTypes")) + "." + d.Name; } return(rtv); }
public void I_can_have_2_branches_to_the_same_yield() { var branch1 = Declare.Step(); var wf = new StatefulWorkflow <StatefulObject>(2, gateway.Object); wf.Yield(1); wf.When(x => true).BranchTo(branch1); wf.Yield(2); wf.When(x => true).BranchTo(branch1); wf.Yield(3); wf.Define(branch1); wf.Yield(4); var transitions = wf.PossibleTransitions.ToList(); transitions.Where(x => (int?)x.From == 1 && (int?)x.To == 4).Count().ShouldBe(1); transitions.Where(x => (int?)x.From == 2 && (int?)x.To == 4).Count().ShouldBe(1); }
private Declare getDeclare(List <SyntaxNode> contents) { var dy = contents.Where(x => x.Catagory == SyntaxCatagory.Declaration).ToList().ToArray(); foreach (SyntaxNode ss in dy) { Declare d = (Declare)ss; if ("d:" + d.Name == _current.Left || d.Name == _current.Left || d.Name.Replace("d:", "") == _current.Left) { return(d); } else if ("p:" + d.Name == _current.Left || d.Name == _current.Left || d.Name.Replace("p:", "") == _current.Left) { return(d); } } return(null); }
public void it_can_branch_using_positive_Unless_with_parameters() { var point = Declare.Step(); var wf = new StatefulWorkflow <Entity>() .Define(point) .Yield("branched") .Yield("start") .Unless((x, opts) => (bool)opts["shouldBranch"]).BranchTo(point) .Yield("didn't branch"); var obj = new Entity() { state = "start" }; wf.StartWithParams(obj, new { shouldBranch = true }); Assert.That(obj.GetStateId(null), Is.EqualTo("didn't branch")); }
public void it_can_branch_using_positive_Unless() { var point = Declare.Step(); var wf = new StatefulWorkflow <Entity>() .Define(point) .Yield("branched") .Yield("start") .Unless(x => true).BranchTo(point) .Yield("didn't branch"); var obj = new Entity() { state = "start" }; wf.Start(obj); Assert.That(obj.GetStateId(null), Is.EqualTo("didn't branch")); }
private Syntax.Statements StatementParser(Declare assignTo) { if (_current.Kind == TokenKind.If) { string content = getValue(Syntax.StatementDefination.IfStatement, _current.Value); var st = new Syntax.IFStatement(assignTo, _current.Span); st.addText(_current.Value); return(st); } else if (Scan(Syntax.StatementDefination.SwitchStatement, _current.Value)) { AddError(Source.Severity.Error, "Switch statement not implimented", _current.Span); return(null); } else { AddError(Source.Severity.Error, "Invalid Statement", _current.Span); return(null); } }
public void SingleBranchBetweenFlowsAddsATransition() { var branch1 = Declare.Step(); var wf = new StatefulWorkflow <StatefulObject>(2, gateway.Object) .Yield(1) .Define(branch1) .Yield(2) .When(x => true).BranchTo(branch1); var transitions = wf.PossibleTransitions.ToList(); transitions.Should(Have.Count.EqualTo(4)); transitions.Should(Have.Some.Matches <ITransition>(x => x.From == null && (int?)x.To == 1)); transitions.Should(Have.Some.Matches <ITransition>(x => (int?)x.From == 1 && (int?)x.To == 2)); transitions.Should(Have.Some.Matches <ITransition>(x => (int?)x.From == 2 && x.To == null)); // as well as transitions.Should(Have.Some.Matches <ITransition>(x => (int?)x.From == 2 && (int?)x.To == 2)); transitions.Should(Have.None.Matches <ITransition>(x => (int?)x.From == 2 && (int?)x.To == 1)); }
public void ItUsesTheOriginalStateWhenCheckingSecurity() { var transitions = new[] { new Transition(null, "start", "end") }; var security = new DefaultTransitionGateway(transitions); var end = Declare.Step(); var wf = new StatefulWorkflow <T>(null, security) .Define(end) .Yield("end") .Yield("start") .Do(x => x.SetStateId(null, "end")) .When(x => true).BranchTo(end); var t = new T(); wf.Start(t); // Main assertion is really that it didn't throw a security exception Assert.That(t.GetStateId(null), Is.EqualTo("end")); }
public static string getInfo(string code) { Declare model = new Declare(); DataTable dt = model.getSubsInfo(code); IsoDateTimeConverter iso = new IsoDateTimeConverter();//序列化JSON对象时,日期的处理格式 try { foreach (DataRow dr in dt.Rows) { dr["ischeck"] = dr["ischeck"].ToString2() == "1" ? "海关查验" : ""; dr["checkpic"] = dr["checkpic"].ToString2() == "1" ? "含查验图片" : ""; dr["inspischeck"] = dr["inspischeck"].ToString2() == "1" ? "国检查验" : ""; dr["lawflag"] = dr["lawflag"].ToString2() == "1" ? "含法检" : ""; dr["declstatus"] = SwitchHelper.switchValue("declstatus", dr["declstatus"].ToString2()); dr["inspstatus"] = SwitchHelper.switchValue("inspstatus", dr["inspstatus"].ToString2()); if (string.IsNullOrEmpty(dr["divideno"].ToString2())) { dr["divideno"] = ""; } if (string.IsNullOrEmpty(dr["logisticsstatus"].ToString2())) { dr["logisticsstatus"] = ""; } if (string.IsNullOrEmpty(dr["contractno"].ToString2())) { dr["contractno"] = ""; } } } catch (Exception e) { LogHelper.Write("BusiSubsDetail:" + e.Message); } iso.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; string json = JsonConvert.SerializeObject(dt, iso); return(json); }
public void DoubleBranchDoesNotAddDuplicate() { var branch1 = Declare.Step(); var wf = new StatefulWorkflow <StatefulObject>(2, gateway.Object) .Yield(1) .Define(branch1) .Yield(2) .When(x => true).BranchTo(branch1) .When(x => true).BranchTo(branch1); var transitions = wf.PossibleTransitions.ToList(); transitions.Should(Have.Count.EqualTo(4)); transitions.Where(x => x.From == null && (int?)x.To == 1).Count().ShouldBe(1); transitions.Where(x => (int?)x.From == 1 && (int?)x.To == 2).Count().ShouldBe(1); transitions.Where(x => (int?)x.From == 2 && x.To == null).Count().ShouldBe(1); // as well as transitions.Where(x => (int?)x.From == 2 && (int?)x.To == 1).Count().ShouldBe(0); transitions.Where(x => (int?)x.From == 2 && (int?)x.To == 2).Count().ShouldBe(1); }
public void BranchingIntoUnallowedState() { var branch1 = Declare.Step(); var wf = new StatefulWorkflow <StatefulObject>(2, gateway.Object) .Yield(1) .Define(branch1) .Do(x => x.Feedback("middle")) .Yield(2) .When(x => true).BranchTo(branch1) ; gateway.SetReturnsDefault <bool>(true); gateway.Setup(x => x.IsTransitionAllowed( It.Is <ITransition>(y => object.Equals(y.From, 2) && object.Equals(y.To, 2)))) .Returns(false); wf.Start(obj.Object); wf.Start(obj.Object); Assert.Throws <UnallowedTransitionException>(() => wf.Start(obj.Object)); obj.Verify(x => x.Feedback("middle"), Times.Once()); // not twice }
private Expression ParseExpression(Declare assignTo) { if (Scan(Expression.ExpressionReg, _current.Value)) { var exp = getValue(Expression.ExpressionReg, _current.Value); try { var cal = new NCalc.Expression(replaceAlpha(exp)).Evaluate(); } catch (Exception e) { AddError(Source.Severity.Error, e.Message, _current.Span); } var ex = new Expression(assignTo, exp, _current.Span); return(ex); } else { AddError(Source.Severity.Error, "Invalid Expression", _current.Span); return(new Expression(assignTo, "", _current.Span)); } }
public static string BindList(string reptime_s, string reptime_e, string declcode, string customsstatus, string modifyflag, string busitype, string ischeck , string ispass, string busiunit, string ordercode, string cusno, string tradeway, string contractno, string blno , string submittime_s, string submittime_e, string sitepasstime_s, string sitepasstime_e , int start, int itemsPerLoad) { WGUserEn user = (WGUserEn)HttpContext.Current.Session["user"]; if (user == null || string.IsNullOrEmpty(user.CustomerCode)) { return("[]"); } string customerCode = user.CustomerCode; string hsCode = user.HSCode; if (user.IsCompany != 1)//如果不是企业角色,不能查出其对应经营单位的订单 { hsCode = ""; } if (user.IsCustomer != 1)//如果不是委托单位角色,不能查出其对应委托单位的订单 { customerCode = ""; } DataSet ds = Declare.getDeclareInfo_my(reptime_s, reptime_e, declcode, customsstatus, getcode("modifyflag", modifyflag), busitype, ischeck , ischeck, busiunit, ordercode, cusno, tradeway, contractno, blno , submittime_s, submittime_e, sitepasstime_s, sitepasstime_e , start, itemsPerLoad, customerCode, hsCode); //DataSet ds = Declare.getDeclareInfo_my(reptime_s, reptime_e, declcode, customsstatus, getcode("modifyflag", modifyflag), busitype, ischeck // , ischeck, busiunit, ordercode, cusno, tradeway, contractno, blno // , submittime_s, submittime_e, sitepasstime_s, sitepasstime_e // , start, itemsPerLoad, "RBDZKJKSYXGS", "3223640003"); IsoDateTimeConverter iso = new IsoDateTimeConverter();//序列化JSON对象时,日期的处理格式 iso.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; var json = "[{\"data\":" + JsonConvert.SerializeObject(ds.Tables[0], iso) + ",\"sum\":" + ds.Tables[1].Rows[0][0] + "}]"; return(json); }
static void AddToStringHelper(CodeTypeDeclaration type, CodeDomProvider provider) { var helperClass = Declare.Class("ToStringInstanceHelper") .AsNestedPublic() .WithReference(out var helperClassType); helperClass.AddField <IFormatProvider> ("formatProvider", TypeReference <System.Globalization.CultureInfo> .Global.Property("InvariantCulture")) .WithReference(out var formatProvider); helperClass.AddProperty <IFormatProvider> ("FormatProvider") .WithGet(formatProvider) .WithSetIgnoresNull(formatProvider); helperClass.AddMethod("ToStringWithCulture") .Returns <string> () .WithParameter <object> ("objectToConvert", out var objectToConvert) .WithStatements( objectToConvert.ThrowIfNull(), Declare.Variable <Type> ("type", objectToConvert.InvokeMethod("GetType"), out var objType), Declare.Variable <Type> ("iConvertibleType", Expression.TypeOf <IConvertible> (), out var iConvertibleType), Statement.If(iConvertibleType.InvokeMethod("IsAssignableFrom", objType), Then: Statement.Return(objectToConvert.Cast <IConvertible> ().InvokeMethod("ToString", formatProvider))), Declare.Variable <System.Reflection.MethodInfo> ("methInfo", objType.InvokeMethod("GetMethod", Expression.Primitive("ToString"), Expression.Array <Type> (iConvertibleType)), out var methInfoLocalRef), Statement.If(methInfoLocalRef.IsNotNull(), Then: Statement.Return(Expression.Cast <string> ( methInfoLocalRef.InvokeMethod("Invoke", objectToConvert, Expression.Array <object> (formatProvider))))), Statement.Return(objectToConvert.InvokeMethod("ToString")) ); var helperFieldName = provider.CreateValidIdentifier("_toStringHelper"); type.AddPropertyGetOnly("ToStringHelper", type.AddField(helperFieldName, helperClassType, Expression.New(helperClassType))); type.AddMember(helperClass); }
/// <summary>Assigns all needed attributes to the tag</summary> /// <returns>This instance downcasted to base class</returns> public virtual IndexedTag attr( Declare? declare = null, string classid = null, string codebase = null, string data = null, MimeType type = null, MimeType codetype = null, string archive = null, string standby = null, Length height = null, Length width = null, string usemap = null, string name = null, int? tabindex = null, string id = null, string @class = null, string style = null, string title = null, LangCode lang = null, string xmllang = null, Dir? dir = null, string onclick = null, string ondblclick = null, string onmousedown = null, string onmouseup = null, string onmouseover = null, string onmousemove = null, string onmouseout = null, string onkeypress = null, string onkeydown = null, string onkeyup = null ) { Declare = declare; ClassId = classid; CodeBase = codebase; Data = data; Type = type; CodeType = codetype; Archive = archive; StandBy = standby; Height = height; Width = width; UseMap = usemap; Name = name; TabIndex = tabindex; Id = id; Class = @class; Style = style; Title = title; Lang = lang; XmlLang = xmllang; Dir = dir; OnClick = onclick; OnDblClick = ondblclick; OnMouseDown = onmousedown; OnMouseUp = onmouseup; OnMouseOver = onmouseover; OnMouseMove = onmousemove; OnMouseOut = onmouseout; OnKeyPress = onkeypress; OnKeyDown = onkeydown; OnKeyUp = onkeyup; return this; }
public static string GetTypeKeyword( Declare d ) { string rtv = ""; if( d.DataType == DataTypes.Array ) { rtv = GetTypeKeyword( d.Childs[ 0 ] ) + "[" + d.MinLen + "]"; } else if( d.DataType == DataTypes.BuiltIn ) { switch( d.Name ) { case "Byte": rtv = "byte"; break; case "SByte": rtv = "sbyte"; break; case "UInt16": rtv = "ushort"; break; case "Int16": rtv = "short"; break; case "UInt32": rtv = "uint"; break; case "Int32": rtv = "int"; break; case "UInt64": rtv = "uint64"; break; case "Int64": rtv = "int64"; break; case "Double": rtv = "double"; break; case "Single": rtv = "float"; break; case "Boolean": rtv = "bool"; break; default: rtv = ( d.Namespace != "" ? ( d.Namespace + "::" ) : "" ) + d.Name; break; } } else if( d.DataType == DataTypes.Custom ) { rtv = ( d.Namespace != "" ? d.Namespace : ( "::" + _pn + "Packets" ) ) + "::" + d.Name; } else { rtv = d.Name + "<"; for( int i = 0; i < d.Childs.Count; ++i ) { if( i > 0 ) rtv += ","; rtv += GetTypeKeyword( d.Childs[ i ] ); } rtv += ">"; } return rtv; }
public static string projEnum = "__projects"; // 重要:生成过程中通过这个枚举来识别项目分类 #endregion Fields #region Methods public static void fillDeclare( Template template, Declare d, Type t ) { var tn = t.Name; if( t.IsArray ) { d.DataType = DataTypes.Array; d.Namespace = "System"; d.Name = "[]"; var cd = new Declare(); d.Childs.Add( cd ); fillDeclare( template, cd, t.GetElementType() ); } else if( t.IsGenericType ) { if( t.Namespace != libNS ) throw new Exception( "unknown data type." ); d.DataType = DataTypes.Generic; d.Name = tn.Substring( 0, tn.LastIndexOf( '`' ) ); d.Namespace = ""; foreach( var ct in t.GenericTypeArguments ) { var cd = new Declare(); d.Childs.Add( cd ); fillDeclare( template, cd, ct ); } } else if( t.Namespace == "System" ) { switch( t.Name ) { case "Byte": case "UInt16": case "UInt32": case "UInt64": case "SByte": case "Int16": case "Int32": case "Int64": case "Double": case "Single": case "Boolean": case "String": case "DateTime": d.DataType = DataTypes.BuiltIn; d.Name = t.Name; d.Namespace = ""; break; default: throw new Exception( "unknown data type." ); } } else { if( t.Namespace != null ) // && t.Namespace != libNS { throw new Exception( "unknown data type." ); } d.DataType = DataTypes.Custom; d.Name = t.Name; d.Namespace = ""; d.Class = template.Classes.Find( a => a.Name == t.Name && a.Namespace == "" ); if( d.Class == null ) { d.Class = template.Enums.Find( a => a.Name == t.Name && a.Namespace == "" ); } } }
public static void fillDeclareLimits( Declare d, LIB.Limits ls, int i = 0 ) { if( d.DataType == DataTypes.Array ) { if( i >= ls.Value.Length ) { throw new Exception( "the Limits is not enough length." ); } d.MinLen = ls.Value[ i++ ]; fillDeclareLimits( d.Childs[ 0 ], ls, i ); } else if( d.DataType == DataTypes.Generic ) { if( i >= ls.Value.Length ) { throw new Exception( "the Limits is not enough length." ); } d.MinLen = ls.Value[ i++ ]; if( i >= ls.Value.Length ) { throw new Exception( "the Limits is not enough length." ); } d.MaxLen = ls.Value[ i++ ]; foreach( var cd in d.Childs ) { fillDeclareLimits( cd, ls, i ); } } }
// todo: 将类型声明尾部的 1组或多组 [???] 分离并返回 public static KeyValuePair<string, string> SplitTypeKeyword( string k, Declare d ) { int n = 0; while( d.DataType == DataTypes.Array ) { n += 2 + d.MinLen.ToString().Length; d = d.Childs[ 0 ]; } return new KeyValuePair<string, string>( k.Substring( 0, k.Length - n ), k.Substring( k.Length - n, n ) ); }
public static TagObject declare(this TagObject tag, Declare value) { tag.Declare = value; return tag; }