Exemple #1
0
 /// <summary>
 /// Command callback.
 /// Called to select a given set.
 /// </summary>
 /// <param name="setInfo">Set to select.</param>
 private void OnSelectSet(UserResourceSetInfo setInfo)
 {
     if (CanChangeSet(setInfo))
     {
         SelectedSetName = setInfo.Name;
         RaiseSettingValueChanged();
     }
 }
Exemple #2
0
 protected override bool CanChangeSet(UserResourceSetInfo setInfo)
 {
     // Show validation messagebox.
     return(MessageBox.Show(NavigationActor.Instance.ActiveWindow,
                            string.Format("Please be aware that modifying the SRS level set may block "
                                          + "some existing SRS items in the case where the new level set has less "
                                          + "levels than the previous one.{0}Also, please note that the current "
                                          + "scheduled review dates will not be affected.", Environment.NewLine),
                            "SRS level set change warning",
                            MessageBoxButton.OKCancel,
                            MessageBoxImage.Warning,
                            MessageBoxResult.Cancel) == MessageBoxResult.OK);
 }
        /// <summary>
        /// Reads the metadata file of the set.
        /// </summary>
        /// <param name="directoryPath">
        /// Path to the base directory of the set.</param>
        /// <returns>Set info read from the file, or null if
        /// any error occured.</returns>
        public UserResourceSetInfo ReadInfo(string directoryPath)
        {
            try
            {
                string infoFilePath = Path.Combine(directoryPath, InfoFilePath);

                XDocument xdoc         = XDocument.Load(infoFilePath);
                XElement  xinfo        = xdoc.Root;
                XElement  xauthor      = xinfo.Element(XmlNode_Author);
                XElement  xdate        = xinfo.Element(XmlNode_Date);
                XElement  xname        = xinfo.Element(XmlNode_Name);
                XElement  xdescription = xinfo.Element(XmlNode_Description);

                UserResourceSetInfo info = new UserResourceSetInfo();
                info.Path = directoryPath;
                if (xauthor != null)
                {
                    info.Author = xauthor.Value.Trim();
                }
                if (xdate != null)
                {
                    DateTime dateValue = DateTime.MinValue;
                    DateTime.TryParseExact(xdate.Value.Trim(), "yyyy-MM-dd",
                                           CultureInfo.InvariantCulture, DateTimeStyles.None, out dateValue);
                    info.Date = dateValue == DateTime.MinValue ? (DateTime?)null : dateValue;
                }
                if (xname != null)
                {
                    info.Name = xname.Value.Trim();
                }
                else
                {
                    throw new Exception("The set must have a name.");
                }
                if (xdescription != null)
                {
                    info.Description = xdescription.Value.Trim();
                }

                return(info);
            }
            catch (Exception ex)
            {
                LogHelper.GetLogger(GetType().Name)
                .Error(string.Format(
                           "Error while loading the info of the set at \"{0}\".",
                           directoryPath), ex);

                return(null);
            }
        }
Exemple #4
0
        protected void DoInitialization()
        {
            var log = LogHelper.GetLogger(this.GetType().Name);

            log.Info("Loading sets...");
            string baseDirectory = GetBaseDirectoryPath();

            // Load the info of all available sets from the base directory.
            List <UserResourceSetInfo> availableSets = new List <UserResourceSetInfo>();

            foreach (string directoryPath in Directory.EnumerateDirectories(baseDirectory))
            {
                UserResourceSetInfo info = _setManager.ReadInfo(directoryPath);
                if (info != null)
                {
                    availableSets.Add(info);
                    log.InfoFormat("Found set '{0}' at '{1}'.",
                                   info.Name, info.Path);
                }
            }
            AvailableSets = availableSets.ToArray();

            // Then, try to match the setting to one of the sets.
            string selectedRadicalSetName = GetSelectedSetName();

            UserResourceSetInfo selectedInfo = _availableSets
                                               .Where(s => s.Name == selectedRadicalSetName)
                                               .FirstOrDefault();

            if (selectedInfo == null || !TryLoad(selectedInfo.Path))
            {
                log.InfoFormat("Cannot find selected set '{0}'. "
                               + "Will attempt to load default set.",
                               selectedRadicalSetName);

                // Info not found or failed to load.
                selectedInfo = _availableSets
                               .Where(s => s.Name == DefaultSetName)
                               .FirstOrDefault();

                if (selectedInfo == null || !TryLoad(selectedInfo.Path))
                {
                    // Default info not found or failed to load.
                    log.Warn("Could not load default format.");
                    CurrentSet = GetDefaultValue();
                }
            }

            log.Info("Finished loading sets.");
        }
Exemple #5
0
 /// <summary>
 /// Command callback.
 /// Called to browse a given set.
 /// </summary>
 /// <param name="setInfo">Set to browse.</param>
 private void OnBrowseSet(UserResourceSetInfo setInfo)
 {
     try
     {
         Process.Start(setInfo.Path);
     }
     catch (Exception ex)
     {
         LogHelper.GetLogger(GetType().Name)
         .Error(string.Format(
                    "Could not open folder (path=\"{0}\") in explorer.",
                    setInfo.Path),
                ex);
     }
 }
        protected override async Task <bool> CanChangeSet(UserResourceSetInfo setInfo)
        {
            // Show validation messagebox.
            var result = await MessageBoxManager.GetMessageBoxStandardWindow(new MessageBoxStandardParams
            {
                ContentTitle   = "SRS level set change warning",
                ContentMessage = "Please be aware that modifying the SRS level set may block "
                                 + "some existing SRS items in the case where the new level set has less "
                                 + $"levels than the previous one.{Environment.NewLine}Also, please note that the current "
                                 + "scheduled review dates will not be affected.",
                ButtonDefinitions = ButtonEnum.OkCancel,
                Icon = Icon.Warning,
            }).ShowDialog(NavigationActor.Instance.MainWindow);

            return(result == ButtonResult.Ok);
        }
Exemple #7
0
        /// <summary>
        /// Attempts to load the set from the given path.
        /// Returns a value indicating if the loading operation was
        /// successful or not.
        /// </summary>
        /// <param name="path">Path to the base directory of the set.</param>
        /// <returns>True if the set has been successfuly loaded.
        /// False otherwise.</returns>
        private bool TryLoad(string path)
        {
            // Try to load the info.
            UserResourceSetInfo info = _setManager.ReadInfo(path);

            if (info != null)
            {
                // If info are properly loaded, try to read the set data.
                T loadedSet = _setManager.ReadData(path);
                if (loadedSet != null)
                {
                    // If the set is properly loaded, set the values and return true.
                    CurrentSet     = loadedSet;
                    CurrentSetInfo = info;
                    return(true);
                }
            }

            // If anything failed, we end up returning false here.
            return(false);
        }
Exemple #8
0
 /// <summary>
 /// In a subclass, determines if switching to the given set is possible.
 /// </summary>
 /// <param name="setInfo">Target set.</param>
 /// <returns>True if the change is confirmed. False otherwise.</returns>
 protected abstract bool CanChangeSet(UserResourceSetInfo setInfo);
Exemple #9
0
 /// <summary>
 /// In a subclass, determines if switching to the given set is possible.
 /// </summary>
 /// <param name="setInfo">Target set.</param>
 /// <returns>True if the change is confirmed. False otherwise.</returns>
 protected abstract Task <bool> CanChangeSet(UserResourceSetInfo setInfo);