public ProjectFile() { Objects = new List <string>(); Track = new ProjectTrack(); TrackViews = new List <ProjectTrackView>(); BlockRoutes = new List <Route>(); BlockRouteGroups = new List <RouteGroup>(); }
public bool Load(string path) { try { Filepath = path; Dirpath = Path.GetDirectoryName(path); if (!File.Exists(path)) { return(false); } string cnt = File.ReadAllText(path, Encoding.UTF8); if (string.IsNullOrEmpty(cnt)) { return(false); } JObject o = JObject.Parse(cnt); if (o["name"] != null) { Name = o["name"].ToString(); } if (o["version"] != null) { float v; Version = float.TryParse(o["version"].ToString(), out v) ? v : 1.0f; } if (o["targetHost"] != null) { TargetHost = o["targetHost"].ToString(); } if (o["targetPort"] != null) { UInt16 v; if (UInt16.TryParse(o["targetPort"].ToString(), out v)) { TargetPort = v; } else { TargetPort = 15471; } } if (o["designerColumns"] != null) { DesignerColumns = (int)o["designerColumns"]; } if (o["designerRows"] != null) { DesignerRows = (int)o["designerRows"]; } if (o["objects"] != null) { JArray ar = o["objects"] as JArray; if (ar != null) { foreach (var e in ar) { if (e == null) { continue; } if (string.IsNullOrEmpty(e.ToString())) { continue; } Objects.Add(e.ToString()); } } } if (o["track"] != null) { JObject ao = o["track"] as JObject; if (ao != null) { var item = new ProjectTrack(); if (item.Parse(ao)) { Track = item; } } } if (o["trackViews"] != null) { JArray ar = o["trackViews"] as JArray; if (ar != null) { for (int i = 0; i < ar.Count; ++i) { var obj = new ProjectTrackView(); if (obj.Parse(ar[i])) { TrackViews.Add(obj); } } } } if (o["routes"] != null || o["blockRoutes"] != null) { JArray ar = o["routes"] as JArray; if (ar == null) { ar = o["blockRoutes"] as JArray; } if (ar != null) { for (int i = 0; i < ar.Count; ++i) { var arr = ar[i] as JArray; if (arr == null) { continue; } Route route = new Route(); for (int j = 0; j < arr.Count; ++j) { WayPoint w = new WayPoint(); if (w.Parse(arr[j])) { route.Add(w); } } if (route.Count > 0) { BlockRoutes.Add(route); } } } if (BlockRoutes != null && BlockRoutes.Count > 0) { BlockRouteGroups = Map.GetRouteGroups(BlockRoutes); } } return(true); } catch (Exception ex) { Trace.WriteLine("<Project> " + ex.Message); return(false); } }