Beispiel #1
0
        public void Basics()
        {
            List <TestEdge> edges = new List <TestEdge>()
            {
                new TestEdge(A, B),
                new TestEdge(B, C),
            };
            var p = new DefaultPath <TestVertex, TestEdge>(edges, new TestDoubleWeight(2.0));

            ValidatePath(p, A, C, 2, new TestDoubleWeight(2.0));
        }
Beispiel #2
0
        /// <summary>
        ///  既定のデータパスを取得します。
        /// </summary>
        /// <param name="path">既定のデータパスの種類です。</param>
        /// <returns>データパスを表すパス文字列です。</returns>
        public static PathString GetDefaultPath(DefaultPath path)
        {
            switch (path)
            {
            case DefaultPath.UserData:
                return(new PathString(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)) + AsmName);

            case DefaultPath.SystemData:
                return(new PathString(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)) + AsmName);

            case DefaultPath.Application:
                return(new PathString(AppContext.BaseDirectory) + "Data");

            default:
                return(new PathString() + $"{VersionInfo.Name}_Data");
            }
        }
Beispiel #3
0
        public override void Equality()
        {
            List <TestEdge> edges1 = new List <TestEdge>()
            {
                new TestEdge(A, B),
                new TestEdge(B, C),
            };
            List <TestEdge> edges2 = new List <TestEdge>()
            {
                new TestEdge(A, B),
                new TestEdge(B, D),
            };

            var p1 = new DefaultPath <TestVertex, TestEdge>(edges1, new TestDoubleWeight(2.0));
            var p2 = new DefaultPath <TestVertex, TestEdge>(new List <TestEdge>(edges1), new TestDoubleWeight(2.0));
            var p3 = new DefaultPath <TestVertex, TestEdge>(edges2, new TestDoubleWeight(2.0));

            Assert.Equal(p1, p2);
            Assert.NotEqual(p1, p3);
        }
Beispiel #4
0
    /// <summary>
    /// Reload control data.
    /// </summary>
    public void ReloadData()
    {
        try
        {
            this.treeFileSystem.Nodes.Clear();
            InitializeTree();

            // Expand current node parent
            if (!String.IsNullOrEmpty(DefaultPath))
            {
                if (!this.DefaultPath.ToLower().StartsWith(this.FullStartingPath.ToLower().TrimEnd('\\')))
                {
                    this.DefaultPath = DirectoryHelper.CombinePath(this.FullStartingPath, this.DefaultPath);
                }

                if (!String.IsNullOrEmpty(ExcludedFolders))
                {
                    foreach (string excludedFolder in ExcludedFolders.Split(';'))
                    {
                        if (DefaultPath.ToLower().StartsWith((DirectoryHelper.CombinePath(FullStartingPath, excludedFolder)).ToLower()))
                        {
                            this.DefaultPath = this.FullStartingPath;
                            break;
                        }
                    }
                }

                string preselectedPath = this.DefaultPath;
                string rootPath        = this.treeFileSystem.Nodes[0].Value;

                if (preselectedPath.ToLower().StartsWith(rootPath.ToLower()))
                {
                    TreeNode parent = this.treeFileSystem.Nodes[0];

                    string[] folders = preselectedPath.ToLower().Substring(rootPath.Length).Split('\\');
                    int      index   = 0;
                    string   path    = rootPath.ToLower() + folders[index];


                    foreach (string folder in folders)
                    {
                        foreach (TreeNode node in parent.ChildNodes)
                        {
                            if (node.Value.ToLower() == path)
                            {
                                parent = node;
                                break;
                            }
                        }
                        if (index < folders.Length - 1)
                        {
                            parent.Expand();
                            path += '\\' + folders[index + 1];
                        }
                        else
                        {
                            if (ExpandDefaultPath)
                            {
                                parent.Expand();
                            }
                        }
                        index++;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            lblError.Text    = GetString("ContentTree.FailedLoad") + ": " + ex.Message;
            lblError.ToolTip = ex.StackTrace;
        }
    }
 /// <summary>
 ///  管理するデータが格納されたディレクトリを設定します。
 /// </summary>
 /// <param name="options">設定情報を格納したオブジェクトです。</param>
 /// <param name="path">既定のデータパスの種類です。</param>
 /// <returns><paramref name="options"/>を返します。</returns>
 public static FileSystemServiceOptions SetDataPath(this FileSystemServiceOptions options, DefaultPath path)
 {
     options.DataPath = Paths.GetDefaultPath(path);
     return(options);
 }
Beispiel #6
0
    /// <summary>
    /// Creation of new tree folder node.
    /// </summary>
    /// <param name="dirInfo">Folder information</param>
    /// <param name="index">Index in tree to check if max number of item isn't exceeded</param>
    /// <returns>Created node</returns>
    protected TreeNode CreateNode(DirectoryInfo dirInfo, int index)
    {
        if (dirInfo == null)
        {
            return(null);
        }

        string fullName      = dirInfo.FullName;
        string lowerFullName = fullName.ToLowerCSafe();

        TreeNode newNode = null;

        if (IsAllowed(lowerFullName) && !IsExcluded(lowerFullName))
        {
            newNode = new TreeNode();

            string        name   = dirInfo.Name;
            DirectoryInfo parent = dirInfo.Parent;

            // Check if node is part of preselected path
            string preselectedPath = DefaultPath;
            if (!DefaultPath.ToLowerCSafe().StartsWithCSafe(FullStartingPath.ToLowerCSafe().TrimEnd('\\')))
            {
                preselectedPath = DirectoryHelper.CombinePath(FullStartingPath, DefaultPath);
            }

            if (index == MaxTreeNodes)
            {
                newNode.Value       = "";
                newNode.Text        = MaxTreeNodeText.Replace("##PARENTNODEID##", ((parent == null) ? "" : parent.FullName.Replace("\\", "\\\\").Replace("'", "\\'")));
                newNode.NavigateUrl = mBasePath + "#";
            }
            else if ((index < MaxTreeNodes) || preselectedPath.ToLowerCSafe().StartsWithCSafe(lowerFullName))
            {
                newNode.Value       = fullName;
                newNode.NavigateUrl = mBasePath + "#";

                string nodeName     = HttpUtility.HtmlEncode(name);
                string nodeNameJava = ScriptHelper.GetString(nodeName);

                string preSel = FullStartingPath.TrimEnd('\\').ToLowerCSafe();
                if (DefaultPath.ToLowerCSafe().StartsWithCSafe(FullStartingPath.ToLowerCSafe().TrimEnd('\\')))
                {
                    preSel = DefaultPath.ToLowerCSafe();
                }
                else if (!String.IsNullOrEmpty(DefaultPath))
                {
                    preSel = DirectoryHelper.CombinePath(preSel, DefaultPath.ToLowerCSafe());
                }


                if ((preSel != "") && (newNode.Value.ToLowerCSafe() == preSel))
                {
                    newNode.Text = SelectedNodeTextTemplate.Replace("##NODENAMEJAVA##", nodeNameJava).Replace("##NODENAME##", nodeName).Replace("##ICON##", "").Replace("##NODEID##", newNode.Value.Replace("\\", "\\\\").Replace("'", "\\'"));
                }
                else
                {
                    newNode.Text = NodeTextTemplate.Replace("##NODENAMEJAVA##", nodeNameJava).Replace("##NODENAME##", nodeName).Replace("##ICON##", "").Replace("##NODEID##", newNode.Value.Replace("\\", "\\\\").Replace("'", "\\'"));
                }

                int childNodesCount = 0;
                try
                {
                    childNodesCount = ValidationHelper.GetInteger(GetAllowedChildNumber(dirInfo), 0);
                    if (childNodesCount == 0)
                    {
                        newNode.PopulateOnDemand = false;
                        newNode.Expanded         = true;
                    }
                    else
                    {
                        newNode.PopulateOnDemand = true;
                        newNode.Expanded         = false;
                    }
                }
                catch
                {
                    // Access error
                    newNode.PopulateOnDemand = false;
                    newNode.Expanded         = true;
                }
                finally
                {
                    newNode.Text = newNode.Text.Replace("##NODECHILDNODESCOUNT##", childNodesCount.ToString());
                }
            }
        }

        return(newNode);
    }
Beispiel #7
0
    /// <summary>
    /// Reload control data.
    /// </summary>
    public void ReloadData()
    {
        try
        {
            treeFileSystem.Nodes.Clear();
            InitializeTree();

            // Expand current node parent
            if (!String.IsNullOrEmpty(DefaultPath))
            {
                if (!DefaultPath.ToLowerCSafe().StartsWithCSafe(FullStartingPath.ToLowerCSafe().TrimEnd('\\')))
                {
                    DefaultPath = DirectoryHelper.CombinePath(FullStartingPath, DefaultPath);
                }

                if (!String.IsNullOrEmpty(ExcludedFolders))
                {
                    foreach (string excludedFolder in ExcludedFolders.Split(';'))
                    {
                        if (DefaultPath.ToLowerCSafe().StartsWithCSafe((DirectoryHelper.CombinePath(FullStartingPath, excludedFolder)).ToLowerCSafe()))
                        {
                            DefaultPath = FullStartingPath;
                            break;
                        }
                    }
                }

                string preselectedPath = DefaultPath;
                string rootPath        = treeFileSystem.Nodes[0].Value;

                if (preselectedPath.ToLowerCSafe().StartsWithCSafe(rootPath.ToLowerCSafe()))
                {
                    TreeNode parent = treeFileSystem.Nodes[0];

                    string[] folders = preselectedPath.ToLowerCSafe().Substring(rootPath.Length).Split('\\');
                    int      index   = 0;
                    string   path    = rootPath.ToLowerCSafe() + folders[index];


                    foreach (string folder in folders)
                    {
                        foreach (TreeNode node in parent.ChildNodes)
                        {
                            if (node.Value.ToLowerCSafe() == path)
                            {
                                parent = node;
                                break;
                            }
                        }

                        if (index < folders.Length - 1)
                        {
                            parent.Expand();
                            path += '\\' + folders[index + 1];
                        }
                        else
                        {
                            if (ExpandDefaultPath)
                            {
                                parent.Expand();
                            }
                        }

                        index++;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            lblError.Text = GetString("ContentTree.FailedLoad");

            Service.Resolve <IEventLogService>().LogException("ContentTree", "LOAD", ex, SiteContext.CurrentSiteID);
        }
    }
        protected override void Invoke(object parameter)
        {
            var d = new System.Windows.Forms.FolderBrowserDialog();

            if (DefaultPath.IsNotNull())
            {
                d.SelectedPath = AyFuncIO.Instance.GetDirectory(DefaultPath);
            }
            d.ShowNewFolderButton = true;
            d.Description         = Description;
            if (d.ShowDialog() == Winform.DialogResult.OK)
            {
                string dirPath    = d.SelectedPath;
                string diskNumber = dirPath[0].ToString();
                double canUsage   = AyFuncDisk.Instance.GetHardDiskFreeSpace1(diskNumber); //单位B
                double totalUsage = AyFuncDisk.Instance.GetHardDiskSpace1(diskNumber);     //单位B
                if (MinSpaceUsage.HasValue && MinSpaceUsage.Value > canUsage)
                {
                    apErrorToolTip.IsOpen = true;
                    _tb.Text = "磁盘可用空间不足,至少需要" + AyFuncDisk.Instance.GetFileOrDirectoryFormatedSize(MinSpaceUsage.Value) + "可用空间";
                    AyTime.setTimeout(3000, () =>
                    {
                        apErrorToolTip.IsOpen = false;
                    });
                    return;
                }
                SelectTotalFolderCapacity = totalUsage;
                SelectFolderCapacity      = canUsage;
                var _1 = TotalSizeStringFormat.StringFormat(AyFuncDisk.Instance.GetFileOrDirectoryFormatedSize(totalUsage));
                var _2 = SizeStringFormat.StringFormat(AyFuncDisk.Instance.GetFileOrDirectoryFormatedSize(canUsage));

                if (SizeTarget.IsNotNull())
                {
                    var _11 = SizeTarget as TextBox;
                    if (_11 != null)
                    {
                        _11.Text = _2;
                    }
                    else
                    {
                        var _12 = SizeTarget as TextBlock;
                        if (_12.IsNotNull())
                        {
                            _12.Text = _2;
                        }
                        else
                        {
                            var _13 = SizeTarget as Label;
                            if (_13.IsNotNull())
                            {
                                _13.Content = _2;
                            }
                        }
                    }
                }

                if (TotalSizeTarget.IsNotNull())
                {
                    var _11 = TotalSizeTarget as TextBox;
                    if (_11 != null)
                    {
                        _11.Text = _1;
                    }
                    else
                    {
                        var _12 = TotalSizeTarget as TextBlock;
                        if (_12.IsNotNull())
                        {
                            _12.Text = _1;
                        }
                        else
                        {
                            var _13 = TotalSizeTarget as Label;
                            if (_13.IsNotNull())
                            {
                                _13.Content = _1;
                            }
                        }
                    }
                }


                if (Selected != null)
                {
                    Selected(dirPath, new RoutedEventArgs()
                    {
                    });
                }
                if (SelectedCommand != null)
                {
                    SelectedCommand.Execute(dirPath);
                }
                if (Target.IsNotNull())
                {
                    var _11 = Target as TextBox;
                    if (_11 != null)
                    {
                        _11.Text = dirPath;
                    }
                    else
                    {
                        var _12 = Target as TextBlock;
                        if (_12.IsNotNull())
                        {
                            _12.Text = dirPath;
                        }
                        else
                        {
                            var _13 = Target as Label;
                            if (_13.IsNotNull())
                            {
                                _13.Content = dirPath;
                            }
                        }
                    }
                }
            }
        }