Пример #1
0
        public string VerifyPath(string subpath)
        {
            var cloudPrefix = string.Empty;

            var  subpathSegments   = subpath?.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            long siteId            = 0;
            long siteActiveThemeId = 0;

            if (subpathSegments?.Length > 2)
            {
                siteId            = NumericUtils.GetLongIntegerValueFromObject(subpathSegments[0]);
                siteActiveThemeId = NumericUtils.GetLongIntegerValueFromObject(subpathSegments[1]);
            }

            try
            {
                cloudPrefix = $"/{siteId}/{siteActiveThemeId}/";

                if (subpath.StartsWith(cloudPrefix, StringComparison.OrdinalIgnoreCase))
                {
                    subpath = $"{subpath.Substring(cloudPrefix.Length - 1)}";
                }
                else if (subpath.StartsWith($"/{siteId}/", StringComparison.OrdinalIgnoreCase))
                {
                    subpath = $"{subpath.Substring($"/{siteId}/".Length - 1)}";
                }
            }
            catch (Exception ex)
            {
                //OE.LogError(ex.Message, ex);
            }

            var isPreserved = IsPreserved(siteId, subpath);

            if (!isPreserved)
            {
                if (!subpath.StartsWith("/local/", StringComparison.InvariantCultureIgnoreCase))
                {
                    subpath = $"/local{subpath}";
                }
            }
            else
            {
                if (!subpath.StartsWith("/local/", StringComparison.InvariantCultureIgnoreCase))
                {
                    subpath = $"/local{subpath}";
                }
            }

            return(subpath.Trim('/'));
        }
Пример #2
0
        public IFileInfo GetFileInfo(string subpath)
        {
            var  subpathSegments = subpath?.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            long siteId          = 0;

            if (subpathSegments?.Length > 2)
            {
                siteId = NumericUtils.GetLongIntegerValueFromObject(subpathSegments[0]);
            }

            subpath = VerifyPath(subpath);

            return(_physicalFileProvider.GetFileInfo(subpath));
        }
Пример #3
0
        public IChangeToken Watch(string filter)
        {
            var  subpathSegments   = filter?.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            long siteId            = 0;
            long siteActiveThemeId = 0;

            if (subpathSegments?.Length > 2)
            {
                siteId = NumericUtils.GetLongIntegerValueFromObject(subpathSegments[0]);
            }

            var path = VerifyPath(filter);

            return(_physicalFileProvider.Watch($"{path}"));
        }
Пример #4
0
        public Dictionary <string, object> PrepareParamValues <A>(RestmeDbQueryType queryType, A data,
                                                                  string[] chosenColumnsOnly = null,
                                                                  string[] columnsToExclude  = null) where A : IRestmeDbEntity
        {
            var paramValues = new Dictionary <string, object>();

            List <KeyValuePair <string, string> > props;

            switch (queryType)
            {
            case RestmeDbQueryType.Update:
                props = MapUpdateColumns <T>(chosenColumnsOnly, columnsToExclude)?.ToList();
                break;

            case RestmeDbQueryType.Delete:
                props = MapDeleteColumns <T>(chosenColumnsOnly, columnsToExclude)?.ToList();
                break;

            case RestmeDbQueryType.Insert:
                props = MapInsertColumns <T>(chosenColumnsOnly, columnsToExclude)?.ToList();
                break;

            default:
                //when executing select query, use type <A> so all properties will be used
                props = MapSelectColumns <A>(chosenColumnsOnly, columnsToExclude)?.ToList();
                break;
            }

            if (props?.Count > 0)
            {
                if (chosenColumnsOnly?.Length > 0)
                {
                    props = props.Where(item => chosenColumnsOnly.Contains(item.Key)).ToList();
                }
                else if (columnsToExclude?.Length > 0)
                {
                    props = props.Where(item => !columnsToExclude.Contains(item.Key)).ToList();
                }
                foreach (var prop in props)
                {
                    try
                    {
                        var objValue = data.GetPropertyValue(prop.Key);
                        if (objValue != null && objValue is DateTime)
                        {
                            paramValues.Add(prop.Key,
                                            DateTimeUtils.IsValidSqlDateTimeValue(objValue) ? objValue : null);
                        }
                        else if (objValue != null && (objValue is int || objValue is long))
                        {
                            if (IsForeignKey <T>(prop) && NumericUtils.GetLongIntegerValueFromObject(objValue) == 0)
                            {
                                paramValues.Add(prop.Key, null);
                            }
                            else
                            {
                                paramValues.Add(prop.Key, objValue);
                            }
                        }
                        else if (objValue != null && objValue.GetType().GetTypeInfo().IsEnum)
                        {
                            paramValues.Add(prop.Key, (int)objValue);
                        }
                        else
                        {
                            paramValues.Add(prop.Key, objValue);
                        }
                    }
                    catch (Exception ex)
                    {
                        RestmeDb.Logger?.LogError(ex.Message, ex, queryType, data, chosenColumnsOnly, columnsToExclude);
                    }
                }
            }

            return(paramValues);
        }