Пример #1
0
        /// <summary>
        /// Gets the url from the config file for each api type
        /// </summary>
        /// <param name="apiTypeEnum">Type of api to be fired</param>
        /// <param name="data">Data, if any to be appended in it</param>
        /// <param name="hasXmlConfigured">Check if the url is to be composed from an xml. Default true</param>
        /// <param name="hasFilter">Check if the url is to be composed from an xml. Default true</param>
        /// <returns></returns>
        static string GetUrlFromConfig(ApiTypeEnum apiTypeEnum, object data = null, bool hasXmlConfigured = true, bool hasFilter = false)
        {
            var url     = string.Empty;
            var xmlPath = string.Empty;
            var xml     = string.Empty;
            var query   = string.Empty;

            if (hasXmlConfigured)
            {
                xmlPath = GetEnumDescription(apiTypeEnum);
                xml     = XDocument.Load(HttpContext.Current.Server.MapPath(xmlPath)).ToString();
                query   = GetQueryFromXml(xml);
            }


            if (apiTypeEnum == ApiTypeEnum.Persons ||
                apiTypeEnum == ApiTypeEnum.AllBackups ||
                apiTypeEnum == ApiTypeEnum.Locations ||
                apiTypeEnum == ApiTypeEnum.AllJobs ||
                apiTypeEnum == ApiTypeEnum.AllRoles)
            {
                url = BaseUrl + "databases" + DatabaseName + "find?" + query;
            }
            else if (apiTypeEnum == ApiTypeEnum.CreateData)
            {
                url = BaseUrl + "models" + DatabaseName + ModelId + "?layoutonopen=true";
            }
            else if (apiTypeEnum == ApiTypeEnum.ModelConnection)
            {
                url = BaseUrl + "/models" + DatabaseName + "/" + ModelId + "/" + "?withcontent=true";
            }
            else if (apiTypeEnum == ApiTypeEnum.DeleteData)
            {
                url = BaseUrl + "models" + DatabaseName + ModelId + "/connections" + "?occid=" + Convert.ToString(data) + "";
            }
            else if (apiTypeEnum == ApiTypeEnum.BackupsByRole ||
                     apiTypeEnum == ApiTypeEnum.RolesByJob ||
                     apiTypeEnum == ApiTypeEnum.Jobs)
            {
                url = BaseUrl + "objects" + DatabaseName + "query";
            }

            if (hasFilter && !string.IsNullOrEmpty(FilterText))
            {
                url += "&attrfilter=" + HttpUtility.UrlEncode("1=" + FilterText.Trim().ToLower() + " ") + " ";
            }

            return(url);
        }
Пример #2
0
        /// <summary>
        /// Gets the description from the enum
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        static string GetEnumDescription(ApiTypeEnum value)
        {
            var fi = value.GetType().GetField(value.ToString());

            var attributes =
                (DescriptionAttribute[])fi.GetCustomAttributes(
                    typeof(DescriptionAttribute),
                    false);

            if (attributes != null && attributes.Length > 0)
            {
                return(attributes[0].Description);
            }

            return(value.ToString());
        }
Пример #3
0
        /// <summary>
        /// This build a url path as per the api configs
        /// </summary>
        /// <param name="apiTypeEnum">API Type enums</param>
        /// <param name="data">Data to be appended at the end of the url</param>
        /// <param name="hasXmlConfigured">bool flag to set if the url is to be contstructed from xml</param>
        /// <param name="hasFilter">bool flag to set if the url is to be contstructed from xml</param>
        /// <returns>Url path as per the configs</returns>
        public static string UrlBuilder(ApiTypeEnum apiTypeEnum, object data = null, bool hasXmlConfigured = true, bool hasFilter = false)
        {
            var url = GetUrlFromConfig(apiTypeEnum, data, hasXmlConfigured, hasFilter);

            return(url);
        }