当前位置: 首页>>代码示例>>C#>>正文


C# FileSystemWatcher.WaitForChanged方法代码示例

本文整理汇总了C#中FileSystemWatcher.WaitForChanged方法的典型用法代码示例。如果您正苦于以下问题:C# FileSystemWatcher.WaitForChanged方法的具体用法?C# FileSystemWatcher.WaitForChanged怎么用?C# FileSystemWatcher.WaitForChanged使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileSystemWatcher的用法示例。


在下文中一共展示了FileSystemWatcher.WaitForChanged方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Renamed_Success

        public void Renamed_Success()
        {
            using (var testDirectory = new TempDirectory(GetTestFilePath()))
            using (var fsw = new FileSystemWatcher(testDirectory.Path))
            {
                Task<WaitForChangedResult> t = Task.Run(() =>
                    fsw.WaitForChanged(WatcherChangeTypes.Renamed | WatcherChangeTypes.Created, SuccessTimeoutMilliseconds)); // on some OSes, the renamed might come through as Deleted/Created

                string name = Path.Combine(testDirectory.Path, Path.GetRandomFileName());
                File.Create(name).Dispose();

                while (!t.IsCompleted)
                {
                    string newName = Path.Combine(testDirectory.Path, Path.GetRandomFileName());
                    File.Move(name, newName);
                    name = newName;
                    Task.Delay(BetweenOperationsDelayMilliseconds).Wait();
                }

                Assert.Equal(TaskStatus.RanToCompletion, t.Status);
                Assert.True(t.Result.ChangeType == WatcherChangeTypes.Created || t.Result.ChangeType == WatcherChangeTypes.Renamed);
                Assert.NotNull(t.Result.Name);
                Assert.False(t.Result.TimedOut);
            }
        }
开发者ID:SamuelEnglard,项目名称:corefx,代码行数:25,代码来源:FileSystemWatcher.WaitForChanged.cs

示例2: RadTreeView1_ContextMenuItemClick

    protected void RadTreeView1_ContextMenuItemClick(object sender, RadTreeViewContextMenuEventArgs e)
    {
        switch (e.MenuItem.Value)
        {

            case "NewFolder":
                if ((RadTreeView1.SelectedNode != null) && (RadTreeView1.SelectedNode.Level == 0))
                {
                    string newNodeTitle = ("New Folder");
                    e.Node.Nodes.Add(new RadTreeNode(newNodeTitle));
                    e.Node.Category = "Folder";
                    e.Node.ImageUrl = "/admin/images/folder.gif";
                    e.Node.ExpandedImageUrl = "/admin/images/folder.gif";
                    e.Node.ContextMenuID = "MainContextMenu";
                    e.Node.Value = getpath(Request["pg"].ToString()) + "\\" + newNodeTitle;
                    e.Node.Expanded = true;
                    Directory.CreateDirectory(getpath(Request["pg"].ToString()) + "\\" + newNodeTitle);
                    createtree("");
                    getfold(ref al, Server.MapPath("~/App_Uploads_Img/"));
                }
                else
                {
                    string newNodeTitle = string.Format("New Folder", e.Node.ParentNode.Nodes.Count + 1);
                    e.Node.Nodes.Add(new RadTreeNode(newNodeTitle));
                    e.Node.Category = "Folder";
                    e.Node.ImageUrl = "/admin/images/folder.gif";
                    e.Node.ExpandedImageUrl = "/admin/images/folder.gif";
                    e.Node.ContextMenuID = "MainContextMenu";
                    e.Node.Value = getpath(Request["pg"].ToString()) + RadTreeView1.SelectedNode.FullPath.Substring(getmainfolder(Request["pg"].ToString()).Length + 1) + "\\" + newNodeTitle;
                    e.Node.Expanded = true;
                    Directory.CreateDirectory(getpath(Request["pg"].ToString()) + RadTreeView1.SelectedNode.FullPath.Substring(getmainfolder(Request["pg"].ToString()).Length + 1) + "\\" + newNodeTitle);
                    createtree(getpath(Request["pg"].ToString()) + (RadTreeView1.SelectedNode.FullPath.Substring(getmainfolder(Request["pg"].ToString()).Length + 1)).Replace("/", "\\"));
                    getfold(ref al, Server.MapPath("~/App_Uploads_Img/"));
                }
                break;

            case "Delete":

                break;

            case "Rename":

                if (RadTreeView1.SelectedNode != null)
                {
                    GC.Collect();
                    RadTreeNode nodeEdited = e.Node;
                    string oldtext = e.Node.Text;
                    string oldpath = e.Node.Value.Substring(0, e.Node.Value.LastIndexOf("\\") + 1);
                    string newText = e.Node.Text;

                    nodeEdited.Text = newText;

                    string newpath = nodeEdited.Value;
                    if (e.Node.Category == "Files")
                    {

                        getitemonserver(e.Node.Category, e.Node.Value, oldpath + newText);
                    }
                    else
                    {

                        getitemonserver(e.Node.Category, oldpath + oldtext, oldpath + newText);
                    }
                    System.IO.FileSystemWatcher mywatcher = new FileSystemWatcher(oldpath);
                    mywatcher.WaitForChanged(WatcherChangeTypes.All, 2000);
                    createtree(oldpath.Substring(0, oldpath.LastIndexOf("\\")));
                    getfold(ref al, Server.MapPath("~/App_Uploads_Img/"));
                }
                break;

        }
    }
开发者ID:wpdildine,项目名称:wwwroot,代码行数:72,代码来源:file.ascx.cs

示例3: NonZeroTimeout_NoEvents_TimesOut

 public void NonZeroTimeout_NoEvents_TimesOut(bool enabledBeforeWait)
 {
     using (var testDirectory = new TempDirectory(GetTestFilePath()))
     using (var dir = new TempDirectory(Path.Combine(testDirectory.Path, GetTestFileName())))
     using (var fsw = new FileSystemWatcher(testDirectory.Path))
     {
         if (enabledBeforeWait) fsw.EnableRaisingEvents = true;
         AssertTimedOut(fsw.WaitForChanged(0, 1));
         Assert.Equal(enabledBeforeWait, fsw.EnableRaisingEvents);
     }
 }
开发者ID:SamuelEnglard,项目名称:corefx,代码行数:11,代码来源:FileSystemWatcher.WaitForChanged.cs

示例4: Changed_Success

        public void Changed_Success()
        {
            using (var testDirectory = new TempDirectory(GetTestFilePath()))
            using (var fsw = new FileSystemWatcher(testDirectory.Path))
            {
                string name = Path.Combine(testDirectory.Path, Path.GetRandomFileName());
                File.Create(name).Dispose();

                Task<WaitForChangedResult> t = Task.Run(() => fsw.WaitForChanged(WatcherChangeTypes.Changed, SuccessTimeoutMilliseconds));
                while (!t.IsCompleted)
                {
                    File.AppendAllText(name, "text");
                    Task.Delay(BetweenOperationsDelayMilliseconds).Wait();
                }

                Assert.Equal(TaskStatus.RanToCompletion, t.Status);
                Assert.Equal(WatcherChangeTypes.Changed, t.Result.ChangeType);
                Assert.NotNull(t.Result.Name);
                Assert.Null(t.Result.OldName);
                Assert.False(t.Result.TimedOut);
            }
        }
开发者ID:SamuelEnglard,项目名称:corefx,代码行数:22,代码来源:FileSystemWatcher.WaitForChanged.cs

示例5: RadTreeView1_NodeEdit

    protected void RadTreeView1_NodeEdit(object sender, RadTreeNodeEditEventArgs e)
    {
        RadTreeNode nodeEdited = e.Node;
        string newText = e.Text;
        nodeEdited.Text = newText;

        string oldpath = e.Node.Value.Substring(0, e.Node.Value.LastIndexOf("\\") + 1);
        string oldtext = e.Node.Value.Substring(oldpath.Length);

        if (nodeEdited.Category == "Files")
        {
            getitemonserver(nodeEdited.Category, nodeEdited.Value, oldpath + newText);
        }
        else { getitemonserver(nodeEdited.Category, oldpath + oldtext, oldpath + newText); }

        System.IO.FileSystemWatcher mywatcher = new FileSystemWatcher(oldpath);
        mywatcher.WaitForChanged(WatcherChangeTypes.All, 2000);
        createtree(oldpath.Substring(0, oldpath.LastIndexOf("\\")));

        //UpdatePanel1.Update();
    }
开发者ID:wpdildine,项目名称:wwwroot,代码行数:21,代码来源:file.ascx.cs

示例6: RadTreeView1_HandleDrop

    protected void RadTreeView1_HandleDrop(object sender, RadTreeNodeDragDropEventArgs e)
    {
        RadTreeNode sourceNode = e.SourceDragNode;
        RadTreeNode destNode = e.DestDragNode;
        RadTreeViewDropPosition dropPosition = e.DropPosition;

        string result = "";

        if (destNode != null)//drag&drop is performed between trees
        {

            if (sourceNode.TreeView.SelectedNodes.Count <= 1)
            {
                result += "<b>" + sourceNode.Text + "</b>" + ";";
                PerformDragAndDrop(dropPosition, sourceNode, destNode);
            }
            else if (sourceNode.TreeView.SelectedNodes.Count > 1)
            {
                foreach (RadTreeNode node in sourceNode.TreeView.SelectedNodes)
                {
                    result += "<b>" + node.Text + "</b>" + ";";
                    PerformDragAndDrop(dropPosition, node, destNode);
                }

            }
            else//dropped node will be a sibling of the destination node
            {
                if (sourceNode.TreeView.SelectedNodes.Count <= 1)
                {

                    if (!sourceNode.IsAncestorOf(destNode))
                    {
                        result += "<b>" + sourceNode.Text + "</b>" + ";";
                        sourceNode.Owner.Nodes.Remove(sourceNode);
                        destNode.Nodes.Add(sourceNode);
                    }
                }
                else if (sourceNode.TreeView.SelectedNodes.Count > 1)
                {
                    foreach (RadTreeNode node in RadTreeView1.SelectedNodes)
                    {
                        if (!node.IsAncestorOf(destNode))
                        {
                            result += "<b>" + node.Text + "</b>" + ";";
                            node.Owner.Nodes.Remove(node);
                            destNode.Nodes.Add(node);
                        }
                    }
                }
            }

            if (e.SourceDragNode.Category == "Files")
            {
                if (!System.IO.File.Exists(e.SourceDragNode.Value))
                {
                    System.IO.File.Move(e.SourceDragNode.Value, e.DestDragNode.Value + "\\" + e.SourceDragNode.Text);

                }
                else
                {
                    string fname = e.SourceDragNode.Text.Substring(0, e.SourceDragNode.Text.LastIndexOf("."));
                    string ext = e.SourceDragNode.Text.Substring(fname.Length);
                    int counter = 1;
                    string targetFileName = Path.Combine(e.DestDragNode.Value, fname + counter.ToString() + ext);

                    while (System.IO.File.Exists(targetFileName))
                    {
                        counter++;
                        targetFileName = Path.Combine(e.DestDragNode.Value, fname + counter.ToString() + ext);

                    }

                    System.IO.File.Move(e.SourceDragNode.Value, targetFileName);
                }
            }
            else
            {
                if (!System.IO.Directory.Exists(e.DestDragNode.Value + "\\" + e.SourceDragNode.Text))
                {
                    if (System.IO.Directory.Exists(e.SourceDragNode.Value))
                    {
                        System.IO.Directory.Move(e.SourceDragNode.Value, e.DestDragNode.Value + "\\" + e.SourceDragNode.Text);
                    }
                }
            }

            destNode.Expanded = true;
            System.IO.FileSystemWatcher mywatcher = new FileSystemWatcher(e.DestDragNode.Value);
            mywatcher.WaitForChanged(WatcherChangeTypes.All, 2000);
            sourceNode.TreeView.ClearSelectedNodes();
            createtree(e.DestDragNode.Value);
            // UpdatePanel1.Update();

        }
    }
开发者ID:wpdildine,项目名称:wwwroot,代码行数:95,代码来源:file.ascx.cs

示例7: CreatedDeleted_Success

        public void CreatedDeleted_Success(WatcherChangeTypes changeType)
        {
            using (var testDirectory = new TempDirectory(GetTestFilePath()))
            using (var fsw = new FileSystemWatcher(testDirectory.Path))
            {
                Task<WaitForChangedResult> t = Task.Run(() => fsw.WaitForChanged(changeType, LongWaitTimeout));
                while (!t.IsCompleted)
                {
                    string path = Path.Combine(testDirectory.Path, Path.GetRandomFileName());
                    File.WriteAllText(path, "text");
                    Task.Delay(BetweenOperationsDelayMilliseconds).Wait();
                    if ((changeType & WatcherChangeTypes.Deleted) != 0)
                    {
                        File.Delete(path);
                    }
                }

                Assert.Equal(TaskStatus.RanToCompletion, t.Status);
                Assert.Equal(changeType, t.Result.ChangeType);
                Assert.NotNull(t.Result.Name);
                Assert.Null(t.Result.OldName);
                Assert.False(t.Result.TimedOut);
            }
        }
开发者ID:Corillian,项目名称:corefx,代码行数:24,代码来源:FileSystemWatcher.WaitForChanged.cs


注:本文中的FileSystemWatcher.WaitForChanged方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。