Beispiel #1
0
        private List <BimCompany> CompanyTableToList(DataTable input)
        {
            List <BimCompany> companies = new List <BimCompany>();

            foreach (DataRow row in input.Rows)
            {
                BimCompany company = new BimCompany();

                company.name              = Util.GetStringOrNull(row["name"]);
                company.trade             = Util.GetStringOrNull(row["trade"]);
                company.address_line_1    = Util.GetStringOrNull(row["address_line_1"]);
                company.address_line_2    = Util.GetStringOrNull(row["address_line_2"]);
                company.city              = Util.GetStringOrNull(row["city"]);
                company.state_or_province = Util.GetStringOrNull(row["state_or_province"]);
                company.postal_code       = Util.GetStringOrNull(row["postal_code"]);
                company.country           = Util.GetStringOrNull(row["country"]);
                company.phone             = Util.GetStringOrNull(row["phone"]);
                company.website_url       = Util.GetStringOrNull(row["website_url"]);
                company.description       = Util.GetStringOrNull(row["description"]);
                company.erp_id            = Util.GetStringOrNull(row["erp_id"]);
                company.tax_id            = Util.GetStringOrNull(row["tax_id"]);

                companies.Add(company);
            }
            return(companies);
        }
        private void ActivateServices(List <BimProject> projects, List <ServiceActivation> services)
        {
            try
            {
                Log.Info("");
                Log.Info("Start add services and admins");
                foreach (BimProject project in projects)
                {
                    foreach (ServiceActivation service in services)
                    {
                        BimCompany comp = DataController.Companies.FirstOrDefault(c => c.name.Equals(service.company));
                        if (comp != null)
                        {
                            service.company_id = comp.id;
                        }

                        Log.Info($"- processing {service.service_type} for {service.email} on { project.name}");
                        string id = DataController.GetProjectIdByName(project.name);
                        if (id == null)
                        {
                            string msg = $"- system was unable to find project name '{project.name}'";
                            Log.Error(msg);
                            Log.Info($"");
                            continue;
                        }
                        ActivateService(service, id);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
            }
        }
        private ProjectUser CustomGetUserForRow(DataRow row, string projectName, BimCompany company)
        {
            ProjectUser user = new ProjectUser();

            user.project_name = projectName;
            user.email        = Util.GetStringOrNull(row["user_email"]);
            if (company != null)
            {
                user.company_id = company.id;
            }
            else
            {
                Util.LogImportant($"No company assigned to user with email: {user.email}.");
            }

            List <IndustryRole> currRole = new List <IndustryRole>();

            if (Util.GetStringOrNull(row["industry_role"]) != null)
            {
                user.industry_roles = GetIndustryRoleIds(projectName, Util.GetStringOrNull(row["industry_role"]));
                List <IndustryRole> roles = GetRolesForProject(projectName);

                List <string> industryRoles =
                    GetIndustryRoleNames(projectName, Util.GetStringOrNull(row["industry_role"]));
                foreach (string userRole in industryRoles)
                {
                    IndustryRole role = roles.Find(x => x.name.ToLower() == userRole.ToLower());
                    if (role != null)
                    {
                        currRole.Add(role);
                    }
                    else
                    {
                        Util.LogImportant(
                            $"Industry role '{userRole}' was not found in project! Skipping this role for user '{user.email}'.");
                    }
                }
            }

            CustomAddServicesFromIndustryRole(user, currRole);

            if (string.IsNullOrWhiteSpace(user.email))
            {
                Util.LogImportant($"No email available for user - something went wrong!");
            }

            return(user);
        }
        public static Dictionary <int, ServiceActivation> GetServiceActivations()
        {
            Dictionary <int, ServiceActivation> serviceActivations = new Dictionary <int, ServiceActivation>();
            int i = 0;

            foreach (DataRow row in _serviceTable.Rows)
            {
                i++;
                // skip empty rows
                if (string.IsNullOrWhiteSpace(Convert.ToString(row)))
                {
                    continue;
                }

                ServiceActivation service = new ServiceActivation();
                try
                {
                    service.project_name = Util.GetStringOrNull(row["project_name"]);
                    if (false == Util.IsNameValid(service.project_name))
                    {
                        Log.Error($"- row {i} skipped. project_name is missing or invalid.");
                        continue;
                    }
                    service.service_type = Util.GetStringOrNull(row["service_type"]);

                    if (string.IsNullOrWhiteSpace(service.service_type))
                    {
                        Log.Warn($"- row {i} skipped. service_type is missing.");
                        continue;
                    }
                    //else if (service.service_type.Contains(Config.secondDelimiter.ToString()))
                    //{
                    //    // Replace service_type delimeter to comma
                    //    service.service_type = service.service_type.Replace(Config.secondDelimiter, ',');
                    //}
                    service.email = Util.GetStringOrNull(row["email"]);
                    if (string.IsNullOrWhiteSpace(service.email))
                    {
                        Log.Warn($"- row {i} skipped. email is missing.");
                        continue;
                    }
                    service.company = Util.GetStringOrNull(row["company"]);
                    if (string.IsNullOrWhiteSpace(service.company))
                    {
                        Log.Warn($"- row {i} skipped. company is missing.");
                        continue;
                    }

                    BimCompany comp = Companies.FirstOrDefault(c => c.name.Equals(service.company));
                    if (comp != null)
                    {
                        service.company_id = comp.id;
                    }
                }
                catch (Exception e)
                {
                    row["result"]         = ResultCodes.ErrorParsing;
                    row["result_message"] = e.Message;
                    Log.Error(e, $"- error parsing row {i}");
                    continue;
                }
                serviceActivations.Add(i - 1, service);
            }
            return(serviceActivations);
        }
Beispiel #5
0
        private List <ProjectUser> CustomGetUsers(DataTable table, List <HqUser> projectUsers, List <BimCompany> companies, string projectName, int startRow)
        {
            List <ProjectUser> resultUsers = new List <ProjectUser>();

            List <string> allUserEmailsInCsv = new List <string>();
            List <string> existingUsers      = GetUserEmails(projectUsers);

            List <string> existingCompanies = GetCompanyNames(companies);

            existingCompanies = existingCompanies.ConvertAll(d => d.ToLower());

            for (int row = startRow; row < table.Rows.Count; row++)
            {
                // Itterate until next project
                if (!string.IsNullOrEmpty(table.Rows[row]["project_name"].ToString()) && row != startRow)
                {
                    break;
                }
                // Continue if no user at this row
                if (string.IsNullOrEmpty(table.Rows[row]["user_email"].ToString()))
                {
                    continue;
                }

                // Check if user with same email already in csv
                if (!string.IsNullOrEmpty(table.Rows[row]["user_email"].ToString()) && allUserEmailsInCsv.Contains(table.Rows[row]["user_email"].ToString()))
                {
                    // Check if user with same email but with multiple rows with 'industry_role' or 'company'
                    if (!string.IsNullOrEmpty(table.Rows[row]["industry_role"].ToString()))
                    {
                        Util.LogImportant($"User with email '{table.Rows[row]["user_email"]}' already exists with other " +
                                          $"'industry_role' values. Only the first values for each user will be taken. See row number {row + 2} in the CSV-File.");
                    }

                    // Check if user with same email but with multiple rows with 'industry_role' or 'company'
                    if (!string.IsNullOrEmpty(table.Rows[row]["company"].ToString()))
                    {
                        Util.LogImportant($"User with email '{table.Rows[row]["user_email"]}' already exists with other " +
                                          $"'company' values. Only the first values for each user will be taken. See row number {row + 2} in the CSV-File.");
                    }
                }

                if (!allUserEmailsInCsv.Contains(table.Rows[row]["user_email"].ToString()))
                {
                    allUserEmailsInCsv.Add(table.Rows[row]["user_email"].ToString());
                }

                // Continue if user with the same email already exists
                if (!string.IsNullOrEmpty(table.Rows[row]["user_email"].ToString()) && existingUsers.Contains(table.Rows[row]["user_email"].ToString()))
                {
                    continue;
                }

                // Check if company exists
                string companyName = table.Rows[row]["company"].ToString();
                if (!string.IsNullOrEmpty(companyName) && !existingCompanies.Contains(companyName.ToLower()))
                {
                    Util.LogImportant($"Something went wrong. Company with name: "
                                      + companyName + $" was not found. User with email: {table.Rows[row]["user_email"]} should be assigned to this company.");
                }

                BimCompany company = companies.Find(x => x.name.ToLower() == companyName.ToLower());

                // Check if user with same email has already been added
                bool        isUserAdded = false;
                ProjectUser projectUser = resultUsers.Find(x => x.email == table.Rows[row]["user_email"].ToString());
                if (projectUser != null)
                {
                    isUserAdded = true;
                    continue;
                }

                ProjectUser user = CustomGetUserForRow(table.Rows[row], projectName, company);

                // Add only if user had not been added already
                if (user != null && !isUserAdded)
                {
                    resultUsers.Add(user);
                }
            }
            return(resultUsers);
        }
Beispiel #6
0
        private List <BimCompany> CustomGetCompanies(DataTable table, List <BimCompany> companies, int startRow)
        {
            if (table == null)
            {
                return(null);
            }

            List <BimCompany> resultCompanies = new List <BimCompany>();

            // Create list with all existing company names
            List <string> existingCompanies = new List <string>();

            foreach (BimCompany existingCompany in companies)
            {
                existingCompanies.Add(existingCompany.name);
            }
            existingCompanies = existingCompanies.ConvertAll(d => d.ToLower());

            for (int row = startRow; row < table.Rows.Count; row++)
            {
                // Itterate until next project
                if (!string.IsNullOrEmpty(table.Rows[row]["project_name"].ToString()) && row != startRow)
                {
                    break;
                }

                if (string.IsNullOrEmpty(table.Rows[row]["company"].ToString()))
                {
                    continue;
                }

                BimCompany newCompany = new BimCompany();

                newCompany.name = Util.GetStringOrNull(table.Rows[row]["company"]);

                // Check if company with same name has been already added
                bool isCompanyAdded = false;
                foreach (BimCompany company in resultCompanies)
                {
                    if (company.name.ToLower() == newCompany.name.ToLower())
                    {
                        isCompanyAdded = true;
                        break;
                    }
                }

                // Check if there was a company with the same name already in the CSV-File
                if (row > 0)
                {
                    for (int j = row - 1; j >= 0; j--)
                    {
                        if (table.Rows[row]["company"].ToString() == table.Rows[j]["company"].ToString())
                        {
                            isCompanyAdded = true;
                            if (!string.IsNullOrEmpty(table.Rows[row]["company_trade"].ToString()))
                            {
                                Util.LogImportant($"Company '{table.Rows[row]["company"]}' has already been added. Company trade is taken only from the first occurrence of the company.");
                            }
                        }
                    }
                }

                if (!isCompanyAdded)
                {
                    string        trade         = Util.GetStringOrNull(table.Rows[row]["company_trade"]);
                    List <string> allowedTrades = GetTrades();

                    allowedTrades = allowedTrades.ConvertAll(d => d.ToLower());

                    if (!allowedTrades.Contains(trade.ToLower()))
                    {
                        trade = "Architecture";
                        Util.LogImportant($"The given company trade '{table.Rows[row]["company_trade"]}' for company '{newCompany.name}' is not recognized. The default trade '{trade}' will be used. For reference see row number {row + 2} in the CSV-File.");
                    }

                    newCompany.trade = trade;

                    // Add only if company had not been added already and company does not already exist
                    if (newCompany != null && !isCompanyAdded && !existingCompanies.Contains(newCompany.name.ToLower()))
                    {
                        resultCompanies.Add(newCompany);
                    }
                }
            }

            return(resultCompanies);
        }