Пример #1
0
        //TODO search Sequencer!!!!
        public Downloadable(string primaryName, string sourcePath, SearchSequencer searchSequence = null)
        {
            SourcePath = ConvertPathToAbsolute(sourcePath);

            PrimaryName = primaryName;
            if (PrimaryName == null)
            {
                PrimaryName = Path.GetFileNameWithoutExtension(sourcePath);
            }
            if (File.Exists(SourcePath))
            {
                OptionsTree = FinalizeOptionsBranch(SourcePath, PrimaryName);
            }
            else
            {
                OptionsTree = BuildOptionsTree(SourcePath, searchSequence, 0, PrimaryName);
            }
        }
Пример #2
0
        public object BuildOptionsTree(string path, SearchSequencer searchSequence, int index, string name)
        {
            if (searchSequence == null || searchSequence.SettingsDepth == index)
            {
                return(FinalizeOptionsBranch(path, name));
            }
            var subDirectories = Directory.GetDirectories(path);

            if (subDirectories.Length == 1)
            {
                var subDirectoryName = Path.GetFileName(subDirectories[0]);
                return(BuildOptionsTree(subDirectories[0], searchSequence, index + 1, name + "_" + subDirectoryName));
            }
            var result = new Dictionary <string, object>();

            switch (searchSequence.GetNextOption())
            {
            case SearchSequencer.SeqrchSequence.AllDirectories:
                result.Add("All", FinalizeOptionsBranch(path, name));
                break;

            case SearchSequencer.SeqrchSequence.Version: {
                try {
                    var versions = subDirectories.ToDictionary(x => new SemVer(Path.GetFileName(x)))
                                   .OrderByDescending(x => x.Key).ToList();
                    if (versions.Count == 0)
                    {
                        return(null);
                    }
                    var stable = versions.FirstOrDefault(x => x.Key.labelsString == "");
                    var latest = versions.First();
                    if (latest.Key != stable.Key)
                    {
                        if (versions.Remove(stable))
                        {
                            versions.Insert(0, stable);
                        }
                    }

                    foreach (var v in versions)
                    {
                        var e          = BuildOptionsTree(v.Value, searchSequence, index + 1, name + "_" + v.Key);
                        var optionName = v.Key.ToString();
                        if (v.Key == stable.Key)
                        {
                            optionName = "Stable " + optionName;
                        }
                        if (v.Key == latest.Key)
                        {
                            optionName = "Latest " + optionName;
                        }
                        if (e != null)
                        {
                            result.Add(optionName, e);
                        }
                    }
                } catch (ArgumentException e) {
                    Log.Error.OnObject(this, e.Message);
                }

                break;
            }

            default: {
                foreach (var d in subDirectories)
                {
                    var subDirectoryName = Path.GetFileName(d);
                    var e = BuildOptionsTree(d, searchSequence, index + 1, name + "_" + subDirectoryName);
                    if (e != null)
                    {
                        result.Add(subDirectoryName, e);
                    }
                }

                break;
            }
            }
            if (result.Count == 0)
            {
                return(null);
            }
            return(result);
        }