System.Data.SQLite

Check-in [e3223fd000]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:the Membership Module now provides 2 SiteMap Providers: SQLiteStaticSiteMap is the equivlent of the old SQLiteSiteMap SQLiteDynamicSiteMap is dynamic provider which does not cache nodes and hence is always up to date
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | sourceforge
Files: files | file ages | folders
SHA1: e3223fd000677c955951ded481e57d45620d99db
User & Date: jeffreyabecker 2006-03-01 22:09:39.000
Context
2006-03-01
22:40
updated membership to have sane defaults check-in: de05d61657 user: jeffreyabecker tags: sourceforge
22:09
the Membership Module now provides 2 SiteMap Providers: SQLiteStaticSiteMap is the equivlent of the old SQLiteSiteMap SQLiteDynamicSiteMap is dynamic provider which does not cache nodes and hence is always up to date check-in: e3223fd000 user: jeffreyabecker tags: sourceforge
06:01
1.0.27.1 check-in: f680e44bbf user: rmsimpson tags: sourceforge
Changes
Unified Diff Ignore Whitespace Patch
Deleted Membership/SiteMap/SQLiteSiteMap.cs.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web;
using System.Data;
using System.Data.SQLite;
using System.IO;

namespace SQLiteProvider
{
    class SQLiteSiteMapProvider : StaticSiteMapProvider
    {
        SiteMapNode _root;
        Dictionary<long, SiteMapNode> _nodes = new Dictionary<long, SiteMapNode>();
        #region CommonProviderComponents
        private string eventSource = "SQLiteSiteMapProvider";
        private string connectionString;

        private bool _WriteExceptionsToEventLog = false;
        public bool WriteExceptionsToEventLog
        {
            get { return _WriteExceptionsToEventLog; }
            set { _WriteExceptionsToEventLog = value; }
        }

        private string _ApplicationName;
        private long _AppID;
        public string ApplicationName
        {
            get { return _ApplicationName; }
            set
            {
                _ApplicationName = value;
                _AppID = ProviderUtility.GetApplicationID(connectionString, value);
            }
        }

        private bool _initialized = false;
        public virtual bool IsInitialized
        {
            get { return _initialized; }
        }
        #endregion

        public override void Initialize(string name, NameValueCollection config)
        {

            lock (this)
            {
                if (_initialized)
                    return;

                //
                // Initialize values from web.config.
                //

                if (config == null)
                    throw new ArgumentNullException("config");

                if (name == null || name.Length == 0)
                    name = "SQLiteSiteMapProvider";

                if (String.IsNullOrEmpty(config["description"]))
                {
                    config.Remove("description");
                    config.Add("description", "SQLite SiteMap Privider");
                }

                /*
                if (!String.IsNullOrEmpty(config["updateFileName"]))
                {
                    _validationFileName = HttpContext.Current.Server.MapPath(String.Format("~/App_Data/{0}", config["updateFileName"]));
                    if (!File.Exists(_validationFileName))
                    {
                        File.Create(_validationFileName).Close();
                    }
                    _validationDate = File.GetLastWriteTime(_validationFileName);

                    FileSystemWatcher watcher = new FileSystemWatcher();
                    watcher.Changed += new FileSystemEventHandler(this.OnSiteMapChanged);
                    watcher.EnableRaisingEvents = true;

                }*/
                // Initialize the abstract base class.
                base.Initialize(name, config);

                _WriteExceptionsToEventLog = ProviderUtility.GetExceptionDesitination(config["writeExceptionsToEventLog"]);
                connectionString = ProviderUtility.GetConnectionString(config["connectionStringName"]);
                ApplicationName = ProviderUtility.GetApplicationName(config["applicationName"]);

            }


        }

        public override SiteMapNode BuildSiteMap()
        {
            lock (this)
            {
                if (_root != null)
                    return _root;

                SQLiteConnection conn = new SQLiteConnection(connectionString);
                SQLiteCommand cmd = new SQLiteCommand(SiteMapSql.GetNodes, conn);
                cmd.Parameters.Add("$AppID", DbType.Int64).Value = _AppID;

                long ID;
                string title;
                string description;
                string url;
                long parent;

                SiteMapNode n = null;
                SiteMapNode parentNode = null;

                try
                {
                    conn.Open();
                    SQLiteDataReader r = cmd.ExecuteReader();
                    if (r.Read())
                    {
                        ID = r.GetInt64(0);
                        
                        title = r.IsDBNull(1) ? null : r.GetString(1).Trim();
                        description = r.IsDBNull(2) ? null : r.GetString(2).Trim();
                        url = r.IsDBNull(3) ? null : r.GetString(3).Trim();
                        _root = new SiteMapNode(this, ID.ToString(), url, title, description);
                        _root.Roles = GetNodeRoles(ID, conn);
                        base.AddNode(_root, null);
                        _nodes.Add(ID, _root);

                    }
                    while (r.Read())
                    {
                        ID = r.GetInt64(0);

                        title = r.IsDBNull(1) ? null : r.GetString(1).Trim();
                        description = r.IsDBNull(2) ? null : r.GetString(2).Trim();
                        url = r.IsDBNull(3) ? null : r.GetString(3).Trim();
                        parent = r.GetInt64(4);

                        parentNode = GetParent(parent);
                        n = new SiteMapNode(this, ID.ToString(), url, title, description);
                        n.Roles = GetNodeRoles(ID, conn);

                        base.AddNode(n, parentNode);
                        _nodes.Add(ID, n);
                    }

                }
                catch (Exception ex)
                {
                    ProviderUtility.HandleException(ex, eventSource, "BuildSiteMap", _WriteExceptionsToEventLog);
                }
                finally
                {
                    conn.Close();
                }
                return _root;
            }

        }

        protected override SiteMapNode GetRootNodeCore()
        {
            lock (this)
            {
                BuildSiteMap();
                return _root;
            }
        }

        private SiteMapNode GetParent(long pid)
        {
            if (!_nodes.ContainsKey(pid))
                throw new System.Configuration.Provider.ProviderException("Invalid Parent ID");
            return _nodes[pid];
        }

        private IList GetNodeRoles(long ID, SQLiteConnection conn)
        {
            SQLiteCommand cmd = new SQLiteCommand(SiteMapSql.GetNodeRoles, conn);
            cmd.Parameters.Add("$AppID", DbType.Int64).Value = _AppID;
            cmd.Parameters.Add("$NodeID", DbType.Int64).Value = ID;
            ArrayList result = new ArrayList();

            SQLiteDataReader r = cmd.ExecuteReader();
            while (r.Read())
            {
                result.Add(r.GetString(0));
            }
            return (IList)result;
        }
    }
}
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<