Beispiel #1
0
        private void OnChanged(IPropertyChanged changed)
        {
            lock (locker)
            {
                if (isSuppressingChange)
                {
                    return;
                }
                isSuppressingChange = true;
            }

            var value = changed.NewValue;

            if (value == null)
            {
                Object = null;
                Directory.DeleteTree();
                Directory.Refresh();
            }
            else
            {
                Object = new DbObjectNode(Database, (IRxObject)changed.NewValue, Directory);
            }

            lock (locker)
            {
                isSuppressingChange = false;
            }
        }
Beispiel #2
0
        private void Load()
        {
            lock (locker)
            {
                if (isSuppressingChange)
                {
                    return;
                }

                isSuppressingChange = true;
            }
            if (Object == null)
            {
                Database.Action(() =>
                {
                    var obj = (IRxObject)Activator.CreateInstance(MetaData.Property.PropertyType);
                    Object  = new DbObjectNode(Database, obj, Directory);
                    MetaData.Property.SetValue(Container, obj);
                });
            }

            lock (locker)
            {
                isSuppressingChange = false;
            }
        }
Beispiel #3
0
        public SexyDatabase(string folder)
        {
            node = new DbObjectNode(this, this, new DirectoryInfo(folder));

            var fileSystemWatcher = new FileSystemWatcher(folder, "*.*");

            fileSystemWatcher.Changed += FileChanged;
            fileSystemWatcher.Created += FileExistance;
            fileSystemWatcher.Deleted += FileExistance;
            fileSystemWatcher.IncludeSubdirectories = true;
            fileSystemWatcher.NotifyFilter          = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
            fileSystemWatcher.EnableRaisingEvents   = true;
        }
Beispiel #4
0
        protected override void OnFileSystemChanged(FileSystemEventArgs args)
        {
            base.OnFileSystemChanged(args);

            lock (locker)
            {
                changeMode = DbChangeMode.Load;
                try
                {
                    if (args.FullPath != Directory.FullName)
                    {
                        var relativePath = args.FullPath.Substring(Directory.FullName.Length).TrimStart(Path.DirectorySeparatorChar);
                        var parts        = relativePath.Split(Path.DirectorySeparatorChar);
                        if (parts.Length == 1)
                        {
                            switch (args.ChangeType)
                            {
                            case WatcherChangeTypes.Created:
                                int index;
                                if (int.TryParse(relativePath, out index))
                                {
                                    if (index >= ItemNodes.Count || ItemNodes[index] == null)
                                    {
                                        var obj  = (IRxObject)Activator.CreateInstance(MetaData.ElementType);
                                        var node = new DbObjectNode(Database, obj, new DirectoryInfo(Path.Combine(Directory.FullName, index.ToString())));
                                        while (index > ItemNodes.Count)
                                        {
                                            ItemNodes.Add(null);
                                        }
                                        while (index > List.Count)
                                        {
                                            List.Add(null);
                                        }
                                        if (index < ItemNodes.Count)
                                        {
                                            ItemNodes[index] = node;
                                        }
                                        else
                                        {
                                            ItemNodes.Add(node);
                                        }
                                        if (index < List.Count)
                                        {
                                            List[index] = obj;
                                        }
                                        else
                                        {
                                            List.Add(obj);
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
                finally
                {
                    changeMode = DbChangeMode.None;
                }
            }
        }