Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
 {
     try
     {
         RemoteArtifactNode node = e.Node as RemoteArtifactNode;
         if (node.IsAssembly)
         {
             addRemoteArtifact(node);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, ex.Message, "NPanday Add Dependency Warning:", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
Esempio n. 3
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            RemoteArtifactNode node = e.Node as RemoteArtifactNode;

            if (node.IsAssembly)
            {
                return;
            }

            List <TreeNode> treeNodes = getNodesFor(node.ArtifactUrl);

            node.Nodes.Clear();
            node.Nodes.AddRange(treeNodes.ToArray());

            addArtifact.Show();
        }
Esempio n. 4
0
        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(this, err.Message, "NPanday Add Dependency Warning:", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            this.Close();
        }
Esempio n. 5
0
        void addRemoteArtifact(RemoteArtifactNode node)
        {
            string uri = node.ArtifactUrl;
            string paths;
            string repoUrl = selectedRepoUrl;

            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;
            //}
        }
Esempio n. 6
0
        List <TreeNode> getNodesFromRemote(string url)
        {
            List <TreeNode> treeNodes = new List <TreeNode>();

            byte[] page = null;

            if (!url.EndsWith("/"))
            {
                url += "/";
            }

            //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;

                // this will convert absolute URI to relative
                if (uri.ToLower().StartsWith("http"))
                {
                    uri = Regex.Replace(uri, url, "", RegexOptions.IgnoreCase);
                }

                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;
                    }

                    String newUrl = url;
                    newUrl          += uri.TrimEnd("/".ToCharArray());;
                    node.ArtifactUrl = newUrl;

                    treeNodes.Add(node);
                }
            }
            return(treeNodes);
        }