public void TestSaveContexts_New()
        {
            DefinedContexts dc    = null;
            DefinedContexts dcNew = null;

            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                dc = sqlite.LoadContexts();
            }

            dc.Add(new Context("b19bce30-96fe-46dc-b408-891a12a3a933", "Weekly Team Meeting"));

            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                sqlite.SaveContexts(dc);
            }

            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                dcNew = sqlite.LoadContexts();
                Assert.AreEqual(7, dcNew.Count);
                Assert.AreEqual("2ad57821-dad5-4e0a-abb4-47d99b314f21", dcNew.FindIdByDescr("Home").ID);
                Assert.AreEqual("be17f3e2-764b-43b5-b943-63faf6223863", dcNew.FindIdByDescr("Office").ID);
                Assert.AreEqual("f89d513b-c24d-468e-99f3-b841e5ceca6f", dcNew.FindIdByDescr("Computer").ID);
                Assert.AreEqual("ae7491da-4a83-4cc6-ad26-cd090e81417b", dcNew.FindIdByDescr("Errands").ID);
                Assert.AreEqual("c50d02de-d22c-475b-9fef-6e24c05f966b", dcNew.FindIdByDescr("Phone").ID);
                Assert.AreEqual("1b9c460b-0287-4011-87fc-0ae0c5f7b81c", dcNew.FindIdByDescr("Manager").ID);
                Assert.AreEqual("b19bce30-96fe-46dc-b408-891a12a3a933", dcNew.FindIdByDescr("Weekly Team Meeting").ID);
            }
            Assert.IsFalse(DefinedContexts.AreDifferences(dc, dcNew));
        }
        public void TestSaveProject_AddProject_WithTasks()
        {
            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                Collection <Project> prjList = sqlite.LoadProjects();
                DefinedContexts      dc      = sqlite.LoadContexts();

                var removedProjectID = prjList[0].UniqueID;
                var newProject       = new Project("New Test Project");
                var newTask          = new Task("New Task")
                {
                    ContextID = dc.FindIdByDescr("Home").ID
                };
                newProject.AddTask(newTask);
                prjList.Add(newProject);

                sqlite.SaveProjects(prjList);

                Collection <Project> prjListNew = sqlite.LoadProjects();

                Assert.IsTrue(ProjectComparer.AreListsEquivalent(prjList, prjListNew,
                                                                 out List <Project> chgList, out List <Project> addList, out List <Project> delList,
                                                                 out List <Project> chgTaskList));
                Assert.IsTrue(prjListNew[10].TaskList.Select(t => t.UniqueID == newTask.UniqueID).First());
            }
        }
Пример #3
0
        static async Task Main(string[] args)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection
            .AddSingleton <LogMessageHandler>()
            .AddConferenceClient()
            .ConfigureHttpClient(
                c => c.BaseAddress = new Uri("https://hc-conference-app.azurewebsites.net/graphql/"),
                b => b.AddHttpMessageHandler <LogMessageHandler>())
            .AddSQLitePersistence("Data Source=mydb.db;");

            IServiceProvider  services    = serviceCollection.BuildServiceProvider();
            SQLitePersistence persistence = services.GetRequiredService <SQLitePersistence>();
            IConferenceClient client      = services.GetRequiredService <IConferenceClient>();

            // 1) fill store with persisted data.
            await persistence.InitializeAsync();

            // 2) watch store for updates
            using var storeSession =
                      client
                      .GetSessions
                      .Watch(ExecutionStrategy.CacheAndNetwork)
                      .Where(r => r.IsSuccessResult())
                      .SelectMany(r => r.Data !.Sessions !.Nodes)
                      .Subscribe(session => Console.WriteLine($"{session.Id} - {session.Title}"));

            Console.ReadLine();

            var result = await client.UpdateSessionTitle.ExecuteAsync("U2Vzc2lvbgppMzU=", "Abc 123");

            Console.ReadLine();
        }
 public void TestLoadContexts()
 {
     using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
     {
         DefinedContexts dc = sqlite.LoadContexts();
         Assert.AreEqual(6, dc.Count);
         Assert.AreEqual("2ad57821-dad5-4e0a-abb4-47d99b314f21", dc.FindIdByDescr("Home").ID);
         Assert.AreEqual("be17f3e2-764b-43b5-b943-63faf6223863", dc.FindIdByDescr("Office").ID);
         Assert.AreEqual("f89d513b-c24d-468e-99f3-b841e5ceca6f", dc.FindIdByDescr("Computer").ID);
         Assert.AreEqual("ae7491da-4a83-4cc6-ad26-cd090e81417b", dc.FindIdByDescr("Errands").ID);
         Assert.AreEqual("c50d02de-d22c-475b-9fef-6e24c05f966b", dc.FindIdByDescr("Phone").ID);
         Assert.AreEqual("1b9c460b-0287-4011-87fc-0ae0c5f7b81c", dc.FindIdByDescr("Manager").ID);
     }
 }
        public void TestSaveProject_ChangedProject()
        {
            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                Collection <Project> prjList = sqlite.LoadProjects();

                var changedID = prjList[0].UniqueID;
                prjList[0].ProjectName = "Changed Name";

                sqlite.SaveProjects(prjList);

                Collection <Project> prjListNew = sqlite.LoadProjects();

                Assert.IsTrue(ProjectComparer.AreListsEquivalent(prjList, prjListNew,
                                                                 out List <Project> chgList, out List <Project> addList, out List <Project> delList,
                                                                 out List <Project> chgTaskList));
            }
        }
        public void TestSaveProject_AddProject_NoTasks()
        {
            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                Collection <Project> prjList = sqlite.LoadProjects();

                var removedProjectID = prjList[0].UniqueID;
                var newProject       = new Project("New Test Project");
                prjList.Add(newProject);

                sqlite.SaveProjects(prjList);

                Collection <Project> prjListNew = sqlite.LoadProjects();

                Assert.IsTrue(ProjectComparer.AreListsEquivalent(prjList, prjListNew,
                                                                 out List <Project> chgList, out List <Project> addList, out List <Project> delList,
                                                                 out List <Project> chgTaskList));
            }
        }
        public void TestSaveProject_DeleteExistingTask()
        {
            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                Collection <Project> prjList = sqlite.LoadProjects();
                DefinedContexts      dc      = sqlite.LoadContexts();

                var deletedTask = prjList[3].TaskList[1].UniqueID;
                prjList[3].TaskList.RemoveAt(1);

                sqlite.SaveProjects(prjList);

                Collection <Project> prjListNew = sqlite.LoadProjects();

                Assert.IsTrue(ProjectComparer.AreListsEquivalent(prjList, prjListNew,
                                                                 out List <Project> chgList, out List <Project> addList, out List <Project> delList,
                                                                 out List <Project> chgTaskList));
                Assert.AreEqual(0, prjListNew[3].TaskList.Where(t => t.UniqueID == deletedTask).Count());
            }
        }
        public void TestSaveProject_ChangeExistingTask()
        {
            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                Collection <Project> prjList = sqlite.LoadProjects();
                DefinedContexts      dc      = sqlite.LoadContexts();

                var changedTask = prjList[2].TaskList[4].UniqueID;
                prjList[2].TaskList[4].Details = "New details";

                sqlite.SaveProjects(prjList);

                Collection <Project> prjListNew = sqlite.LoadProjects();

                Assert.IsTrue(ProjectComparer.AreListsEquivalent(prjList, prjListNew,
                                                                 out List <Project> chgList, out List <Project> addList, out List <Project> delList,
                                                                 out List <Project> chgTaskList));
                Assert.AreEqual("New details", prjListNew[2].TaskList.Where(t => t.UniqueID == changedTask).First().Details);
            }
        }
        public void TestSaveProject_DeleteProject()
        {
            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                Collection <Project> prjList = sqlite.LoadProjects();

                var removedProjectID = prjList[0].UniqueID;
                prjList.RemoveAt(0);

                sqlite.SaveProjects(prjList);

                Collection <Project> prjListNew = sqlite.LoadProjects();

                Assert.IsTrue(ProjectComparer.AreListsEquivalent(prjList, prjListNew,
                                                                 out List <Project> chgList, out List <Project> addList, out List <Project> delList,
                                                                 out List <Project> chgTaskList));

                // test that tasks tied to the removed project have been deleted from the DB
                Assert.AreEqual(0, sqlite.LoadTasks(removedProjectID.ToString()).Count);
            }
        }
        public void TestSaveContexts_NoChanges()
        {
            DefinedContexts dc    = null;
            DefinedContexts dcNew = null;

            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                dc = sqlite.LoadContexts();
            }

            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                sqlite.SaveContexts(dc);
            }

            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                dcNew = sqlite.LoadContexts();
            }

            Assert.IsFalse(DefinedContexts.AreDifferences(dc, dcNew));
        }
        public void TestSaveProject_AddTaskToExistingProject()
        {
            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                Collection <Project> prjList = sqlite.LoadProjects();
                DefinedContexts      dc      = sqlite.LoadContexts();

                var prjIDWithNewTask = prjList[0].UniqueID;
                var newTask          = new Task("New Task")
                {
                    ContextID = dc.FindIdByDescr("Home").ID
                };
                prjList[0].AddTask(newTask);

                sqlite.SaveProjects(prjList);

                Collection <Project> prjListNew = sqlite.LoadProjects();

                Assert.IsTrue(ProjectComparer.AreListsEquivalent(prjList, prjListNew,
                                                                 out List <Project> chgList, out List <Project> addList, out List <Project> delList,
                                                                 out List <Project> chgTaskList));
                Assert.IsNotNull(prjListNew[0].TaskList.Where(t => t.UniqueID == newTask.UniqueID).First());
            }
        }
Пример #12
0
        public int SaveHostOptions(HostOptions hostOptions)
        {
            try {
                int result = -1;
                using (DbConnection = new SQLitePersistence(DbConnectionSettings)) {
                    if (DbConnection.IsConnected()) {
                        using (DbCommand = new SQLiteCommand()) {
                            string sql =
                                        "UPDATE HostOptions " +
                                        "SET sessiontimeout = @SessionTimeout, locktimeout = @LockTimeout " +
                                        "WHERE id = 1";

                            DbCommand.CommandText = sql;
                            DbCommand.Parameters.Clear();
                            DbCommand.Parameters.AddWithValue("@SessionTimeout", hostOptions.SessionTimeout);
                            DbCommand.Parameters.AddWithValue("@LockTimeout", hostOptions.LockTimeout);
                            result = DbConnection.ExecuteCommand(DbCommand);
                        }
                    }else {
                        throw new Exception("Unable to Connect");
                    }
                }
                return result;
            }catch {
                throw;
            }
        }
Пример #13
0
        public int CreateTables()
        {
            try {
                int result = 0;
                using (DbConnection = new SQLitePersistence(DbConnectionSettings)) {
                    if (DbConnection.IsConnected()) {
                        using (DbCommand = new SQLiteCommand()) {
                            string sql = "CREATE TABLE if not exists  HostSettings " +
                                         " (" +
                                         "ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " +
                                         "DataSource VARCHAR(200)  NULL, " +
                                         "DatabaseName VARCHAR(100)  NULL, " +
                                         "UserLogin VARCHAR(30)  NULL," +
                                         "Password VARCHAR(30)  NULL," +
                                         "SALogin VARCHAR(30)  NULL," +
                                         "SAPassword VARCHAR(30)  NULL," +
                                         "BaseKey TEXT  NULL" +
                                         ")";
                            DbCommand.CommandText = sql;
                            result = DbConnection.ExecuteCommand(DbCommand);

                            // Build HostOptions Table
                            sql = "CREATE TABLE if not exists  HostOptions " +
                                  " (" +
                                  "ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " +
                                  "SessionTimeout int  NULL," +
                                  "LockTimeout int  NULL" +
                                  ");";
                            DbCommand.CommandText = sql;
                            result = DbConnection.ExecuteCommand(DbCommand);

                            // Build HostOptions Table
                            sql = "CREATE TABLE if not exists Accounting" +
                                  " (" +
                                  "InterfaceId int  NULL," +
                                  "Setting1 TEXT  NULL," +
                                  "Setting2 TEXT  NULL," +
                                  "Setting3 TEXT  NULL," +
                                  "Setting4 TEXT  NULL," +
                                  "Setting5 TEXT  NULL" +
                                  ");";
                            DbCommand.CommandText = sql;
                            result = DbConnection.ExecuteCommand(DbCommand);

                            // Remains Last to indicate setup complete
                            // Insert Defaults
                            sql = "SELECT COUNT(ID) AS COUNT FROM HostOptions";
                            DbCommand.CommandText = sql;
                            int count = Convert.ToInt32(DbConnection.ExecuteScalar(DbCommand));
                            if (count <= 0) {
                                sql = "insert into HostOptions (SessionTimeout, LockTimeout) Values(480,30);";
                                DbCommand.CommandText = sql;
                                result = DbConnection.ExecuteCommand(DbCommand);
                            }
                        }
                    }
                }
                return result;
            }catch {
                throw;
            }
        }
Пример #14
0
        public AccountingSettings GetAccountingSettings()
        {
            try {
                AccountingSettings result = new AccountingSettings();
                using (DbConnection = new SQLitePersistence(DbConnectionSettings)) {
                    if (DbConnection.IsConnected()) {
                        using (DbCommand = new SQLiteCommand()) {
                            string sql =
                                "SELECT InterfaceId, Setting1, Setting2, Setting3, Setting4, Setting5 from Accounting";

                            DbCommand.CommandText = sql;
                            DataTable returnDT = DbConnection.ExecuteQuery(DbCommand);
                            if (returnDT.Rows.Count > 0) {
                                DataRow row = returnDT.Rows[0];
                                result.InterfaceId = Convert.ToInt32(row["InterfaceId"]);
                                result.Setting1 = row["Setting1"].ToString();
                                result.Setting2 = row["Setting2"].ToString();
                                result.Setting3 = row["Setting3"].ToString();
                                result.Setting4 = row["Setting4"].ToString();
                                result.Setting5 = row["Setting5"].ToString();
                                row = null;
                            }
                            returnDT = null;
                        }
                    }else {
                        throw new Exception("Unable to Connect");
                    }
                }
                return result;
            }catch {
                throw;
            }
        }
Пример #15
0
        // IDisposable
        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposedValue) {
                if (disposing) {
                    if (this.dbConnectionSettings != null) this.dbConnectionSettings = null;

                    if (this.dbConnection != null) {
                        this.dbConnection.Dispose();
                        this.dbConnection = null;
                    }

                    if (this.dbCommand != null) {
                        this.dbCommand.Dispose();
                        this.dbCommand = null;
                    }
                }
            }
            this.disposedValue = true;
        }
Пример #16
0
        public bool VerifySetup()
        {
            try {
                bool result = false;
                using (DbConnection = new SQLitePersistence(DbConnectionSettings)) {
                    if (DbConnection.IsConnected()) {
                        using (DbCommand = new SQLiteCommand()) {
                            string sql =
                                "SELECT DatabaseName from HostSettings WHERE id = 1";

                            DbCommand.CommandText = sql;
                            DataTable returnDT = DbConnection.ExecuteQuery(DbCommand);
                            if (returnDT.Rows.Count == 1) {
                                DataRow row = returnDT.Rows[0];
                                result = row["DatabaseName"] != DBNull.Value;
                                row = null;
                            }
                            returnDT = null;
                        }
                    }else {
                        throw new Exception("Unable to Connect");
                    }
                }
                return result;
            }catch {
                throw;
            }
        }
Пример #17
0
        public int SaveHostSettings(IHostSettings hostSettings)
        {
            try {
                int result = -1;
                string sql;
                using (DbConnection = new SQLitePersistence(DbConnectionSettings)) {
                    if (DbConnection.IsConnected()) {
                        using (DbCommand = new SQLiteCommand()) {
                            DbCommand.Parameters.Clear();
                            if (hostSettings.Id <= 0) {
                                sql =
                                     "INSERT INTO HostSettings " +
                                     "(datasource, databasename, userlogin, password, salogin, sapassword,basekey) " +
                                     "Values(@DataSource,@DatabaseName,@UserLogin, @Password, @SaLogin, @SaPassword, @BaseKey);";

                                DbCommand.Parameters.AddWithValue("@BaseKey", Security.GetSha2Hash(hostSettings.BaseKey, Crc32.Compute(hostSettings.BaseKey).ToString()));
                            }else {
                                sql =
                                     "UPDATE HostSettings " +
                                     "SET datasource = @DataSource, databasename = @DatabaseName, userlogin = @UserLogin, password = @Password, salogin = @SaLogin, sapassword = @SaPassword " +
                                     "WHERE id = @ID";
                                DbCommand.Parameters.AddWithValue("@ID", hostSettings.Id);
                            }
                            DbCommand.CommandText = sql;
                            DbCommand.Parameters.AddWithValue("@DataSource", hostSettings.DataSource);
                            DbCommand.Parameters.AddWithValue("@DatabaseName", hostSettings.DatabaseName);
                            DbCommand.Parameters.AddWithValue("@UserLogin", hostSettings.UserLogin);
                            DbCommand.Parameters.AddWithValue("@Password", hostSettings.Password);
                            DbCommand.Parameters.AddWithValue("@SaLogin", hostSettings.SALogin);
                            DbCommand.Parameters.AddWithValue("@SaPassword", hostSettings.SAPassword);

                            result = DbConnection.ExecuteCommand(DbCommand);
                        }
                    }else {
                        throw new Exception("Unable to Connect");
                    }
                }
                return result;
            }catch {
                throw;
            }
        }
Пример #18
0
        public HostOptions GetHostOptions()
        {
            try {
                HostOptions result = new HostOptions();
                using (DbConnection = new SQLitePersistence(DbConnectionSettings)) {
                    if (DbConnection.IsConnected()) {
                        using (DbCommand = new SQLiteCommand()) {
                            string sql =
                                "SELECT SessionTimeout, LockTimeout from HostOptions";

                            DbCommand.CommandText = sql;
                            DataTable returnDT = DbConnection.ExecuteQuery(DbCommand);
                            if (returnDT.Rows.Count == 1) {
                                DataRow row = returnDT.Rows[0];
                                result.SessionTimeout = Convert.ToInt32(row["SessionTimeout"]);
                                result.LockTimeout = Convert.ToInt32(row["LockTimeout"]);
                                row = null;
                            }
                            returnDT = null;
                        }
                    }else {
                        throw new Exception("Unable to Connect");
                    }
                }
                return result;
            }catch {
                throw;
            }
        }
Пример #19
0
        public IHostSettings GetHostSettings()
        {
            try {
                IHostSettings result = new HostSettings();
                using (DbConnection = new SQLitePersistence(DbConnectionSettings)) {
                    if (DbConnection.IsConnected()) {
                        using (DbCommand = new SQLiteCommand()) {
                            string sql =
                                        "SELECT Id, DataSource,DatabaseName, UserLogin, Password, SALogin, SAPassword, BaseKey from HostSettings " +
                                        "WHERE Id = 1";

                            DbCommand.CommandText = sql;
                            DataTable returnDT = DbConnection.ExecuteQuery(DbCommand);
                            if (returnDT.Rows.Count == 1) {
                                DataRow row = returnDT.Rows[0];
                                result.Id = Convert.ToInt32(row["Id"]);
                                result.DataSource = row["DataSource"].ToString();
                                result.DatabaseName = row["DatabaseName"].ToString();
                                result.UserLogin = row["UserLogin"].ToString();
                                result.Password = row["Password"].ToString();
                                result.SALogin = row["SALogin"].ToString();
                                result.SAPassword = row["SAPassword"].ToString();
                                result.BaseKey = row["BaseKey"].ToString();
                                row = null;
                            }
                            returnDT = null;
                        }
                    }else {
                        throw new Exception("Unable to Connect");
                    }
                }
                return result;
            }catch {
                throw;
            }
        }
        public void TestLoadProjects()
        {
            using (SQLitePersistence sqlite = new SQLitePersistence(new SQLitePersistenceConfig(GetTestDBLocation())))
            {
                Collection <Project> prjList = sqlite.LoadProjects();
                Assert.AreEqual(10, prjList.Count);
                foreach (var prj in prjList)
                {
                    Assert.AreEqual(5, prj.TaskCount);
                }

                Project prj1 = prjList.First(p => p.ProjectName == "Test Project  1");
                Task    t1_1 = prj1.GetTask("49f184a0-d6bb-44b2-a6e4-cb49559d494e");
                Task    t1_2 = prj1.GetTask("d34c00e4-bdcb-42a5-88e9-4b8961a543f0");
                Task    t1_3 = prj1.GetTask("871ba660-c08c-4bf0-9cd5-650c51a968f0");
                Task    t1_4 = prj1.GetTask("fcbfc3e8-88df-48f5-ae89-80a9ca159113");
                Task    t1_5 = prj1.GetTask("6d1ac5a8-1e68-4de9-901c-ee426d8ec681");

                Assert.AreEqual("Test Task  1.1", t1_1.Name);
                Assert.AreEqual("Detail 1.1", t1_1.Details);
                Assert.AreEqual(1000, t1_1.Order);
                Assert.AreEqual(Model.Task.StatusEnum.New, t1_1.Status);
                Assert.AreEqual(DateTime.Parse("2018-01-01 01:30:54"), t1_1.DateTimeCreated);
                Assert.AreEqual(null, t1_1.DateDue);
                Assert.AreEqual(null, t1_1.DateCompleted);
                Assert.AreEqual(null, t1_1.DateStarted);

                Assert.AreEqual("Test Task  1.2", t1_2.Name);
                Assert.AreEqual("", t1_2.Details);
                Assert.AreEqual(2000, t1_2.Order);
                Assert.AreEqual(Model.Task.StatusEnum.Done, t1_2.Status);
                Assert.AreEqual(DateTime.Parse("2018-01-02 02:30:54"), t1_2.DateTimeCreated);
                Assert.IsTrue(DateTime.Now >= t1_2.DateTimeCreated);
                Assert.AreEqual(null, t1_2.DateDue);
                Assert.AreEqual(DateTime.Parse("2018-01-02"), t1_2.DateCompleted);
                Assert.AreEqual(null, t1_2.DateStarted);

                Assert.AreEqual("Test Task  1.3", t1_3.Name);
                Assert.AreEqual("", t1_3.Details);
                Assert.AreEqual(3000, t1_3.Order);
                Assert.AreEqual(Model.Task.StatusEnum.InProgress, t1_3.Status);
                Assert.AreEqual(DateTime.Parse("2018-01-03 03:30:54"), t1_3.DateTimeCreated);
                Assert.AreEqual(null, t1_3.DateStarted);
                Assert.AreEqual(null, t1_3.DateCompleted);
                Assert.AreEqual(DateTime.Parse("2018-01-03"), t1_3.DateDue);

                Assert.AreEqual("Test Task  1.4", t1_4.Name);
                Assert.AreEqual("", t1_4.Details);
                Assert.AreEqual(4000, t1_4.Order);
                Assert.AreEqual(Model.Task.StatusEnum.Waiting, t1_4.Status);
                Assert.AreEqual(DateTime.Parse("2018-01-04 04:30:54"), t1_4.DateTimeCreated);
                Assert.AreEqual(null, t1_4.DateDue);
                Assert.AreEqual(null, t1_4.DateCompleted);
                Assert.AreEqual(DateTime.Parse("2018-01-04"), t1_4.DateStarted);

                Assert.AreEqual("Test Task  1.5", t1_5.Name);
                Assert.AreEqual("", t1_5.Details);
                Assert.AreEqual(5000, t1_5.Order);
                Assert.AreEqual(Model.Task.StatusEnum.NotStarted, t1_5.Status);
                Assert.AreEqual(DateTime.Parse("2018-01-05 05:30:54"), t1_5.DateTimeCreated);
                Assert.AreEqual(null, t1_5.DateDue);
                Assert.AreEqual(null, t1_5.DateCompleted);
                Assert.AreEqual(null, t1_5.DateStarted);

                Project prj2 = prjList.First(p => p.ProjectName == "Test Project  2");
                Task    t2_1 = prj2.GetTask("19f6e9eb-1cf6-4416-81b1-e4b42e9d6dfe");
                Task    t2_2 = prj2.GetTask("56138652-f14a-4a26-bda6-c43976adb414");
                Task    t2_3 = prj2.GetTask("79962192-ad3d-44fc-bf15-cf9de5926dde");
                Task    t2_4 = prj2.GetTask("bd69d3bf-7dbe-4b88-88ca-d44d96b025f8");
                Task    t2_5 = prj2.GetTask("b76551c7-45f5-4712-a697-9dc0f93829ca");

                Assert.AreEqual("Test Task  2.1", t2_1.Name);
                Assert.AreEqual("Test Task  2.2", t2_2.Name);
                Assert.AreEqual("Test Task  2.3", t2_3.Name);
                Assert.AreEqual("Test Task  2.4", t2_4.Name);
                Assert.AreEqual("Test Task  2.5", t2_5.Name);

                Project prj3 = prjList.First(p => p.ProjectName == "Test Project  3");
                Task    t3_1 = prj3.GetTask("c61e4925-294c-4a68-81a3-aedd4c7754ac");
                Task    t3_2 = prj3.GetTask("9d3f2cee-84aa-4deb-b8e1-c5b88792f7e8");
                Task    t3_3 = prj3.GetTask("3c69e3d5-8883-4fe6-82e3-a19160db20a1");
                Task    t3_4 = prj3.GetTask("c98839f0-9ea5-4103-a72d-40f0afa6a114");
                Task    t3_5 = prj3.GetTask("6cb81a5a-439e-4b08-83a9-e4df143573f1");


                Assert.AreEqual("Test Task  3.1", t3_1.Name);
                Assert.AreEqual("Test Task  3.2", t3_2.Name);
                Assert.AreEqual("Test Task  3.3", t3_3.Name);
                Assert.AreEqual("Test Task  3.4", t3_4.Name);
                Assert.AreEqual("Test Task  3.5", t3_5.Name);

                Project prj4 = prjList.First(p => p.ProjectName == "Test Project  4");
                Task    t4_1 = prj4.GetTask("e95f56cb-5f37-4d87-af3d-a3267924c9aa");
                Task    t4_2 = prj4.GetTask("a73b0a06-a0b3-4f7f-827c-0a8c158565d4");
                Task    t4_3 = prj4.GetTask("d30a9ff9-fd68-41c8-9126-51c56c1f7e85");
                Task    t4_4 = prj4.GetTask("535a323a-3cc4-45f2-a0ad-a89debace4a2");
                Task    t4_5 = prj4.GetTask("6b1e3072-47de-4fc5-9579-4f07a2fa144c");

                Assert.AreEqual("Test Task  4.1", t4_1.Name);
                Assert.AreEqual("Test Task  4.2", t4_2.Name);
                Assert.AreEqual("Test Task  4.3", t4_3.Name);
                Assert.AreEqual("Test Task  4.4", t4_4.Name);
                Assert.AreEqual("Test Task  4.5", t4_5.Name);

                Project prj5 = prjList.First(p => p.ProjectName == "Test Project  5");
                Task    t5_1 = prj5.GetTask("e51921e6-1a20-407b-aca3-f0f50af176c8");
                Task    t5_2 = prj5.GetTask("e3edd351-f76d-465f-82e5-b44a772d72be");
                Task    t5_3 = prj5.GetTask("3a1dc098-c85c-49c9-bf76-48caf8bd7f3a");
                Task    t5_4 = prj5.GetTask("a2be4560-65e2-42e7-a930-04af97866c4f");
                Task    t5_5 = prj5.GetTask("a08c62ca-8036-4723-9b4d-2e2b615f9fef");

                Assert.AreEqual("Test Task  5.1", t5_1.Name);
                Assert.AreEqual("Test Task  5.2", t5_2.Name);
                Assert.AreEqual("Test Task  5.3", t5_3.Name);
                Assert.AreEqual("Test Task  5.4", t5_4.Name);
                Assert.AreEqual("Test Task  5.5", t5_5.Name);

                Project prj6 = prjList.First(p => p.ProjectName == "Test Project  6");
                Task    t6_1 = prj6.GetTask("a6dc6a7d-5744-4767-8f27-4dce529975f8");
                Task    t6_2 = prj6.GetTask("7c13673d-422e-411a-ac1d-2c3a166c1683");
                Task    t6_3 = prj6.GetTask("0a8935f4-2a80-40ff-ab1b-90a3bfa33d49");
                Task    t6_4 = prj6.GetTask("fb9cd0b5-4b50-4b52-9b81-ee2a577629e3");
                Task    t6_5 = prj6.GetTask("4ed89d52-47ca-4fd0-a7f2-df7a2c8c75cf");

                Assert.AreEqual("Test Task  6.1", t6_1.Name);
                Assert.AreEqual("Test Task  6.2", t6_2.Name);
                Assert.AreEqual("Test Task  6.3", t6_3.Name);
                Assert.AreEqual("Test Task  6.4", t6_4.Name);
                Assert.AreEqual("Test Task  6.5", t6_5.Name);

                Project prj7 = prjList.First(p => p.ProjectName == "Test Project  7");
                Task    t7_1 = prj7.GetTask("0fcbae3c-ac37-4ee8-95ef-10d190b17e2c");
                Task    t7_2 = prj7.GetTask("a4efcf3c-a920-4b6b-869f-1dc2340f4f1b");
                Task    t7_3 = prj7.GetTask("095c6c3b-4e4d-407e-9580-e7dd1c972a54");
                Task    t7_4 = prj7.GetTask("002d22b2-e42b-4b39-89c7-3d002783cc2e");
                Task    t7_5 = prj7.GetTask("4f5c8442-21a6-4235-b3a0-6bef72642e69");

                Assert.AreEqual("Test Task  7.1", t7_1.Name);
                Assert.AreEqual("Test Task  7.2", t7_2.Name);
                Assert.AreEqual("Test Task  7.3", t7_3.Name);
                Assert.AreEqual("Test Task  7.4", t7_4.Name);
                Assert.AreEqual("Test Task  7.5", t7_5.Name);

                Project prj8 = prjList.First(p => p.ProjectName == "Test Project  8");
                Task    t8_1 = prj8.GetTask("02fadb5d-e9d5-4726-b458-c4e15ca98633");
                Task    t8_2 = prj8.GetTask("b771aaa9-81b3-4e68-a7c9-a00c6135331f");
                Task    t8_3 = prj8.GetTask("366e78a9-c8fa-41f8-8660-4019c98614b1");
                Task    t8_4 = prj8.GetTask("3292b766-7206-4ff2-86dc-5957587975ec");
                Task    t8_5 = prj8.GetTask("1e676e6c-8ff7-462f-9500-e2cd2d613e94");

                Assert.AreEqual("Test Task  8.1", t8_1.Name);
                Assert.AreEqual("Test Task  8.2", t8_2.Name);
                Assert.AreEqual("Test Task  8.3", t8_3.Name);
                Assert.AreEqual("Test Task  8.4", t8_4.Name);
                Assert.AreEqual("Test Task  8.5", t8_5.Name);

                Project prj9 = prjList.First(p => p.ProjectName == "Test Project  9");
                Task    t9_1 = prj9.GetTask("f76bec0c-ac6d-4c5d-ba7a-64102867a307");
                Task    t9_2 = prj9.GetTask("d84f4b07-3ad6-44dd-8696-a770a044d660");
                Task    t9_3 = prj9.GetTask("04effe3e-d355-4094-b604-37ab8641307e");
                Task    t9_4 = prj9.GetTask("45c96282-7d5d-43dc-99aa-0dda9d550c38");
                Task    t9_5 = prj9.GetTask("d968c831-5def-433e-95f7-38965f50e1dd");

                Assert.AreEqual("Test Task  9.1", t9_1.Name);
                Assert.AreEqual("Test Task  9.2", t9_2.Name);
                Assert.AreEqual("Test Task  9.3", t9_3.Name);
                Assert.AreEqual("Test Task  9.4", t9_4.Name);
                Assert.AreEqual("Test Task  9.5", t9_5.Name);

                Project prj10 = prjList.First(p => p.ProjectName == "Test Project 10");
                Task    t10_1 = prj10.GetTask("0c6be24d-6516-41d6-9022-f50ddd1d7293");
                Task    t10_2 = prj10.GetTask("a5f571ff-3641-444d-8c8c-465e3b2081fe");
                Task    t10_3 = prj10.GetTask("68a7e284-cfb6-4435-8c0f-e8c68e437225");
                Task    t10_4 = prj10.GetTask("06b9a45c-e628-4bd5-ad30-2bca2a8b9ed9");
                Task    t10_5 = prj10.GetTask("2585ee54-2202-441f-9112-3ba9a8c7a3f9");

                Assert.AreEqual("Test Task 10.1", t10_1.Name);
                Assert.AreEqual("Test Task 10.2", t10_2.Name);
                Assert.AreEqual("Test Task 10.3", t10_3.Name);
                Assert.AreEqual("Test Task 10.4", t10_4.Name);
                Assert.AreEqual("Test Task 10.5", t10_5.Name);
            }
        }
Пример #21
0
        public int SaveAccountingSettings(AccountingSettings accountingSettings)
        {
            try {
                int result = -1;
                bool isNew = true;
                using (DbConnection = new SQLitePersistence(DbConnectionSettings)) {
                    if (DbConnection.IsConnected()) {
                        using (DbCommand = new SQLiteCommand()) {
                            string sql = "SELECT COUNT(*) AS COUNT FROM Accounting ";

                            DbCommand.CommandText = sql;
                            isNew = Convert.ToBoolean(DbConnection.ExecuteCommand(DbCommand));

                            if (isNew) {
                                sql = "insert into Accounting (InterfaceId,Setting1,Setting2,Setting3,Setting4,Setting5) Values(@InterfaceId,@Setting1,@Setting2,@Setting3,@Setting4,@Setting5)";
                            }else {
                                sql =
                                    @"UPDATE Accounting
                                    SET InterfaceId = @InterfaceId, Setting1 = @Setting1,Setting2 = @Setting2,Setting3 = @Setting3,Setting4 = @Setting4,Setting5 = @Setting5
                                    ";
                            }

                            DbCommand.CommandText = sql;
                            DbCommand.Parameters.Clear();
                            DbCommand.Parameters.AddWithValue("@InterfaceId", accountingSettings.InterfaceId);
                            DbCommand.Parameters.AddWithValue("@Setting1", accountingSettings.Setting1 ?? string.Empty);
                            DbCommand.Parameters.AddWithValue("@Setting2", accountingSettings.Setting2 ?? string.Empty);
                            DbCommand.Parameters.AddWithValue("@Setting3", accountingSettings.Setting3 ?? string.Empty);
                            DbCommand.Parameters.AddWithValue("@Setting4", accountingSettings.Setting4 ?? string.Empty);
                            DbCommand.Parameters.AddWithValue("@Setting5", accountingSettings.Setting5 ?? string.Empty);
                            result = DbConnection.ExecuteCommand(DbCommand);
                        }
                    }else {
                        throw new Exception("Unable to Connect");
                    }
                }
                return result;
            }catch {
                throw;
            }
        }