// Summary: // Load objects from database public virtual bool LoadObjs(DGObjects objs, DbContext dbContext) { DGObjectLoader loader2 = new DGObjectLoader(dbContext); bool success = loader2.Load(objs); return(success); }
// Summary: // Load objects from database public async Task <bool> loadObjects(string objDefName) { if (parent == null) { return(false); } DGObjectsDefinition def = objsDefinitions[objDefName]; if (def == null) { return(false); } DGObjects objs = new DGObjects(def); objs.parent = this; objs.SetContainer(await objs.QueryAllByObjs()); // build a empty DGObjects for use objsContainer[def.Name] = objs; return(true); }
// Summary: // Load project from a definition file. // Remarks: // It involoved two steps: // (1) Load defintion at first // (2) Load project domain data specifiled in the definition file // public static async Task <Project> load(string definitionFile) { Project prj = new Project(); iS3.Core.Globals.project = prj; // Load project definition first // prj.loadDefinition(definitionFile); foreach (Domain domain in prj.domains.Values) { // load all objects into domain await domain.loadAllObjects(); // sync objects on the tree //temp //prj.syncObjectsOnTree(domain.root); // build objects index based on layer ID // which is specified in the DGObjectsDefinition.GISLayerName foreach (var def in domain.objsDefinitions) { string defName = def.Key; DGObjects objs = domain.objsContainer[defName]; prj.objsDefIndex[defName] = objs; } } return(prj); }
// Summary: // Load project from a definition file. // Remarks: // It involoved two steps: // (1) Load defintion at first // (2) Load project domain data specifiled in the definition file // //public static DbContext dbContext; public static Project load(string definitionFile) { Project prj = new Project(); iS3.Core.Globals.project = prj; // Load project definition first // prj.loadDefinition(definitionFile); foreach (Domain domain in prj.domains) { // load all objects into domain domain.loadAllObjects(); // sync objects on the tree prj.syncObjectsOnTree(domain.root); // build objects index based on layer ID // which is specified in the DGObjectsDefinition.GISLayerName foreach (var def in domain.objsDefinitions) { string defName = def.Name; string layerID = def.GISLayerName; if (layerID != null && layerID.Length > 0) { DGObjects objs = domain.objsContainer[defName]; prj.objsLayerIndex[layerID] = objs; prj.dataSetIndex[objs.rawDataSet] = objs; } } } return(prj); }
// Summary: // Load objects from database public bool loadObjects(string objDefName, DbContext dbContext) { if (parent == null) { return(false); } DGObjectsDefinition def = objsDefinitions[objDefName]; if (def == null) { return(false); } DGObjects objs = new DGObjects(def); bool success = objs.load(dbContext); objs.parent = this; // Old objs will be replaced recently loaded objects. if (success) { objsContainer[def.Name] = objs; } return(success); }
public bool loadObjects(string objDefName) { if (parent == null) { return(false); } DGObjectsDefinition def = objsDefinitions[objDefName]; if (def == null) { return(false); } DGObjects objs = new DGObjects(def); //bool success = objs.load(); objs.parent = this; // Old objs will be replaced recently loaded objects. //if (success) objsContainer[def.Name] = objs; return(true); }
List <DGObject> getSelected(DGObjects objs) { List <DGObject> selectedObjs = new List <DGObject>(); //need to be code implemented return(selectedObjs); }
// Summary: // Synchronize objects on the tree. // Remarks: // After synchronization, each tree will have an a DataView of objects. // public int syncObjectsOnTree(Tree inputTree, bool readSubTree = true) { int nSync = 0; List <Tree> trees = null; if (readSubTree == true) { trees = inputTree.ToList(); } else { trees = new List <Tree>(); trees.Add(inputTree); } foreach (Tree tree in trees) { if (tree.RefDomainName == null || tree.RefObjsName == null) { continue; } Domain domain = null; if (domains.ContainsKey(tree.RefDomainName)) { domain = domains[tree.RefDomainName]; } if (domain == null) { continue; } DGObjects objs = null; if (domain.objsContainer.ContainsKey(tree.RefObjsName)) { objs = domain.objsContainer[tree.RefObjsName]; } if (objs == null) { continue; } if (objs.rawDataSet.Tables.Count == 0) { continue; } // Open a view on the table, and apply filter and sort rule on the table // DataTable dt = objs.rawDataSet.Tables[0]; DataView dv = new DataView(dt, tree.Filter, tree.Sort, DataViewRowState.CurrentRows); tree.ObjectsView = dv; tree.RefObjs = objs; } return(nSync); }
// Summary: // Load project from a definition file. // Remarks: // It involoved two steps: // (1) Load defintion at first // (2) Load project domain data specifiled in the definition file // //public static DbContext dbContext; public static async Task <Project> load(string definitionFile) { Project prj = new Project(); iS3.Core.Globals.project = prj; // Load project definition first // prj.loadDefinition(definitionFile); // Load project data foreach (Domain domain in prj.domains.Values) { // load all objects into domain //domain.loadAllObjects(dbContext); domain.loadAllObjects(); // sync objects on the tree prj.syncObjectsOnTree(domain.root); // build objects index based on layer ID // which is specified in the DGObjectsDefinition.GISLayerName foreach (var def in domain.objsDefinitions) { string defName = def.Key; DGObjects objs = domain.objsContainer[defName]; prj.objsDefIndex[defName] = objs; if ((objs.definition.GISLayerName != null) && (objs.definition.GISLayerName.Length > 0)) { if (!prj.objs2DIndex.ContainsKey(objs.definition.GISLayerName)) { prj.objs2DIndex[objs.definition.GISLayerName] = new List <DGObjects>(); } prj.objs2DIndex[objs.definition.GISLayerName].Add(objs); } if ((objs.definition.Layer3DName != null) && (objs.definition.Layer3DName.Length > 0)) { if (!prj.objs3DIndex.ContainsKey(objs.definition.Layer3DName)) { prj.objs3DIndex[objs.definition.Layer3DName] = new List <DGObjects>(); } prj.objs3DIndex[objs.definition.Layer3DName].Add(objs); } } } //dbContext.Close(); return(prj); }
// Summary: // Synchronize objects on the tree. // Remarks: // After synchronization, each tree will have an a DataView of objects. // public int syncObjectsOnTree(Tree inputTree, bool readSubTree = true) { int nSync = 0; List <Tree> trees = null; if (readSubTree == true) { trees = inputTree.ToList(); } else { trees = new List <Tree>(); trees.Add(inputTree); } foreach (Tree tree in trees) { if (tree.RefDomainName == null || tree.RefObjsName == null) { continue; } Domain domain = null; if (domains.ContainsKey(tree.RefDomainName)) { domain = domains[tree.RefDomainName]; } if (domain == null) { continue; } DGObjects objs = null; if (domain.objsContainer.ContainsKey(tree.RefObjsName)) { objs = domain.objsContainer[tree.RefObjsName]; } if (objs == null) { continue; } tree.RefObjs = objs; } return(nSync); }
getSelectedObjs() { Dictionary <string, IEnumerable <DGObject> > selectedObjsDict = new Dictionary <string, IEnumerable <DGObject> >(); foreach (string layerID in objsLayerIndex.Keys) { DGObjects objs = objsLayerIndex[layerID]; List <DGObject> selectedObjs = getSelected(objs); if (selectedObjs != null && selectedObjs.Count > 0) { selectedObjsDict[layerID] = selectedObjs; } } return(selectedObjsDict); }
// Summary: // Set object selection state. // Remarks: // For more info on IsSelected property, // see remarks of objSelectionChangedListener() function. void setObjSelectionState( Dictionary <string, IEnumerable <DGObject> > selectedObjs, bool isSelected) { // Method1: // set object selection state through layer index // //foreach (string layerID in selectedObjs.Keys) //{ // if (objsLayerIndex.ContainsKey(layerID)) // { // DGObjects objs = objsLayerIndex[layerID]; // foreach (DGObject obj in selectedObjs[layerID]) // { // if (objs.obj2RowView.Keys.Contains(obj)) // { // DataRow dr = objs.obj2RowView[obj]; // dr.SetField<bool>("IsSelected", isSelected); // } // } // } //} // Method 2: // set object selection state from object's parent // Method 2 is robust than method 1 because it bypass layer index. // foreach (var objs in selectedObjs.Values) { if (objs.Count() == 0) { continue; } DGObjects parent = objs.First().parent; foreach (var obj in objs) { if (parent.obj2RowView.Keys.Contains(obj)) { DataRow dr = parent.obj2RowView[obj]; dr.SetField <bool>("IsSelected", isSelected); } } } }
List <DGObject> getSelected(DGObjects objs) { List <DGObject> selectedObjs = new List <DGObject>(); foreach (DGObject obj in objs.values) { if (objs.obj2RowView.Keys.Contains(obj)) { DataRow dr = objs.obj2RowView[obj]; //if (dr.IsNull("IsSelected")) // continue; bool isSelected = dr.Field <bool>("IsSelected"); if (isSelected) { selectedObjs.Add(obj); } } } return(selectedObjs); }
// Summary: // Get objects according to the specified object type // Remarks: // If there is only a DGObjects with the specified object type, // it will be returned directly. // // If there are multiple DGObjects with the specified object type, // then a new DGObjects is returned which will merged all the objects. // In this situation, the index of the DGObjects are lost. public DGObjectsCollection getObjects(string objType) { IEnumerable <DGObjectsDefinition> defs = objsDefinitions.Values.Where(x => x.Type == objType); if (defs == null || defs.Count() == 0) { return(null); } DGObjectsCollection result = new DGObjectsCollection(); foreach (DGObjectsDefinition def in defs) { if (objsContainer.ContainsKey(def.Name)) { DGObjects objs = objsContainer[def.Name]; result.Add(objs); } } return(result); }