예제 #1
0
        public ClockBlock(STFReader stf, string shapePath, List <ClockList> clockLists, string listName)
        {
            var clockDataItems = new List <ClockShape>();
            var count          = stf.ReadInt(null);

            stf.ParseBlock(new STFReader.TokenProcessor[] {
                new STFReader.TokenProcessor("clockitem", () => {
                    if (--count < 0)
                    {
                        STFException.TraceWarning(stf, "Skipped extra ClockItem");
                    }
                    else
                    {
                        var dataItem = new ClockShape(stf, shapePath);
                        if (File.Exists(shapePath + dataItem.Name))
                        {
                            clockDataItems.Add(dataItem);
                        }
                        else
                        {
                            STFException.TraceWarning(stf, String.Format("Non-existent shape file {0} referenced", dataItem.Name));
                        }
                    }
                }),
            });
            if (count > 0)
            {
                STFException.TraceWarning(stf, count + " missing ClockItem(s)");
            }
            ClockList clockList = new ClockList(clockDataItems, listName);

            clockLists.Add(clockList);
        }
예제 #2
0
        /// <summary>
        /// Parses next item from JSON data, populating a ClockShape and issuing error messages.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        protected virtual bool TryParse(JsonReader item)
        {
            var stringValue = "";

            switch (item.Path)
            {
            case "":
                // Ignore these items.
                break;

            case "[].":
                // Create an object with properties which are initially incomplete, so omissions can be detected and the object rejected later.
                ClockShape = new ClockShape(stringValue, null);
                ClockShapeList.Add(ClockShape);
                break;

            case "[].Name":
                // Parse the property with default value as invalid, so errors can be detected and the object rejected later.
                stringValue = item.AsString(stringValue);
                var path = ShapePath + stringValue;
                ClockShape.Name = path;
                if (string.IsNullOrEmpty(stringValue))
                {
                    return(false);
                }
                if (File.Exists(path) == false)
                {
                    Trace.TraceWarning($"Non-existent shape file {path} referenced in animated.clocks-or");
                }
                break;

            case "[].ClockType":
                stringValue = item.AsString(stringValue).ToLower();
                if (stringValue == "analog")
                {
                    ClockShape.ClockType = ClockType.Analog;
                }
                else
                {
                    Trace.TraceWarning($"ClockType \"{stringValue}\" found, but \"analog\" expected");
                    return(false);
                }
                break;

            default:
                Trace.TraceWarning($"Unexpected entry \"{item.Path}\" found");
                return(false);
            }
            return(true);
        }