public static List <SharingInfo> GetSharingFileList() { List <SharingInfo> sharingList = null; lock ( conn ) { if (conn.State == ConnectionState.Closed) { conn.Open(); } using (SqliteCommand cmd = new SqliteCommand()) { cmd.Connection = PreKeyring.conn; cmd.CommandText = string.Format(SQLStatement.SharingFile_All); SqliteDataReader reader = cmd.ExecuteReader(); Boolean canRead; sharingList = new List <SharingInfo>(); while ((canRead = reader.Read()) == true) { SharingInfo sf = new SharingInfo(); sf.CopyRef = reader.GetString(0); sf.FileName = reader.GetString(1); sf.ID_From = reader.GetString(2); sf.CKEY_E = reader.GetString(3); sf.CKEY_F = reader.GetString(4); sf.CKEY_U = reader.GetString(5); sf.CKEY_W = reader.GetString(6); sharingList.Add(sf); } } return(sharingList); } }
public static void SharingFile_Update(SharingInfo sf) { if (PreKeyring.SharingFile_Query(sf.CopyRef) == null) { SharingFile_Insert(sf); } else { lock (PreKeyring.conn) { String sql = string.Format(SQLStatement.SharingFile_Update, sf.CopyRef, sf.FileName, sf.ID_From, sf.CKEY_E, sf.CKEY_F, sf.CKEY_U, sf.CKEY_W); if (conn.State == ConnectionState.Closed) { conn.Open(); } using (SqliteCommand cmd = new SqliteCommand()) { cmd.Connection = PreKeyring.conn; cmd.CommandText = sql; if (cmd.ExecuteNonQuery() != 1) { throw new DBException(); } } } } }
private static Boolean SharingFile_Insert(SharingInfo sf) { lock ( conn ) { try { if (conn.State == ConnectionState.Closed) { conn.Open(); } using (SqliteCommand cmd = new SqliteCommand()) { cmd.Connection = PreKeyring.conn; cmd.CommandText = string.Format(SQLStatement.SharingFile_Insert, sf.CopyRef, sf.FileName, sf.ID_From, sf.CKEY_E, sf.CKEY_F, sf.CKEY_U, sf.CKEY_W); cmd.ExecuteNonQuery(); } } catch (System.Exception) { log.ErrorFormat("SharingFile insert {0}", sf.FileName); return(false); } } return(true); }
public static void SharingFile_TEST() { PreKeyring.SharingFile_Update( new SharingInfo { CopyRef = "ref1", FileName = "file", ID_From = "Hjnubys", CKEY_E = "testE", CKEY_F = "testF", CKEY_U = "testU", CKEY_W = "testW" }); PreKeyring.SharingFile_Update(new SharingInfo { CopyRef = "ref2", FileName = "file2", ID_From = "Hjnubys", CKEY_E = "testE", CKEY_F = "testF", CKEY_U = "testU", CKEY_W = "testW" }); PreKeyring.SharingFile_Update(new SharingInfo { CopyRef = "ref3", FileName = "file2", ID_From = "Hjnubys", CKEY_E = "testE", CKEY_F = "testF", CKEY_U = "testU", CKEY_W = "testW" }); SharingInfo sf = PreKeyring.SharingFile_Query("ref1"); Console.WriteLine( (sf == null) ? "The SharingFileInfo is not exist" : "Find the file info of the copyref with ref"); PreKeyring.SharingFile_Delete(new String[] { "ref1", "ref3" }); List <SharingInfo> sharingfileList = PreKeyring.GetSharingFileList(); foreach (SharingInfo f in sharingfileList) { Console.WriteLine(f.CopyRef + " " + f.FileName + " " + f.ID_From + " " + f.CKEY_E + " " + f.CKEY_F + " " + f.CKEY_U + " " + f.CKEY_W + " "); } }
public static SharingInfo SharingFile_Query(String copyRef) { SharingInfo sf = null; //取出数据 lock ( conn ) { if (conn.State == ConnectionState.Closed) { conn.Open(); } using (SqliteCommand cmd = new SqliteCommand()) { cmd.Connection = PreKeyring.conn; cmd.CommandText = string.Format(SQLStatement.SharingFile_Query, copyRef); SqliteDataReader reader = cmd.ExecuteReader(); Boolean canRead = reader.Read(); if (canRead == false) { return(sf); } else { sf = new SharingInfo(); sf.CopyRef = reader.GetString(0); sf.FileName = reader.GetString(1); sf.ID_From = reader.GetString(2); sf.CKEY_E = reader.GetString(3); sf.CKEY_F = reader.GetString(4); sf.CKEY_U = reader.GetString(5); sf.CKEY_W = reader.GetString(6); } } } return(sf); }
private static Boolean SharingFile_Insert( SharingInfo sf ) { lock ( conn ) { try { if ( conn.State == ConnectionState.Closed ) conn.Open(); using ( SqliteCommand cmd = new SqliteCommand() ) { cmd.Connection = PreKeyring.conn; cmd.CommandText = string.Format( SQLStatement.SharingFile_Insert , sf.CopyRef , sf.FileName , sf.ID_From , sf.CKEY_E , sf.CKEY_F , sf.CKEY_U , sf.CKEY_W ); cmd.ExecuteNonQuery(); } } catch ( System.Exception ){ log.ErrorFormat("SharingFile insert {0}", sf.FileName); return false; } } return true; }
public static void SharingFile_Update( SharingInfo sf ) { if ( PreKeyring.SharingFile_Query( sf.CopyRef ) == null ) { SharingFile_Insert( sf ); } else { lock ( PreKeyring.conn ) { String sql = string.Format( SQLStatement.SharingFile_Update , sf.CopyRef , sf.FileName , sf.ID_From , sf.CKEY_E , sf.CKEY_F , sf.CKEY_U , sf.CKEY_W ); if ( conn.State == ConnectionState.Closed ) conn.Open(); using ( SqliteCommand cmd = new SqliteCommand() ) { cmd.Connection = PreKeyring.conn; cmd.CommandText = sql; if (cmd.ExecuteNonQuery() != 1) throw new DBException(); } } } }
public static SharingInfo SharingFile_Query( String copyRef ) { SharingInfo sf = null; //取出数据 lock ( conn ) { if ( conn.State == ConnectionState.Closed ) conn.Open(); using ( SqliteCommand cmd = new SqliteCommand() ) { cmd.Connection = PreKeyring.conn; cmd.CommandText = string.Format( SQLStatement.SharingFile_Query , copyRef ); SqliteDataReader reader = cmd.ExecuteReader(); Boolean canRead = reader.Read(); if ( canRead == false ) return sf; else { sf = new SharingInfo(); sf.CopyRef = reader.GetString( 0 ); sf.FileName = reader.GetString( 1 ); sf.ID_From = reader.GetString( 2 ); sf.CKEY_E = reader.GetString( 3 ); sf.CKEY_F = reader.GetString( 4 ); sf.CKEY_U = reader.GetString( 5 ); sf.CKEY_W = reader.GetString( 6 ); } } } return sf; }
public static List<SharingInfo> GetSharingFileList() { List<SharingInfo> sharingList = null; lock ( conn ) { if ( conn.State == ConnectionState.Closed ) conn.Open(); using ( SqliteCommand cmd = new SqliteCommand() ) { cmd.Connection = PreKeyring.conn; cmd.CommandText = string.Format( SQLStatement.SharingFile_All ); SqliteDataReader reader = cmd.ExecuteReader(); Boolean canRead; sharingList = new List<SharingInfo>(); while ( ( canRead = reader.Read() ) == true ) { SharingInfo sf = new SharingInfo(); sf.CopyRef = reader.GetString( 0 ); sf.FileName = reader.GetString( 1 ); sf.ID_From = reader.GetString( 2 ); sf.CKEY_E = reader.GetString( 3 ); sf.CKEY_F = reader.GetString( 4 ); sf.CKEY_U = reader.GetString( 5 ); sf.CKEY_W = reader.GetString( 6 ); sharingList.Add( sf ); } } return sharingList; } }