Exemplo n.º 1
0
        internal static object ToJsonModel(Site site, string path)
        {
            var section = GetDirectoryBrowseSection(site, path);

            DirectoryBrowsingId dirbId = new DirectoryBrowsingId(site?.Id, path, section.IsLocallyStored);

            DirectoryBrowseShowFlags showFlags = section.ShowFlags;

            Dictionary <string, bool> showDictionary = new Dictionary <string, bool>();

            showDictionary.Add("date", showFlags.HasFlag(DirectoryBrowseShowFlags.Date));
            showDictionary.Add("time", showFlags.HasFlag(DirectoryBrowseShowFlags.Time));
            showDictionary.Add("size", showFlags.HasFlag(DirectoryBrowseShowFlags.Size));
            showDictionary.Add("extension", showFlags.HasFlag(DirectoryBrowseShowFlags.Extension));
            showDictionary.Add("long_date", showFlags.HasFlag(DirectoryBrowseShowFlags.LongDate));

            var obj = new {
                id                 = dirbId.Uuid,
                scope              = site == null ? string.Empty : site.Name + path,
                metadata           = ConfigurationUtility.MetadataToJson(section.IsLocallyStored, section.IsLocked, section.OverrideMode, section.OverrideModeEffective),
                enabled            = section.Enabled,
                allowed_attributes = showDictionary,
                website            = SiteHelper.ToJsonModelRef(site),
            };

            return(Environment.Hal.Apply(Defines.Resource.Guid, obj));
        }
Exemplo n.º 2
0
        public static void UpdateSettings(dynamic model, Site site, string path, string configPath = null)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            var section = GetDirectoryBrowseSection(site, path, configPath);

            try {
                DynamicHelper.If <bool>((object)model.enabled, v => section.Enabled = v);

                if (model.allowed_attributes != null)
                {
                    Dictionary <string, bool> showDictionary = JsonConvert.DeserializeObject <Dictionary <string, bool> >(model.allowed_attributes.ToString());

                    if (showDictionary == null)
                    {
                        throw new ApiArgumentException("allowed_attributes");
                    }

                    DirectoryBrowseShowFlags showFlags = section.ShowFlags;
                    if (showDictionary.ContainsKey("date"))
                    {
                        if (showDictionary["date"])
                        {
                            showFlags |= DirectoryBrowseShowFlags.Date;
                        }
                        else
                        {
                            showFlags &= ~DirectoryBrowseShowFlags.Date;
                        }
                    }
                    if (showDictionary.ContainsKey("time"))
                    {
                        if (showDictionary["time"])
                        {
                            showFlags |= DirectoryBrowseShowFlags.Time;
                        }
                        else
                        {
                            showFlags &= ~DirectoryBrowseShowFlags.Time;
                        }
                    }
                    if (showDictionary.ContainsKey("size"))
                    {
                        if (showDictionary["size"])
                        {
                            showFlags |= DirectoryBrowseShowFlags.Size;
                        }
                        else
                        {
                            showFlags &= ~DirectoryBrowseShowFlags.Size;
                        }
                    }
                    if (showDictionary.ContainsKey("extension"))
                    {
                        if (showDictionary["extension"])
                        {
                            showFlags |= DirectoryBrowseShowFlags.Extension;
                        }
                        else
                        {
                            showFlags &= ~DirectoryBrowseShowFlags.Extension;
                        }
                    }
                    if (showDictionary.ContainsKey("long_date"))
                    {
                        if (showDictionary["long_date"])
                        {
                            showFlags |= DirectoryBrowseShowFlags.LongDate;
                        }
                        else
                        {
                            showFlags &= ~DirectoryBrowseShowFlags.LongDate;
                        }
                    }

                    section.ShowFlags = showFlags;
                }


                if (model.metadata != null)
                {
                    DynamicHelper.If <OverrideMode>((object)model.metadata.override_mode, v => section.OverrideMode = v);
                }
            }
            catch (JsonSerializationException e) {
                throw new ApiArgumentException("allowed_attributes", e);
            }
            catch (FileLoadException e) {
                throw new LockedException(section.SectionPath, e);
            }
            catch (DirectoryNotFoundException e) {
                throw new ConfigScopeNotFoundException(e);
            }
        }