/// <summary>Closes the reader.</summary> public void Close() { if (CloseBaseStream) { reader?.Close(); } reader = null; }
private void learnFormAssetFile(string path) { FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); DataReader dr = new DataReader(fs); int version = AssetToolUtility.GetAssetsFileVersion(path); var serializeAssets = SerializeAssetFactory.CreateWithVersion(version); serializeAssets.DeSerialize(dr); var assetTypeTreeDB = AssetToolUtility.GenerateTypeTreeDataBase(serializeAssets); typeTreeDatabase = assetTypeTreeDB.Merage(typeTreeDatabase); dr.Close(); fs.Dispose(); }
public void CloseReader() { DataReader?.Close(); }
public override bool ParseBytesAndExecute(byte[] data) { DataStream ds = new DataStream(data); DataReader dr = new DataReader(ds); long PEID = dr.ReadLong(); byte type = dr.ReadByte(); Entity e = TheClient.TheRegion.GetEntity(PEID); if (type == 0) { if (e is PlayerEntity) { ((PlayerEntity)e).InVehicle = true; int drivecount = dr.ReadInt(); int steercount = dr.ReadInt(); PlayerEntity player = (PlayerEntity)e; player.DrivingMotors.Clear(); player.SteeringMotors.Clear(); for (int i = 0; i < drivecount; i++) { long jid = dr.ReadLong(); JointVehicleMotor jvm = (JointVehicleMotor)TheClient.TheRegion.GetJoint(jid); if (jvm == null) { dr.Close(); return(false); } player.DrivingMotors.Add(jvm); } for (int i = 0; i < steercount; i++) { long jid = dr.ReadLong(); JointVehicleMotor jvm = (JointVehicleMotor)TheClient.TheRegion.GetJoint(jid); if (jvm == null) { dr.Close(); return(false); } player.SteeringMotors.Add(jvm); } dr.Close(); return(true); } // TODO: other CharacterEntity's } else if (type == 1) { if (e is PlayerEntity) { long heloid = dr.ReadLong(); Entity helo = TheClient.TheRegion.GetEntity(heloid); if (!(helo is ModelEntity)) { dr.Close(); return(false); } ((PlayerEntity)e).InVehicle = true; ((PlayerEntity)e).Vehicle = helo; ModelEntity helomod = (ModelEntity)helo; helomod.TurnIntoHelicopter((PlayerEntity)e); dr.Close(); return(true); } // TODO: other CharacterEntity's dr.Close(); return(true); } else if (type == 2) { if (e is PlayerEntity) { long planeid = dr.ReadLong(); Entity plane = TheClient.TheRegion.GetEntity(planeid); if (!(plane is ModelEntity)) { dr.Close(); return(false); } ((PlayerEntity)e).InVehicle = true; ((PlayerEntity)e).Vehicle = plane; ModelEntity planemod = (ModelEntity)plane; planemod.TurnIntoPlane((PlayerEntity)e); dr.Close(); return(true); } // TODO: other CharacterEntity's dr.Close(); return(true); } dr.Close(); return(false); }
/// <summary> /// 关闭读取器。 /// </summary> public override void Close() { DataReader?.Close(); }
public void DoAssetRollup() { // Loop through each asset and fill the ASSET_SECTION_<network_id> table according to the rollup logic. AssetRollupMessaging.AddMessge("Begin asset rollup in network: " + m_networkID + " at " + DateTime.Now.ToString("HH:mm:ss")); String query = ""; StreamWriter tw = null; if (DBOp.IsTableInDatabase("ASSET_SECTION_" + m_networkID)) { // Drop the table as we are going to make a new one. try { DBMgr.ExecuteNonQuery("DROP TABLE ASSET_SECTION_" + m_networkID); } catch (Exception exc) { throw exc; } } // Creating the ASSET_SECTION_<networkID> table. AssetRollupMessaging.AddMessge("Creating ASSET_SECTION table..."); List <DatabaseManager.TableParameters> listColumn = new List <DatabaseManager.TableParameters>(); listColumn.Add(new DatabaseManager.TableParameters("GEO_ID", DataType.Int, false, false)); listColumn.Add(new DatabaseManager.TableParameters("SECTIONID", DataType.Int, false, false)); listColumn.Add(new DatabaseManager.TableParameters("ASSET_TYPE", DataType.VarChar(-1), false)); listColumn.Add(new DatabaseManager.TableParameters("FACILITY", DataType.VarChar(-1), false)); listColumn.Add(new DatabaseManager.TableParameters("BEGIN_STATION", DataType.Float, true)); listColumn.Add(new DatabaseManager.TableParameters("END_STATION", DataType.Float, true)); listColumn.Add(new DatabaseManager.TableParameters("DIRECTION", DataType.VarChar(50), true)); listColumn.Add(new DatabaseManager.TableParameters("SECTION", DataType.VarChar(-1), true)); listColumn.Add(new DatabaseManager.TableParameters("AREA", DataType.Float, true)); listColumn.Add(new DatabaseManager.TableParameters("UNITS", DataType.VarChar(50), true)); String strTable = "ASSET_SECTION_" + m_networkID; try { DBMgr.CreateTable(strTable, listColumn); } catch (Exception exc) { throw exc; } // Get a text writer and file ready to do a bulk copy. String strMyDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); strMyDocumentsFolder += "\\RoadCare Projects\\Temp"; Directory.CreateDirectory(strMyDocumentsFolder); // LRS, Get the LRS data from each asset table... foreach (String assetName in m_assetNames) { AssetRollupMessaging.AddMessge("Rolling up LRS based asset " + assetName + "..."); ConnectionParameters cp = DBMgr.GetAssetConnectionObject(assetName); List <String> assetColumnNames = DBMgr.GetTableColumns(assetName, cp); if (assetColumnNames.Contains("BEGIN_STATION")) { switch (cp.Provider) { case "MSSQL": query = "SELECT GEO_ID, FACILITY, DIRECTION, BEGIN_STATION, END_STATION FROM " + assetName + " WHERE (FACILITY <> '' AND FACILITY IS NOT NULL) ORDER BY FACILITY, DIRECTION, BEGIN_STATION"; break; case "ORACLE": query = "SELECT GEO_ID, FACILITY, DIRECTION, BEGIN_STATION, END_STATION FROM " + assetName + " WHERE (FACILITY LIKE '_%' AND FACILITY IS NOT NULL) ORDER BY FACILITY, DIRECTION, BEGIN_STATION"; break; default: throw new NotImplementedException("TODO: Create ANSI implementation for XXXXXXXXXXXX"); //break; } String strOutFile = strMyDocumentsFolder + "\\" + assetName + ".txt"; tw = new StreamWriter(strOutFile); DataSet sectionSet; DataReader assetReader; try { // Get the Segmented network data from the SECTION_<networkID> table. // sectionSet will hold the section data, and assetReader will loop through each asset. sectionSet = DBMgr.ExecuteQuery("SELECT SECTIONID, FACILITY, BEGIN_STATION, END_STATION, DIRECTION FROM SECTION_" + m_networkID + " WHERE BEGIN_STATION IS NOT NULL ORDER BY FACILITY, DIRECTION, BEGIN_STATION"); assetReader = new DataReader(query, cp); } catch (Exception exc) { throw exc; } // If there is data to read, start reading it. if (assetReader.Read()) { DataPoint assetInfo; DataRow sectionRow; DataPoint sectionInfo; bool bMoreData = true; int iCurrentSection = 0; // bMoreData is true while there is more data to read, and false when the dataReader is finished. // we then go back to the foreach loop (outside the while) and start rolling up the next asset. while (bMoreData) { // AssetInfo is going to hold this particular row of asset data. assetInfo = new DataPoint(-1, (int)assetReader["GEO_ID"], assetReader["FACILITY"].ToString(), assetReader["BEGIN_STATION"].ToString(), assetReader["END_STATION"].ToString(), assetReader["DIRECTION"].ToString()); // SectionInfo is going to hold this particular row of sections data. sectionRow = sectionSet.Tables[0].Rows[iCurrentSection]; sectionInfo = new DataPoint((int)sectionRow["SECTIONID"], sectionRow["FACILITY"].ToString(), sectionRow["BEGIN_STATION"].ToString(), sectionRow["END_STATION"].ToString(), sectionRow["DIRECTION"].ToString()); // We increment the section if // We increment the asset if // AssetInSection returns: // -1 increments asset // 0 adds asset to Asset Rollup Table // 1 increments section bool bIncrementSection = false; bool bIncrementAsset = false; int assetSectionComparison = AssetInSection(assetInfo, sectionInfo); // Based on the result from AssetInSection we are going to increment something. Here its the asset if (assetSectionComparison < 0) { bIncrementAsset = true; } // Here, we have a match and we need to look ahead to see how many sections a linear asset might belong to // before moving on to the next asset. In either case, point or linear, we add the asset to the Rollup table. else if (assetSectionComparison == 0) { AddAssetToRollupTable(assetInfo, sectionInfo, assetName, tw); if (assetInfo.m_ptsExtent.Y != -1) //don't bother with looking ahead if we're using point assets { // Keep looping through the sections and checking to see if this asset is still valid for each // consecutive section. When it fails on a section, we are done with the linear asset, otherwise // we add the asset to the new section. (This is why we needed the sections in a DataSet, as a // dataReader would not allow this type of operation...easily). for (int iSectionLookAhead = 1; iSectionLookAhead + iCurrentSection < sectionSet.Tables[0].Rows.Count; iSectionLookAhead++) { sectionRow = sectionSet.Tables[0].Rows[iCurrentSection + iSectionLookAhead]; sectionInfo = new DataPoint((int)sectionRow["SECTIONID"], sectionRow["FACILITY"].ToString(), sectionRow["BEGIN_STATION"].ToString(), sectionRow["END_STATION"].ToString(), sectionRow["DIRECTION"].ToString()); if (AssetInSection(assetInfo, sectionInfo) == 0) { AddAssetToRollupTable(assetInfo, sectionInfo, assetName, tw); } else { break; } } } // Point asset match...we assigned the section already so just tell the loop to move to the next asset. bIncrementAsset = true; } // AssetInSection returned non-zero, and was not negative. Which is a long way of saying, it returned positive. // so we need to increment the section on a positive result. else { bIncrementSection = true; } if (bIncrementAsset) { if (bIncrementSection) { // This can't happen logically, but was useful during debugging. throw new Exception(); } else { // Read in the new data if we are incrementing the asset bMoreData = assetReader.Read(); } } else { // Increment the section row in the section data set. (Assuming there are sections remaining) // If there arent any sections remaining, then we can't assign any more assets can we? // so that means we are done. if (bIncrementSection) { if (iCurrentSection + 1 < sectionSet.Tables[0].Rows.Count) { iCurrentSection++; bMoreData = true; } else { bMoreData = false; } } else { // Again, impossible, but useful for debugging. throw new Exception(); } } } } tw.Close(); assetReader.Close(); AssetRollupMessaging.AddMessge("Bulk loading rolled up LRS asset data..."); // Now try to load all that beautifully segmented data into an Asset Rollup table. (tab delimited). try { switch (DBMgr.NativeConnectionParameters.Provider) { case "MSSQL": DBMgr.SQLBulkLoad("ASSET_SECTION_" + m_networkID, strOutFile, '\t'); break; case "ORACLE": throw new NotImplementedException("TODO: Figure out tables for DoAssetRollup()"); //DBMgr.OracleBulkLoad( DBMgr.NativeConnectionParameters, "ASSET_SECTION_" + m_networkID, strOutFile, //break; default: throw new NotImplementedException("TODO: Create ANSI implementation for XXXXXXXXXXXX"); //break; } } catch (Exception exc) { throw exc; } } } AssetRollupMessaging.AddMessge("Finished LRS asset data rollup..."); //foreach (String assetName in m_assetNames) //{ // AssetRollupMessaging.AddMessge("Rolling up SRS asset " + assetName + "..."); // ConnectionParameters cp = DBMgr.GetAssetConnectionObject(assetName); // List<String> assetColumnNames = DBMgr.GetTableColumns(assetName, cp); // if (assetColumnNames.Contains("SECTION")) // { // query = "SELECT GEO_ID, FACILITY, SECTION FROM " + assetName + " WHERE (SECTION <> '' AND SECTION IS NOT NULL) ORDER BY FACILITY, SECTION"; // String strOutFile = strMyDocumentsFolder + "\\" + assetName + ".txt"; // tw = new StreamWriter(strOutFile); // DataReader sectionReader = null; // DataReader assetReader = null; // try // { // // Get the Segmented network data from the SECTION_<networkID> table. // // sectionSet will hold the section data, and assetReader will loop through each asset. // //sectionSet = DBMgr.ExecuteQuery("SELECT SECTIONID, FACILITY, SECTION SECTION_" + m_networkID + " WHERE SECTION IS NOT NULL ORDER BY FACILITY, SECTION"); // sectionReader = new DataReader("SELECT SECTIONID, FACILITY, SECTION FROM SECTION_" + m_networkID + " WHERE SECTION IS NOT NULL ORDER BY FACILITY, SECTION"); // assetReader = new DataReader(query, cp); // } // catch (Exception exc) // { // throw exc; // } // bool bContinue = true; // String strFacility = ""; // String strSection = ""; // String strSectionID = ""; // String strAssetFacility = ""; // String strAssetSection = ""; // String strGeoID = ""; // while (bContinue) // { // if (strFacility == "") // { // if (!sectionReader.Read()) // { // bContinue = false; // continue; // } // strFacility = sectionReader["FACILITY"].ToString(); // strSection = sectionReader["SECTION"].ToString(); // strSectionID = sectionReader["SECTIONID"].ToString(); // //if (strSectionID == "1006136") // //{ } // //strFacility = strFacility.Replace(" ", ""); // //strSection = strSection.Replace(" ", ""); // } // if (strAssetFacility == "") // { // if (!assetReader.Read()) // { // bContinue = false; // continue; // } // strAssetFacility = assetReader["FACILITY"].ToString(); // strAssetSection = assetReader["SECTION"].ToString(); // strGeoID = assetReader["GEO_ID"].ToString(); // //if (strAssetFacility == "NW - Connecticut Ave") // //{ } // //strAssetFacility = strAssetFacility.Replace(" ", ""); // //strAssetSection = strAssetSection.Replace(" ", ""); // } // if (CompareInfo.GetCompareInfo("en-US").Compare(strFacility, strAssetFacility) < 0) // { // strFacility = ""; // } // else if (CompareInfo.GetCompareInfo("en-US").Compare(strFacility, strAssetFacility) == 0) // { // if (CompareInfo.GetCompareInfo("en-US").Compare(strSection, strAssetSection) < 0) // { // strFacility = ""; // } // else if (CompareInfo.GetCompareInfo("en-US").Compare(strSection, strAssetSection) == 0) // { // //Write out to file // tw.WriteLine(strGeoID // + "\t" + strSectionID // + "\t" + assetName // + "\t" + sectionReader["FACILITY"].ToString() // + "\t" //+ a.m_ptsExtent.X.ToString() // + "\t" //+ ((a.m_ptsExtent.Y == -1) ? "" : a.m_ptsExtent.Y.ToString()) // + "\t" //+ a.m_strDirection // + "\t" + sectionReader["SECTION"].ToString() // + "\t" //+ a.m_strArea // + "\t"); //+ a.m_strUnit); // strAssetFacility = ""; // } // else // { // strAssetFacility = ""; // } // } // else // { // strAssetFacility = ""; // } // } // tw.Close(); // assetReader.Close(); // sectionReader.Close(); // AssetRollupMessaging.AddMessge("Bulk loading rolled up SRS asset data..."); // // Now try to load all that beautifully segmented data into an Asset Rollup table. (tab delimited). // try // { // switch (cp.Provider) // { // case "MSSQL": // //query = "SELECT GEO_ID, FACILITY, SECTION FROM " + assetName + " WHERE (SECTION <> '' AND SECTION IS NOT NULL) ORDER BY FACILITY, SECTION"; // DBMgr.SQLBulkLoad("ASSET_SECTION_" + m_networkID, strOutFile, '\t'); // break; // case "ORACLE": // query = "SELECT GEO_ID, FACILITY, SECTION FROM " + assetName + " WHERE (SECTION LIKE '_%' AND SECTION IS NOT NULL) ORDER BY FACILITY, SECTION"; // break; // default: // throw new NotImplementedException("TODO: Create ANSI implementation for XXXXXXXXXXXX"); // break; // } // } // catch (Exception exc) // { // throw exc; // } // } //} AssetRollupMessaging.AddMessge("Asset Rollup complete."); }
//[Variation("Simple positive test 1", Pri = 0, Params = new object[] { "NNS" })] //[Variation("Simple positive test 2", Pri = 0, Params = new object[] { "DNS" })] //[Variation("Simple positive test 3", Pri = 0, Params = new object[] { "NS" })] public int v() { string type = CurVariation.Params[0].ToString(); CError.WriteLine("Test Type : " + type); ReloadSource(new StringReader(_xmlStr)); DataReader.PositionOnElement("root"); switch (type) { case "NNS": DataReader.ReadToDescendant("elem"); DataReader.ReadToNextSibling("elem"); if (DataReader.HasAttributes) { CError.Compare(DataReader.GetAttribute("att"), "1", "Not the expected attribute"); } else { CError.WriteLine("Positioned on wrong element"); DumpStat(); return(TEST_FAIL); } while (DataReader.Read()) { ; } DataReader.Close(); return(TEST_PASS); case "DNS": DataReader.ReadToDescendant("elem", "elem"); DataReader.ReadToNextSibling("elem", "elem"); if (DataReader.HasAttributes) { if (DataReader.GetAttribute("att") == null) { CError.WriteLine("Positioned on wrong element, not on DNS"); return(TEST_FAIL); } } else { CError.WriteLine("Positioned on wrong element"); DumpStat(); return(TEST_FAIL); } while (DataReader.Read()) { ; } DataReader.Close(); return(TEST_PASS); case "NS": DataReader.ReadToDescendant("e:elem"); DataReader.ReadToNextSibling("e:elem"); if (DataReader.HasAttributes) { if (DataReader.GetAttribute("xmlns:e") == null) { CError.WriteLine("Positioned on wrong element, not on DNS"); return(TEST_FAIL); } } else { CError.WriteLine("Positioned on wrong element"); DumpStat(); return(TEST_FAIL); } while (DataReader.Read()) { ; } DataReader.Close(); return(TEST_PASS); default: throw new CTestFailedException("Error in Test type"); } }
//[Variation("Read to next sibling with same names 1", Pri = 1, Params = new object[] { "NNS", "<root><a att='1'/><a att='2'/><a att='3'/></root>" })] //[Variation("Read on next sibling with same names 2", Pri = 1, Params = new object[] { "DNS", "<root xmlns='a'><a att='1'/><a att='2'/><a att='3'/></root>" })] //[Variation("Read on next sibling with same names 3", Pri = 1, Params = new object[] { "NS", "<root xmlns:a='a'><a:a att='1'/><a:a att='2'/><a:a att='3'/></root>" })] public int v3() { string type = CurVariation.Params[0].ToString(); string xml = CurVariation.Params[1].ToString(); CError.WriteLine("Test Type : " + type); ReloadSource(new StringReader(xml)); DataReader.Read(); if (IsBinaryReader()) { DataReader.Read(); } //Doing a sequential read. switch (type) { case "NNS": DataReader.ReadToDescendant("a"); DataReader.ReadToNextSibling("a"); DataReader.ReadToNextSibling("a"); CError.Compare(DataReader.GetAttribute("att"), "3", "Wrong node"); while (DataReader.Read()) { ; } DataReader.Close(); return(TEST_PASS); case "DNS": DataReader.ReadToDescendant("a", "a"); DataReader.ReadToNextSibling("a", "a"); DataReader.ReadToNextSibling("a", "a"); CError.Compare(DataReader.GetAttribute("att"), "3", "Wrong node"); while (DataReader.Read()) { ; } DataReader.Close(); return(TEST_PASS); case "NS": DataReader.ReadToDescendant("a:a"); DataReader.ReadToNextSibling("a:a"); DataReader.ReadToNextSibling("a:a"); CError.Compare(DataReader.GetAttribute("att"), "3", "Wrong node"); while (DataReader.Read()) { ; } DataReader.Close(); return(TEST_PASS); default: throw new CTestFailedException("Error in Test type"); } }
/// <summary>Closes this instance.</summary> public void Close() { m_Reader.Close(); m_Reader = null; }
public static List <SqlColumn> GetSqlColumns(string sql, IList parameters) { List <SqlColumn> cols = new List <SqlColumn>(); Connection connection = new Connection(@"Data Source=U:\Documentacoes_Equipe_ERP\OpenPOS\database\openpos.db;Version=3;"); connection.Open(); Tables tables = Tables.GetTables(connection); if (tables.Contains(sql)) { cols = new List <SqlColumn>(from c in tables[sql].Fields select new SqlColumn { Name = c.Name, DataType = c.GetFieldType() }); } else { Command cmSQL = null; DataReader dr = null; Cursor saveCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; try { cmSQL = connection.CreateCommand(); cmSQL.CommandText = sql; AddParameters(cmSQL, parameters); dr = cmSQL.ExecuteReader(CommandBehavior.SchemaOnly); for (int i = 0; i < dr.FieldCount; i++) { SqlColumn sc = new SqlColumn(); sc.Name = dr.GetName(i).TrimEnd('\0'); sc.DataType = dr.GetFieldType(i); cols.Add(sc); } } catch (SqlException sqle) { MessageBox.Show(sqle.Message, Strings.DesignerUtility_Show_SQLError); } catch (Exception e) { MessageBox.Show(e.InnerException == null ? e.Message : e.InnerException.Message, Strings.DesignerUtility_Show_Error); } finally { if (connection != null) { if (cmSQL != null) { cmSQL.Dispose(); if (dr != null) { dr.Close(); } } connection.Close(); connection.Dispose(); } Cursor.Current = saveCursor; } } return(cols); }