Пример #1
0
 // Category.ToThemeList, overloads
 public ThemeListNode(string name, string path, Metadata metadata, string desc)
     : base(name, null, metadata, desc)
 {
     IsInitialized = false;
     FilePath = path;
     Author = new ThemeListAuthor();
     _status = ThemeListStatus.Created;
     GetDataSource();
     // TryToGetDataStore() will set _readonly for theme
     ThemeList = this;
     IsInitialized = true;
 }
Пример #2
0
 public void Save()
 {
     if (this is ThemeListNode && _status == ThemeListStatus.Dirty)
     {
         _status = ThemeListStatus.Saving;
         _dataStore.Save(this);
         _status = ThemeListStatus.Loaded;
     }
 }
Пример #3
0
        // FIXME - work needs to be done on the UI to put this new node in the Themelist treeview
        private void SaveAs(string path, string version)
        {
            // create backup of current settings in case save doesn't work.
            Store oldDatastore = _dataStore;
            ThemeListStatus oldStatus = _status;

            string ext = Path.GetExtension(path);
            if (ext != null)
                ext = ext.ToLower();
            switch (ext)
            {
                case ".tmz":
                    throw new NotImplementedException();
                case ".tml":
                case ".xml":
                    _dataStore = XmlStore.CreateNew(path, version); break;
                case ".mdb":
                    _dataStore = MdbStore.CreateNew(path, version); break;
                default:
                    throw new ArgumentException(path + " is not a supported theme list file type.");
            }
            if (_dataStore == null)
            {
                _dataStore = oldDatastore;
                throw new ArgumentException("Unable to create a Theme List at " + path);
            }
            FilePath = path;
            FileType = ext.Substring(1, 3);
            _status = ThemeListStatus.Dirty;

            try
            {
                Save();
            }
            catch (Exception)
            {
                _dataStore = oldDatastore;
                _status = oldStatus;
                throw;
            }
        }
Пример #4
0
        // Build is not thread safe.  In a multi-threaded app, it must be called in side a lock.
        // Locking is the callers responsibility.
        public void Build()
        {
            if (!IsValid)
                throw new Exception("File is not a valid ThemeList");

            if (_status == ThemeListStatus.Initialized)
            {
                _status = ThemeListStatus.Loading;

                _dataStore.Build(this);
                //UpdateImageIndex(true);

                _status = ThemeListStatus.Loaded;
            }
        }
Пример #5
0
        private Store TryToGetDataStore()
        {
            // If we return from this routine prematurely, then we do not have a valid datastore
            _status = ThemeListStatus.Created;

            if (!HasData)
                return null;

            //if (string.IsNullOrEmpty(Data.Path))
            //    return null;

            Store datastore;
            string ext = Path.GetExtension(FilePath);
            if (ext != null)
                ext = ext.ToLower();
            switch (ext)
            {
                case ".tmz":
                    throw new NotImplementedException();
                case ".tml":
                case ".xml":
                    datastore = new XmlStore(FilePath); break;
                case ".mdb":
                    datastore = new MdbStore(FilePath); break;
                default:
                    return null;
            }
            if (!datastore.IsThemeList)
                return null;

            _status = ThemeListStatus.Initialized;

            return datastore;
        }
Пример #6
0
        public TmNode(TmNodeType nodeType, string name, TmNode parent, ThemeData data, Metadata metadata, string desc, DateTime? pubDate)
        {
            _type = nodeType;
            _name = name;
            Parent = parent;

            _pubDate = pubDate.HasValue ? pubDate.Value : DefaultPubDate;
            //_readonly = (Parent == null) ? false : Parent._readonly;

            _description = desc;

            // Always create a data and Metadata object, else data binding in properties form won't work.
            _data = data ?? new ThemeData();
            _data.PropertyChanged += Data_PropertyChanged;
            Metadata = metadata ?? new Metadata();
            Metadata.PropertyChanged += Metadata_PropertyChanged;

            if (_type == TmNodeType.ThemeList)
            {
                Author = new ThemeListAuthor();
                _status = ThemeListStatus.Created;
                _dataStore = TryToGetDataStore();
                // TryToGetDataStore() will set _readonly for theme
                ThemeList = this;
            }
        }
Пример #7
0
        // Build is not thread safe.  In a multi-threaded app, it must be called in side a lock.
        // Locking is the callers responsibility.
        public void Build()
        {
            if (!IsValidThemeList)
                throw new Exception("File is not a valid ThemeList");

            if (_status == ThemeListStatus.Initialized)
            {
                _status = ThemeListStatus.Loading;

                _dataStore.Build(this);
                //FIXME - Remove side effects, This should be a call to update Age
                _ageInDays = -1; // Needs to be reset based on children
                // call UpdateImageIndex on all descendents (they may not have been set correctly when loaded).
                UpdateImageIndex(true);

                _status = ThemeListStatus.Loaded;
            }
        }
Пример #8
0
        // FIXME - work needs to be done on the UI to put this new node in the Themelist treeview
        private void SaveAs(string path, string version)
        {
            Debug.Assert(IsThemeList, "SaveAs... is only valid for a themelist");
            //Debug.Assert(HasData, "Theme List has no data object");
            // create backup of current settings in case save doesn't work.
            ThemeData oldData = (ThemeData)Data.Clone();
            TmNodeType oldKind = Type;
            Store oldDatastore = _dataStore;
            ThemeListStatus oldStatus = _status;

            string ext = Path.GetExtension(path);
            if (ext != null)
                ext = ext.ToLower();
            switch (ext)
            {
                case ".tmz":
                    throw new NotImplementedException();
                case ".tml":
                case ".xml":
                    _dataStore = XmlStore.CreateNew(path, version); break;
                case ".mdb":
                    _dataStore = MdbStore.CreateNew(path, version); break;
                default:
                    throw new ArgumentException(path + " is not a supported theme list file type.");
            }
            if (_dataStore == null)
            {
                _dataStore = oldDatastore;
                throw new ArgumentException("Unable to create a Theme List at " + path);
            }
            Data.Path = path;
            Data.Type = ext.Substring(1, 3);
            Data.Version = version;
            _type = TmNodeType.ThemeList;
            _status = ThemeListStatus.Dirty;

            try
            {
                Save();
            }
            catch (Exception)
            {
                Data = oldData;
                _type = oldKind;
                _dataStore = oldDatastore;
                _status = oldStatus;
                throw;
            }
            IsReadOnly = false;
        }