コード例 #1
0
        // TODO: belongs in another utility class
        private static void SetReferenceFromFile(FileInfo dll, Reference reference)
        {
            string path = string.Empty;

            if (dll.Exists)
            {
                path = dll.FullName;
            }
            else
            {
                ArtifactContext artifactContext = new ArtifactContext();
                Artifact.Artifact a = artifactContext.GetArtifactRepository().GetArtifact(dll);

                if (a != null)
                {
                    if (!a.FileInfo.Exists)
                    {
                        if (!a.FileInfo.Directory.Exists)
                            a.FileInfo.Directory.Create();

                        string localRepoPath = artifactContext.GetArtifactRepository().GetLocalRepositoryPath(a, dll.Extension);
                        if (File.Exists(localRepoPath))
                        {
                            File.Copy(localRepoPath, a.FileInfo.FullName);
                            path = a.FileInfo.FullName;
                        }
                        else
                        {
                            if (Reference.downloadArtifactFromRemoteRepository(a, dll.Extension))
                            {
                                path = a.FileInfo.FullName;
                            }
                            else
                            {
                                path = reference.getBinReference(dll.Name);
                                if (!string.IsNullOrEmpty(path))
                                {
                                    File.Copy(path, a.FileInfo.FullName);
                                }
                            }
                            //copy assembly to repo if not found.
                            if (!string.IsNullOrEmpty(path) && !File.Exists(localRepoPath))
                            {
                                if (!Directory.Exists(Path.GetDirectoryName(localRepoPath)))
                                    Directory.CreateDirectory(Path.GetDirectoryName(localRepoPath));

                                File.Copy(path, localRepoPath);
                            }
                        }
                    }
                    else
                    {
                        path = a.FileInfo.FullName;
                    }
                }
                if (a == null || string.IsNullOrEmpty(path))
                {
                    log.Warn("Cannot find or download the artifact " + dll.Name + ",  project may not build properly.");
                    return;
                }
            }

            reference.SetAssemblyInfoValues(AssemblyName.GetAssemblyName(path).FullName);
        }
コード例 #2
0
ファイル: Reference.cs プロジェクト: tocsleung/npanday
        // TODO: belongs in another utility classs
        public static bool downloadArtifactFromRemoteRepository(Artifact.Artifact artifact, string ext)
        {
            try
            {
                Dictionary<string, string> repos = SettingsUtil.GetSettingsRepositories();
                foreach (string id in repos.Keys)
                {
                    string url = repos[id];

                    ArtifactContext artifactContext = new ArtifactContext();

                    if (artifact.Version.Contains("SNAPSHOT"))
                    {
                        string newVersion = GetSnapshotVersion(artifact, url);

                        if (newVersion != null)
                        {
                            artifact.RemotePath = artifactContext.GetArtifactRepository().GetRemoteRepositoryPath(artifact, artifact.Version.Replace("SNAPSHOT", newVersion), url, ext);
                        }

                        else
                        {
                            artifact.RemotePath = artifactContext.GetArtifactRepository().GetRemoteRepositoryPath(artifact, url, ext);
                        }

                    }
                    else
                    {
                        artifact.RemotePath = artifactContext.GetArtifactRepository().GetRemoteRepositoryPath(artifact, url, ext);
                    }

                    if (downloadArtifact(artifact))
                    {
                        return true;
                    }
                }
                return false;
            }
            catch (Exception e)
            {
                log.Error("Cannot add reference of " + artifact.ArtifactId + ", an exception occurred trying to download it: " + e.Message);
                return false;
            }
        }