Пример #1
0
        private async Task <Prop> LoadModelFileAsync(string filePath)
        {
            Prop p = null;
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.Async = true;
            using (XmlReader reader = XmlReader.Create(filePath, settings))
            {
                await reader.MoveToContentAsync();

                if ("custommodel".Equals(reader.Name) && reader.HasAttributes)
                {
                    string name = reader.GetAttribute("name");
                    p = PropModelServices.Instance().CreateProp(name);

                    //These are the size of the grid near as I can tell
                    //We will use them to gauge a scale.
                    int x, y;
                    int.TryParse(reader.GetAttribute("parm1"), out x);
                    int.TryParse(reader.GetAttribute("parm2"), out y);

                    CalculateScale(x, y);

                    int nodeSize;
                    int.TryParse(reader.GetAttribute("PixelSize"), out nodeSize);
                    string model = reader.GetAttribute("CustomModel");

                    List <SubModel> subModels = new List <SubModel>();
                    while (reader.Read())
                    {
                        if ("subModel".Equals(reader.Name))
                        {
                            SubModel sm = new SubModel();
                            sm.Name   = reader.GetAttribute("name");
                            sm.Layout = reader.GetAttribute("layout");
                            var type = reader.GetAttribute("type");
                            switch (type)
                            {
                            case "ranges":
                                sm.Type   = SubModelType.Ranges;
                                sm.Ranges = ParseRanges(reader.GetAttribute("line0"));
                                break;
                            }
                            subModels.Add(sm);
                        }
                    }

                    var modelNodes = await CreateModelNodesAsync(model);

                    Assemble(modelNodes, subModels, nodeSize);
                }
            }

            return(p);
        }
Пример #2
0
        private async Task <Prop> LoadModelFileAsync(string filePath)
        {
            Prop p = null;
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.Async = true;
            using (XmlReader reader = XmlReader.Create(filePath, settings))
            {
                await reader.MoveToContentAsync();

                if ("custommodel".Equals(reader.Name) && reader.HasAttributes)
                {
                    string name = reader.GetAttribute("name");
                    p           = PropModelServices.Instance().CreateProp(name);
                    p.CreatedBy = @"xModel Import";

                    //These are the size of the grid near as I can tell
                    //We will use them to gauge a scale.
                    int x, y;
                    int.TryParse(reader.GetAttribute("parm1"), out x);
                    int.TryParse(reader.GetAttribute("parm2"), out y);

                    CalculateScale(x, y);

                    int nodeSize;
                    int.TryParse(reader.GetAttribute("PixelSize"), out nodeSize);
                    string model = reader.GetAttribute("CustomModel");

                    List <SubModel> subModels = new List <SubModel>();
                    while (reader.Read())
                    {
                        if (reader.NodeType != XmlNodeType.Element)
                        {
                            continue;
                        }

                        if ("subModel".Equals(reader.Name))
                        {
                            SubModel sm = new SubModel();
                            sm.Name   = reader.GetAttribute("name");
                            sm.Layout = reader.GetAttribute("layout");
                            var type = reader.GetAttribute("type");
                            switch (type)
                            {
                            case "ranges":
                                sm.Type   = SubModelType.Ranges;
                                sm.Ranges = ProcessRanges(reader);    //ParseRanges(reader.GetAttribute("line0"));
                                break;
                            }
                            subModels.Add(sm);
                        }
                        else if ("faceInfo".Equals(reader.Name))
                        {
                            var type = reader.GetAttribute("Type");
                            if (!string.IsNullOrEmpty(type) && type.Equals("NodeRange"))
                            {
                                foreach (var attribute in FaceInfo.Attributes)
                                {
                                    var range = reader.GetAttribute(attribute.Key);
                                    if (!string.IsNullOrEmpty(range))
                                    {
                                        SubModel sm = new SubModel();
                                        sm.Name   = attribute.Key;
                                        sm.Type   = SubModelType.Ranges;
                                        sm.Ranges = new List <RangeGroup> {
                                            ParseRanges(range)
                                        };
                                        sm.FaceInfo = new FaceInfo(attribute.Value);
                                        subModels.Add(sm);
                                    }
                                }
                            }
                        }
                    }

                    var modelNodes = await CreateModelNodesAsync(model);

                    Assemble(modelNodes, subModels, nodeSize);
                }
                else
                {
                    var dependencyResolver = this.GetDependencyResolver();
                    var ms = dependencyResolver.Resolve <IMessageService>();
                    await ms.ShowErrorAsync($"Unsupported model type: {reader.Name}. \nImport only supports custom model types at this time.", "Model import error");
                }
            }

            return(p);
        }