public void AddWithValue(string key, string value, IStringConverter strConv) { var data = new MyStructData(); if (value == "") { data.myString = ""; data.type = MySqlDataType.VAR_STRING; } else if (value != null) { //replace some value if (strConv != null) { AddWithValue(key, strConv.WriteConv(value)); return; } else { data.myString = value.Replace("\'", "\\\'"); data.type = MySqlDataType.VAR_STRING; } } else { data.myString = null; data.type = MySqlDataType.NULL; } _values[key] = data; }
/// <summary> /// Tries to parse the dataFields using the delimiter and fields. If true, /// result will hold an IStringConverter that can convert all valid input /// in the form of dataFields, only extracting fields. /// </summary> /// <param name="dataFields">Input string</param> /// <param name="delimiter">Seperator</param> /// <param name="fields">Required (conversion) fields</param> /// <param name="result">Converter</param> /// <param name="options">Parseoptions</param> /// <returns>Parse is possible</returns> public static Boolean TryParse(String dataFields, Char delimiter, String[] fields, out IStringConverter result, ParseOptions options = ParseOptions.CleanupQuotes) { result = new DelimiterConverter(delimiter); var splittedDataFields = new Queue<String>(dataFields.Split(delimiter)); var fieldsQueue = new Queue<String>(fields); while (fieldsQueue.Count > 0 && splittedDataFields.Count > 0) { var field = fieldsQueue.Peek(); var data = splittedDataFields.Dequeue().Trim(); if (options.HasFlag(ParseOptions.GlueStrings)) while (data.StartsWith("\"") && !data.EndsWith("\"") && splittedDataFields.Count > 0) data = data + "," + splittedDataFields.Dequeue().Trim(); if (options.HasFlag(ParseOptions.CleanupQuotes)) data = data.Replace("\"", "").Trim(); (result as DelimiterConverter).PushMask(field == data); if (field == data) fieldsQueue.Dequeue(); } return fieldsQueue.Count == 0; }
static SisoEnvironment() { Formatting = new SisoDbFormatting(); StringConverter = new StringConverter(Formatting); StringComparer = StringComparer.InvariantCultureIgnoreCase; HashService = new Crc32HashService(); }
public static void UnregisterStringConverter(IStringConverter stringConverter) { lock (_staticLock) { _stringConverters?.Remove(stringConverter); } }
public EmployeeController(IConversation conversation, IMappingEngine mapper, EmployeeRepository repository, IValidator validator, IStringConverter<Employee> stringConverter) { _conversation = conversation; _mapper = mapper; _repository = repository; _validator = validator; _stringConverter = stringConverter; }
public OrderDetailController(IConversation conversation, IMappingEngine mapper, OrderDetailRepository repository, IValidator validator, IStringConverter<OrderDetail> stringConverter) { _conversation = conversation; _mapper = mapper; _repository = repository; _validator = validator; _stringConverter = stringConverter; }
public RegionController(IConversation conversation, IMappingEngine mapper, RegionRepository repository, IValidator validator, IStringConverter<Region> stringConverter) { _conversation = conversation; _mapper = mapper; _repository = repository; _validator = validator; _stringConverter = stringConverter; }
public ProductController(IConversation conversation, IMappingEngine mapper, ProductRepository repository, IValidator validator, IStringConverter<Product> stringConverter) { _conversation = conversation; _mapper = mapper; _repository = repository; _validator = validator; _stringConverter = stringConverter; }
public TerritoryController(IConversation conversation, IMappingEngine mapper, TerritoryRepository repository, IValidator validator, IStringConverter<Territory> stringConverter) { _conversation = conversation; _mapper = mapper; _repository = repository; _validator = validator; _stringConverter = stringConverter; }
public ConfiguredFileSource(IStringPersistence stringPersistence, IStringConverter <TDTO> stringConverter) { FileSource <TDTO> fileSource = new FileSource <TDTO>(stringPersistence, stringConverter); DataSourceLoad = fileSource; DataSourceSave = fileSource; DataSourceCRUD = new DataSourceCRUDNotSupported <TDTO>(); }
public CustomerController(IConversation conversation, IMappingEngine mapper, CustomerRepository repository, IValidator validator, IStringConverter<Customer> stringConverter) { _conversation = conversation; _mapper = mapper; _repository = repository; _validator = validator; _stringConverter = stringConverter; }
public Settings(string bindingPath = null, IStringConverter converter = null) { _converter = converter ?? new InvariantStringConverter(); var comparer = StringComparer.InvariantCultureIgnoreCase; _cache = new Dictionary <string, CacheEntry>(comparer); _bindingPath = bindingPath ?? GetBindingPath(); }
protected virtual bool TryGetRawValue(TextBox textBox, IStringConverter converter, out object rawValue) { rawValue = textBox.GetRawValue(); if (rawValue != RawValueTracker.Unset) { return(true); } return(false); }
public static void RegisterStringConverter(IStringConverter stringConverter) { lock (_staticLock) { _stringConverters = _stringConverters ?? new List <IStringConverter>(); _stringConverters.Add(stringConverter); } }
protected Settings(string bindingPath = null, IStringConverter converter = null) { _converter = converter ?? new InvariantStringConverter(); var comparer = StringComparer.InvariantCultureIgnoreCase; _cache = new Dictionary <string, CacheEntry>(comparer); SetBindingPath(bindingPath); Environment = ""; }
/// <summary> /// Register a new converter for a type /// </summary> /// <param name="type"></param> /// <param name="converter"></param> /// <param name="overwrite">false, does not replace existing converter</param> /// <returns></returns> public bool Register(Type type, IStringConverter converter, bool overwrite = true) { if (_items.ContainsKey(type) && !overwrite) { return(false); } _items[type] = converter; return(true); }
/// <summary> /// Try to get IStringConverter /// </summary> /// <param name="converter"></param> /// <returns>true if found</returns> public bool TryGetConverter(Type type, out IStringConverter converter) { if (_items.ContainsKey(type) && _items[type] is IStringConverter c) { converter = c; return(true); } converter = StringConverterFactory.Empty(type); return(false); }
public StringList(IPointerTable pointerTable, IStringConverter stringConverter, int maxSize, int capacity) : base(capacity) { _pointerTable = pointerTable; _maxSize = maxSize; _stringConverter = stringConverter; var stringTableStart = pointerTable.Min(p => p.Offset); _currentSize = _pointerTable.Max(p => _stringConverter.GetLength(p) + p.Offset - stringTableStart); }
protected object ConverItem(string value, out bool succeeded) { succeeded = ConverterFactory.Converters.ContainsKey(this.ValueType); if (!succeeded) { return(null); } IStringConverter converter = ConverterFactory.Converters[this.ValueType]; return(converter.ConvertTo(value, out succeeded)); }
// .cctor static StringConvertManager() { // Create new pow2 converter instance IStringConverter pow2StringConverter = new Pow2StringConverter(); // Create new classic converter instance IStringConverter classicStringConverter = new ClassicStringConverter(pow2StringConverter); // Fill publicity visible converter fields ClassicStringConverter = classicStringConverter; FastStringConverter = new FastStringConverter(pow2StringConverter, classicStringConverter); }
/// <summary> /// Try to get IStringConverter<T> /// </summary> /// <param name="converter"></param> /// <typeparam name="T"></typeparam> /// <returns>true if found</returns> public bool TryGetConverter <T>(out IStringConverter <T> converter) { var type = typeof(T); if (_items.ContainsKey(type) && _items[type] is IStringConverter <T> c) { converter = c; return(true); } converter = StringConverterFactory.Empty <T>(); return(false); }
public static string ReadLengthCodedString(this BufferReader reader, IStringConverter strConverter) { //var length = this.parseLengthCodedNumber(); uint length = ReadLengthCodedNumber(reader, out bool isNull); //if (length === null) { // return null; //} return(isNull ? null : ReadString(reader, length, strConverter)); //return this.parseString(length); }
protected virtual bool TryUpdateTextBox(TextBox textBox, IStringConverter converter, object rawValue) { string formatted = converter.ToFormattedString(rawValue, textBox) ?? String.Empty; if (formatted != textBox.Text) { textBox.SetIsUpdating(true); textBox.SetTextUndoable(formatted); textBox.SetIsUpdating(false); return(true); } return(false); }
public void Convert_To_When_Called_Several_Ways_Returns_Expected_Results() { string testString = "123"; int testResult = 123; // Happy Path (_converter.Convert.To) Assert.That(_converter.Convert(testString).To <int>(), Is.TypeOf <int>().And.EqualTo(testResult)); // Sad Path (stored converter no long just returns default when not provided a string; string is stored internally) IStringConverter newConverter = _converter.Convert(testString); Assert.That(_converter.To <int>(), Is.TypeOf <int>().And.EqualTo(default(int))); Assert.That(newConverter.To <int>(), Is.TypeOf <int>().And.EqualTo(testResult)); }
public VirtualMemory(string filePath, int pageCapacity, int pageNumber, bool overwrite = true, IIntConverter intConverter = null, IBoolConverter boolConverter = null, IStringConverter stringConverter = null) { var simpleConverter = new SimpleConverter(); _intConverter = intConverter ?? simpleConverter; _boolConverter = boolConverter ?? simpleConverter; _stringConverter = stringConverter ?? simpleConverter; _markerSize = _stringConverter.ToBytes(_marker).Length; var exist = !overwrite && File.Exists(filePath); _memoryFile = new FileStream(filePath, overwrite ? FileMode.Create : FileMode.OpenOrCreate, FileAccess.ReadWrite); _memoryFile.Seek(0, SeekOrigin.Begin); _br = new BinaryReader(_memoryFile); _bw = new BinaryWriter(_memoryFile); PageCapacity = pageCapacity; PageNumber = pageNumber; if (exist) { var marker = Encoding.Unicode.GetString(_br.ReadBytes(_markerSize)); var tempCapacity = _intConverter.ToInt(_br.ReadBytes(_intConverter.IntSize)); var tempNumber = _intConverter.ToInt(_br.ReadBytes(_intConverter.IntSize)); if (marker != _marker || tempCapacity != pageCapacity || tempNumber != pageNumber) { throw new FileLoadException(); } LoadPage(0); } else { CurrentPage = new MemoryPage(0, PageCapacity); _bw.Write(_stringConverter.ToBytes(_marker)); _bw.Write(_intConverter.ToBytes(PageCapacity)); _bw.Write(_intConverter.ToBytes(PageNumber)); for (int i = 0; i < PageNumber; i++) { WritePage(i); } } }
public void get(uint row, uint column, IStringConverter conv) { if (Rows.Count <= row) { return; } CsvRow r = Rows[(int)row]; CsvColumn c = r.getColumn(column); if (c == null) { return; } c.get(conv); }
private void ApplyStringConverter(IStringConverter converter) { int startPos = ActiveTextAreaControl.SelectionManager.SelectionCollection[0].Offset; int length = ActiveTextAreaControl.SelectionManager.SelectionCollection[0].Length; if (startPos >= 0) { string selection = ActiveTextAreaControl.SelectionManager.SelectedText; string newSelection = converter.Convert(startPos, selection); if ((newSelection != null) && (selection != newSelection)) { Document.Replace(startPos, selection.Length, newSelection); SetSelection(startPos, newSelection.Length); } } }
public MethodCache(Type inComponentType, IStringConverter inConverter) { if (inConverter == null) { throw new ArgumentNullException("inConverter"); } if (inComponentType == null) { throw new ArgumentNullException("inComponentType"); } m_Types = new Dictionary <Type, TypeDescription>(); m_StringConverter = inConverter; m_StringSplitter = new StringUtils.ArgsList.Splitter(true); m_ComponentType = inComponentType; }
/// <summary> /// settings loaded from a file /// </summary> /// <param name="fileName">file name</param> /// <param name="converter"></param> /// <param name="deserializer">deserializer</param> public XmlFileSettings(string fileName, IStringConverter converter, IGenericDeserializer deserializer) : base(converter, deserializer) { try { fileName = System.IO.Path.GetFullPath(fileName); var content = File.ReadAllBytes(fileName); _root = XDocument.Load(new MemoryStream(content)).Root; Identity = this.GetIdentitySource(fileName); Path = System.IO.Path.GetDirectoryName(fileName); _fm = this.GetMonitoring(fileName, content); } catch(SystemException ex) { throw new ApplicationException(string.Format("Unable to load file `{0}'", fileName), ex); } }
public XmlSystemSettings(string sectionName, IStringConverter converter, IGenericDeserializer deserializer) : base(converter, deserializer) { _sectionName = sectionName; var confFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; confFile = System.IO.Path.GetFullPath(confFile); _directory = System.IO.Path.GetDirectoryName(confFile); try { var section = ConfigurationManager.GetSection(_sectionName) as PlainXmlSection; if(section == null || section.PlainXml == null) throw new FormatException("section not found"); _root = section.PlainXml.Root; } catch(SystemException ex) { throw new ApplicationException(string.Format("Unable to system section `{0}'", sectionName), ex); } }
public IniFileSettings(string fileName, IStringConverter converter, IGenericDeserializer deserializer) : base(converter, deserializer) { try { fileName = System.IO.Path.GetFullPath(fileName); var content = File.ReadAllBytes(fileName); var context = new ParseContext(); context.ParseSource(Encoding.UTF8.GetString(content)); _sections = new List<Section>(context.Sections); Identity = this.GetIdentitySource(fileName); Path = System.IO.Path.GetDirectoryName(fileName); _fm = this.GetMonitoring(fileName, content); } catch(SystemException ex) { throw new ApplicationException(string.Format("Unable to load file `{0}'", fileName), ex); } }
protected bool ParseParameters(IStringConverter inConverter) { for (int i = 0; i < m_Parameters.Length; ++i) { ParameterInfo info = m_Parameters[i]; if (i == 0) { m_ContextBind = info.GetCustomAttribute <BindContextAttribute>(); if (m_ContextBind != null) { m_ContextOffset = 1; continue; } } Type paramType = info.ParameterType; if (!inConverter.CanConvertTo(paramType)) { return(false); } if ((info.Attributes & ParameterAttributes.HasDefault) != 0) { if (m_DefaultArguments == null) { m_DefaultArguments = new object[m_Parameters.Length]; } m_DefaultArguments[i] = info.DefaultValue; } else { m_RequiredParameterCount++; } } return(true); }
public JsonFileSettings(string fileName, IStringConverter converter, IGenericDeserializer deserializer) : base(converter, deserializer) { try { fileName = System.IO.Path.GetFullPath(fileName); var content = File.ReadAllBytes(fileName); var val = JValue.Parse(Encoding.UTF8.GetString(content)); if (val.Type != TokenType.Object) throw new FormatException("required json object in content"); _obj = (JObject)val; Identity = this.GetIdentitySource(fileName); Path = System.IO.Path.GetDirectoryName(fileName); _fm = this.GetMonitoring(fileName, content); } catch(SystemException ex) { throw new ApplicationException(string.Format("Unable to load file `{0}'", fileName), ex); } }
/// <summary> /// Creates new <see cref="ClassicStringConverter" /> instance. /// </summary> /// <param name="pow2StringConverter">Converter for pow2 case.</param> public ClassicStringConverter(IStringConverter pow2StringConverter) : base(pow2StringConverter) { }
public void SetConverter(IStringConverter stringConverter) { _stringConverter = stringConverter; }
public static string ReadString(this BufferReader reader, uint length, IStringConverter strConverter) { return strConverter.Conv(reader.ReadBytes((int)length)); }
/// <summary> /// 分析对话内容 /// </summary> /// <param name="runtime">脚本运行环境</param> /// <param name="raw">原始对话内容</param> /// <param name="language">语言(不提供则使用脚本运行环境的语言)</param> /// <returns></returns> public static (List <IDialogueItem> Content, bool NoWait, bool NoClear) CreateDialogueContent(ScriptRuntime runtime, IStringConverter raw, string language = null) { var result = new List <IDialogueItem>(); var content = new StringBuilder(); var style = new StyleList(); var noWait = false; var noClear = false; var i = -1; language = language ?? runtime.ActiveLanguage; var data = raw.ConvertToString(language); if (data.StartsWith("[noclear]", StringComparison.OrdinalIgnoreCase)) { noClear = true; i = 8; } void FlushCache() { result.Add(style.Combine(content.ToString())); content.Clear(); } void ApplyDefault(string command) { content.Append($"[{command}]"); } for (; ++i < data.Length;) { switch (data[i]) { // 转义字符 case '\\' when i < data.Length - 1: switch (data[i + 1]) { case 'n': content.Append('\n'); break; case 't': content.Append('\t'); break; case 's': content.Append(' '); break; default: content.Append(data[i + 1]); break; } ++i; break; // 最后一个字符是[时的容错处理 case '[' when i == data.Length - 1: content.Append('['); break; // 指令 case '[': var endIndex = data.IndexOf(']', i + 1); if (endIndex <= i) // 容错处理 { content.Append('['); break; } var command = data.Substring(i + 1, endIndex - i - 1); i = endIndex; if (string.IsNullOrEmpty(command)) // 空指令不处理 { content.Append("[]"); } else if (command.StartsWith("@#")) // 常量 { var constantName = command.Substring(2); if (string.IsNullOrEmpty(constantName)) { throw new ArgumentException($"Unable to create dialog command: missing constant name at {i}"); } var constant = runtime.ActiveScope?.FindVariable(constantName, true, VariableSearchMode.OnlyConstant); if (constant == null) { ApplyDefault(command); } else { content.Append(constant.Value is IStringConverter stringConverter ? stringConverter.ConvertToString() : constant.Value.ToString()); } } else if (command.StartsWith("@")) // 变量 { var variableName = command.Substring(1); if (string.IsNullOrEmpty(variableName)) { throw new ArgumentException($"Unable to create dialog command: missing variable name at {i}"); } var variable = runtime.ActiveScope?.FindVariable(variableName, true, VariableSearchMode.All); if (variable == null) { ApplyDefault(command); } else { content.Append(variable.Value is IStringConverter stringConverter ? stringConverter.ConvertToString() : variable.Value.ToString()); } } else { var commandContent = command.ToLower().Trim(); if (commandContent.StartsWith("size")) // 字号 { var parameter = ExtractParameter(commandContent); var relative = parameter.Value.Value.StartsWith("+") || parameter.Value.Value.StartsWith("-"); if (parameter.HasValue && float.TryParse(parameter.Value.Value, out var number)) { FlushCache(); style.Size.AddLast((Mathf.RoundToInt(number), relative)); } else { ApplyDefault(command); } } else if (commandContent == "/size") // 取消字号 { if (style.Size.Any()) { FlushCache(); style.Size.RemoveLast(); } else { ApplyDefault(command); } } else if (commandContent.StartsWith("color")) // 颜色 { var parameter = ExtractParameter(commandContent); if (parameter.HasValue) { FlushCache(); style.Color.AddLast(parameter.Value.Value); } else { ApplyDefault(command); } } else if (commandContent == "/color") // 取消颜色 { if (style.Color.Any()) { FlushCache(); style.Color.RemoveLast(); } else { ApplyDefault(command); } } else if (commandContent.StartsWith("pause")) // 暂停 { if (commandContent == "pause") { FlushCache(); result.Add(new PauseDialogueItem { Time = null }); } else { var parameter = ExtractParameter(commandContent); if (parameter.HasValue && float.TryParse(parameter.Value.Value, out var number)) { FlushCache(); result.Add(new PauseDialogueItem { Time = number }); break; } ApplyDefault(command); } } else { switch (commandContent) { case "clear": // 清空 FlushCache(); result.Add(new ClearDialogueItem()); break; case "nowait": if (i == data.Length - 1) { noWait = true; } break; default: switch (command) { case "b": // 粗体 FlushCache(); style.Bold = true; break; case "/b": // 取消粗体 FlushCache(); style.Bold = false; break; case "i": // 斜体 FlushCache(); style.Italic = true; break; case "/i": // 取消斜体 FlushCache(); style.Italic = false; break; case "s": // 删除线 FlushCache(); style.Strikethrough = true; break; case "/s": // 取消删除线 FlushCache(); style.Strikethrough = false; break; case "u": // 下划线 FlushCache(); style.Underline = true; break; case "/u": // 取消下划线 FlushCache(); style.Underline = false; break; default: ApplyDefault(command); break; } break; } } } break; default: content.Append(data[i]); break; } } if (content.Length > 0) { result.Add(style.Combine(content.ToString())); } return(result, noWait, noClear); }
/// <summary> /// If nothing else is specified, data is stored /// in a text file called (NameOfClass)Model.dat, /// for instance CarModel.dat. /// </summary> public FileSource(IStringPersistence stringPersistence, IStringConverter <T> stringConverter, string fileSuffix = "Model.dat") { _stringPersistence = stringPersistence; _stringConverter = stringConverter; _fileName = typeof(T).Name + fileSuffix; }
public StringCacher(T value, IStringConverter <T> stringConverter) { this.Value = value; this.stringConverter = stringConverter; }
public static void RegisterStringConverter <T>(IStringConverter <T> stringConverter) { RegisterStringConverter(new TypedStringConverter <T>(stringConverter)); }
IStringConverter _classicStringConverter; // classic converter #endregion Fields #region Constructors /// <summary> /// Creates new <see cref="FastStringConverter" /> instance. /// </summary> /// <param name="pow2StringConverter">Converter for pow2 case.</param> /// <param name="classicStringConverter">Classic converter.</param> public FastStringConverter(IStringConverter pow2StringConverter, IStringConverter classicStringConverter) : base(pow2StringConverter) { _classicStringConverter = classicStringConverter; }
/// <summary> /// Initializes a new instance of the <see cref="Config"/> class. /// </summary> /// <param name="store"> /// The store that manages loading and saving the configuration data. /// </param> /// <param name="propertySearcher"> /// Provides a mechanism for searching the configuration properties of a Type. /// </param> /// <param name="converter"> /// Provides a mechanism that converts between configuration properties and string values that /// are stored in the IConfigStore. /// </param> protected Config( IConfigStore store, IConfigPropertySearcher propertySearcher, IStringConverter converter ) { Contract.Requires<ArgumentNullException>( store != null ); Contract.Requires<ArgumentNullException>( propertySearcher != null ); Contract.Requires<ArgumentNullException>( converter != null ); this.store = store; this.propertySearcher = propertySearcher; this.converter = converter; }
public StringCacher(T value) { this.Value = value; this.stringConverter = new DefaultStringConverter <T>(); }
public StringCacher(IStringConverter <T> stringConverter) { this.Value = default(T); this.stringConverter = stringConverter; }
public TypedStringConverter(IStringConverter <T> converter) { _converter = converter; }
public static string ReadString(this BufferReader reader, uint length, IStringConverter strConverter) { return(strConverter.ReadConv(reader.ReadBytes((int)length))); }
public static string ReadLengthCodedString(this BufferReader reader, IStringConverter strConverter) { //var length = this.parseLengthCodedNumber(); bool isNull; uint length = ReadLengthCodedNumber(reader, out isNull); //if (length === null) { // return null; //} return isNull ? null : ReadString(reader, length, strConverter); //return this.parseString(length); }
public XmlFileSettingsLoader(IGenericDeserializer deserializer, IStringConverter converter) : base(deserializer) { _converter = converter; }
IStringConverter _pow2StringConverter; // converter for pow2 case #endregion Fields #region Constructors /// <summary> /// Creates new <see cref="StringConverterBase" /> instance. /// </summary> /// <param name="pow2StringConverter">Converter for pow2 case.</param> public StringConverterBase(IStringConverter pow2StringConverter) { _pow2StringConverter = pow2StringConverter; }
public StringCacher() { this.Value = default(T); this.stringConverter = new DefaultStringConverter <T>(); }