예제 #1
0
파일: Reference.cs 프로젝트: matzew/npanday
        static bool downloadArtifact(Artifact.Artifact artifact, NPanday.Logging.Logger logger)
        {
            WebClient client     = new WebClient();
            bool      dirCreated = false;

            try
            {
                if (!artifact.FileInfo.Directory.Exists)
                {
                    artifact.FileInfo.Directory.Create();
                    dirCreated = true;
                }


                logger.Log(NPanday.Logging.Level.INFO, string.Format("Download Start: {0} Downloading From {1}\n", DateTime.Now, artifact.RemotePath));

                client.DownloadFile(artifact.RemotePath, artifact.FileInfo.FullName);

                logger.Log(NPanday.Logging.Level.INFO, string.Format("Download Finished: {0}\n", DateTime.Now));

                string artifactDir = GetLocalUacPath(artifact, artifact.FileInfo.Extension);

                if (!Directory.Exists(Path.GetDirectoryName(artifactDir)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(artifactDir));
                }
                if (!File.Exists(artifactDir))
                {
                    File.Copy(artifact.FileInfo.FullName, artifactDir);
                }

                return(true);
            }

            catch (Exception e)
            {
                if (dirCreated)
                {
                    artifact.FileInfo.Directory.Delete();
                }

                logger.Log(NPanday.Logging.Level.WARNING, string.Format("Download Failed {0}\n", e.Message));

                return(false);
            }

            finally
            {
                client.Dispose();
            }
        }
예제 #2
0
파일: Reference.cs 프로젝트: matzew/npanday
        private static string GetSnapshotVersion(NPanday.Artifact.Artifact artifact, string repo, NPanday.Logging.Logger logger)
        {
            WebClient client           = new WebClient();
            string    timeStampVersion = null;
            string    metadataPath     = repo + "/" + artifact.GroupId.Replace('.', '/') + "/" + artifact.ArtifactId;
            string    snapshot         = "<snapshot>";
            string    metadata         = "/maven-metadata.xml";

            try
            {
                metadataPath = metadataPath + "/" + artifact.Version + metadata;

                string   content = client.DownloadString(metadataPath);
                string[] lines   = content.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);

                string timeStamp   = null;
                string buildNumber = null;

                foreach (string line in lines)
                {
                    int startIndex;
                    int len;

                    if (line.Contains("<timestamp>"))
                    {
                        startIndex = line.IndexOf("<timestamp>") + "<timestamp>".Length;
                        len        = line.IndexOf("</timestamp>") - startIndex;

                        timeStamp = line.Substring(startIndex, len);
                    }

                    if (line.Contains("<buildNumber>"))
                    {
                        startIndex = line.IndexOf("<buildNumber>") + "<buildNumber>".Length;
                        len        = line.IndexOf("</buildNumber>") - startIndex;

                        buildNumber = line.Substring(startIndex, len);
                    }
                }

                if (timeStamp == null)
                {
                    logger.Log(NPanday.Logging.Level.WARNING, "Timestamp was not specified in maven-metadata.xml - using default snapshot version");
                    return(null);
                }

                if (buildNumber == null)
                {
                    logger.Log(NPanday.Logging.Level.WARNING, "Build number was not specified in maven-metadata.xml - using default snapshot version");
                    return(null);
                }

                logger.Log(NPanday.Logging.Level.INFO, "Resolved SNAPSHOT: Timestamp = " + timeStamp + "; Build Number = " + buildNumber);
                timeStampVersion = timeStamp + "-" + buildNumber;
            }
            catch (Exception e)
            {
                return(null);
            }
            finally
            {
                client.Dispose();
            }

            return(timeStampVersion);
        }