protected override bool OnBuild(ProgressMonitor monitor, DeployContext ctx)
        {
            string             sourceFile;
            SolutionFolderItem entry = RootSolutionItem;

            if (entry is SolutionFolder)
            {
                sourceFile = entry.ParentSolution.FileName;
            }
            else
            {
                sourceFile = ((SolutionItem)entry).FileName;
            }

            AggregatedProgressMonitor mon = new AggregatedProgressMonitor();

            mon.AddSlaveMonitor(monitor, MonitorAction.WriteLog | MonitorAction.ReportError | MonitorAction.ReportWarning | MonitorAction.ReportSuccess);

            string tmpFolder = FileService.CreateTempDirectory();

            try {
                string tf = Path.GetFileNameWithoutExtension(targetFile);
                if (tf.EndsWith(".tar"))
                {
                    tf = Path.GetFileNameWithoutExtension(tf);
                }

                string folder = FileService.GetFullPath(Path.Combine(tmpFolder, tf));
                Directory.CreateDirectory(folder);

                // Export the project

                SolutionFolderItem[] ents   = GetChildEntries();
                string[]             epaths = new string [ents.Length];
                for (int n = 0; n < ents.Length; n++)
                {
                    epaths [n] = ents [n].ItemId;
                }

                var r = Services.ProjectService.Export(mon, sourceFile, epaths, folder, FileFormat).Result;
                if (string.IsNullOrEmpty(r))
                {
                    return(false);
                }

                // Create the archive
                string td = Path.GetDirectoryName(targetFile);
                if (!Directory.Exists(td))
                {
                    Directory.CreateDirectory(td);
                }
                DeployService.CreateArchive(mon, tmpFolder, targetFile);
            }
            finally {
                Directory.Delete(tmpFolder, true);
            }
            monitor.Log.WriteLine(GettextCatalog.GetString("Created file: {0}", targetFile));
            return(true);
        }
Exemplo n.º 2
0
        protected override bool OnBuild(IProgressMonitor monitor, DeployContext ctx)
        {
            string tmpFolder = null;

            try {
                SolutionConfigurationSelector conf = (SolutionConfigurationSelector)configuration;
                BuildResult res = RootSolutionItem.Build(monitor, conf);
                if (res.ErrorCount > 0)
                {
                    foreach (BuildError e in res.Errors)
                    {
                        monitor.ReportError(e.ToString(), null);
                    }
                    monitor.ReportError(GettextCatalog.GetString("The source project failed to build."), null);
                    return(false);
                }

                tmpFolder = FileService.CreateTempDirectory();

                string tf = Path.GetFileNameWithoutExtension(targetFile);
                if (tf.EndsWith(".tar"))
                {
                    tf = Path.GetFileNameWithoutExtension(tf);
                }
                string folder = FileService.GetFullPath(Path.Combine(tmpFolder, tf));

                // Export the binary files
                DeployFileCollection deployFiles = GetDeployFiles(ctx, conf);
                foreach (DeployFile file in deployFiles)
                {
                    string tfile = Path.Combine(folder, file.ResolvedTargetFile);
                    string tdir  = FileService.GetFullPath(Path.GetDirectoryName(tfile));
                    if (!Directory.Exists(tdir))
                    {
                        Directory.CreateDirectory(tdir);
                    }
                    File.Copy(file.SourcePath, tfile, true);
                }

                // Create the archive
                string td = Path.GetDirectoryName(targetFile);
                if (!Directory.Exists(td))
                {
                    Directory.CreateDirectory(td);
                }
                DeployService.CreateArchive(monitor, tmpFolder, targetFile);
            }
            catch (Exception ex) {
                monitor.ReportError("Package creation failed", ex);
                LoggingService.LogError("Package creation failed", ex);
                return(false);
            }
            finally {
                if (tmpFolder != null)
                {
                    Directory.Delete(tmpFolder, true);
                }
            }
            if (monitor.AsyncOperation.Success)
            {
                monitor.Log.WriteLine(GettextCatalog.GetString("Created file: {0}", targetFile));
            }
            return(true);
        }