コード例 #1
0
ファイル: Domain.cs プロジェクト: 1aurent/DataSearch
        public Domain(int id, string name, int flags, Engine parent, Data.IBackendProxy proxy)
        {
            _id     = id;
            _name   = name;
            _parent = parent;
            _flags  = flags;

            _domainValues = new Dictionary <string, ValueType>(StringComparer.InvariantCultureIgnoreCase);
            var link = new List <DomainLink>();

            using (var metadata = proxy.GetDomainMetadata(id))
            {
                while (metadata.MoveNext())
                {
                    switch (metadata.Current.Type)
                    {
                    case "key":
                        _domainValues.Add(metadata.Current.Name, ValueType.Key);
                        break;

                    case "text":
                        _domainValues.Add(metadata.Current.Name, ValueType.Text);
                        break;

                    case "link":
                        _domainValues.Add(metadata.Current.Name, ValueType.Link);
                        link.Add(new DomainLink(parent, metadata.Current.Infos, metadata.Current.Name));
                        break;
                    }
                }
            }
            _domainLinks = link.ToArray();
        }
コード例 #2
0
        private Engine(string backend)
        {
            _backendPath = backend;

            log.DebugFormat("Opening back-end [{0}]", backend);
            var cxStr = new SQLiteConnectionStringBuilder
            {
                DataSource    = _backendPath,
                FailIfMissing = true,
                ReadOnly      = true,
                SyncMode      = SynchronizationModes.Off,
                JournalMode   = SQLiteJournalModeEnum.Off
            };

            _backend = new SQLiteConnection(cxStr.ConnectionString);
            _backend.Open();

            _proxy = BridgeCompiler.CreateInstance <Data.IBackendProxy>(_backend);

            _domainDict = new Dictionary <string, int>(StringComparer.InvariantCultureIgnoreCase);
            var domFlags = new Dictionary <int, int>();

            using (var domains = _proxy.GetDomains())
            {
                while (domains.MoveNext())
                {
                    log.DebugFormat("Domain [{0}] = {1}", domains.Current.Name, domains.Current.ID);
                    domFlags.Add(domains.Current.ID, domains.Current.Flags);
                    _domainDict.Add(domains.Current.Name, domains.Current.ID);
                }
            }

            _domains = new Dictionary <int, Domain>(_domainDict.Count);
            foreach (var domain in _domainDict)
            {
                _domains.Add(domain.Value,
                             new Domain(domain.Value, domain.Key, domFlags[domain.Value], this, _proxy)
                             );
            }

            // Create domain link queries
            foreach (var domain in _domains.Values)
            {
                domain.CreateQueries();
            }
        }