Beispiel #1
0
        public static DataView GetCustomUrls(Guid organizationId)
        {
            using (CustomUrlTableAdapter adapter = new CustomUrlTableAdapter())
            {
                MasterDataSet.CustomUrlDataTable table = adapter.GetCustomUrlsByOrganizationId(organizationId);
                table.Columns.Add("Name", typeof(string));

                Organization org = null;
                foreach (MasterDataSet.CustomUrlRow row in table)
                {
                    if (org == null)
                    {
                        org = OrganizationProvider.GetOrganization(organizationId);
                    }

                    string name = string.Empty;

                    if (row.IsInstanceIdNull())
                    {
                        name = org.Name;
                    }
                    else
                    {
                        Instance inst = InstanceProvider.GetInstance(row.InstanceId);
                        if (inst != null)
                        {
                            name = inst.Name;
                        }
                    }
                    row["Name"] = name;
                }
                table.DefaultView.Sort = string.Format(CultureInfo.InvariantCulture, "{0}, Name", table.InstanceIdColumn.ColumnName);
                return(table.DefaultView);
            }
        }
Beispiel #2
0
        public static void DeleteCustomUrl(Guid customUrlId)
        {
            using (CustomUrlTableAdapter adapter = new CustomUrlTableAdapter())
            {
                using (MasterDataSet.CustomUrlDataTable table = adapter.GetCustomUrl(customUrlId))
                {
                    if (table.Count > 0)
                    {
                        MasterDataSet.CustomUrlRow row = table[0];

                        if (row.IsInstanceIdNull())
                        {
                            RemoveOrganizationCustomUrlFromCache(row.OrganizationId);
                        }
                        else
                        {
                            RemoveInstanceCustomUrlFromCache(row.InstanceId);
                        }

                        row.Delete();

                        adapter.Update(table);
                    }
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Returns the custom URLs by by specified organization id and instance id.
 /// </summary>
 /// <param name="host">The host of the URL to find the custom URLs.</param>
 /// <returns>The Micajah.Common.Dal.MasterDataSet.CustomUrlRow that pupulated by data of the custom URLs.</returns>
 public static MasterDataSet.CustomUrlRow GetCustomUrl(Guid organizationId, Guid instanceId)
 {
     using (CustomUrlTableAdapter adapter = new CustomUrlTableAdapter())
     {
         using (MasterDataSet.CustomUrlDataTable table = adapter.GetCustomUrls(organizationId, instanceId, null, null))
         {
             return((table.Count > 0) ? table[0] : null);
         }
     }
 }
Beispiel #4
0
 public static MasterDataSet.CustomUrlRow GetCustomUrl(Guid customUrlId)
 {
     using (CustomUrlTableAdapter adapter = new CustomUrlTableAdapter())
     {
         using (MasterDataSet.CustomUrlDataTable table = adapter.GetCustomUrl(customUrlId))
         {
             return((table.Count > 0) ? table[0] : null);
         }
     }
 }
Beispiel #5
0
        /// <summary>
        /// Returns the custom URLs by specified host.
        /// </summary>
        /// <param name="host">The host of the URL to find the custom URLs.</param>
        /// <returns>The Micajah.Common.Dal.MasterDataSet.CustomUrlRow that pupulated by data of the custom URLs.</returns>
        public static MasterDataSet.CustomUrlRow GetCustomUrl(string host)
        {
            if (!string.IsNullOrEmpty(host))
            {
                host = host.ToLowerInvariant();
            }

            using (CustomUrlTableAdapter adapter = new CustomUrlTableAdapter())
            {
                using (MasterDataSet.CustomUrlDataTable table = adapter.GetCustomUrls(null, null, host, host))
                {
                    return((table.Count > 0) ? table[0] : null);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Checks if custom url is exists in system
        /// </summary>
        /// <param name="partialCustomUrl">Partial Custom Url with out domain</param>
        /// <returns></returns>
        public static bool ValidateCustomUrl(string partialCustomUrl)
        {
            if (!string.IsNullOrEmpty(partialCustomUrl))
            {
                using (CustomUrlTableAdapter adapter = new CustomUrlTableAdapter())
                {
                    using (MasterDataSet.CustomUrlDataTable table = adapter.GetCustomUrls(null, null, partialCustomUrl, partialCustomUrl))
                    {
                        if (table.Count > 0)
                        {
                            return(false);
                        }
                        else
                        {
                            Organization org     = null;
                            string       segment = RemoveSchemeFormUri(partialCustomUrl);
                            if (segment.Contains("-"))
                            {
                                org = OrganizationProvider.GetOrganizationByPseudoId(segment.Split('-')[0]);
                            }
                            else
                            {
                                org = OrganizationProvider.GetOrganizationByPseudoId(segment);
                            }

                            if (org == null)
                            {
                                MasterDataSet.CustomUrlRow row = GetCustomUrl(segment);
                                if (row != null)
                                {
                                    org = OrganizationProvider.GetOrganization(row.OrganizationId);
                                }
                            }

                            return(org == null);
                        }
                    }
                }
            }

            return(false);
        }
Beispiel #7
0
        public static Guid InsertCustomUrl(Guid organizationId, Guid?instanceId, string fullCustomUrl, string partialCustomUrl)
        {
            ValidatePartialCustomUrl(partialCustomUrl);

            using (CustomUrlTableAdapter adapter = new CustomUrlTableAdapter())
            {
                using (MasterDataSet.CustomUrlDataTable table = adapter.GetCustomUrls(organizationId, instanceId, fullCustomUrl, partialCustomUrl))
                {
                    if (table.Count > 0)
                    {
                        throw new ConstraintException(Resources.CustomUrlProvider_CustomUrlAlreadyExists);
                    }
                }

                Guid customUrlId = Guid.NewGuid();
                if (string.IsNullOrEmpty(fullCustomUrl))
                {
                    fullCustomUrl = string.Empty;
                }
                else
                {
                    fullCustomUrl = fullCustomUrl.ToLowerInvariant();
                }
                if (string.IsNullOrEmpty(partialCustomUrl))
                {
                    partialCustomUrl = string.Empty;
                }
                else
                {
                    partialCustomUrl = partialCustomUrl.ToLowerInvariant();
                }

                adapter.Insert(customUrlId, organizationId, instanceId, fullCustomUrl, partialCustomUrl);

                return(customUrlId);
            }
        }
Beispiel #8
0
        public static void UpdateCustomUrl(Guid customUrlId, string fullCustomUrl, string partialCustomUrl)
        {
            if (customUrlId == Guid.Empty)
            {
                return;
            }

            ValidatePartialCustomUrl(partialCustomUrl);

            using (CustomUrlTableAdapter adapter = new CustomUrlTableAdapter())
            {
                using (MasterDataSet.CustomUrlDataTable table = adapter.GetCustomUrls(null, null, fullCustomUrl, partialCustomUrl))
                {
                    MasterDataSet.CustomUrlRow row = null;
                    if (table.Count > 0)
                    {
                        if (table.Count == 1)
                        {
                            if (table[0].CustomUrlId == customUrlId)
                            {
                                row = table[0];
                            }
                            else
                            {
                                throw new ConstraintException(Resources.CustomUrlProvider_CustomUrlAlreadyExists);
                            }
                        }
                        else
                        {
                            throw new ConstraintException(Resources.CustomUrlProvider_CustomUrlAlreadyExists);
                        }
                    }

                    if (row == null)
                    {
                        row = GetCustomUrl(customUrlId);
                    }

                    if (!ValidateCustomUrl(fullCustomUrl) && !string.IsNullOrEmpty(fullCustomUrl) && (row != null && string.Compare(row.FullCustomUrl, fullCustomUrl, StringComparison.OrdinalIgnoreCase) != 0))
                    {
                        throw new ConstraintException(Resources.CustomUrlProvider_CustomUrlAlreadyExists);
                    }

                    if (!ValidateCustomUrl(partialCustomUrl) && !string.IsNullOrEmpty(partialCustomUrl) && (row != null && string.Compare(row.PartialCustomUrl, partialCustomUrl, StringComparison.OrdinalIgnoreCase) != 0))
                    {
                        throw new ConstraintException(Resources.CustomUrlProvider_CustomUrlAlreadyExists);
                    }

                    if (string.IsNullOrEmpty(fullCustomUrl))
                    {
                        fullCustomUrl = string.Empty;
                    }
                    if (string.IsNullOrEmpty(partialCustomUrl))
                    {
                        partialCustomUrl = string.Empty;
                    }

                    adapter.Update(customUrlId, fullCustomUrl, partialCustomUrl);

                    if (row.IsInstanceIdNull())
                    {
                        RemoveOrganizationCustomUrlFromCache(row.OrganizationId);
                    }
                    else
                    {
                        RemoveInstanceCustomUrlFromCache(row.InstanceId);
                    }
                }
            }
        }