blob: b5408bab68004bfe428fe77c4ce2baa5854a7f99 [file] [log] [blame]
#region Apache License, Version 2.0
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
#endregion
using Extensibility;
using EnvDTE;
using EnvDTE80;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Net;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
using VSLangProj;
using NPanday.Artifact;
using NPanday.Logging;
using NPanday.Model.Pom;
using NPanday.Model.Setting;
using NPanday.Utils;
namespace NPanday.VisualStudio.Addin
{
public partial class AddArtifactsForm : Form
{
private List<NPanday.Artifact.Artifact> localArtifacts = new List<NPanday.Artifact.Artifact>();
private ArtifactContext artifactContext;
private Project project;
private NPanday.Logging.Logger logger;
private FileInfo pom;
private WebClient webClient = new WebClient();
bool _remoteRepoChanged = false;
public bool fileProtocol = false;
#region configure repo
private Settings settings;
private String settingsPath;
#endregion
/// <summary>
/// For Testing
/// </summary>
public AddArtifactsForm()
{
//InitializeForm();
InitializeComponent();
addArtifact.Show();
// localListView.View = View.Details;
#region Initialize Configuration Repo
settingsPath = SettingsUtil.GetUserSettingsPath();
try
{
settings = SettingsUtil.ReadSettings(new FileInfo(settingsPath));
}
catch (Exception e)
{
MessageBox.Show(e.Message + e.StackTrace);
}
#endregion
}
public AddArtifactsForm(Project project, ArtifactContext container, Logger logger, FileInfo pom)
{
this.project = project;
this.logger = logger;
InitializeForm();
InitializeComponent();
addArtifact.Visible = true;
localListView.View = View.Details;
artifactContext = container;
this.pom = pom;
}
private void InitializeForm()
{
this.SuspendLayout();
//
// AddArtifactsForm
//
this.ClientSize = new System.Drawing.Size(292, 260);
this.Name = "AddArtifactsForm";
this.Load += new System.EventHandler(this.AddArtifactsForm_Load);
this.ResumeLayout(false);
}
private void refresh()
{
localListView.Items.Clear();
localArtifacts = artifactContext.GetArtifactRepository().GetArtifacts();
foreach (NPanday.Artifact.Artifact artifact in localArtifacts)
{
LocalArtifactItem item = new LocalArtifactItem(new string[] {
artifact.ArtifactId, artifact.Version}, -1);
item.Artifact = artifact;
localListView.Items.Add(item);
}
String url = RepoCombo.Text;
SetUnsafeHttpHeaderParsing();
List<TreeNode> treeNodes = getNodesFor(url);
treeView1.Nodes.Clear();
treeView1.Nodes.AddRange(treeNodes.ToArray());
treeView1.MouseClick += new System.Windows.Forms.MouseEventHandler(treeView_MouseUp);
}
private void AddArtifactsForm_Load(object sender, EventArgs e)
{
localListView.Items.Clear();
localArtifacts = artifactContext.GetArtifactRepository().GetArtifacts();
foreach (NPanday.Artifact.Artifact artifact in localArtifacts)
{
LocalArtifactItem item = new LocalArtifactItem(new string[] {
artifact.ArtifactId, artifact.Version}, -1);
item.Artifact = artifact;
localListView.Items.Add(item);
}
String settingsPath = SettingsUtil.GetUserSettingsPath();
Settings settings = null;
try
{
if (File.Exists(settingsPath))
{
settings = SettingsUtil.ReadSettings(new FileInfo(settingsPath));
}
else
{
MessageBox.Show("Sorry, but no settings.xml file was found in your Local Repository.", "Repository Configuration", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
catch (Exception ex)
{
MessageBox.Show("Invalid Settings File: " + ex.Message + ex.StackTrace);
return;
}
if (settings.profiles == null)
{
MessageBox.Show("No Profile Found. Please Configure your Repository. ","Repository Configuration",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
String url = getRepositoryUrl();
if (url == null)
{
MessageBox.Show("Remote repository not yet set: Please set your Remote Repository.","Repository Configuration",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
SetUnsafeHttpHeaderParsing();
List<TreeNode> treeNodes = getNodesFor(url);
treeView1.Nodes.AddRange(treeNodes.ToArray());
treeView1.MouseClick += new System.Windows.Forms.MouseEventHandler(treeView_MouseUp);
updateUrlList();
RepoCombo.SelectedIndex = RepoCombo.Items.IndexOf(url);
_remoteRepoChanged = false;
}
private void addArtifact_Click(object sender, EventArgs e)
{
try
{
ListView.SelectedListViewItemCollection selectedItems = localListView.SelectedItems;
if (selectedItems != null)
{
foreach (ListViewItem item in selectedItems)
{
addLocalArtifact(item as LocalArtifactItem);
}
}
if (treeView1.SelectedNode != null)
{
RemoteArtifactNode treeNode = treeView1.SelectedNode as RemoteArtifactNode;
if (treeNode.IsAssembly)
{
addRemoteArtifact(treeNode);
}
else
{
MessageBox.Show(this, string.Format("Cannot add {0} not an artifact assembly.", treeNode.FullPath), this.Text);
return;
}
}
}
catch (Exception err)
{
MessageBox.Show(err.Message, "NPanday Add Dependency Error:");
return;
}
this.Close();
}
private Boolean IsIncluded(String name, String uri)
{
if (name.StartsWith(".") || name.Equals("Parent Directory") || name.Equals("Terms of Use"))
{
return false;
}
if (uri.StartsWith(".."))
{
return false;
}
if (uri.Contains("."))
{
String[] tokens = name.Split(".".ToCharArray());
String extension = tokens[tokens.Length -1];
if (extension.Equals("txt") || extension.Equals("pom") ||
extension.Equals("md5") || extension.Equals("sha1") ||
extension.Equals("xml") || extension.Equals("tar") ||
extension.Equals("gz") || extension.Equals("rb") ||
extension.Equals("htm") || extension.Equals("html") ||
extension.Equals("jsp"))
{
return false;
}
}
if (uri.ToLower().StartsWith("http") || uri.ToLower().StartsWith("mailto"))
{
return false;
}
return true;
}
private Boolean IsDirectory(String name)
{
if (name.Contains("."))
{
String[] tokens = name.Split(".".ToCharArray());
String extension = tokens[tokens.Length - 1];
if (extension.Equals("dll") || extension.Equals("jar") ||
extension.Equals("exe"))
{
return false;
}
}
return true;
}
List<TreeNode> getNodesFor(String url)
{
try
{
Uri repoUri = new Uri(url);
if (repoUri.IsFile)
{
return getNodesFromLocal(repoUri.LocalPath);
}
else
{
return getNodesFromRemote(url);
}
}
catch (Exception e)
{
MessageBox.Show("There was a problem with the provided URL. \nStack Trace:"+e.Message,"Get Artifacts from Remote Repository Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
return null;
}
List<TreeNode> getNodesFromLocal(string repoFolder)
{
List<TreeNode> nodes = new List<TreeNode>();
if (!Directory.Exists(repoFolder))
{
MessageBox.Show(this, "Local repository path not found.", "Local Repository");
return nodes;
}
foreach (FileSystemInfo fsi in (new DirectoryInfo(repoFolder).GetFileSystemInfos()))
{
if (fsi is FileInfo)
{
string ext = Path.GetExtension(fsi.FullName).ToLower();
if (ext != ".dll" && ext != ".exe" && ext != ".netmodule" && ext != ".ocx")
continue;
}
RemoteArtifactNode node = new RemoteArtifactNode(fsi.Name);
node.IsFileSystem = true;
node.ArtifactUrl = Path.Combine(repoFolder, fsi.Name);
node.IsAssembly = (fsi is FileInfo);
nodes.Add(node);
}
return nodes;
}
//TODO: make a function to check if the url is accessable or not
/// <summary>
/// Checks if a remote repository url is accessible or not
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
private void verifyRemoteAccess(string url)
{
while (true)
{
try
{
webClient.DownloadData(url);
break;
}
catch (WebException ex)
{
// ask for user credentials then try again
if (ex.Response != null && (ex.Response as HttpWebResponse).StatusCode == HttpStatusCode.Unauthorized)
{
LoginForm dialog = new LoginForm();
if (dialog.ShowDialog(this) == DialogResult.OK)
{
CredentialCache cache = new CredentialCache();
cache.Add(new Uri(url), "Basic", new NetworkCredential(dialog.Username, dialog.Password));
webClient.Credentials = cache;
continue;
}
throw new Exception("Sorry, but you are not authorized to access the specified URL.");
}
else
{
throw new Exception("Sorry, but you have entered an invalid URL for the Remote Repository.");
}
}
catch (Exception)
{
throw new Exception("Sorry, but you have entered an invalid URL for the Remote Repository.");
}
}
}
private void verifyFileProtocol(string url)
{
string chkDir = url.Replace("file:///", "");
if (Directory.Exists(chkDir))
{
}
else
{
throw new Exception("Sorry, but you have entered an invalid URL for the Remote Repository.");
}
}
List<TreeNode> getNodesFromRemote(string url)
{
List<TreeNode> treeNodes = new List<TreeNode>();
byte[] page = null;
//prevent VS crash
try
{
page = webClient.DownloadData(url);
}
catch (Exception)
{
//MessageBox.Show("Cannot read remote repository: " + url + " " + ex.Message + ex.StackTrace);
MessageBox.Show("Cannot read remote repository: " + url,"Configure Repository",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return treeNodes;
}
String pattern =
(@"<a[^>]*href\s*=\s*[\""\']?(?<URI>[^""'>\s]*)[\""\']?[^>]*>(?<Name>[^<]+|.*?)?<");
MatchCollection matches = Regex.Matches(Encoding.ASCII.GetString(page), pattern, RegexOptions.IgnoreCase);
// treeView1.ImageList = imageList1;
foreach (Match match in matches)
{
String name = match.Groups["Name"].Value;
String uri = match.Groups["URI"].Value;
if (IsIncluded(name, uri))
{
RemoteArtifactNode node = new RemoteArtifactNode(name); // new TreeNode(name);
if (!IsDirectory(name))
{
node.ImageIndex = 1;
}
node.IsFileSystem = false;
string ext = Path.GetExtension(name).ToLower();
if (ext == ".dll" || ext == ".exe" || ext == ".netmodule" || ext == ".ocx")
{
node.IsAssembly = true;
}
else
{
node.IsAssembly = false;
}
node.ArtifactUrl = url + "/" + uri.TrimEnd("/".ToCharArray()); ;
treeNodes.Add(node);
}
}
return treeNodes;
}
private void treeView_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point point = new Point(e.X, e.Y);
RemoteArtifactNode node = treeView1.GetNodeAt(point) as RemoteArtifactNode;
if (node.IsAssembly)
return;
List<TreeNode> treeNodes = getNodesFor( node.ArtifactUrl);
node.Nodes.Clear();
node.Nodes.AddRange(treeNodes.ToArray());
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
public static void SetUnsafeHttpHeaderParsing()
{
Assembly assembly = Assembly.GetAssembly(typeof(System.Net.Configuration.SettingsSection));
Type settingsSectionType = assembly.GetType("System.Net.Configuration.SettingsSectionInternal");
object settingsSection = settingsSectionType.InvokeMember("Section",
BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.NonPublic,
null, null, new object[] { });
FieldInfo fieldInfo = settingsSectionType.GetField("useUnsafeHeaderParsing",
BindingFlags.NonPublic | BindingFlags.Instance);
fieldInfo.SetValue(settingsSection, true);
}
private Boolean isValidRemoteRepositoryUrl(String repoUrl)
{
byte[] page = null;
try
{
page = webClient.DownloadData(repoUrl);
}
catch (Exception ex)
{
MessageBox.Show("Cannot read remote repository: " + repoUrl + " " + ex.Message + ex.StackTrace);
return false;
}
return true;
}
/*
* e.g.: Castle/./Castle.Core/./2.0-rc2/./Castle.Core-2.0-rc2.dll
* transform it to: Castle/Castle.Core/2.0-rc2/Castle.Core-2.0-rc2.dll
*
*/
private String normalizePath(String path)
{
return path.Replace("/./", "/");
}
private String getRepositoryUrl()
{
Settings settings = null;
String settingsPath = SettingsUtil.GetUserSettingsPath();
try
{
settings = SettingsUtil.ReadSettings(new FileInfo(settingsPath));
}
catch (Exception e)
{
MessageBox.Show(e.Message + e.StackTrace);
}
foreach (NPanday.Model.Setting.Profile profile in settings.profiles)
{
if ("NPanday.id".Equals(profile.id))
{
if (profile.repositories.Length > 0)
{
return profile.repositories[0].url;
}
break;
}
}
return null;
}
private void localListView_DoubleClick(object sender, EventArgs e)
{
try
{
LocalArtifactItem item = localListView.SelectedItems[0] as LocalArtifactItem;
addLocalArtifact(item);
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message, "Add Artifacts");
}
}
private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
RemoteArtifactNode node = e.Node as RemoteArtifactNode;
if (node.IsAssembly)
{
addRemoteArtifact(node);
}
}
void addArtifactToPom(Artifact.Artifact artifact)
{
try
{
if (pom != null)
{
PomHelperUtility pomUtil = new PomHelperUtility(pom);
pomUtil.AddPomDependency(artifact.GroupId, artifact.ArtifactId, artifact.Version);
}
}
catch (Exception err1)
{
MessageBox.Show(err1.Message, "NPanday Add Dependency Error:");
return;
}
}
bool addVSProjectReference(Artifact.Artifact artifact, string name)
{
VSProject vsProject = (VSProject)project.Object;
if (vsProject.References.Find(name) != null)
{
MessageBox.Show(this, "A version of artifact is already added to the project, please remove it first before adding this version.", this.Text);
return false;
}
try
{
Assembly a = Assembly.LoadFile(artifact.FileInfo.FullName);
//if (a.ToString().Split(",".ToCharArray())[0].ToLower().StartsWith("interop."))
//{
// MessageBox.Show("Cannot add COM Interop reference from a Maven Artifact, just use Add Reference if you wish to add a COM reference.", "Add Maven Artifact", MessageBoxButtons.OK, MessageBoxIcon.Information);
// return false;
//}
addArtifactToPom(artifact);
vsProject.References.Add(artifact.FileInfo.FullName);
return true;
}
catch
{
MessageBox.Show("Cannot add COM reference from a Maven Artifact.", "Add Maven Artifact", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
}
bool addVSWebProjectReference(Artifact.Artifact artifact, string name)
{
try
{
VsWebSite.VSWebSite website = (VsWebSite.VSWebSite)project.Object;
Assembly a = Assembly.LoadFile(artifact.FileInfo.FullName);
if (a.ToString().Split(",".ToCharArray())[0].ToLower().StartsWith("interop."))
{
MessageBox.Show("Cannot add COM Interop reference from a Maven Artifact, just use Add Reference if you wish to add a COM reference.", "Add Maven Artifact", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
bool referenced = false;
try
{
referenced = (website.References.Item(name) != null);
}
catch
{
referenced = false;
}
if (referenced)
{
MessageBox.Show(this, "A version of artifact is already added to the project, please remove it first before adding this version.", this.Text);
return false;
}
// not need to written in pom anymore
//addArtifactToPom(artifact);
website.References.AddFromFile(artifact.FileInfo.FullName);
return true;
}
catch
{
MessageBox.Show("Cannot add COM reference from a Maven Artifact.", "Add Maven Artifact", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
}
void addLocalArtifact(LocalArtifactItem item)
{
NPanday.Artifact.Artifact artifact = item.Artifact;
addReferenceToProject(ref artifact, item.Text);
}
private void addReferenceToProject(ref NPanday.Artifact.Artifact artifact, string text)
{
if (project.Object is VSProject)
{
IReferenceManager refMgr = new ReferenceManager();
refMgr.Initialize((VSLangProj80.VSProject2)project.Object);
artifact = refMgr.Add(new ReferenceInfo(artifact));
if (!addVSProjectReference(artifact, text))
return;
}
else if (Connect.IsWebProject(project))
{
if (!addVSWebProjectReference(artifact, text))
return;
}
else
{
MessageBox.Show(this, "Cannot add artifact to none VS projects.", this.Text);
return;
}
}
void addRemoteArtifact(RemoteArtifactNode node)
{
String uri = node.ArtifactUrl;
String paths;
String repoUrl = getRepositoryUrl();
if (node.IsFileSystem)
{
//Uri repoUri = new Uri(repoUrl);
//paths = uri.Substring(repoUri.LocalPath.Length).Replace(@"\",@"/");
paths = uri;
}
else
{
paths = normalizePath(uri.Substring(repoUrl.Length));
}
NPanday.Artifact.Artifact artifact =
artifactContext.GetArtifactRepository().GetArtifactFor(paths);
//Download
artifact.FileInfo.Directory.Create();
if (node.IsFileSystem)
{
if (!File.Exists(artifact.FileInfo.FullName))
{
File.Copy(node.ArtifactUrl, artifact.FileInfo.FullName);
}
}
else
{
if (!File.Exists(artifact.FileInfo.FullName))
{
byte[] assembly = webClient.DownloadData(uri);
FileStream stream = new FileStream(artifact.FileInfo.FullName, FileMode.Create);
stream.Write(assembly, 0, assembly.Length);
stream.Flush();
stream.Close();
stream.Dispose();
webClient.Dispose();
}
//make sure that file is properly closed before adding it to the reference
System.Threading.Thread.Sleep(1000);
}
addReferenceToProject(ref artifact, artifact.ArtifactId);
//if (project.Object is VSProject)
//{
// if (!addVSProjectReference(artifact, artifact.ArtifactId))
// return;
//}
//else if (Connect.IsWebProject(project))
//{
// if (!addVSWebProjectReference(artifact, artifact.ArtifactId))
// return;
//}
//else
//{
// MessageBox.Show(this, "Cannot add artifact to none VS projects.", this.Text);
// return;
//}
}
private void updateRepositoryFor(NPanday.Model.Setting.Profile profile, NPanday.Model.Setting.Repository repository)
{
NPanday.Model.Setting.Activation activation = new NPanday.Model.Setting.Activation();
activation.activeByDefault = true;
profile.activation = activation;
NPanday.Model.Setting.RepositoryPolicy releasesPolicy = new NPanday.Model.Setting.RepositoryPolicy();
NPanday.Model.Setting.RepositoryPolicy snapshotsPolicy = new NPanday.Model.Setting.RepositoryPolicy();
releasesPolicy.enabled = checkBoxRelease.Checked;
snapshotsPolicy.enabled = checkBoxSnapshot.Checked;
repository.releases = releasesPolicy;
repository.snapshots = snapshotsPolicy;
repository.id = repository.url;
}
private void update_Click(object sender, EventArgs e)
{
executeRepoUpdate();
}
private string prevRepo=string.Empty;
private void executeRepoUpdate()
{
if (prevRepo.Equals(RepoCombo.Text))
{
return;
}
if (string.IsNullOrEmpty(RepoCombo.Text))
{
MessageBox.Show("Sorry, Repository cannot be blank.", "Repository Configuration", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
bool profileExists = false;
XmlSerializer serializer = new XmlSerializer(typeof(NPanday.Model.Setting.Settings));
TextWriter writer;
string selectedUrl = RepoCombo.Text;
// get system path of settings.xml
if (settingsPath == null)
{
settingsPath = SettingsUtil.GetUserSettingsPath();
}
// load settings.xml
if (settings == null)
{
try
{
settings = SettingsUtil.ReadSettings(new FileInfo(settingsPath));
}
catch (Exception err)
{
MessageBox.Show(err.Message + err.StackTrace);
}
}
// verify if URL is accessible
try
{
if (RepoCombo.Text.Contains("file:///"))
{
verifyFileProtocol(selectedUrl);
}
else
{
verifyRemoteAccess(selectedUrl);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Repository Configuration", MessageBoxButtons.OK, MessageBoxIcon.Warning);
artifactTabControl.SelectedIndex = 2;
RepoCombo.Text = string.Empty;
return;
}
// look for "NPanday.id" profile
if (settings.profiles != null)
{
foreach (NPanday.Model.Setting.Profile profile in settings.profiles)
{
if ("NPanday.id".Equals(profile.id))
{
profileExists = true;
NPanday.Model.Setting.Repository selectedRepo = getRepositoryFromProfile(profile, selectedUrl);
// if found, remove then add
if (selectedRepo != null)
{
removeRepositoryFromProfile(selectedRepo, profile);
updateRepositoryFor(profile, selectedRepo);
}
else
{
selectedRepo = new NPanday.Model.Setting.Repository();
selectedRepo.url = selectedUrl;
updateRepositoryFor(profile, selectedRepo);
}
addRepositoryToProfile(selectedRepo, profile);
MessageBox.Show(this, "Successfully Changed Remote Repository.", "Repository Configuration");
prevRepo = selectedUrl;
writer = new StreamWriter(settingsPath);
serializer.Serialize(writer, settings);
writer.Close();
break;
}
}
}
// add new profile if not found
if (!profileExists)
{
// create new profile
NPanday.Model.Setting.Profile newProfile = new NPanday.Model.Setting.Profile();
newProfile.id = "NPanday.id";
// create new repo
NPanday.Model.Setting.Repository newRepo = new NPanday.Model.Setting.Repository();
newRepo.url = selectedUrl;
updateRepositoryFor(newProfile, newRepo);
newProfile.repositories = new NPanday.Model.Setting.Repository[] { newRepo };
if (settings.profiles == null)
{
settings.profiles = new NPanday.Model.Setting.Profile[] { newProfile };
}
else
{
List<NPanday.Model.Setting.Profile> profiles = new List<NPanday.Model.Setting.Profile>();
profiles.AddRange(settings.profiles);
profiles.Add(newProfile);
settings.profiles = profiles.ToArray();
}
writer = new StreamWriter(settingsPath);
serializer.Serialize(writer, settings);
writer.Close();
prevRepo = selectedUrl;
MessageBox.Show(this, "Successfully Changed Remote Repository.", "Repository Configuration");
}
RepoCombo.Items.Clear();
updateUrlList();
RepoCombo.SelectedIndex = RepoCombo.Items.IndexOf(selectedUrl);
refresh();
}
}
private void updateUrlList()
{
List<string> urls = getUrls();
foreach (string item in urls)
{
if (!RepoCombo.Items.Contains(item))
{
RepoCombo.Items.Add(item);
}
}
}
private void addRepositoryToProfile(NPanday.Model.Setting.Repository repository, NPanday.Model.Setting.Profile profile)
{
// activate profile
NPanday.Model.Setting.Activation activation = new NPanday.Model.Setting.Activation();
activation.activeByDefault = true;
profile.activation = activation;
// add repository to profile
if (profile.repositories == null)
{
profile.repositories = new NPanday.Model.Setting.Repository[] { repository };
}
else
{
List<NPanday.Model.Setting.Repository> repositories = new List<NPanday.Model.Setting.Repository>();
repositories.AddRange(profile.repositories);
repositories.Insert(0,repository);
profile.repositories = repositories.ToArray();
}
}
private void removeRepositoryFromProfile(NPanday.Model.Setting.Repository repository, NPanday.Model.Setting.Profile profile)
{
List<NPanday.Model.Setting.Repository> repositories = new List<NPanday.Model.Setting.Repository>();
repositories.AddRange(profile.repositories);
repositories.Remove(repository);
profile.repositories = repositories.ToArray();
}
private NPanday.Model.Setting.Repository getRepositoryFromProfile(NPanday.Model.Setting.Profile profile, string url)
{
foreach (NPanday.Model.Setting.Repository repo in profile.repositories)
{
if (url.Equals(repo.url))
{
return repo;
}
}
return null;
}
private List<string> getUrls()
{
if (settingsPath == null)
{
settingsPath = SettingsUtil.GetUserSettingsPath();
}
if (settings == null)
{
try
{
settings = SettingsUtil.ReadSettings(new FileInfo(settingsPath));
}
catch (Exception err)
{
MessageBox.Show(err.Message + err.StackTrace);
}
}
List<string> urls = new List<string>();
foreach (NPanday.Model.Setting.Profile profile in settings.profiles)
{
foreach (NPanday.Model.Setting.Repository repository in profile.repositories)
{
//if (repository.id.Equals("NPanday.id"))
{
if (!urls.Contains(repository.url))
{
urls.Add(repository.url);
}
}
}
}
return urls;
}
private void RepoListBox_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void ConfigureTab_Click(object sender, EventArgs e)
{
addArtifact.Hide();
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
addArtifact.Show();
}
private void remoteTabPage_Click(object sender, EventArgs e)
{
addArtifact.Show();
}
private void localTabPage_Click(object sender, EventArgs e)
{
addArtifact.Show();
}
private void localListView_SelectedIndexChanged(object sender, EventArgs e)
{
addArtifact.Show();
}
private void RepoCombo_SelectedIndexChanged(object sender, EventArgs e)
{
_remoteRepoChanged = true;
addArtifact.Hide();
}
private void artifactTabControl_SelectedIndexChanged(object sender, EventArgs e)
{
String settingsPath = SettingsUtil.GetUserSettingsPath();
if (artifactTabControl.SelectedIndex == 2)
{
//check if there is an existing settings.xml file
if (settingsPath == null)
{
MessageBox.Show("Sorry, but you cannot Configure Remote Repository without a Settings.xml file", "Repository Configuration", MessageBoxButtons.OK, MessageBoxIcon.Warning);
AddArtifactsForm.ActiveForm.Hide();
artifactTabControl.SelectedIndex = 0;
}
else
{
updateUrlList();
addArtifact.Hide();
}
}
else if (artifactTabControl.SelectedIndex == 1)
{
//check if there is an existing settings.xml file
if (settingsPath == null)
{
MessageBox.Show("Sorry, but you cannot Access Remote Repository without a Settings.xml file", "Repository Configuration", MessageBoxButtons.OK, MessageBoxIcon.Warning);
artifactTabControl.SelectedIndex = 0;
}
else
{
if (_remoteRepoChanged)
{
_remoteRepoChanged = false;
executeRepoUpdate();
}
treeView1.Focus();
addArtifact.Show();
}
}
else
{
localListView.Focus();
addArtifact.Show();
}
}
}
class LocalArtifactItem : ListViewItem
{
public LocalArtifactItem() { }
public LocalArtifactItem(string name)
: base(name)
{
}
public LocalArtifactItem(string[] items) : base(items) { }
public LocalArtifactItem(string[] items, int imageIndex) : base(items, imageIndex) { }
private NPanday.Artifact.Artifact artifact;
public NPanday.Artifact.Artifact Artifact
{
get { return artifact; }
set { artifact = value; }
}
}
class RemoteArtifactNode : TreeNode
{
public RemoteArtifactNode() { }
public RemoteArtifactNode(string name) : base(name)
{
}
private bool isAssembly;
public bool IsAssembly
{
get { return isAssembly; }
set { isAssembly = value; }
}
private string artifactUrl;
public string ArtifactUrl
{
get { return artifactUrl; }
set { artifactUrl = value; }
}
private bool isFileSystem;
public bool IsFileSystem
{
get { return isFileSystem; }
set { isFileSystem = value; }
}
}
}