/// <summary> /// Construct the class by copying from another object. /// </summary> /// <param name="attr">base attribute to copy to the new one</param> public LimePropertyAttribute(LimePropertyAttribute attr) { if (attr != null) { LimeLib.CopyPropertyValues(attr, this); } }
/// <summary> /// Duplicate a LimeCommand, and enable to make it a Toggle comand /// </summary> /// <param name="copy">Source command to copy</param> /// <param name="toggle">enable to create a Toggle command</param> public LimeCommand(LimeCommand copy, bool toggle) { // Copy properties LimeLib.CopyPropertyValues(copy, this); ToggleCmdName = copy.ToggleCmdName; _ToggleCmd = copy._ToggleCmd; // Convert to Toggle command AlwaysToggle = (copy.IsToggle && toggle); }
// -------------------------------------------------------------------------------------------------- #region ctors /// <summary> /// Construct a reference to a property in a class /// </summary> /// <param name="ident">identifier of the LimeProperty</param> /// <param name="source">Parent object of the class where the property belongs</param> /// <param name="pi">PropertyInfo of the property (null if not referenced)</param> /// <param name="attr">Configuration attributes attached to this property</param> /// <param name="name">User-friendly name of the object. Automatically taken from translation by default.</param> /// <param name="readOnly">Define readOnly attribute</param> /// <param name="visible">Define visibility to the user</param> private void Factory(string ident, object source, PropertyInfo pi, LimePropertyAttribute attr, string name = null, bool?readOnly = null, bool?visible = null) { LimeLib.LifeTrace(this); Source = source; string languageSection = IniLanguageSection; if (pi != null) { // Referenced source PInfo = pi; var vobj = pi.GetValue(Source); Type = vobj != null?vobj.GetType() : pi.PropertyType; Ident = ident ?? pi.Name; } else { // Unreferenced source Type = source.GetType(); Ident = ident; } // Implied attributes if (source is System.Windows.Input.ICommand) { ReadOnly = true; languageSection = IniLanguageCommand; } // Copy attribute if (attr != null) { if (attr.GetType() != typeof(LimePropertyAttribute)) { attr = new LimePropertyAttribute(attr); } LimeLib.CopyPropertyValues(attr, this); } // Forced attributes if (readOnly != null) { ReadOnly = readOnly == true; } if (visible != null) { Visible = visible == true; } // Bind the object if (source is INotifyPropertyChanged src) { //LimeMsg.Debug("LimeProperty Factory: Subscribe {0} / {1}", Ident, src); src.PropertyChanged += SourcePropertyChanged; } if (Ident == null || name != null || !Visible) { Name = name ?? ident; Desc = null; } else { // Retrieve properties from LimeLanguage Name = LimeLanguage.Translate(languageSection, Ident + ".name", Ident); Desc = LimeLanguage.Translate(languageSection, Ident + ".desc", Name); } }
/// <summary> /// Try to retrieve the Person data from the local database, or Internet /// </summary> /// <returns>true if successful (false if not found)</returns> public bool Load() { if (IsLoading || IsSaving || IsLoaded) { return(true); } if (string.IsNullOrEmpty(Name)) { return(false); } // Make filename from person name string path = null; string localDb = LimeLib.ResolvePath(LocalDbPath); if (localDb != null) { var name = Name; // Remove characters forbidden in filenames string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars()); foreach (char c in invalid) { name = name.Replace(c.ToString(), ""); } path = Path.Combine(localDb, name + Extension); } try { IsLoading = true; if (File.Exists(path)) { LimePerson lp; // Local Database using (Stream file = File.Open(path, FileMode.Open)) { lp = ZeroFormatterSerializer.Deserialize <LimePerson>(file); } // Properties to be preserved var roles = Roles; var rolesReadOnly = RolesReadOnly; // Copy properties LimeLib.CopyPropertyValues(lp, this); // Restore Properties to be preserved Roles = roles; RolesReadOnly = rolesReadOnly; // Done IsLoaded = true; return(true); } } catch { LimeMsg.Error("UnableFileDir", path); } finally { IsLoading = false; } if (IsDownloading && MetaSearch != null) { bool ret = false; try { IsLoading = true; LimeMsg.Debug("Person Load: Download {0}", Name); ret = MetaSearch.GetPersonAsync(this).Result; } catch { LimeMsg.Error("ErrPersonDownload", Name); } finally { IsLoading = false; IsDownloading = false; } IsLoaded = true; if (ret && AutoSave) { Save(); } return(ret); } return(false); }
/// <summary> /// Convert a TagLib IPicture to a LimePicture /// </summary> /// <param name="pic">IPicture source to copy</param> public LimePicture(IPicture pic) { LimeLib.CopyPropertyValues(pic, this); }