public List <Site_Worker_Dto> SiteWorkerLoadAllFromRemote()
        {
            log.LogEverything("Not Specified", t.GetMethodName() + " called");

            var parsedData             = JRaw.Parse(http.SiteWorkerLoadAllFromRemote());
            List <Site_Worker_Dto> lst = new List <Site_Worker_Dto>();

            foreach (JToken item in parsedData)
            {
                int             microtingUid = int.Parse(item["id"].ToString());
                int             siteUId      = int.Parse(item["site_id"].ToString());
                int             workerUId    = int.Parse(item["user_id"].ToString());
                Site_Worker_Dto temp         = new Site_Worker_Dto(microtingUid, siteUId, workerUId);
                lst.Add(temp);
            }
            return(lst);
        }
        //public string RetractEforms()
        //{
        //    string reply = "";

        //    Communicator communicator = new Communicator(sqlController, log);
        //    if (communicator == null)
        //        return "Failed to create a communicator. Action canceled. Database maybe not configured correct";

        //    List<string> lstCaseMUIds = sqlController.UnitTest_FindAllActiveCases();
        //    foreach (string mUId in lstCaseMUIds)
        //    {
        //        try
        //        {
        //            var aCase = sqlController.CaseReadByMUId(mUId);
        //            if (aCase != null)
        //            {
        //                communicator.Delete(mUId, aCase.SiteUId);

        //                try
        //                {
        //                    sqlController.CaseDelete(mUId);
        //                }
        //                catch
        //                {
        //                    sqlController.CaseDeleteReversed(mUId);
        //                }
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            reply += "EformDelete  :'" + mUId + "' failed, due to:" + ex.Message + Environment.NewLine;
        //        }
        //    }

        //    return reply.Trim();
        //}

        //public string RetractEntities()
        //{
        //    string reply = "";

        //    Communicator communicator = new Communicator(sqlController, log);
        //    if (communicator == null)
        //        return "Failed to create a communicator. Action canceled. Database maybe not configured correct";

        //    List<string> lstEntityMUIds = sqlController.UnitTest_EntitiesFindAllActive();
        //    foreach (string mUId in lstEntityMUIds)
        //    {
        //        try
        //        {
        //            string type = sqlController.EntityGroupDelete(mUId);
        //            if (type != null)
        //                communicator.EntityGroupDelete(type, mUId);
        //        }
        //        catch (Exception ex)
        //        {
        //            reply += "EntityDelete :'" + mUId + "' failed, due to:" + ex.Message + Environment.NewLine;
        //        }
        //    }

        //    return reply.Trim();
        //}

        //public string DbClearData()
        //{
        //    try
        //    {
        //        RetractEforms();

        //        sqlController.UnitTest_TruncateTable(typeof(cases).Name);
        //        sqlController.UnitTest_TruncateTable(typeof(case_versions).Name);
        //        //---
        //        sqlController.UnitTest_TruncateTable(typeof(check_list_sites).Name);
        //        sqlController.UnitTest_TruncateTable(typeof(check_list_site_versions).Name);
        //        //---
        //        sqlController.UnitTest_TruncateTable(typeof(check_list_values).Name);
        //        sqlController.UnitTest_TruncateTable(typeof(check_list_value_versions).Name);
        //        //---
        //        sqlController.UnitTest_TruncateTable(typeof(field_values).Name);
        //        sqlController.UnitTest_TruncateTable(typeof(field_value_versions).Name);
        //        //---
        //        sqlController.UnitTest_TruncateTable(typeof(uploaded_data).Name);
        //        sqlController.UnitTest_TruncateTable(typeof(uploaded_data_versions).Name);
        //        //---
        //        sqlController.UnitTest_TruncateTable(typeof(a_interaction_case_list_versions).Name);
        //        sqlController.UnitTest_TruncateTable(typeof(a_interaction_case_lists).Name);
        //        //---
        //        sqlController.UnitTest_TruncateTable(typeof(a_interaction_case_versions).Name);
        //        sqlController.UnitTest_TruncateTable(typeof(a_interaction_cases).Name);
        //        //---

        //        //---
        //        sqlController.UnitTest_TruncateTable(typeof(notifications).Name);

        //        return "";
        //    }
        //    catch (Exception ex)
        //    {
        //        return t.PrintException(t.GetMethodName() + " failed", ex);
        //    }
        //}

        //public string DbClearTemplat()
        //{
        //    try
        //    {
        //        RetractEntities();

        //        sqlController.UnitTest_TruncateTable(typeof(entity_groups).Name);
        //        sqlController.UnitTest_TruncateTable(typeof(entity_group_versions).Name);
        //        //---
        //        sqlController.UnitTest_TruncateTable(typeof(entity_items).Name);
        //        sqlController.UnitTest_TruncateTable(typeof(entity_item_versions).Name);
        //        //---
        //        sqlController.UnitTest_TruncateTable(typeof(fields).Name);
        //        sqlController.UnitTest_TruncateTable(typeof(field_versions).Name);
        //        //---
        //        sqlController.UnitTest_TruncateTable(typeof(check_lists).Name);
        //        sqlController.UnitTest_TruncateTable(typeof(check_list_versions).Name);

        //        return "";
        //    }
        //    catch (Exception ex)
        //    {
        //        return t.PrintException(t.GetMethodName() + " failed", ex);
        //    }
        //}

        //public string DbClear()
        //{
        //    string reply = "";

        //    Communicator communicator = new Communicator(sqlController, log);
        //    if (communicator == null)
        //        return "Failed to create a communicator. Action canceled. Database maybe not configured correct";

        //    reply += RetractEforms() + Environment.NewLine;
        //    reply += RetractEntities() + Environment.NewLine;
        //    reply += DbClearData() + Environment.NewLine;
        //    reply += DbClearTemplat() + Environment.NewLine;

        //    return reply.TrimEnd();
        //}

        public string DbSetup(string token)
        {
            try
            {
                sqlController = new SqlController(connectionString);

                if (token == null)
                {
                    token = sqlController.SettingRead(Settings.token);
                }

                //if (token.ToLower() == "unittest")
                //    return DbSetupUnitTest();

                sqlController.SettingUpdate(Settings.token, token);

                // configure db
                DbSettingsReloadRemote();

                //sqlController.UnitTest_TruncateTablesIfEmpty();

                Communicator communicator = new Communicator(sqlController, log);

                #region add site's data to db
                if (!bool.Parse(sqlController.SettingRead(Settings.knownSitesDone)))
                {
                    //sqlController.UnitTest_TruncateTable(typeof(sites).Name);
                    foreach (var item in communicator.SiteLoadAllFromRemote())
                    {
                        SiteName_Dto siteDto = sqlController.SiteRead(item.SiteUId);
                        if (siteDto == null)
                        {
                            sqlController.SiteCreate(item.SiteUId, item.SiteName);
                        }
                    }

                    //sqlController.UnitTest_TruncateTable(typeof(workers).Name);
                    foreach (var item in communicator.WorkerLoadAllFromRemote())
                    {
                        Worker_Dto workerDto = sqlController.WorkerRead(item.WorkerUId);
                        if (workerDto == null)
                        {
                            sqlController.WorkerCreate(item.WorkerUId, item.FirstName, item.LastName, item.Email);
                        }
                    }

                    //sqlController.UnitTest_TruncateTable(typeof(site_workers).Name);
                    foreach (var item in communicator.SiteWorkerLoadAllFromRemote())
                    {
                        Site_Worker_Dto siteWorkerDto = sqlController.SiteWorkerRead(item.MicrotingUId, null, null);
                        if (siteWorkerDto == null)
                        {
                            try
                            {
                                sqlController.SiteWorkerCreate(item.MicrotingUId, item.SiteUId, item.WorkerUId);
                            }
                            catch
                            {
                                // We do catch this because right now we a descripency at the API side.
                            }
                        }
                    }

                    int customerNo = communicator.OrganizationLoadAllFromRemote(token).CustomerNo;

                    //sqlController.UnitTest_TruncateTable(typeof(units).Name);
                    foreach (var item in communicator.UnitLoadAllFromRemote(customerNo))
                    {
                        Unit_Dto unitDto = sqlController.UnitRead(item.UnitUId);
                        if (unitDto == null)
                        {
                            try
                            {
                                sqlController.UnitCreate(item.UnitUId, item.CustomerNo, item.OtpCode, item.SiteUId);
                            }
                            catch
                            {
                                // We do catch this because right now we a descripency at the API side.
                            }
                        }
                    }
                    sqlController.SettingUpdate(Settings.knownSitesDone, "true");
                }
                #endregion

                sqlController.SettingUpdate(Settings.firstRunDone, "true");

                return("");
            }
            catch (Exception ex)
            {
                return(t.PrintException(t.GetMethodName() + " failed", ex));
            }
        }
示例#3
0
        public void SQL_SiteWorker_SiteWorkerRead_ReadsSiteWorker()
        {
            // Arrance

            #region Arrance

            #region Checklist
            DateTime    cl1_Ca = DateTime.Now;
            DateTime    cl1_Ua = DateTime.Now;
            check_lists Cl1    = testHelpers.CreateTemplate(cl1_Ca, cl1_Ua, "A1", "D1", "caseType1", "WhereItIs", 1, 0);

            #endregion

            #region SubCheckList

            check_lists Cl2 = testHelpers.CreateSubTemplate("A2", "D2", "caseType2", 2, 0, Cl1);

            #endregion

            #region Fields

            #region field1


            fields f1 = testHelpers.CreateField(1, "barcode", Cl2, "e2f4fb", "custom", null, "", "Comment field description",
                                                5, 1, DbContext.field_types.Where(x => x.field_type == "picture").First(), 0, 0, 1, 0, "Comment field", 1, 55, "55", "0", 0, 0, null, 1, 0,
                                                0, 0, "", 49);

            #endregion

            #region field2


            fields f2 = testHelpers.CreateField(1, "barcode", Cl2, "f5eafa", "custom", null, "", "showPDf Description",
                                                45, 1, DbContext.field_types.Where(x => x.field_type == "comment").First(), 0, 1, 0, 0,
                                                "ShowPdf", 0, 5, "5", "0", 0, 0, null, 0, 0, 0, 0, "", 9);


            #endregion

            #region field3

            fields f3 = testHelpers.CreateField(0, "barcode", Cl2, "f0f8db", "custom", 3, "", "Number Field Description",
                                                83, 0, DbContext.field_types.Where(x => x.field_type == "picture").First(), 0, 0, 1, 0,
                                                "Numberfield", 1, 8, "4865", "0", 0, 1, null, 1, 0, 0, 0, "", 1);


            #endregion

            #region field4


            fields f4 = testHelpers.CreateField(1, "barcode", Cl2, "fff6df", "custom", null, "", "date Description",
                                                84, 0, DbContext.field_types.Where(x => x.field_type == "picture").First(), 0, 0, 1, 0,
                                                "Date", 1, 666, "41153", "0", 0, 1, null, 0, 1, 0, 0, "", 1);


            #endregion

            #region field5

            fields f5 = testHelpers.CreateField(0, "barcode", Cl2, "ffe4e4", "custom", null, "", "picture Description",
                                                85, 0, DbContext.field_types.Where(x => x.field_type == "comment").First(), 1, 0, 1, 0,
                                                "Picture", 1, 69, "69", "1", 0, 1, null, 0, 1, 0, 0, "", 1);


            #endregion

            #region field6

            fields f6 = testHelpers.CreateField(0, "barcode", Cl2, "ffe4e4", "custom", null, "", "picture Description",
                                                86, 0, DbContext.field_types.Where(x => x.field_type == "comment").First(), 1, 0, 1, 0,
                                                "Picture", 1, 69, "69", "1", 0, 1, null, 0, 1, 0, 0, "", 1);


            #endregion

            #region field7

            fields f7 = testHelpers.CreateField(0, "barcode", Cl2, "ffe4e4", "custom", null, "", "picture Description",
                                                87, 0, DbContext.field_types.Where(x => x.field_type == "comment").First(), 1, 0, 1, 0,
                                                "Picture", 1, 69, "69", "1", 0, 1, null, 0, 1, 0, 0, "", 1);


            #endregion

            #region field8

            fields f8 = testHelpers.CreateField(0, "barcode", Cl2, "ffe4e4", "custom", null, "", "picture Description",
                                                88, 0, DbContext.field_types.Where(x => x.field_type == "comment").First(), 1, 0, 1, 0,
                                                "Picture", 1, 69, "69", "1", 0, 1, null, 0, 1, 0, 0, "", 1);


            #endregion

            #region field9

            fields f9 = testHelpers.CreateField(0, "barcode", Cl2, "ffe4e4", "custom", null, "", "picture Description",
                                                89, 0, DbContext.field_types.Where(x => x.field_type == "comment").First(), 1, 0, 1, 0,
                                                "Picture", 1, 69, "69", "1", 0, 1, null, 0, 1, 0, 0, "", 1);


            #endregion

            #region field10

            fields f10 = testHelpers.CreateField(0, "barcode", Cl2, "ffe4e4", "custom", null, "", "picture Description",
                                                 90, 0, DbContext.field_types.Where(x => x.field_type == "comment").First(), 1, 0, 1, 0,
                                                 "Picture", 1, 69, "69", "1", 0, 1, null, 0, 1, 0, 0, "", 1);


            #endregion

            #endregion

            #region Workers

            #region worker1
            workers worker1 = testHelpers.CreateWorker("*****@*****.**", "Arne", "Jensen", 21);

            #endregion

            #region worker2
            workers worker2 = testHelpers.CreateWorker("*****@*****.**", "Lasse", "Johansen", 44);

            #endregion

            #region worker3
            workers worker3 = testHelpers.CreateWorker("*****@*****.**", "Svend", "Jensen", 22);

            #endregion

            #region worker4
            workers worker4 = testHelpers.CreateWorker("*****@*****.**", "Bjarne", "Nielsen", 23);

            #endregion

            #region worker5
            workers worker5 = testHelpers.CreateWorker("*****@*****.**", "Ib", "Hansen", 24);

            #endregion

            #region worker6
            workers worker6 = testHelpers.CreateWorker("*****@*****.**", "Hozan", "Aziz", 25);

            #endregion

            #region worker7
            workers worker7 = testHelpers.CreateWorker("*****@*****.**", "Nicolai", "Peders", 26);

            #endregion

            #region worker8
            workers worker8 = testHelpers.CreateWorker("*****@*****.**", "Amin", "Safari", 27);

            #endregion

            #region worker9
            workers worker9 = testHelpers.CreateWorker("*****@*****.**", "Leo", "Rebaz", 28);

            #endregion

            #region worker10
            workers worker10 = testHelpers.CreateWorker("*****@*****.**", "Stig", "Berthelsen", 29);

            #endregion

            #endregion

            #region sites

            #region Site1
            sites site1 = testHelpers.CreateSite("SiteName1", 88);

            #endregion

            #region Site2
            sites site2 = testHelpers.CreateSite("SiteName2", 89);

            #endregion

            #region Site3
            sites site3 = testHelpers.CreateSite("SiteName3", 90);

            #endregion

            #region Site4
            sites site4 = testHelpers.CreateSite("SiteName4", 91);

            #endregion

            #region Site5
            sites site5 = testHelpers.CreateSite("SiteName5", 92);

            #endregion

            #region Site6
            sites site6 = testHelpers.CreateSite("SiteName6", 93);

            #endregion

            #region Site7
            sites site7 = testHelpers.CreateSite("SiteName7", 94);

            #endregion

            #region Site8
            sites site8 = testHelpers.CreateSite("SiteName8", 95);

            #endregion

            #region Site9
            sites site9 = testHelpers.CreateSite("SiteName9", 96);

            #endregion

            #region Site10
            sites site10 = testHelpers.CreateSite("SiteName10", 97);

            #endregion

            #endregion

            #region units
            units unit = testHelpers.CreateUnit(48, 49, site1, 348);

            #endregion

            #region site_workers
            site_workers site_workers = testHelpers.CreateSiteWorker(55, site1, worker1);

            #endregion

            #endregion

            // Act

            Site_Worker_Dto match = sut.SiteWorkerRead(site_workers.microting_uid, site1.id, worker1.id);

            // Assert

            Assert.AreEqual(site_workers.microting_uid, match.MicrotingUId);
            Assert.AreEqual(site_workers.worker.microting_uid, match.WorkerUId);
            Assert.AreEqual(site_workers.site.microting_uid, match.SiteUId);
        }
示例#4
0
        public string DbSetup(string token)
        {
            try
            {
                sqlController = new SqlController(connectionString);

                if (token == null)
                {
                    token = sqlController.SettingRead(Settings.token);
                }

                sqlController.SettingUpdate(Settings.token, token);

                // configure db
                DbSettingsReloadRemote();


                string       comAddressApi       = sqlController.SettingRead(Settings.comAddressApi);
                string       comAddressBasic     = sqlController.SettingRead(Settings.comAddressBasic);
                string       comOrganizationId   = sqlController.SettingRead(Settings.comOrganizationId);
                string       ComAddressPdfUpload = sqlController.SettingRead(Settings.comAddressPdfUpload);
                string       ComSpeechToText     = sqlController.SettingRead(Settings.comSpeechToText);
                Communicator communicator        = new Communicator(token, comAddressApi, comAddressBasic, comOrganizationId, ComAddressPdfUpload, log, ComSpeechToText);

                #region add site's data to db
                if (!bool.Parse(sqlController.SettingRead(Settings.knownSitesDone)))
                {
                    foreach (var item in communicator.SiteLoadAllFromRemote())
                    {
                        SiteName_Dto siteDto = sqlController.SiteRead(item.SiteUId);
                        if (siteDto == null)
                        {
                            sqlController.SiteCreate(item.SiteUId, item.SiteName);
                        }
                    }

                    foreach (var item in communicator.WorkerLoadAllFromRemote())
                    {
                        Worker_Dto workerDto = sqlController.WorkerRead(item.WorkerUId);
                        if (workerDto == null)
                        {
                            sqlController.WorkerCreate(item.WorkerUId, item.FirstName, item.LastName, item.Email);
                        }
                    }

                    foreach (var item in communicator.SiteWorkerLoadAllFromRemote())
                    {
                        Site_Worker_Dto siteWorkerDto = sqlController.SiteWorkerRead(item.MicrotingUId, null, null);
                        if (siteWorkerDto == null)
                        {
                            try
                            {
                                sqlController.SiteWorkerCreate(item.MicrotingUId, item.SiteUId, item.WorkerUId);
                            }
                            catch
                            {
                                // We do catch this because right now we a descripency at the API side.
                            }
                        }
                    }

                    int customerNo = communicator.OrganizationLoadAllFromRemote(token).CustomerNo;

                    foreach (var item in communicator.UnitLoadAllFromRemote(customerNo))
                    {
                        Unit_Dto unitDto = sqlController.UnitRead(item.UnitUId);
                        if (unitDto == null)
                        {
                            try
                            {
                                sqlController.UnitCreate(item.UnitUId, item.CustomerNo, item.OtpCode, item.SiteUId);
                            }
                            catch
                            {
                                // We do catch this because right now we a descripency at the API side.
                            }
                        }
                    }
                    sqlController.SettingUpdate(Settings.knownSitesDone, "true");
                }
                #endregion

                sqlController.SettingUpdate(Settings.firstRunDone, "true");

                return("");
            }
            catch (Exception ex)
            {
                return(t.PrintException(t.GetMethodName("AdminTools") + " failed", ex));
            }
        }