public async override Task AddNugetPackages() { await this.Context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, "Adding Nuget Packages"); var wcfDSInstallLocation = CodeGeneratorUtils.GetWCFDSInstallLocation(); var packageSource = Path.Combine(wcfDSInstallLocation, @"bin\NuGet"); if (Directory.Exists(packageSource)) { var files = Directory.EnumerateFiles(packageSource, "*.nupkg").ToList(); foreach (var nugetPackage in Common.Constants.V3NuGetPackages) { if (!files.Any(f => Regex.IsMatch(f, nugetPackage + @"(.\d){2,4}.nupkg"))) { packageSource = Common.Constants.NuGetOnlineRepository; } } } else { packageSource = Common.Constants.NuGetOnlineRepository; } if (!PackageInstallerServices.IsPackageInstalled(this.Project, this.ClientNuGetPackageName)) { Version packageVersion = null; PackageInstaller.InstallPackage(Common.Constants.NuGetOnlineRepository, this.Project, this.ClientNuGetPackageName, packageVersion, false); } }
private async Task AddNuGetPackagesAsync(ConnectedServiceHandlerContext context, Project currentProject, Version version) { await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, "Adding Nuget Packages"); Version packageVersion = null; if (version.Major.Equals(3)) { var wcfDSInstallLocation = CodeGeneratorUtils.GetWCFDSInstallLocation(); var packageSource = Path.Combine(wcfDSInstallLocation, @"bin\NuGet"); if (Directory.Exists(packageSource)) { var files = Directory.EnumerateFiles(packageSource, "*.nupkg").ToList(); foreach (var nugetPackage in Common.Constants.V3NuGetPackages) { if (!files.Any(f => Regex.IsMatch(f, nugetPackage + @"(.\d){2,4}.nupkg"))) { packageSource = Common.Constants.NuGetOnlineRepository; } } } else { packageSource = Common.Constants.NuGetOnlineRepository; } if (!PackageInstallerServices.IsPackageInstalled(currentProject, Common.Constants.V3ClientNuGetPackage)) { PackageInstaller.InstallPackage(packageSource, currentProject, Common.Constants.V3ClientNuGetPackage, packageVersion, false); } } }
/// <summary> /// Checks and installs nuget packages in the project /// </summary> /// <param name="packageSource">The source of the package</param> /// <param name="packageName">The name of the package to be installed</param> public async Task CheckAndInstallNuGetPackageAsync(string packageSource, string packageName) { if (PackageInstallerServices != null) { try { if (!PackageInstallerServices.IsPackageInstalled(this.Project, packageName)) { Version packageVersion = null; PackageInstaller.InstallPackage(packageSource, this.Project, packageName, packageVersion, false); await(this.MessageLogger?.WriteMessageAsync(LogMessageCategory.Information, $"Nuget Package \"{packageName}\" for OData client was added.")).ConfigureAwait(false); } else { await(this.MessageLogger?.WriteMessageAsync(LogMessageCategory.Information, $"Nuget Package \"{packageName}\" for OData client already installed.")).ConfigureAwait(false); } } catch (Exception ex) { await(this.MessageLogger?.WriteMessageAsync(LogMessageCategory.Error, $"Nuget Package \"{packageName}\" for OData client not installed. Error: {ex.Message}.")).ConfigureAwait(false); } } else { await(this.MessageLogger?.WriteMessageAsync(LogMessageCategory.Error, $"The packages were not installed. An error occurred during the installation of packages.")).ConfigureAwait(false); } }
public override async Task AddNugetPackages() { await this.Context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, "Adding Nuget Packages"); if (!PackageInstallerServices.IsPackageInstalled(this.Project, this.ClientNuGetPackageName)) { Version packageVersion = null; PackageInstaller.InstallPackage(Common.Constants.NuGetOnlineRepository, this.Project, this.ClientNuGetPackageName, packageVersion, false); } }
public void ProjectFinishedGenerating(Project project) { var packages = PackageDescriptor.ParseAllFromXml(ParameterData); if (PackageInstaller != null) { foreach (var package in packages) { CakePackage.Dte.ShowStatusBarText($"Installing NuGet package {package.Id}.{package.Version}"); PackageInstaller.InstallPackage(package.Source, project, package.Id, package.Version, true); } } Wizard.ProjectFinishedGenerating(project); }
public override async Task <int> Execute(InstallAllTaskArguments arguments, string[] args) { DirectoryInfo moduleDirectory = arguments.ModuleDirectory != null ? new DirectoryInfo(Path.GetFullPath(arguments.ModuleDirectory)) : PathUtility.GetDefaultModulePath(); DirectoryInfo packageDirectory = arguments.PackageDirectory != null ? new DirectoryInfo(Path.GetFullPath(arguments.PackageDirectory)) : DirectoryProvider.WorkingDirectory; int exitCode = 0; foreach (var package in packageDirectory.EnumerateFiles("*.snowpkg")) { try { var pkg = new PackageInstaller(File.OpenRead(package.FullName)); if (!arguments.NoVerify) { Console.WriteLine($"Verifying {package.Name}..."); bool verified = await pkg.VerifyPackage(); if (!verified) { throw new InvalidOperationException( $"Package failed to verify, use --noverify to install regardless."); } } Console.WriteLine($"Installing package {package.Name}..."); string installPath = await pkg.InstallPackage(moduleDirectory); Console.WriteLine($"Installed {package.Name} to {installPath}."); } catch (Exception e) { Console.WriteLine($"Unable to install package {package.Name} due to {e.Message}."); exitCode = 1; continue; } } return(exitCode); }
private void AddNuGetDependencyIfMissing(Project project, string packageId) { //Once the generated code has been added, we need to ensure that //the required ServiceStack.Interfaces package is installed. var installedPackages = PackageInstallerServices.GetInstalledPackages(project); //TODO check project references incase ServiceStack.Interfaces is referenced via local file. //VS has different ways to check different types of projects for refs, need to find method to check all. //Check if existing nuget reference exists if (installedPackages.FirstOrDefault(x => x.Id == packageId) == null) { PackageInstaller.InstallPackage("https://www.nuget.org/api/v2/", project, packageId, version: (string)null, //Latest version of packageId ignoreDependencies: false); } }
internal async Task CheckAndInstallNuGetPackageAsync(string packageSource, string nugetPackage) { try { if (!PackageInstallerServices.IsPackageInstalled(this.Project, nugetPackage)) { PackageInstaller.InstallPackage(packageSource, this.Project, nugetPackage, (Version)null, false); await this.Context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, $"Nuget Package \"{nugetPackage}\" forOpenAPI (Swagger) was added."); } else { await this.Context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, $"Nuget Package \"{nugetPackage}\" for OpenAPI (Swagger) already installed."); } } catch (Exception ex) { await this.Context.Logger.WriteMessageAsync(LoggerMessageCategory.Warning, $"Nuget Package \"{nugetPackage}\" for OpenAPI (Swagger) not installed. Error: {ex.Message}."); } }
internal async Task CheckAndInstallNuGetPackageAsync(string packageSource, string nugetPackage) { try { if (!PackageInstallerServices.IsPackageInstalled(this.Project, nugetPackage)) { Version packageVersion = null; PackageInstaller.InstallPackage(packageSource, this.Project, nugetPackage, packageVersion, false); await this.Context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, $"Nuget Package \"{nugetPackage}\" for OData client was added."); } else { await this.Context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, $"Nuget Package \"{nugetPackage}\" for OData client already installed."); } } catch (Exception ex) { await this.Context.Logger.WriteMessageAsync(LoggerMessageCategory.Error, $"Nuget Package \"{nugetPackage}\" for OData client not installed. Error: {ex.Message}."); } }
public RESTStatus FinaliseUpload(SQLLib sql, object dummy, NetworkConnectionInfo ni) { if (ni.Upload == null) { ni.Error = "Upload is not running"; ni.ErrorID = ErrorFlags.UploadNotRunning; return(RESTStatus.Fail); } if (ni.Upload.Data == null) { ni.Error = "No data"; ni.ErrorID = ErrorFlags.NoData; return(RESTStatus.Fail); } if (ni.Upload.Size != ni.Upload.CurrentPosition) { ni.Error = "Upload not completed"; ni.ErrorID = ErrorFlags.UploadNotCompleted; return(RESTStatus.Fail); } switch (ni.Upload.FileType) { case FlagsConst.Document_Type_Package: { ni.Upload.Data.Close(); PackageInstaller pki = new PackageInstaller(); string ErrorText; PKGStatus res; PKGRecieptData reciept; List <byte[]> CER = PolicyCertificates.GetPolicyCertificates(sql); if (pki.InstallPackage(Settings.Default.DataPath + ni.Upload.TempFilename, CER, PackageInstaller.InstallMode.TestPackageOnly, false, out ErrorText, out res, out reciept) == false) { try { CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + ni.Upload.TempFilename); } catch { } ni.Error = "Package contains errors: " + ErrorText; ni.ErrorID = ErrorFlags.FaultyData; ni.Upload = null; return(RESTStatus.Fail); } string GUID = Guid.NewGuid().ToString(); string Filename = "PKG_" + GUID + ".foxpkg"; string FilenameMeta = "PKG_" + GUID + ".meta.foxpkg"; File.Move(Settings.Default.DataPath + ni.Upload.TempFilename, Settings.Default.DataPath + Filename); if (pki.CreateMetaDataPackage(Settings.Default.DataPath + Filename, Settings.Default.DataPath + FilenameMeta, out ErrorText) == false) { try { CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + Filename); } catch { } try { CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + FilenameMeta); } catch { } ni.Error = "Cannot create meta Package: " + ErrorText; ni.ErrorID = ErrorFlags.FaultyData; ni.Upload = null; return(RESTStatus.Fail); } if (pki.PackageInfo(Settings.Default.DataPath + Filename, CER, out ErrorText) == false) { try { CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + Filename); } catch { } try { CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + FilenameMeta); } catch { } ni.Error = "Cannot read Package Info: " + ErrorText; ni.ErrorID = ErrorFlags.FaultyData; ni.Upload = null; return(RESTStatus.Fail); } Int64?NewID = null; lock (ni.sqllock) { NewID = sql.InsertMultiDataID("Packages", new SQLData("PackageID", pki.PackageInfoData.PackageID), new SQLData("Version", pki.PackageInfoData.VersionID), new SQLData("Title", pki.PackageInfoData.Title), new SQLData("Description", pki.PackageInfoData.Description), new SQLData("Filename", Filename), new SQLData("MetaFilename", FilenameMeta), new SQLData("Size", ni.Upload.Size)); } if (NewID == null) { try { CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + Filename); } catch { } try { CommonUtilities.SpecialDeleteFile(Settings.Default.DataPath + FilenameMeta); } catch { } ni.Error = "Error storing data"; return(RESTStatus.Fail); } this.NewID = new NewUploadDataID(); this.NewID.NewID = NewID.Value; this.NewID.FileType = ni.Upload.FileType; ni.Upload = null; break; } //case FlagsConst.Document_Type_Invoice: //case FlagsConst.Document_Type_Voucher: //case FlagsConst.Document_Type_ClientData: // { // ni.Error = "Cannot use this function"; // return (false); // } default: { ni.Error = "Invalid type"; ni.ErrorID = ErrorFlags.InvalidType; return(RESTStatus.Fail); } } return(RESTStatus.Success); }
public void InstallLatestPackage(EnvDTE.Project project, string packageId) { PackageInstaller.InstallPackage(null, project, packageId, (string)null, false); }
static int Main(string[] args) { Console.WriteLine("Fox Installer"); Console.WriteLine(""); if (args.Length < 2) { Help(); return(1); } ComputerCertificate ccert = new ComputerCertificate(); if (ccert.GetCertificate() == false) { Console.WriteLine("Cannot load computer certificate from Fox SDC"); #if DEBUG Console.WriteLine("Press any key . . ."); Console.ReadKey(true); #endif return(2); } PackageInstaller pkgi = new PackageInstaller(); PKGStatus pkgres = PKGStatus.NotNeeded; PKGRecieptData reciept = null; string ErrorText = ""; bool res = false; List <byte[]> cer = new List <byte[]>(); switch (args[0].ToLower().Trim()) { case "-install": Console.WriteLine("Installing " + args[1].Trim()); cer = LoadCERFiles(args); res = pkgi.InstallPackage(args[1].Trim(), cer, PackageInstaller.InstallMode.Install, false, out ErrorText, out pkgres, out reciept); break; case "-test": Console.WriteLine("Testing " + args[1].Trim()); cer = LoadCERFiles(args); res = pkgi.InstallPackage(args[1].Trim(), cer, PackageInstaller.InstallMode.Test, false, out ErrorText, out pkgres, out reciept); break; case "-info": cer = LoadCERFiles(args); res = pkgi.PackageInfo(args[1].Trim(), cer, out ErrorText); Console.WriteLine(ErrorText); #if DEBUG Console.WriteLine("Press any key . . ."); Console.ReadKey(true); #endif return(res == true ? 0 : 1); default: Console.WriteLine("Invalid argurments"); #if DEBUG Console.WriteLine("Press any key . . ."); Console.ReadKey(true); #endif return(1); } Console.WriteLine("Status: " + pkgres.ToString()); if (res == false) { Console.WriteLine(ErrorText); } else { if (reciept != null) { string recppath = Path.GetDirectoryName(args[1].Trim()); if (recppath.EndsWith("\\") == false) { recppath += "\\"; } string recieptfile = recppath + Path.GetFileNameWithoutExtension(args[1].Trim()) + ".foxrecp"; string recieptfilesign = recppath + Path.GetFileNameWithoutExtension(args[1].Trim()) + ".sign"; #if DEBUG string recps = JsonConvert.SerializeObject(reciept, Formatting.Indented); #else string recps = JsonConvert.SerializeObject(reciept); #endif File.WriteAllText(recieptfile, recps, Encoding.UTF8); byte[] sign = ccert.Sign(Encoding.UTF8.GetBytes(recps)); File.WriteAllBytes(recieptfilesign, sign); } } #if DEBUG Console.WriteLine("Press any key . . ."); Console.ReadKey(true); #endif return(0); }
public static void RunPipeClient() { Process2ProcessComm p2p = new Process2ProcessComm(); if (p2p.ConnectPipe(ProgramAgent.PipeGUID) == false) { FoxEventLog.VerboseWriteEventLog("Cannot connect to pipe " + ProgramAgent.PipeGUID, EventLogEntryType.Error); return; } string Action = p2p.GetAction(); if (Action == null) { FoxEventLog.VerboseWriteEventLog("Got no action data from pipe " + ProgramAgent.PipeGUID, EventLogEntryType.Error); return; } switch (Action.ToLower()) { case "install": { PackageInstaller inst = new PackageInstaller(); DataHInstallPackageTODO todo = p2p.GetTODO <DataHInstallPackageTODO>(); if (todo == null) { FoxEventLog.VerboseWriteEventLog("Got no todo data from pipe " + ProgramAgent.PipeGUID, EventLogEntryType.Error); return; } DataHInstallPackageResult result = new DataHInstallPackageResult(); result.Return = inst.InstallPackage(todo.Filename, todo.CerCertificates, todo.Mode, todo.ZipIsMetaOnly, out result.ErrorText, out result.res, out result.Reciept, todo.OtherDLL); if (inst.ScriptTempDLLFilename != null) { FoxEventLog.VerboseWriteEventLog("Script DLL file = " + inst.ScriptTempDLLFilename, EventLogEntryType.Information); } result.TempDLLFilename = inst.ScriptTempDLLFilename; p2p.SetResult(result); break; } case "runuser": { DataHRunasUserTODO todo = p2p.GetTODO <DataHRunasUserTODO>(); DataHRunasUserResult res = new DataHRunasUserResult(); try { Process p = new Process(); p.StartInfo.FileName = todo.Filename; p.StartInfo.Arguments = todo.Args; p.StartInfo.UserName = todo.Username; p.StartInfo.Password = Utilities.MakeSecString(todo.Password); p.StartInfo.UseShellExecute = false; p.Start(); } catch (Win32Exception ee) { FoxEventLog.VerboseWriteEventLog("RUNUSER: Cannot run " + todo.Filename + " as user " + todo.Username + ": " + ee.ToString(), EventLogEntryType.Warning); res.Result = 0x00000000FFFFFFFF & ee.NativeErrorCode; Debug.WriteLine(ee.ToString()); } catch (Exception ee) { FoxEventLog.VerboseWriteEventLog("RUNUSER: Cannot run " + todo.Filename + " as user " + todo.Username + ": " + ee.ToString(), EventLogEntryType.Warning); res.Result = 0x8000ffff; Debug.WriteLine(ee.ToString()); } p2p.SetResult(res); break; } case "conredir": { DataHRunConredir R = p2p.GetTODO <DataHRunConredir>(); MainSTDIORedir.RunPipeConsoleEnd(p2p, R); break; } default: FoxEventLog.VerboseWriteEventLog("Action " + Action + " from pipe " + ProgramAgent.PipeGUID + "?? häh???", EventLogEntryType.Warning); return; } }
static void ReadVersions() { string AppPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (AppPath.EndsWith("\\") == false) { AppPath += "\\"; } AppPath += "Packages\\"; string NormalUpdate = AppPath + "SDCA.foxpkg"; string EarlyUpdate = AppPath + "SDCA-Early.foxpkg"; string Error; if (File.Exists(NormalUpdate) == false) { FoxEventLog.WriteEventLog("No client updates will be provided. The file " + NormalUpdate + " is missing.", System.Diagnostics.EventLogEntryType.Error); CurrentVersion = CurrentEarlyVersion = null; return; } PackageInstaller pkg = new PackageInstaller(); PKGStatus status; PKGRecieptData receipt; Int64?NormalVersion = null; Int64?EarlyVersion = null; try { if (pkg.InstallPackage(NormalUpdate, null, PackageInstaller.InstallMode.TestPackageOnly, false, out Error, out status, out receipt) == false) { FoxEventLog.WriteEventLog("No client updates will be provided. The file " + NormalUpdate + " is invalid / invalid signatures.", System.Diagnostics.EventLogEntryType.Error); CurrentVersion = CurrentEarlyVersion = null; return; } if (pkg.PackageInfo(NormalUpdate, null, out Error) == false) { FoxEventLog.WriteEventLog("No client updates will be provided. The file " + NormalUpdate + " is invalid / invalid info.", System.Diagnostics.EventLogEntryType.Error); CurrentVersion = CurrentEarlyVersion = null; return; } if (pkg.PackageInfoData.PackageID != "Vulpes-SDCA1-Update") { FoxEventLog.WriteEventLog("No client updates will be provided. The file " + NormalUpdate + " is has an invalid identifier.", System.Diagnostics.EventLogEntryType.Error); CurrentVersion = CurrentEarlyVersion = null; return; } } catch { NormalVersion = null; EarlyVersion = null; CurrentVersion = NormalVersion; CurrentEarlyVersion = EarlyVersion; FoxEventLog.WriteEventLog("Update packages contains errors. No updates will be provided.", System.Diagnostics.EventLogEntryType.Error); return; } NormalVersion = pkg.PackageInfoData.VersionID; if (File.Exists(EarlyUpdate) == true) { if (pkg.InstallPackage(EarlyUpdate, null, PackageInstaller.InstallMode.TestPackageOnly, false, out Error, out status, out receipt) == true) { if (pkg.PackageInfo(EarlyUpdate, null, out Error) == true) { if (pkg.PackageInfoData.PackageID == "Vulpes-SDCA1-Update") { EarlyVersion = pkg.PackageInfoData.VersionID; if (EarlyVersion < NormalVersion) { FoxEventLog.WriteEventLog("The version ID of the file " + EarlyUpdate + " is older than the normal version - not deploying.", System.Diagnostics.EventLogEntryType.Warning); EarlyVersion = null; } else { FoxEventLog.WriteEventLog("The file " + EarlyUpdate + " will be deployed along with the normal updates.", System.Diagnostics.EventLogEntryType.Information); } } } } } CurrentVersion = NormalVersion; CurrentEarlyVersion = EarlyVersion; FoxEventLog.WriteEventLog("The Agent update system is working normally.\r\nVersion: " + CurrentVersion.ToString() + "\r\nEarly Version: " + CurrentEarlyVersion.ToString(), System.Diagnostics.EventLogEntryType.Information); }
static int Main(string[] args) { foreach (string arg in args) { if (arg.ToLower() == "-nopackages") { NoPackages = true; } } FoxEventLog.Shutup = true; ProgramAgent.Init(); if (ProgramAgent.LoadDLL() == false) { return(1); } FoxEventLog.Shutup = false; #if !DEBUG List <string> Additionals = new List <string>(); Additionals.Add(Assembly.GetExecutingAssembly().Location); if (ProgramAgent.TestIntegrity(Additionals) == false) { FoxEventLog.WriteEventLog("Apply User settings: Integrity failed!", EventLogEntryType.Error, true); return(1); } #endif FoxEventLog.Shutup = true; if (SystemInfos.CollectSystemInfo() != 0) { return(1); } if (ApplicationCertificate.LoadCertificate() == false) { FoxEventLog.Shutup = false; FoxEventLog.WriteEventLog("Apply User settings: Cannot load certificate", System.Diagnostics.EventLogEntryType.Error); return(1); } FoxEventLog.Shutup = false; if (FilesystemData.LoadCertificates(true) == false) { return(1); } if (FilesystemData.LoadPolicies() == false) { return(1); } FilesystemData.LoadLocalPackageData(); FilesystemData.LoadLocalPackages(); FilesystemData.LoadUserPackageData(); FilesystemData.LoadEventLogList(); SyncPolicy.ApplyPolicy(SyncPolicy.ApplyPolicyFunction.ApplyUser); if (NoPackages == true) { return(0); } string PackagesFolder = SystemInfos.ProgramData + "Packages\\"; if (Directory.Exists(PackagesFolder) == false) { return(2); } foreach (PackagesToInstall pkg in FilesystemData.LocalPackages) { LocalPackageData lpkg = FilesystemData.FindLocalPackageFromListLatest(pkg.PackageID); if (lpkg == null) { continue; } if (pkg.Version != lpkg.Version) { continue; } PackageInstaller inst = new PackageInstaller(); string metafile = PackagesFolder + pkg.MetaFilename; if (File.Exists(metafile) == false) { continue; } string Error; PKGRecieptData Reciept; PKGStatus res; if (inst.InstallPackage(metafile, PackageCertificate.ActivePackageCerts, PackageInstaller.InstallMode.ApplyUserSettingsTest, true, out Error, out res, out Reciept) == false) { FoxEventLog.WriteEventLog("Apply User settings: The Metapackage " + pkg.MetaFilename + " cannot be tested: " + Error, System.Diagnostics.EventLogEntryType.Error); continue; } FoxEventLog.VerboseWriteEventLog("Apply User settings: Applying user settings for " + pkg.MetaFilename, EventLogEntryType.Information); if (inst.ApplyUserSettings(metafile, PackageCertificate.ActivePackageCerts, out Error, out res) == false) { FoxEventLog.WriteEventLog("Apply User settings: The Metapackage " + pkg.MetaFilename + " cannot be used to apply user settings: " + Error, System.Diagnostics.EventLogEntryType.Error); continue; } } if (RegistryData.Verbose == 1) { FoxEventLog.VerboseWriteEventLog("Apply User settings: ApplyUserSettings success for " + Environment.UserDomainName + "\\" + Environment.UserName, EventLogEntryType.Information); } return(0); }