internal async Task <DataModel.Configuration> Get()
        {
            DataModel.Configuration config = new DataModel.Configuration();

            HttpResponseMessage response = await Client.GetAsync(Configuration.Path);

            if (response.IsSuccessStatusCode)
            {
                Response.ConfigurationResponse resultItem = await response.Content.ReadAsAsync <Response.ConfigurationResponse>();

                config.VotingEnabled           = resultItem.votingEnabled;
                config.WatchingEnabled         = resultItem.watchingEnabled;
                config.UnassignedIssuesAllowed = resultItem.unassignedIssuesAllowed;
                config.SubTasksEnabled         = resultItem.subTasksEnabled;
                config.IssueLinkingEnabled     = resultItem.issueLinkingEnabled;
                config.TimeTrackingEnabled     = resultItem.timeTrackingEnabled;
                config.AttachmentsEnabled      = resultItem.attachmentsEnabled;

                config.WorkingHoursPerDay      = resultItem.timeTrackingConfiguration.workingHoursPerDay;
                config.WorkingDaysPerWeek      = resultItem.timeTrackingConfiguration.workingDaysPerWeek;
                config.TimeTrackingTimeFormat  = resultItem.timeTrackingConfiguration.timeFormat;
                config.TimeTrackingDefaultUnit = resultItem.timeTrackingConfiguration.defaultUnit;
            }
            else if (response.StatusCode != System.Net.HttpStatusCode.Unauthorized)
            {
                response.EnsureSuccessStatusCode();
            }

            return(config);
        }
Exemple #2
0
        public int UpdateCustomerConfiguration(Customer Customer)
        {
            if (!BusinessRule.CheckConfigurationCount(Customer))
            {
                throw new ConfigurationCountLimitExceededException("1 configuration set should not have more than 3 configurations!");
            }

            if (!BusinessRule.CheckConfigurationType(Customer))
            {
                throw new DuplicatedConfigurationTypeException("1 configuration set should not have 2 or more configurations that are of the same type!");
            }

            Dictionary <string, string> suspectConfs = null;

            if (!BusinessRule.CheckConfigurationDBConnectionString(Customer, out suspectConfs))
            {
                throw new DuplicatedDatabaseException("1 configuration set should not have 2 or more configurations that are using the same database!");
            }
            else if ((suspectConfs != null) && (suspectConfs.Count > 0))
            {
                string message = "Suspect databases found in the bindings of the following configurations, please double check to make sure that they are not the same database:";

                string suspectConfListTemplate = "Business Name: \"{0}\", Server Name: \"{1}\"; ";

                message += System.Environment.NewLine;

                foreach (string bizName in suspectConfs.Keys)
                {
                    message += string.Format(suspectConfListTemplate, bizName, suspectConfs[bizName]);
                    message += System.Environment.NewLine;
                }

                throw new DuplicatedDatabaseException(message);
            }

            if (!BusinessRule.ValidateConfigurationDBConnectionString(Customer))
            {
                throw new InvalidConnectionStringException("Connection string is invalid! Make sure each field of the connection string has its value assigned, and also make sure loopback address is not used.");
            }

            int returnValue = -9;

            using (DataModel.DataModelContainer container = new DataModelContainer())
            {
                DataModel.Customer cust = container.Customers.First((o) => (o.Id.ToLower() == Customer.ID.ToLower()));

                cust.Name = Customer.Name;

                //cust.ReferenceId = Customer.ReferenceID;

                if (Customer.ReferenceID != null)
                {
                    cust.ReferenceId = "";

                    for (int i = 0; i < Customer.ReferenceID.Length; i++)
                    {
                        cust.ReferenceId += Customer.ReferenceID[i];

                        if (i != (Customer.ReferenceID.Length - 1))
                        {
                            cust.ReferenceId += ",";
                        }
                    }
                }

                var confs = container.Configurations.Where((o) => (o.CustomerId == Customer.ID)).ToArray();

                List <Configuration> customerConfList = new List <Configuration>(Customer.Configurations);

                for (int i = 0; i < confs.Length; i++)
                {
                    for (int j = 0; j < customerConfList.Count; j++)
                    {
                        if ((confs[i] != null) && (customerConfList[j] != null))
                        {
                            if (confs[i].Id.ToLower() == customerConfList[j].ID.ToLower())
                            {
                                confs[i].DbConnectionString = customerConfList[j].DbConnectionString;
                                confs[i].TypeId             = ((int)(customerConfList[j].ConfigurationType));

                                customerConfList.RemoveAt(j);
                                j--;
                            }
                        }
                    }
                }

                if (customerConfList.Count > 0)
                {
                    foreach (var conf in customerConfList)
                    {
                        if (conf != null)
                        {
                            DataModel.Configuration configuration = new DataModel.Configuration()
                            {
                                Customer           = cust,
                                Id                 = conf.ID,
                                CustomerId         = cust.Id,
                                DbConnectionString = conf.DbConnectionString,
                                TypeId             = (int)(conf.ConfigurationType)
                            };

                            container.Configurations.Add(configuration);
                        }
                    }
                }

                returnValue = container.SaveChanges();
            }

            return(returnValue);
        }
Exemple #3
0
        public string AddCustomerConfiguration(Customer Customer)
        {
            if (!BusinessRule.CheckConfigurationCount(Customer))
            {
                throw new ConfigurationCountLimitExceededException("1 configuration set should not have more than 3 configurations!");
            }

            if (!BusinessRule.CheckConfigurationType(Customer))
            {
                throw new DuplicatedConfigurationTypeException("1 configuration set should not have 2 or more configurations that are of the same type!");
            }

            Dictionary <string, string> suspectConfs = null;

            if (!BusinessRule.CheckConfigurationDBConnectionString(Customer, out suspectConfs))
            {
                throw new DuplicatedDatabaseException("1 configuration set should not have 2 or more configurations that are using the same database!");
            }
            else if ((suspectConfs != null) && (suspectConfs.Count > 0))
            {
                string message = "Suspect databases found in the bindings of the following configurations, please double check to make sure that they are not the same database:";

                string suspectConfListTemplate = "Business Name: \"{0}\", Server Name: \"{1}\"; ";

                message += System.Environment.NewLine;

                foreach (string bizName in suspectConfs.Keys)
                {
                    message += string.Format(suspectConfListTemplate, bizName, suspectConfs[bizName]);
                    message += System.Environment.NewLine;
                }

                throw new DuplicatedDatabaseException(message);
            }

            if (!BusinessRule.ValidateConfigurationDBConnectionString(Customer))
            {
                throw new InvalidConnectionStringException("Connection string is invalid! Make sure each field of the connection string has its value assigned, and also make sure loopback address is not used.");
            }

            using (DataModelContainer container = new DataModelContainer())
            {
                DataModel.Customer cust = new DataModel.Customer()
                {
                    Id   = Customer.ID,
                    Name = Customer.Name
                };

                //if (String.IsNullOrEmpty(Customer.ReferenceID))
                //{
                //    cust.ReferenceId = Customer.ReferenceID;
                //}

                if (Customer.ReferenceID != null)
                {
                    cust.ReferenceId = "";

                    for (int i = 0; i < Customer.ReferenceID.Length; i++)
                    {
                        cust.ReferenceId += Customer.ReferenceID[i];

                        if (i != (Customer.ReferenceID.Length - 1))
                        {
                            cust.ReferenceId += ",";
                        }
                    }
                }

                container.Customers.Add(cust);

                foreach (var conf in Customer.Configurations)
                {
                    if (conf != null)
                    {
                        DataModel.Configuration configuration = new DataModel.Configuration()
                        {
                            Customer           = cust,
                            Id                 = conf.ID,
                            CustomerId         = cust.Id,
                            DbConnectionString = conf.DbConnectionString,
                            TypeId             = (int)(conf.ConfigurationType)
                        };

                        container.Configurations.Add(configuration);
                    }
                }

                container.SaveChanges();
            }

            return(Customer.ID);
        }