public void SetText(List <ITypeToken> tokens_, ITypeToken FormatPattern_) { List <string> str = new List <string>(); this.FormatPattern = FormatPattern_; this.Tokens = tokens_; if (this.Tokens != null && this.FormatPattern != null) { foreach (ITypeToken tt in this.Tokens) { if (tt != null) { str.Add(tt.Text); } else { str.Add(null); } } try { this.Text = new TextToken() { Text = string.Format(this.FormatPattern.Text, str.ToArray()) }; } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e.Message); } } }
///<summary>Defined NESTED, concatenates every command according to it format. ///Results concatenated according to passed FormatPettern. ///FULL concatenates all tokens from all commandBuilders according to new passed patterformat</summary> public string Build(List <ICommandBuilder> texts_, ITypeToken FormatPattern_) { this.FormatPattern = FormatPattern_; this.Tokens = new List <ITypeToken>(); List <ITypeToken> str = new List <ITypeToken>(); foreach (ICommandBuilder tb in texts_) { //build string tb.SetText(tb.Tokens, tb.FormatPattern); //add tokens to list this.Tokens.AddRange(tb.Tokens); //concatenate formats according to new, nested format str.Add(tb.FormatPattern); } string[] arr = (from s in str select s.Text).ToArray(); //add format concatenation //concatenate collection of formats according to format this.FormatPattern.Text = string.Format(this.FormatPattern.Text, arr); //recount foramt variables from 0 to max this.FormatPattern.Text = FormatStringReArrange(this.FormatPattern.Text); //build new string SetText(this.Tokens, this.FormatPattern); return(GetText()); }
public ITypeToken FromatFromTokenArray(List <ITypeToken> tokens_, ITypeToken delimeter_ = null) { ITypeToken res = _factory.NewToken(); delimeterCheck(delimeter_); if (tokens_ != null) { int cnt = tokens_.Where(s => s != null && s.Text != null).Count(); this.elements_ = new List <int>(cnt) { }; int i2 = 0; for (int i = 0; i < tokens_.Count; i++) { if (tokens_[i] != null && tokens_[i].Text != null) { this.elements_.Add(i2); i2 += 1; } } } res.Text = formatFromArray(); return(res); }
protected override TokenList Evaluate(ITypeToken first, ITypeToken last) { switch (first.Type) { case TokenType.IntToken: TypeToken<int> iFirst = (TypeToken<int>)first; switch (last.Type) { case TokenType.IntToken: return new TokenList(new IntToken(iFirst.Value + ((TypeToken<int>)last).Value)); case TokenType.DoubleToken: return new TokenList(new DoubleToken(iFirst.Value + ((TypeToken<double>)last).Value)); case TokenType.StringToken: return new TokenList(new StringToken(iFirst.Value + last.ToString())); } break; case TokenType.DoubleToken: TypeToken<double> dFirst = (TypeToken<double>)first; switch (last.Type) { case TokenType.IntToken: return new TokenList(new DoubleToken(dFirst.Value + ((TypeToken<int>)last).Value)); case TokenType.DoubleToken: return new TokenList(new DoubleToken(dFirst.Value + ((TypeToken<double>)last).Value)); case TokenType.StringToken: return new TokenList(new StringToken(dFirst.Value + last.ToString())); } break; case TokenType.StringToken: TypeToken<string> sFirst = (TypeToken<string>)first; return new TokenList(new StringToken(sFirst.Value + last)); } return base.Evaluate(first, last); }
//cocatenates URLbuilders Token collections from URLbuilders with format pattern public Textbuilder(List <ITextBuilder> texts_, ITypeToken FormatPattern_, BuildTypeFormates type_) { this.FormatPattern = FormatPattern_; this.Tokens = new List <ITypeToken>(); if (type_ == BuildTypeFormates.FULL) { this.FormatPattern = FormatPattern_; this.Tokens = texts_.SelectMany(s => s.Tokens).ToList(); SetText(this.Tokens, this.FormatPattern); } if (type_ == BuildTypeFormates.NESTED) { List <ITypeToken> str = new List <ITypeToken>(); foreach (ITextBuilder tb in texts_) { //build string tb.SetText(tb.Tokens, tb.FormatPattern); //add tokens to list this.Tokens.AddRange(tb.Tokens); //concatenate formats according to new, nested format str.Add(tb.FormatPattern); } string[] arr = (from s in str select s.Text).ToArray(); //add format concatenation //concatenate collection of formats according to format this.FormatPattern.Text = string.Format(this.FormatPattern.Text, arr); //recount foramt variables from 0 to max this.FormatPattern.Text = FormatStringReArrange(this.FormatPattern.Text); //build new string SetText(this.Tokens, this.FormatPattern); } }
protected override IToken Evaluate(ITypeToken first, ITypeToken last) { switch (first.Type) { case TokenType.IntToken: TypeToken<int> iFirst = (TypeToken<int>)first; switch (last.Type) { case TokenType.IntToken: return new IntToken(iFirst.Value / ((TypeToken<int>)last).Value); case TokenType.DoubleToken: return new DoubleToken(iFirst.Value / ((TypeToken<double>)last).Value); } break; case TokenType.DoubleToken: TypeToken<double> dFirst = (TypeToken<double>)first; switch (last.Type) { case TokenType.IntToken: return new DoubleToken(dFirst.Value / ((TypeToken<int>)last).Value); case TokenType.DoubleToken: return new DoubleToken(dFirst.Value / ((TypeToken<double>)last).Value); } break; case TokenType.StringToken: TypeToken<string> sFirst = (TypeToken<string>)first; switch (last.Type) { case TokenType.StringToken: return new StringToken(sFirst.Value.CountInstances(((TypeToken<string>)last).Value).ToString()); } break; } return base.Evaluate(first, last); }
public ITypeToken Get(Type type_) { ITypeToken token_ = null; types.TryGetValue(type_, out token_); return(token_); }
public ITypeToken Get(IOrientObject object_) { ITypeToken token_ = null; types.TryGetValue(object_.GetType(), out token_); return(token_); }
public CommandBuilder(ITokenMiniFactory tokenFactory_, IFormatFactory formatFactory_ , List <ICommandBuilder> command_, ITypeToken format_) { this._tokenMiniFactory = tokenFactory_; this._formatFactory = formatFactory_; formatGenerator = formatFactory_.FormatGenerator(tokenFactory_); TokenFormatConcatenation(command_, format_); }
//cocatenates URLbuilders Token collections from URLbuilders with format pattern public CommandBuilder(List <ICommandBuilder> texts_, ITypeToken FormatPattern_) { this.FormatPattern = FormatPattern_; TokenFormatConcatenation(texts_, FormatPattern_); //build new string SetText(this.Tokens, this.FormatPattern); }
public CommandBuilder(ITokenMiniFactory tokenFactory_, IFormatFactory formatFactory_ , List <ITypeToken> tokens_, ITypeToken format_ = null) { this._formatFactory = formatFactory_; this._tokenMiniFactory = tokenFactory_; formatGenerator = formatFactory_.FormatGenerator(tokenFactory_); AddTokens(tokens_); AddFormat(format_); }
public ITypeToken GetBase(Type type_) { ITypeToken token_ = null; Type tp = type_.BaseType; types.TryGetValue(tp, out token_); return(token_); }
protected override IToken Evaluate(ITypeToken operand) { switch (operand.Type) { case TokenType.IntToken: return new IntToken(-((IntToken)operand).Value); case TokenType.DoubleToken: return new DoubleToken(-((DoubleToken)operand).Value); } return base.Evaluate(operand); }
protected override TokenList Evaluate(ITypeToken operand) { switch (operand.Type) { case TokenType.IntToken: return new TokenList((IntToken)operand); case TokenType.DoubleToken: return new TokenList((DoubleToken)operand); } return base.Evaluate(operand); }
void delimeterCheck(ITypeToken delimeter_ = null) { placeholder = @"} {"; if (delimeter_ != null) { if (delimeter_.Text != null) { placeholder = string.Join("", "}", delimeter_.Text, "{"); } } }
public ITypeToken GetBase(IOrientObject object_) { ITypeToken token_ = null; Type tp = object_.GetType().BaseType; IOrientObject t2 = (IOrientObject)object_; types.TryGetValue(object_.GetType().BaseType, out token_); return(token_); }
protected override IToken Evaluate(ITypeToken operand) { switch (operand.Type) { case TokenType.IntToken: return (IntToken)operand; case TokenType.DoubleToken: return (DoubleToken)operand; } return base.Evaluate(operand); }
//property add public List <ITypeToken> Command(ITypeToken command_, IOrientObject orientObject, IOrientObject orientClass_, ITypeToken orientTypeClass_, bool mandatory = false, bool notNull = false) { List <ITypeToken> result = new List <ITypeToken>(); if (command_ is OrientCreateToken && orientObject is OrientProperty && orientClass_ is OrientClass) { result.Add(command_); result.Add(new OrientPropertyToken()); result.Add(typeConverter.Get(orientObject)); result.Add(new OrientDotToken()); result.Add(typeConverter.Get(orientClass_)); } if (mandatory) { //add itypetokens } return(result); }
//for create (Class,Vertex) command public List <ITypeToken> Command(ITypeToken command_, IOrientObject orientObject, ITypeToken orientContext = null) { List <ITypeToken> result = new List <ITypeToken>(); if (command_ is OrientCreateToken) { result.Add(command_); result.Add(typeConverter.GetBase(orientObject)); result.Add(typeConverter.Get(orientObject)); if (orientContext != null) { if (orientObject is OrientClass) { result.Add(new OrientExtendsToken()); } if (orientObject is OrientVertex) { result.Add(new OrientContentToken()); result.Add(orientContext); } } } if (command_ is OrientDeleteToken) { result.Add(command_); if (orientObject is OrientClass) { result.Add(new OrientClassToken()); result.Add(typeConverter.Get(orientObject)); } if (orientObject is OrientVertex || orientObject is OrientEdge) { result.Add(typeConverter.GetBase(orientObject)); result.Add(typeConverter.Get(orientObject)); if (orientContext != null) { result.Add(new OrientWhereToken()); result.Add(orientContext); } } } return(result); }
public CommandBuilder(ITokenMiniFactory tokenFactory_, IFormatFactory formatFactory_ , ITypeToken token_, ITypeToken format_ = null) { List <ITypeToken> tokens_ = new List <ITypeToken>(); tokens_.Add(token_); this._tokenMiniFactory = tokenFactory_; this._formatFactory = formatFactory_; formatGenerator = formatFactory_.FormatGenerator(tokenFactory_); AddTokens(tokens_); if (format_ != null) { AddFormat(format_); } else { AddFormat(formatGenerator.FromatFromTokenArray(tokens_)); } }
protected override IToken Evaluate(ITypeToken first, ITypeToken last) { switch (first.Type) { case TokenType.IntToken: TypeToken<int> iFirst = (TypeToken<int>)first; switch (last.Type) { case TokenType.IntToken: return new IntToken(iFirst.Value * ((TypeToken<int>)last).Value); case TokenType.DoubleToken: return new DoubleToken(iFirst.Value * ((TypeToken<double>)last).Value); case TokenType.StringToken: return new StringToken(StringUtils.CreateString(last.ToString(), iFirst.Value)); } break; case TokenType.DoubleToken: TypeToken<double> dFirst = (TypeToken<double>)first; switch (last.Type) { case TokenType.IntToken: return new DoubleToken(dFirst.Value * ((TypeToken<int>)last).Value); case TokenType.DoubleToken: return new DoubleToken(dFirst.Value * ((TypeToken<double>)last).Value); case TokenType.StringToken: return new StringToken(StringUtils.CreateString(last.ToString(), dFirst.Value)); } break; case TokenType.StringToken: TypeToken<string> sFirst = (TypeToken<string>)first; switch (last.Type) { case TokenType.IntToken: return new StringToken(StringUtils.CreateString(sFirst.Value, ((TypeToken<int>)last).Value)); case TokenType.DoubleToken: return new StringToken(StringUtils.CreateString(sFirst.Value, ((TypeToken<double>)last).Value)); } break; } return base.Evaluate(first, last); }
public void SetText(List <ITypeToken> tokens_, ITypeToken FormatPattern_) { List <string> str = new List <string>(); this.FormatPattern = FormatPattern_; this.Tokens = tokens_; foreach (ITypeToken tt in this.Tokens) { if (tt != null) { str.Add(tt.Text); } else { str.Add(null); } } this.Text = new TextToken() { Text = string.Format(this.FormatPattern.Text, str.ToArray()) }; }
public string Add(IOrientObject obj_, ITypeToken from, ITypeToken to) { string content = jm.SerializeObject(obj_); List <ITypeToken> commandTk = tb.Command(new OrientCreateToken(), obj_, from, to, new TextToken() { Text = content }); string command = txb.Build(commandTk, new OrientTokenFormatFromListGenerate(commandTk)); queryUrl = CommandUrl + "/" + command; owm.Authenticate(AuthUrl, new NetworkCredential(ConfigurationManager.AppSettings["ParentLogin"], ConfigurationManager.AppSettings["ParentPassword"])); string resp = ir.ReadResponse( owm.GetResponse(queryUrl, new POST().Text) ); return(resp); }
public void AddFormat(ITypeToken formatPatern_) { if (this.FormatPattern != null) { if (formatPatern_ != null) { this.FormatPattern.Text += formatPatern_.Text; } } //<<< change else { if (formatPatern_ != null && formatPatern_.Text != string.Empty) { this.FormatPattern = formatPatern_; } else { this.FormatPattern = this.formatGenerator.FromatFromTokenArray(this.Tokens); } } this.FormatPattern.Text = FormatStringReArrange(this.FormatPattern.Text); }
//add edge with IDs public List <ITypeToken> Command(ITypeToken command_, IOrientObject orientObject, ITypeToken from, ITypeToken to, ITypeToken orientContext = null) { List <ITypeToken> result = new List <ITypeToken>(); if (command_ is OrientCreateToken) { result.Add(command_); if (orientObject is OrientEdge) { result.Add(typeConverter.GetBase(orientObject)); result.Add(typeConverter.Get(orientObject)); result.Add(new OrientFromToken()); result.Add(from); result.Add(new OrientToToken()); result.Add(to); if (orientContext != null) { result.Add(new OrientContentToken()); result.Add(orientContext); } } } return(result); }
public ICommandBuilder CommandBuilder(ITokenMiniFactory tokenFactory_, IFormatFactory formatFactory_ , List <ITypeToken> tokens_, ITypeToken format_) { return(new CommandBuilder(tokenFactory_, formatFactory_, tokens_, format_)); }
public void BindBuilders(List <ICommandBuilder> texts_, ITypeToken FormatPattern_) { TokenFormatConcatenation(texts_, FormatPattern_); }
protected override TokenList Evaluate(ITypeToken first, ITypeToken last) { return new TokenList(new StringToken(first.Text + last.Text)); }
//concatenates Tokens from colection with format pattern public Textbuilder(List <ITypeToken> tokens_, ITypeToken FormatPattern_) { this.FormatPattern = FormatPattern_; this.Tokens = tokens_; SetText(this.Tokens, this.FormatPattern); }
protected override IToken Evaluate(ITypeToken token) { return new ExpressionToken(null, this, token); }
public void Add(Type type_, ITypeToken token_) { this.types.Add(type_, token_); }
public ITypeToken FromatFromTokenArray(List <ICommandBuilder> builders_, ITypeToken delimeter_ = null) { ITypeToken res = _factory.NewToken(); this.elements_ = new List <int>() { }; string result_ = null; delimeterCheck(delimeter_); if (builders_ != null) { int i2 = 0; foreach (ICommandBuilder cb_ in builders_) { if (cb_ != null) { if (cb_.Tokens != null) { this.elements_.Add(i2); i2 += 1; } } } //for (int i=0; i < builders_.Count; i++) //{ // if (builders_[i].Tokens != null) // { // this.elements_.Add(i2); // i2 += 1; // } //} } if (this.elements_.Count() > 0) { result_ = formatFromArray(); //List<ITypeToken> formats_=new List<ITypeToken>(); //foreach(ICommandBuilder b in builders_) //{ // if (b != null) // { // if (b.FormatPattern != null) {formats_.Add(b.FormatPattern);} // else // { // formats_.Add( // FromatFromTokenArray(b.Tokens, (ITypeToken)null) // ); // } // } //} //string[] formatsArr=(from s in formats_ select s.Text).ToArray(); //res.Text=string.Format(result_, formatsArr); res.Text = result_; } return(res); }
public OrientDeleteClauseBuilder(List <ITypeToken> tokens_, ITypeToken format_) : base(tokens_, format_) { }
public OrientCommandURIBuilder(List <ITextBuilder> texts_, ITypeToken FormatPattern_, Textbuilder.BuildTypeFormates type_) : base(texts_, FormatPattern_, type_) { }
public string Build(List <ITypeToken> tokens_, ITypeToken FormatPattern_) { BindTokens(tokens_); BindFormat(FormatPattern_); return(Build().GetText()); }
protected virtual IToken Evaluate(ITypeToken first, ITypeToken last) { throw new Exception($"Operation binary {Text} not supported for ({first.Type}, {last.Type})."); }
protected override IToken Evaluate(ITypeToken first, ITypeToken last) { return new StringToken(first.Text + last.Text); }
protected virtual IToken Evaluate(ITypeToken token) { throw new Exception($"Operation unary {Text} not supported for {token.Type}."); }
public OrientCommandBuilder(List <ITypeToken> tokens_, ITypeToken FormatPattern_) : base(tokens_, FormatPattern_) { }
internal void TokenFormatConcatenation(List <ICommandBuilder> texts_, ITypeToken FormatPattern_ = null) { List <ITypeToken> tempTokens = new List <ITypeToken>(); List <ITypeToken> str = new List <ITypeToken>(); ITypeToken newFromat = _tokenMiniFactory.NewToken(); foreach (ICommandBuilder tb in texts_) { if (tb != null) { if (tb.FormatPattern == null) { tb.FormatPattern = formatGenerator.FromatFromTokenArray(tb.Tokens); } if (tb.Tokens != null) { //build string tb.SetText(tb.Tokens, tb.FormatPattern); //add tokens to list tempTokens.AddRange(tb.Tokens); //concatenate formats according to new, nested format str.Add(tb.FormatPattern); } } } //concatenating of all formatpatterns string[] arr = (from s in str select s.Text).ToArray(); this.Tokens = tempTokens; if (FormatPattern_ == null) { //if (this.FormatPattern==null || this.FormatPattern.Text == null) //{ //try to generate if no format passed try { if (formatGenerator == null) { throw new Exception("No ForamtPattern no FormatGenerator not binded"); } FormatPattern = formatGenerator.FromatFromTokenArray(str, null); } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e.Message); } //} } else { FormatPattern = FormatPattern_; } try { newFromat.Text = FormatStringReArrange(string.Format(FormatPattern.Text, arr)); this.Tokens = tempTokens; this.FormatPattern = newFromat; } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e.Message); } }
public void BindFormat(ITypeToken formatPatern_) { this.FormatPattern = formatPatern_; this.FormatPattern.Text = FormatStringReArrange(this.FormatPattern.Text); }