Beispiel #1
0
        private static void Main(string[] args)
        {
            XmlConfigurator.Configure();

            var options = new Options();
            var result  = options.Parse(args);

            Log.Debug(options);

            if (result.HasErrors)
            {
                Log.Error(result.ErrorText);
                Environment.Exit(-1);
            }

            if (options.HasErrors())
            {
                Log.Error(options.ErrorText);
                Environment.Exit(-1);
            }

            var projectFile = new FileInfo(options.ProjectFile);
            var outputDir   = new DirectoryInfo(options.TempDirectory + "\\" + Guid.NewGuid());

            var archiveLocation = new ArchiveLocation
            {
                Uri      = options.ArchiveLocation,
                User     = options.ArchiveUser,
                Password = options.ArchivePassword
            };

            var exitCode = 0;

            try
            {
                // ReSharper disable once PossibleInvalidOperationException
                ExecuteBuild(projectFile, options.Version, options.TargetsAsArray, (InstallType)options.Type,
                             options.ServiceName, options.WebsiteName, options.AppPoolName, outputDir, archiveLocation);
            }
            catch (Exception e)
            {
                Log.Error("Unable to build project, cause: " + e, e);
                exitCode = 1;
            }
            finally
            {
                if (outputDir.Exists)
                {
                    outputDir.Delete(true);
                }
            }

            Environment.Exit(exitCode);
        }
Beispiel #2
0
        /// <summary>
        /// Replicates the <see cref="GSF.Historian.IArchive"/>.
        /// </summary>
        protected override void ReplicateArchive()
        {
            WriteTrace("Archive replication started");

            // Parse FTP client information.
            Uri replicaUri = new Uri(ReplicaLocation);

            string[] credentials = replicaUri.UserInfo.Split(':');

            // Ensure credentials are supplied.
            if (credentials.Length != 2)
            {
                throw new ArgumentException("FTP credentials are missing in ReplicaLocation.");
            }

            // Create FTP client for uploading.
            FtpClient ftpClient = new FtpClient();

            ftpClient.Server = replicaUri.Host;
            ftpClient.Port   = replicaUri.Port;
            ftpClient.FileTransferProgress += FtpClient_FileTransferProgress;

            // Initialize the replication log.
            WriteTrace("Initializing archive replication log");
            DataTable replicationLog = new DataTable("ReplicationRecord");

            replicationLog.Columns.Add("DateTime");
            replicationLog.Columns.Add("FileName");
            replicationLog.Columns.Add("FileHash");
            replicationLog.Columns.Add("FileSync");
            replicationLog.Columns.Add("HashingTime");
            replicationLog.Columns.Add("TransferTime");
            replicationLog.Columns.Add("TransferRate");
            replicationLog.Columns.Add("ServerRequests");
            replicationLog.Columns.Add("ServerResponse");
            if (File.Exists(FilePath.GetAbsolutePath(ReplicationLogFile)))
            {
                replicationLog.ReadXml(FilePath.GetAbsolutePath(ReplicationLogFile));
            }
            WriteTrace("Archive replication log initialized");

            try
            {
                // Connect FTP client to server.
                WriteTrace("Connecting to ftp://{0}:{1}", ftpClient.Server, ftpClient.Port);
                ftpClient.Connect(credentials[0], credentials[1]);
                WriteTrace("Connection successful");
                WriteTrace("Changing current directory to '{0}'", replicaUri.AbsolutePath);
                ftpClient.SetCurrentDirectory(replicaUri.LocalPath);
                WriteTrace("Current directory changed to '{0}'", ftpClient.CurrentDirectory.FullPath);

                // Process all archive location(s).
                foreach (string folder in ArchiveLocation.Split(';'))
                {
                    if (!string.IsNullOrEmpty(folder))
                    {
                        ReplicateToHadoop(ftpClient, folder.Trim(), replicationLog);
                    }
                }
            }
            finally
            {
                ftpClient.Dispose();
                replicationLog.WriteXml(FilePath.GetAbsolutePath(ReplicationLogFile));
            }

            WriteTrace("Archive replication complete");
        }
Beispiel #3
0
        private static void ExecuteBuild(FileInfo projectFile, string version, IEnumerable <string> targets,
                                         InstallType installType, string serviceName, string websiteName, string appPoolName,
                                         DirectoryInfo outputDir, ArchiveLocation archiveLocation)
        {
            var projectDir   = projectFile.Directory;
            var assemblyName = GetAssemblyName(projectFile);
            var nugetExe     = new FileInfo(ConfigurationManager.AppSettings["NuGet.exe"]);

            var nugetRestoreTask = new NugetRestoreTask
            {
                ProjectDirectory = projectDir,
                NugetExe         = nugetExe
            };

            nugetRestoreTask.Execute();

            var updateAssemblyTask = new UpdateAssemblyTask
            {
                ProjectDirectory = projectDir,
                Version          = version
            };

            updateAssemblyTask.Execute();

            foreach (var s in targets)
            {
                var target             = s.ToLower();
                var compileProjectTask = new CompileProjectTask
                {
                    ProjectFile     = projectFile,
                    OutputDirectory = outputDir,
                    Target          = target
                };
                compileProjectTask.Execute();

                var transformConfigTask = new TransformConfigTask
                {
                    ProjectDirectory = projectDir,
                    BuildDirectory   = outputDir,
                    ProjectName      = Path.GetFileNameWithoutExtension(projectFile.FullName),
                    Type             = installType,
                    Executable       = compileProjectTask.Executable,
                    Target           = target
                };
                transformConfigTask.Execute();

                if (InstallType.Library == installType)
                {
                    var nugetPackageTask = new NugetPackageTask
                    {
                        ProjectFile     = projectFile,
                        Version         = version,
                        Target          = target,
                        NugetExe        = nugetExe,
                        OutputDirectory = outputDir
                    };
                    nugetPackageTask.Execute();

                    var nugetPushTask = new NugetPushTask
                    {
                        ProjectDirectory = projectDir,
                        Version          = version,
                        AssemblyName     = assemblyName,
                        Target           = target,
                        NugetExe         = nugetExe,
                        Archive          = archiveLocation
                    };
                    nugetPushTask.Execute();
                }
                else
                {
                    var buildSetupExeTask = new BuildSetupExeTask
                    {
                        BuildDirectory = outputDir,
                        ProjectFile    = projectFile,
                        AssemblyName   = assemblyName,
                        Target         = target,
                        Version        = version,
                        Type           = installType,
                        ServiceName    = serviceName,
                        WebsiteName    = websiteName,
                        AppPoolName    = appPoolName,
                        Archive        = archiveLocation
                    };
                    buildSetupExeTask.Execute();
                }
            }
        }