コード例 #1
0
 private static bool CanBeChildOf(IBuildFolderViewModel build, string parentPath, int parentDepth)
 {
     // Check depth and name
     if (parentDepth >= MaxBuildDepth)
         return false;
     var name = build.Build.Name;
     if (!IsNameValid(name, Path.Combine(parentPath, FileNameForFolder(name))))
         return false;
     // Check all subbuilds
     var nextPath = Path.Combine(parentPath, SerializationUtils.EncodeFileName(name));
     var nextDepth = parentDepth + 1;
     foreach (var child in build.Children)
     {
         var folder = child as IBuildFolderViewModel;
         if (folder == null)
         {
             if (!CanBeChildOf(child, nextPath))
             {
                 return false;
             }
         }
         else
         {
             if (!CanBeChildOf(folder, nextPath, nextDepth))
             {
                 return false;
             }
         }
     }
     return true;
 }
コード例 #2
0
        private async void BuildOnCollectionChanged(IBuildFolderViewModel build)
        {
            await SaveBuildToFile(build);

            // It's ok that this method doesn't return Task as it is used like an event handler and the
            // async action in SaveBuildToFile does not require to be waited upon.
        }
コード例 #3
0
        private static string?ValidateName(string name, string fullPath, IBuildViewModel?build,
                                           IBuildFolderViewModel parent)
        {
            if (!IsNameUnique(name, build, parent))
            {
                return(L10n.Message("A build or folder with this name already exists."));
            }

            IsNameValid(name, fullPath, out var message);
            return(message);
        }
コード例 #4
0
        public void NewBuild(IBuildFolderViewModel folder)
        {
            var name = Util.FindDistinctName(SerializationConstants.DefaultBuildName,
                                             folder.Children.Select(b => b.Build.Name));
            var build = new BuildViewModel(new PoEBuild {
                Name = name
            }, Filter);

            folder.Children.Add(build);
            CurrentBuild = build;
        }
コード例 #5
0
        private async Task <PoEBuild> PasteFromClipboard(IBuildFolderViewModel targetFolder)
        {
            var str      = Clipboard.GetText();
            var newBuild = await PersistentData.ImportBuildAsync(str);

            if (newBuild == null)
            {
                return(null);
            }
            newBuild.Name = Util.FindDistinctName(newBuild.Name, targetFolder.Children.Select(b => b.Build.Name));
            return(newBuild);
        }
コード例 #6
0
        /// <summary>
        /// Returns true iff <paramref name="build"/> can be moved to <paramref name="parent"/>.
        /// </summary>
        public bool CanMoveTo(IBuildViewModel build, IBuildFolderViewModel parent)
        {
            if (!IsNameUnique(build.Build.Name, build, parent))
                return false;

            var parentPath = BasePathFor(parent);
            var folder = build as IBuildFolderViewModel;
            if (folder == null)
            {
                return CanBeChildOf(build, parentPath);
            }
            else
            {
                var parentDepth = GetDepthOfFolder(parent);
                return CanBeChildOf(folder, parentPath, parentDepth);
            }
        }
コード例 #7
0
        private async Task NewFolder(IBuildFolderViewModel folder)
        {
            var name = await _dialogCoordinator.ShowValidatingInputDialogAsync(this,
                                                                               L10n.Message("New Folder"),
                                                                               L10n.Message("Enter the name of the new folder."),
                                                                               "",
                                                                               s => _buildValidator.ValidateNewFolderName(s, folder));

            if (string.IsNullOrWhiteSpace(name))
            {
                return;
            }
            var newFolder = new BuildFolderViewModel(new BuildFolder {
                Name = name
            }, Filter, BuildOnCollectionChanged);

            folder.Children.Add(newFolder);
            await SaveBuildToFile(newFolder);
        }
コード例 #8
0
        private async Task NewBuild(IBuildFolderViewModel folder)
        {
            var name = await _dialogCoordinator.ShowValidatingInputDialogAsync(this,
                                                                               L10n.Message("New Build"),
                                                                               L10n.Message("Enter the name of the new build."),
                                                                               "",
                                                                               s => _buildValidator.ValidateNewBuildName(s, folder));

            if (string.IsNullOrWhiteSpace(name))
            {
                return;
            }
            var build = new BuildViewModel(new PoEBuild {
                Name = name
            }, Filter);

            folder.Children.Add(build);
            CurrentBuild = build;
        }
コード例 #9
0
        private async void ExportGGGBuild(IBuildFolderViewModel target)
        {
            var build = new GGGBuild()
            {
                Name    = target.Build.Name,
                Version = PoESkillTree.Properties.Version.GGGPatchVersion,
                Parts   = new List <GGGBuildPart>()
            };

            foreach (var c in target.Children)
            {
                if (!c.GetType().Equals(typeof(BuildFolderViewModel)))
                {
                    build.Parts.Add(new GGGBuildPart()
                    {
                        Label = c.Build.Name, Link = ((PoEBuild)c.Build).TreeUrl
                    });
                }
            }

            var dialogSettings = new FileSelectorDialogSettings
            {
                DefaultPath    = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                IsFolderPicker = true,
            };
            var path = await _dialogCoordinator.ShowFileSelectorAsync(this,
                                                                      L10n.Message("Select save directory"),
                                                                      L10n.Message("Select the directory where you want to export this build structure."),
                                                                      dialogSettings);

            if (path == null)
            {
                return;
            }
            path = Path.Combine(path, $"{SerializationUtils.EncodeFileName(build.Name)}.build");

            byte[] jsonEncodedText = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(build));
            using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize: jsonEncodedText.Length, useAsync: true))
            {
                await stream.WriteAsync(jsonEncodedText, 0, jsonEncodedText.Length);
            }
        }
コード例 #10
0
        /// <summary>
        /// Returns true iff <paramref name="build"/> can be moved to <paramref name="parent"/>.
        /// </summary>
        public bool CanMoveTo(IBuildViewModel build, IBuildFolderViewModel parent)
        {
            if (!IsNameUnique(build.Build.Name, build, parent))
            {
                return(false);
            }

            var parentPath = BasePathFor(parent);
            var folder     = build as IBuildFolderViewModel;

            if (folder == null)
            {
                return(CanBeChildOf(build, parentPath));
            }
            else
            {
                var parentDepth = GetDepthOfFolder(parent);
                return(CanBeChildOf(folder, parentPath, parentDepth));
            }
        }
コード例 #11
0
        private static bool CanBeChildOf(IBuildFolderViewModel build, string parentPath, int parentDepth)
        {
            // Check depth and name
            if (parentDepth >= MaxBuildDepth)
            {
                return(false);
            }
            var name = build.Build.Name;

            if (!IsNameValid(name, Path.Combine(parentPath, FileNameForFolder(name))))
            {
                return(false);
            }
            // Check all subbuilds
            var nextPath  = Path.Combine(parentPath, SerializationUtils.EncodeFileName(name));
            var nextDepth = parentDepth + 1;

            foreach (var child in build.Children)
            {
                var folder = child as IBuildFolderViewModel;
                if (folder == null)
                {
                    if (!CanBeChildOf(child, nextPath))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (!CanBeChildOf(folder, nextPath, nextDepth))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
コード例 #12
0
 /// <summary>
 /// Returns true iff the <paramref name="folder"/> can have subfolders. There can only be a constant number
 /// of folders nested into each other.
 /// </summary>
 public bool CanHaveSubfolder(IBuildFolderViewModel folder)
 {
     return(GetDepthOfFolder(folder) < MaxBuildDepth);
 }
コード例 #13
0
 private static bool IsNameUnique(string name, IBuildViewModel build, IBuildFolderViewModel parent)
 {
     return(parent.Children.All(b => b == build || b.Build.Name != name));
 }
コード例 #14
0
 /// <summary>
 /// Returns an string that contains an error message if it is not null or empty that describes
 /// why <paramref name="name"/> is not allowed as a name for a new build located in <paramref name="parent"/>.
 /// </summary>
 public string ValidateNewBuildName(string name, IBuildFolderViewModel parent)
 {
     return(ValidateName(name, PathForBuild(name, parent), null, parent));
 }
コード例 #15
0
 /// <summary>
 /// Returns true iff the <paramref name="folder"/> can have subfolders. There can only be a constant number
 /// of folders nested into each other.
 /// </summary>
 public bool CanHaveSubfolder(IBuildFolderViewModel folder)
 {
     return GetDepthOfFolder(folder) < MaxBuildDepth;
 }
コード例 #16
0
 /// <summary>
 /// Returns an string that contains an error message if it is not null or empty that describes
 /// why <paramref name="name"/> is not allowed as a name for a new build located in <paramref name="parent"/>.
 /// </summary>
 public string ValidateNewBuildName(string name, IBuildFolderViewModel parent)
 {
     return ValidateName(name, PathForBuild(name, parent), null, parent);
 }
コード例 #17
0
 private static int GetDepthOfFolder(IBuildFolderViewModel folder)
 {
     return folder.Parent == null ? 1 : 1 + GetDepthOfFolder(folder.Parent);
 }
コード例 #18
0
 private static string ValidateName(string name, string fullPath, IBuildViewModel build,
     IBuildFolderViewModel parent)
 {
     if (!IsNameUnique(name, build, parent))
     {
         return L10n.Message("A build or folder with this name already exists.");
     }
     string message;
     IsNameValid(name, fullPath, out message);
     return message;
 }
コード例 #19
0
 private static int GetDepthOfFolder(IBuildFolderViewModel folder)
 {
     return(folder.Parent == null ? 1 : 1 + GetDepthOfFolder(folder.Parent));
 }
コード例 #20
0
 private static bool IsNameUnique(string name, IBuildViewModel build, IBuildFolderViewModel parent)
 {
     return parent.Children.All(b => b == build || b.Build.Name != name);
 }