Example #1
0
        private ISensoryUnit GetOrCreateSensoryUnit(SensoryTypes senseType, string value)
        {
            ISensoryUnit result = new SensoryUnit(senseType, value, IS_SAVEABLE_UNIT);

            if (_kownSensoryUnits.Contains(result))
            {
                result = _kownSensoryUnits[_kownSensoryUnits.IndexOf(result)];
            }
            else
            {
                _kownSensoryUnits.Add(result);
                _kownSensoryUnits.Sort();
            }
            return(result);
        }
        static public ISensoryPattern Parse(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            string parseText = text.Trim();

            if (!parseText.StartsWith("{") || !parseText.EndsWith("}"))
            {
                return(null);
            }
            parseText = parseText.Substring(1, parseText.Length - 2);

            string[] splits = parseText.Split(new[] { ',' });
            if (splits.Length != 2)
            {
                return(null);
            }

            DirectionTypes direction        = (DirectionTypes)Enum.Parse(typeof(DirectionTypes), splits[0].Trim(), true);
            string         sensoryUnitsText = splits[1].Trim();

            if (sensoryUnitsText.Length >= 2)
            {
                sensoryUnitsText = sensoryUnitsText.Substring(1, sensoryUnitsText.Length - 2);
            }
            else
            {
                sensoryUnitsText = string.Empty;
            }
            string[]            sensoryUnitSplittedText = sensoryUnitsText.Split(new[] { ';' });
            List <ISensoryUnit> sensoryUnits            = new List <ISensoryUnit>();

            foreach (string sensoryUnitText in sensoryUnitSplittedText)
            {
                sensoryUnits.Add(SensoryUnit.Parse(sensoryUnitText));
            }

            return(new SensoryPattern(direction, sensoryUnits));
        }
        static public IPartialSnapshotCompressionNode Parse(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            string parseText = text.Trim();

            if (!parseText.StartsWith("{") || !parseText.EndsWith("}"))
            {
                return(null);
            }
            parseText = parseText.Substring(1, parseText.Length - 2);
            int seperatorIndex = parseText.IndexOf(':');
            var unitParseText  = seperatorIndex > 0 ? parseText.Substring(0, seperatorIndex) : parseText;

            var unit   = SensoryUnit.Parse(unitParseText);
            var result = new PartialSnapshotCompressionNode(unit);

            if (seperatorIndex > 0)
            {
                string childCountParseText = parseText.Substring(seperatorIndex + 1).Trim();
                if (childCountParseText.Length > 2)
                {
                    childCountParseText = childCountParseText.Substring(1, childCountParseText.Length - 2);
                    int    multiplierIndex = childCountParseText.IndexOf('*');
                    int    childCount      = int.Parse(childCountParseText.Substring(0, multiplierIndex));
                    string childParseText  = childCountParseText.Substring(multiplierIndex + 1);
                    var    child           = Parse(childParseText);
                    for (int i = 0; i < childCount; i++)
                    {
                        result.ChildNodes.Add(new PartialSnapshotCompressionNode(child.Unit));
                    }
                }
            }
            return(result);
        }