Пример #1
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var connectionString = new SqliteConnectionStringBuilder {
                DataSource = MarsherFilesystem.GetPath("database.sqlite3")
            }.ConnectionString;
            var connection = new SqliteConnection(connectionString);

            optionsBuilder.UseLazyLoadingProxies().UseSqlite(connection);
        }
Пример #2
0
        public LocalListPersistence()
        {
            var directory = MarsherFilesystem.GetPath(ListDirectoryName);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            foreach (var file in Directory.EnumerateFiles(directory))
            {
                if (!Path.HasExtension(file) || Path.GetExtension(file) != ExtensionName)
                {
                    continue;
                }
                LoadList(file);
            }
        }
Пример #3
0
        public QaListStubs CreateList(string name, IList <QaItem> initialMembers = null)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new IllegalListNameException();
            }
            if (_lists.Any(it => it.Name == name))
            {
                throw new DuplicateListNameException();
            }
            if (name.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
            {
                throw new IllegalListNameException();
            }

            var filename = MarsherFilesystem.GetPath(ListDirectoryName, name + ExtensionName);

            if (File.Exists(filename))
            {
                LoadList(filename);
                throw new DuplicateListNameException();
            }

            try
            {
                File.Create(filename).Close();
            }
            catch (IOException)
            {
                throw new IllegalListNameException();
            }
            var list = new QaListStubs()
            {
                Name     = name,
                Filename = filename
            };

            _lists.Add(list);
            if (initialMembers != null)
            {
                list.Items.AddRange(initialMembers.Select(it => it.Id));
            }
            OnListModified?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, list));
            return(list);
        }
Пример #4
0
        public bool CheckDuplicateListName(string name, QaListStubs current = null)
        {
            if (_lists.Any(it => it.Name == name && !ReferenceEquals(it, current)))
            {
                return(true);
            }
            if (current != null)
            {
                return(false);
            }
            var filename = MarsherFilesystem.GetPath(ListDirectoryName, name + ExtensionName);

            if (!File.Exists(filename))
            {
                return(false);
            }
            LoadList(filename);
            return(true);
        }
Пример #5
0
        public MarsherUpdateManager()
        {
            var updateUrlPath = MarsherFilesystem.GetPath(UpdateUrlPath);
            var nf            = MarsherFilesystem.GetPath(NewVersionIdentifierPath);

            if (!File.Exists(nf))
            {
                File.WriteAllText(nf, Assembly.GetCallingAssembly().GetName().Version.ToString());
                Updated = true;
            }
            else
            {
                var versionStr = File.ReadAllText(nf).Trim();
                Version.TryParse(versionStr, out var version);
                if (version != null && Assembly.GetCallingAssembly().GetName().Version > version)
                {
                    File.WriteAllText(nf, Assembly.GetCallingAssembly().GetName().Version.ToString());
                    Updated = true;
                }
            }
            if (!File.Exists(updateUrlPath))
            {
                Updated = false;
                File.WriteAllText(updateUrlPath, DefaultUpdateUrl);
            }
            else
            {
                _updateUrl = File.ReadAllText(updateUrlPath);
            }
            try
            {
                _mgr = new UpdateManager(_updateUrl);
            }
            catch (Exception)
            {
                _mgr = null;
            }
        }
Пример #6
0
        public void UpdateList(QaListStubs stub, bool filenameChanged = false)
        {
            var filename = MarsherFilesystem.GetPath(ListDirectoryName, stub.Name + ExtensionName);

            if (filenameChanged && stub.Filename != filename)
            {
                if (string.IsNullOrWhiteSpace(stub.Name))
                {
                    throw new IllegalListNameException();
                }
                if (_lists.Any(it => it.Name == stub.Name && it != stub))
                {
                    throw new DuplicateListNameException();
                }
                if (stub.Name.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
                {
                    throw new IllegalListNameException();
                }
                try
                {
                    File.Move(stub.Filename, filename);
                }
                catch (FileNotFoundException)
                {
                    // Ignored
                }
                catch (IOException)
                {
                    throw new IllegalListNameException();
                }
                stub.Filename = filename;
            }

            File.WriteAllLines(filename, stub.Items);

            OnListModified?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, stub, stub));
        }
Пример #7
0
 protected Service()
 {
     SessionFolder = MarsherFilesystem.GetPath("sessions");
     LoadCookie();
 }