2 using System
.Collections
.Generic
;
4 using System
.Data
.Common
;
5 using System
.Diagnostics
;
7 using MySql
.Data
.MySqlClient
;
11 internal class AltModel
: IDisposable
13 private readonly string _connectionString
;
14 private readonly DbConnection _connection
;
18 DbConnectionStringBuilder dbcsb
19 = new DbConnectionStringBuilder
21 { "Data Source", "localhost" }
,
22 { "User ID", "root" }
,
23 { "Database", "shares_index" }
26 _connectionString
= dbcsb
.ConnectionString
;
28 _connection
= new MySqlConnection( _connectionString
);
33 /// Saves given path to the database
35 /// <param name="path"></param>
36 /// <returns>Leaf node ID</returns>
37 public int SavePath( string path
)
39 IEnumerable
<string> getTokens
= GetTokens( path
);
42 bool addingNodes
= false;
44 foreach ( string token
in getTokens
)
46 if ( addingNodes
== false )
48 parentId
= FindNode( token
, parentId
);
57 parentId
= AddNode( token
, parentId
);
65 /// Adds new node to the database.
67 /// <param name="nodeName"></param>
68 /// <param name="parentId"></param>
69 /// <returns>Added node ID</returns>
70 private int AddNode( string nodeName
, int parentId
)
72 DbCommand cmd
= _connection
.CreateCommand();
73 cmd
.CommandText
= "proc_add_node";
74 cmd
.CommandType
= CommandType
.StoredProcedure
;
77 throw new NotImplementedException();
81 /// Gets an ID of a node with name given and withc is a child node of
84 /// <param name="nodeName"></param>
85 /// <param name="parentNodeId"></param>
86 /// <returns></returns>
87 private int FindNode( string nodeName
, int parentNodeId
)
89 throw new NotImplementedException();
93 /// Split given path into separate tokens (directory and file names).
95 /// <param name="path"></param>
96 /// <returns></returns>
97 private static IEnumerable
<string> GetTokens( string path
)
99 return path
.Substring( 1 ).Split( new[] { '/', '\\' }
);
102 public void Dispose()
104 if ( _connection
.State
!= ConnectionState
.Closed
)
110 catch ( DbException ex
)
112 Trace
.WriteLine( ex
.Message
, "Closing connection" );