Exemplo n.º 1
0
        public string GetProperty(string propertyName, string format, CultureInfo formatProvider, UserInfo accessingUser, Scope accessLevel, ref bool propertyNotFound)
        {
            string retVal = "";
            switch (propertyName.ToLower())
            {
                case "all":
                    int moduleId = _moduleContext.ModuleId;
                    int portalId = _moduleContext.PortalId;
                    int tabId = _moduleContext.TabId;
                    ModuleInfo module = new ModuleController().GetModule(moduleId, tabId);

                    dynamic properties = new ExpandoObject();
                    System.IO.FileInfo fi = new System.IO.FileInfo(HttpContext.Current.Server.MapPath("~/" + _moduleContext.Configuration.ModuleControl.ControlSrc.Replace(".html", "") + ".resx"));
                    string physResourceFile = fi.DirectoryName + "/App_LocalResources/" + fi.Name;
                    string relResourceFile = "/DesktopModules/" + module.DesktopModule.FolderName + "/App_LocalResources/" + fi.Name;
                    if (File.Exists(physResourceFile))
                    {
                        using (var rsxr = new ResXResourceReader(physResourceFile))
                        {
                            var res = rsxr.OfType<DictionaryEntry>()
                                .ToDictionary(
                                    entry => entry.Key.ToString().Replace(".", "_"),
                                    entry => Localization.GetString(entry.Key.ToString(), relResourceFile));

                            properties.Resources = res;
                        }
                    }
                    else
                    {
                        properties.Resources = physResourceFile + " not found";
                    }
                    properties.Settings = _moduleContext.Settings;
                    properties.Editable = _moduleContext.EditMode && _moduleContext.IsEditable;
                    properties.Admin = accessingUser.IsInRole(PortalSettings.Current.AdministratorRoleName);
                    properties.ModuleId = moduleId;
                    properties.PortalId = portalId;
                    properties.UserId = accessingUser.UserID;
                    properties.HomeDirectory = PortalSettings.Current.HomeDirectory.Substring(1);
                    properties.RawUrl = HttpContext.Current.Request.RawUrl;

                    List<string> languages = new List<string>();
                    LocaleController lc = new LocaleController();
                    Dictionary<string, Locale> loc = lc.GetLocales(_moduleContext.PortalId);
                    foreach (KeyValuePair<string, Locale> item in loc)
                    {
                        string cultureCode = item.Value.Culture.Name;
                        languages.Add(cultureCode);
                    }
                    properties.Languages = languages;
                    properties.CurrentLanguage = System.Threading.Thread.CurrentThread.CurrentCulture.Name;

                    retVal = JsonConvert.SerializeObject(properties);
                    break;
                case "view":
                    retVal = (string)_moduleContext.Settings["View"];
                    if (String.IsNullOrEmpty(retVal))
                        retVal = "View.html";
                    break;
                case "list":
                    retVal = (string)_moduleContext.Settings["List"];
                    if (String.IsNullOrEmpty(retVal))
                        retVal = "List.html";
                    break;
            }
            return retVal;

        }