Exemplo n.º 1
0
        public List <Worker_Dto> WorkerLoadAllFromRemote()
        {
            log.LogEverything("Not Specified", t.GetMethodName() + " called");

            var parsedData        = JRaw.Parse(http.WorkerLoadAllFromRemote());
            List <Worker_Dto> lst = new List <Worker_Dto>();

            foreach (JToken item in parsedData)
            {
                string     firstName    = item["first_name"].ToString();
                string     lastName     = item["last_name"].ToString();
                string     email        = item["email"].ToString();
                int        microtingUid = int.Parse(item["id"].ToString());
                DateTime?  createdAt    = DateTime.Parse(item["created_at"].ToString());
                DateTime?  updatedAt    = DateTime.Parse(item["updated_at"].ToString());
                Worker_Dto temp         = new Worker_Dto(microtingUid, firstName, lastName, email, createdAt, updatedAt);
                lst.Add(temp);
            }
            return(lst);
        }
Exemplo n.º 2
0
        //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));
            }
        }
Exemplo n.º 3
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));
            }
        }