private string[] ConstructCommandText(TikCommandParameterFormat defaultParameterFormat) { EnsureCommandTextSet(); string commandText = CommandText; if (!StringHelper.IsNullOrWhiteSpace(commandText) && !commandText.Contains("\n") && !commandText.StartsWith("/")) { commandText = "/" + commandText; } List <string> result = new List <string> { commandText }; //parameters result.AddRange(_parameters.Select(p => { switch (ResolveParameterFormat(defaultParameterFormat, _defaultParameterFormat, p.ParameterFormat)) { case TikCommandParameterFormat.Filter: return(string.Format("?{0}={1}", p.Name, p.Value)); case TikCommandParameterFormat.NameValue: return(string.Format("={0}={1}", p.Name, p.Value)); //case TikCommandParameterFormat.NameOnly: // return string.Format("={0}", p.Name); default: throw new NotImplementedException(); } })); return(result.ToArray()); }
public ITikCommand CreateCommand(string commandText, TikCommandParameterFormat defaultParameterFormat, params ITikCommandParameter[] parameters) { var result = CreateCommand(commandText, parameters); result.DefaultParameterFormat = defaultParameterFormat; return(result); }
public ITikCommand CreateCommandAndParameters(string commandText, TikCommandParameterFormat defaultParameterFormat, params string[] parameterNamesAndValues) { var result = CreateCommandAndParameters(commandText, parameterNamesAndValues); result.DefaultParameterFormat = defaultParameterFormat; return(result); }
public ITikCommandParameter CreateParameter(string name, string value, TikCommandParameterFormat parameterFormat) { var result = CreateParameter(name, value); result.ParameterFormat = parameterFormat; return(result); }
public ITikCommand CreateCommand(TikCommandParameterFormat defaultParameterFormat) { var result = CreateCommand(); result.DefaultParameterFormat = defaultParameterFormat; return(result); }
public ITikCommandParameter AddParameter(string name, string value, TikCommandParameterFormat parameterFormat) { ITikCommandParameter result = AddParameter(name, value); result.ParameterFormat = parameterFormat; return(result); }
/// <summary> /// Initializes a new instance of the <see cref="TikEntityAttribute"/> class. /// </summary> /// <param name="entityPath">The entity path in API notation (/ip/firewall/mangle).</param> /// <param name="loadCommand">Sufix added to entity path when loading. eq. /print</param> /// <param name="loadDefaultParameneterFormat">Parameter format (when parameter itself is set to <see cref="TikCommandParameterFormat.Default"/>) during load operation.</param> /// <param name="isReadOnly">If the whole entity is R/O.</param> /// <param name="isOrdered">If entity list is ordered (move operation does make sense).</param> /// <param name="includeDetails">If entity should be loaded with =detail= option.</param> /// <param name="isSingleton">If entity exists in single instance</param> public TikEntityAttribute(string entityPath, string loadCommand, TikCommandParameterFormat loadDefaultParameneterFormat, bool isReadOnly, bool isOrdered, bool includeDetails, bool isSingleton) { Guard.ArgumentNotNullOrEmptyString(entityPath, "entityPath"); EntityPath = entityPath; LoadCommand = loadCommand; LoadDefaultParameneterFormat = loadDefaultParameneterFormat; IsReadOnly = isReadOnly; IsOrdered = isOrdered; IncludeDetails = includeDetails; IsSingleton = isSingleton; }
private TikCommandParameterFormat ResolveParameterFormat(TikCommandParameterFormat usecaseDefaultFormat, TikCommandParameterFormat commandDefaultFormat, TikCommandParameterFormat parameterFormat) { if (parameterFormat != TikCommandParameterFormat.Default) { return(parameterFormat); } else if (commandDefaultFormat != TikCommandParameterFormat.Default) { return(commandDefaultFormat); } else if (usecaseDefaultFormat != TikCommandParameterFormat.Default) { return(usecaseDefaultFormat); } else { return(TikCommandParameterFormat.NameValue); } }
private TikCommandParameterFormat ResolveParameterFormat(TikCommandParameterFormat usecaseDefaultFormat, TikCommandParameterFormat commandDefaultFormat, ITikCommandParameter parameter) { if (parameter.ParameterFormat != TikCommandParameterFormat.Default) { return(parameter.ParameterFormat); } else if (parameter.Name == TikSpecialProperties.Tag) { return(TikCommandParameterFormat.Tag); //.tag=1231 } else if (commandDefaultFormat != TikCommandParameterFormat.Default) { return(commandDefaultFormat); } else if (usecaseDefaultFormat != TikCommandParameterFormat.Default) { return(usecaseDefaultFormat); } else { return(TikCommandParameterFormat.NameValue); } }
public ApiCommandParameter(string name, string value, TikCommandParameterFormat parameterFormat) : this(name, value) { _parameterFormat = parameterFormat; }
private string[] ConstructCommandText(TikCommandParameterFormat defaultParameterFormat, params ITikCommandParameter[] additionalParamemeters) { EnsureCommandTextSet(); foreach (var additionalParameter in additionalParamemeters) { if (_parameters.Any(p => p.Name == additionalParameter.Name)) { throw new ArgumentException($"Parameter {additionalParameter.Name} already defined (could not be additionalParameter / proplist / etc.)."); } } string commandText = CommandText; if (!StringHelper.IsNullOrWhiteSpace(commandText) && !commandText.Contains("\n") && !commandText.StartsWith("/")) { commandText = "/" + commandText; } List <string> result; if (commandText.Contains('\n')) { result = new List <string>(commandText.Split('\n').Select(row => row.Trim())); } else { result = new List <string> { commandText }; } //parameters result.AddRange(_parameters.Concat(additionalParamemeters).Select(p => { if (p.Name.StartsWith("=")) //NameValue format in parameter name { return(string.Format("{0}={1}", p.Name, p.Value)); } else if (p.Name.StartsWith("?")) //Filter format in parameter name { return(string.Format("{0}={1}", p.Name, p.Value)); } else { switch (ResolveParameterFormat(defaultParameterFormat, _defaultParameterFormat, p)) { case TikCommandParameterFormat.Filter: return(string.Format("?{0}={1}", p.Name, p.Value)); case TikCommandParameterFormat.NameValue: return(string.Format("={0}={1}", p.Name, p.Value)); case TikCommandParameterFormat.Tag: return(string.Format("{0}={1}", p.Name, p.Value)); //case TikCommandParameterFormat.NameOnly: // return string.Format("={0}", p.Name); default: throw new NotImplementedException(); } } })); return(result.ToArray()); }
public ITikCommand WithParameter(string name, string value, TikCommandParameterFormat parameterFormat) { AddParameter(name, value, parameterFormat); return(this); }
private static ITikCommand CreateLoadCommandWithFilter <TEntity> (ITikConnection connection, string commandSufix, TikCommandParameterFormat defaultParameterFormat, ITikCommandParameter[] parameters) { var metadata = TikEntityMetadataCache.GetMetadata <TEntity>(); ITikCommand command = connection.CreateCommand(metadata.EntityPath + commandSufix, defaultParameterFormat); // =detail= if (metadata.IncludeDetails) { command.AddParameter("detail", "", TikCommandParameterFormat.NameValue); } //.proplist if (metadata.IncludeProplist) { command.AddParameter(TikSpecialProperties.Proplist, string.Join(",", metadata.Properties.Select(prop => prop.FieldName).ToArray()), TikCommandParameterFormat.NameValue); } //filter //parameters if (parameters != null) { foreach (ITikCommandParameter param in parameters) { command.Parameters.Add(param); } } return(command); }
public ITikCommand CreateCommand(TikCommandParameterFormat defaultParameterFormat) { var result = CreateCommand(); result.DefaultParameterFormat = defaultParameterFormat; return result; }
public ApiCommand(ITikConnection connection, string commandText, TikCommandParameterFormat defaultParameterFormat, params ITikCommandParameter[] parameters) : this(connection, commandText, defaultParameterFormat) { _parameters.AddRange(parameters); }
public ITikCommand CreateCommandAndParameters(string commandText, TikCommandParameterFormat defaultParameterFormat, params string[] parameterNamesAndValues) { var result = CreateCommandAndParameters(commandText, parameterNamesAndValues); result.DefaultParameterFormat = defaultParameterFormat; return result; }
public ApiCommand(ITikConnection connection, string commandText, TikCommandParameterFormat defaultParameterFormat) : this(connection, defaultParameterFormat) { CommandText = commandText; }
public ApiCommand(ITikConnection connection, TikCommandParameterFormat defaultParameterFormat) : this(defaultParameterFormat) { Connection = connection; }
public ApiCommand(TikCommandParameterFormat defaultParameterFormat) { _defaultParameterFormat = defaultParameterFormat; }
public ITikCommandParameter CreateParameter(string name, string value, TikCommandParameterFormat parameterFormat) { var result = CreateParameter(name, value); result.ParameterFormat = parameterFormat; return result; }
public ITikCommandParameter AddParameter(string name, string value, TikCommandParameterFormat parameterFormat) { ITikCommandParameter result = AddParameter(name, value); result.ParameterFormat = parameterFormat; return result; }
public ApiCommand() { _defaultParameterFormat = TikCommandParameterFormat.Default; }
public ITikCommand CreateCommand(string commandText, TikCommandParameterFormat defaultParameterFormat, params ITikCommandParameter[] parameters) { var result = CreateCommand(commandText, parameters); result.DefaultParameterFormat = defaultParameterFormat; return result; }
private string[] ConstructCommandText(TikCommandParameterFormat defaultParameterFormat) { EnsureCommandTextSet(); string commandText = CommandText; if (!StringHelper.IsNullOrWhiteSpace(commandText) && !commandText.Contains("\n") && !commandText.StartsWith("/")) commandText = "/" + commandText; List<string> result; if (commandText.Contains('\n')) { result = new List<string>(commandText.Split('\n').Select(row => row.Trim())); } else { result = new List<string> { commandText }; } //parameters result.AddRange(_parameters.Select(p => { switch (ResolveParameterFormat(defaultParameterFormat, _defaultParameterFormat, p.ParameterFormat)) { case TikCommandParameterFormat.Filter: return string.Format("?{0}={1}", p.Name, p.Value); case TikCommandParameterFormat.NameValue: return string.Format("={0}={1}", p.Name, p.Value); //case TikCommandParameterFormat.NameOnly: // return string.Format("={0}", p.Name); default: throw new NotImplementedException(); } })); return result.ToArray(); }
private TikCommandParameterFormat ResolveParameterFormat(TikCommandParameterFormat usecaseDefaultFormat, TikCommandParameterFormat commandDefaultFormat, TikCommandParameterFormat parameterFormat) { if (parameterFormat != TikCommandParameterFormat.Default) return parameterFormat; else if (commandDefaultFormat != TikCommandParameterFormat.Default) return commandDefaultFormat; else if (usecaseDefaultFormat != TikCommandParameterFormat.Default) return usecaseDefaultFormat; else return TikCommandParameterFormat.NameValue; }