本文整理汇总了C#中FileNode.AddTo方法的典型用法代码示例。如果您正苦于以下问题:C# FileNode.AddTo方法的具体用法?C# FileNode.AddTo怎么用?C# FileNode.AddTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileNode
的用法示例。
在下文中一共展示了FileNode.AddTo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public override void Run()
{
WebReferenceNode node = Owner as WebReferenceNode;
if (node != null && node.Project != null && node.ProjectItem != null) {
WebReferenceUrl url = (WebReferenceUrl)node.ProjectItem;
try {
// Discover web services at url.
DiscoveryClientProtocol protocol = DiscoverWebServices(url.UpdateFromURL);
if (protocol != null) {
// Save web services.
WebReference webReference = new WebReference(url.Project, url.UpdateFromURL, node.Text, url.Namespace, protocol);
webReference.Save();
// Update project.
WebReferenceChanges changes = webReference.GetChanges(url.Project);
if (changes.Changed) {
foreach (ProjectItem itemRemoved in changes.ItemsRemoved) {
ProjectService.RemoveProjectItem(url.Project, itemRemoved);
FileService.RemoveFile(itemRemoved.FileName, false);
}
foreach (ProjectItem newItem in changes.NewItems) {
ProjectService.AddProjectItem(url.Project, newItem);
FileNode fileNode = new FileNode(newItem.FileName, FileNodeStatus.InProject);
fileNode.AddTo(node);
}
ProjectBrowserPad.Instance.ProjectBrowserControl.TreeView.Sort();
url.Project.Save();
}
// Update code completion.
ParserService.ParseFile(webReference.WebProxyFileName);
}
} catch (WebException ex) {
MessageService.ShowError(ex, String.Format(StringParser.Parse("${res:ICSharpCode.SharpDevelop.Commands.ProjectBrowser.RefreshWebReference.ReadServiceDescriptionError}"), url.UpdateFromURL));
}
}
}
示例2: Run
public override void Run()
{
TreeNode selectedNode = ProjectBrowserPad.Instance.ProjectBrowserControl.SelectedNode;
DirectoryNode node = selectedNode as DirectoryNode;
if (node == null) {
node = selectedNode.Parent as DirectoryNode;
}
if (node == null) {
return;
}
node.Expanding();
node.Expand();
using (OpenFileDialog fdiag = new OpenFileDialog()) {
fdiag.AddExtension = true;
string[] fileFilters = (string[])(AddInTree.GetTreeNode("/SharpDevelop/Workbench/FileFilter").BuildChildItems(this)).ToArray(typeof(string));
fdiag.FilterIndex = GetFileFilterIndex(node.Project, fileFilters);
fdiag.Filter = String.Join("|", fileFilters);
fdiag.Multiselect = true;
fdiag.CheckFileExists = true;
fdiag.Title = StringParser.Parse("${res:ProjectComponent.ContextMenu.AddExistingFiles}");
if (fdiag.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm) == DialogResult.OK) {
List<KeyValuePair<string, string>> fileNames = new List<KeyValuePair<string, string>>(fdiag.FileNames.Length);
foreach (string fileName in fdiag.FileNames) {
fileNames.Add(new KeyValuePair<string, string>(fileName, ""));
}
bool addedDependentFiles = false;
foreach (string fileName in fdiag.FileNames) {
foreach (string additionalFile in FindAdditionalFiles(fileName)) {
if (!fileNames.Exists(delegate(KeyValuePair<string, string> pair) {
return FileUtility.IsEqualFileName(pair.Key, additionalFile);
}))
{
addedDependentFiles = true;
fileNames.Add(new KeyValuePair<string, string>(additionalFile, Path.GetFileName(fileName)));
}
}
}
string copiedFileName = Path.Combine(node.Directory, Path.GetFileName(fileNames[0].Key));
if (!FileUtility.IsEqualFileName(fileNames[0].Key, copiedFileName)) {
int res = MessageService.ShowCustomDialog(fdiag.Title, "${res:ProjectComponent.ContextMenu.AddExistingFiles.Question}",
0, 2,
"${res:ProjectComponent.ContextMenu.AddExistingFiles.Copy}",
"${res:ProjectComponent.ContextMenu.AddExistingFiles.Link}",
"${res:Global.CancelButtonText}");
if (res == 1) {
foreach (KeyValuePair<string, string> pair in fileNames) {
string fileName = pair.Key;
string relFileName = FileUtility.GetRelativePath(node.Project.Directory, fileName);
FileNode fileNode = new FileNode(fileName, FileNodeStatus.InProject);
FileProjectItem fileProjectItem = new FileProjectItem(node.Project, node.Project.GetDefaultItemType(fileName), relFileName);
fileProjectItem.SetEvaluatedMetadata("Link", Path.Combine(node.RelativePath, Path.GetFileName(fileName)));
fileProjectItem.DependentUpon = pair.Value;
fileNode.ProjectItem = fileProjectItem;
fileNode.AddTo(node);
ProjectService.AddProjectItem(node.Project, fileProjectItem);
}
node.Project.Save();
if (addedDependentFiles)
node.RecreateSubNodes();
return;
}
if (res == 2) {
return;
}
}
bool replaceAll = false;
foreach (KeyValuePair<string, string> pair in fileNames) {
copiedFileName = Path.Combine(node.Directory, Path.GetFileName(pair.Key));
if (!replaceAll && File.Exists(copiedFileName) && !FileUtility.IsEqualFileName(pair.Key, copiedFileName)) {
ReplaceExistingFile res = ShowReplaceExistingFileDialog(fdiag.Title, Path.GetFileName(pair.Key), true);
if (res == ReplaceExistingFile.YesToAll) {
replaceAll = true;
} else if (res == ReplaceExistingFile.No) {
continue;
} else if (res == ReplaceExistingFile.Cancel) {
break;
}
}
FileProjectItem item = CopyFile(pair.Key, node, true);
if (item != null) {
item.DependentUpon = pair.Value;
}
}
node.Project.Save();
if (addedDependentFiles)
node.RecreateSubNodes();
}
}
}
示例3: CreateNewFile
FileProjectItem CreateNewFile(DirectoryNode upper, string fileName)
{
upper.Expanding();
FileNode fileNode = new FileNode(fileName, FileNodeStatus.InProject);
fileNode.AddTo(upper);
fileNode.EnsureVisible();
return IncludeFileInProject.IncludeFileNode(fileNode);
}
示例4: CopyFile
public static FileProjectItem CopyFile(string fileName, DirectoryNode node, bool includeInProject)
{
string copiedFileName = Path.Combine(node.Directory, Path.GetFileName(fileName));
if (!FileUtility.IsEqualFileName(fileName, copiedFileName)) {
File.Copy(fileName, copiedFileName, true);
}
if (includeInProject) {
FileNode fileNode;
foreach (TreeNode childNode in node.AllNodes) {
if (childNode is FileNode) {
fileNode = (FileNode)childNode;
if (FileUtility.IsEqualFileName(fileNode.FileName, copiedFileName)) {
if (fileNode.FileNodeStatus == FileNodeStatus.Missing) {
fileNode.FileNodeStatus = FileNodeStatus.InProject;
} else if (fileNode.FileNodeStatus == FileNodeStatus.None) {
return IncludeFileInProject.IncludeFileNode(fileNode);
}
return fileNode.ProjectItem as FileProjectItem;
}
}
}
fileNode = new FileNode(copiedFileName);
fileNode.AddTo(node);
return IncludeFileInProject.IncludeFileNode(fileNode);
}
return null;
}