public void DeployConsole() { Trace.WriteLine("Installer::DeployConsole"); SetOutput(_isPassive, _isPassive && _isForced); try { System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent(); System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity); if (!principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) { DeployElevated(); return; } List <GitInstallation> installations = null; // use the custom installation path if supplied if (!String.IsNullOrEmpty(_customPath)) { if (!Directory.Exists(_customPath)) { Console.Out.WriteLine(); Console.Error.WriteLine("Fatal: custom path does not exist: '{0}'. U_U", _customPath); Pause(); Result = ResultValue.InvalidCustomPath; return; } Console.Out.WriteLine(); Console.Out.WriteLine("Deploying to custom path: '{0}'.", _customPath); // if the custom path points to a git location then treat it properly GitInstallation installation; if (Where.FindGitInstallation(_customPath, KnownGitDistribution.GitForWindows64v2, out installation) || Where.FindGitInstallation(_customPath, KnownGitDistribution.GitForWindows32v2, out installation) || Where.FindGitInstallation(_customPath, KnownGitDistribution.GitForWindows32v1, out installation)) { Trace.Write(" Git found: " + installation.Path); // track known Git installtations installations = new List <GitInstallation>(); installations.Add(installation); } } // since no custom installation path was supplied, use default logic else { Console.Out.WriteLine(); Console.Out.WriteLine("Looking for Git installation(s)..."); if (Where.FindGitInstallations(out installations)) { foreach (var installation in installations) { Console.Out.WriteLine(" {0}", installation.Path); } } } if (installations == null) { Console.Out.WriteLine(); Console.Error.WriteLine("Fatal: Git was not detected, unable to continue. U_U"); Pause(); Result = ResultValue.GitNotFound; return; } List <string> cleanedFiles; foreach (var installation in installations) { Console.Out.WriteLine(); Console.Out.WriteLine("Deploying from '{0}' to '{1}'.", Program.Location, installation.Path); if (CopyFiles(Program.Location, installation.Libexec, out cleanedFiles)) { foreach (var file in cleanedFiles) { Console.Out.WriteLine(" {0}", file); } Console.Out.WriteLine(" {0} file(s) copied", cleanedFiles.Count); } else if (_isForced) { Console.Error.WriteLine(" deployment failed. U_U"); } else { Console.Error.WriteLine(" deployment failed. U_U"); Pause(); Result = ResultValue.RemovalFailed; return; } } Console.Out.WriteLine(); Console.Out.WriteLine("Deploying from '{0}' to '{1}'.", Program.Location, UserBinPath); if (!Directory.Exists(UserBinPath)) { Directory.CreateDirectory(UserBinPath); } if (CopyFiles(Program.Location, UserBinPath, out cleanedFiles)) { foreach (var file in cleanedFiles) { Console.Out.WriteLine(" {0}", file); } Console.Out.WriteLine(" {0} file(s) copied", cleanedFiles.Count); } else if (_isForced) { Console.Error.WriteLine(" deployment failed. U_U"); } else { Console.Error.WriteLine(" deployment failed. U_U"); Pause(); Result = ResultValue.RemovalFailed; return; } Configuration.Type types = Configuration.Type.Global; Configuration.Type updateTypes; if (SetGitConfig(installations, GitConfigAction.Set, types, out updateTypes)) { if ((updateTypes & Configuration.Type.Global) == Configuration.Type.Global) { Console.Out.WriteLine("Updated your ~/.gitconfig [git config --global]"); } else { Console.Out.WriteLine(); Console.Error.WriteLine("Fatal: Unable to update your ~/.gitconfig correctly."); Result = ResultValue.GitConfigGlobalFailed; return; } } // all necissary content has been deployed to the system Result = ResultValue.Success; Console.Out.WriteLine(); Console.Out.WriteLine("Success! {0} was deployed! ^_^", Program.Title); Pause(); } finally { SetOutput(true, true); } }
public bool SetGitConfig(List <GitInstallation> installations, GitConfigAction action, Configuration.Type type, out Configuration.Type updated) { Trace.WriteLine("Installer::SetGitConfig"); Trace.WriteLine(" action = " + action + "."); updated = Configuration.Type.None; if (installations == null && !Where.FindGitInstallations(out installations)) { Trace.WriteLine(" No Git installations detected to update."); return(false); } if ((type & Configuration.Type.Global) == Configuration.Type.Global) { // the 0 entry in the installations list is the "preferred" instance of Git string gitCmdPath = installations[0].Git; string globalCmd = action == GitConfigAction.Set ? "config --global credential.helper manager" : "config --global --unset credential.helper"; if (ExecuteGit(gitCmdPath, globalCmd, 0, 5)) { Trace.WriteLine(" updating ~/.gitconfig succeeded."); updated |= Configuration.Type.Global; } else { Trace.WriteLine(" updating ~/.gitconfig failed."); Console.Out.WriteLine(); Console.Error.WriteLine("Fatal: Unable to update ~/.gitconfig."); Pause(); return(false); } } if ((type & Configuration.Type.System) == Configuration.Type.System) { string systemCmd = action == GitConfigAction.Set ? "config --system credential.helper manager" : "config --system --unset credential.helper"; int successCount = 0; foreach (var installation in installations) { if (ExecuteGit(installation.Git, systemCmd, 0, 5)) { Trace.WriteLine(" updating /etc/gitconfig succeeded."); successCount++; } else { Trace.WriteLine(" updating ~/.gitconfig failed."); } } if (successCount == installations.Count) { updated |= Configuration.Type.System; } else { return(false); } } return(true); }
public Файл СформироватьОтчет(ШаблонОтчета Шаблон, Хранилище Хранилище, string user, string domain) { if (Шаблон.Колонки == null) { Шаблон.Колонки = new ШаблонОтчета.Колонка[0]; } else { Шаблон.Колонки = Шаблон.Колонки.Where(p => !string.IsNullOrEmpty(p.Атрибут)).ToArray(); } switch (Шаблон.ФорматОтчета) { //case ФорматОтчета.ПоУмолчанию: case ФорматОтчета.Xaml: case ФорматОтчета.Xps: throw new Exception(string.Format("Формат '{0}' не поддерживается конструктором отчетов", Шаблон.ФорматОтчета.ToString())); } var sb = new StringBuilder(10000); #region Подготовить DataSet var querys = Шаблон.Запросы.Select(p => Query.Deserialize(p)).ToArray(); foreach (var item in querys.Where(p => p != null)) { item.ИгнорироватьСтраницы = true; } var ds = BuildDataSet(Шаблон.НазваниеОтчета, querys, Хранилище, user, domain); #endregion #region generate columns var table = new System.Data.DataTable("Columns"); table.Columns.Add("Атрибут", typeof(string)); table.Columns.Add("Название", typeof(string)); table.Columns.Add("Размер", typeof(int)); foreach (var item in Шаблон.Колонки) { table.Rows.Add(new object[] { item.Атрибут, item.Название, !double.IsNaN(item.азмер) ? item.азмер : 140 }); } ds.Merge(table); #endregion #region Columns Display sb = new StringBuilder(); var source = "//Значение1"; if (Шаблон.Группировки != null) { foreach (var item in Шаблон.Группировки) { var _Группировки = item.Trim().Replace("/", "_x002F_").Replace("@", "_x0040_"); sb.AppendFormat(@"<xsl:for-each-group select=""{0}"" group-by=""{1}"">", source, _Группировки); sb.AppendLine(); sb.AppendLine(@"<xsl:sort select=""current-grouping-key()""/>"); sb.AppendLine(@"<Row>"); sb.AppendFormat("\t<Cell ss:MergeAcross=\"{0}\" ss:StyleID=\"s177\">", Шаблон.Колонки.Length - 1); sb.AppendLine(); sb.AppendLine("\t\t<Data ss:Type=\"String\"><xsl:value-of select=\"current-grouping-key()\"/></Data>"); sb.AppendLine("\t</Cell>"); sb.AppendLine(@"</Row>"); source = "current-group()"; } } #region <Header> sb.Append(@" <Row ss:Height=""13.5""> <xsl:for-each select=""//Columns""> <Cell ss:StyleID=""s97""> <Data ss:Type=""String""> <xsl:value-of select=""Название"" /> </Data> </Cell> </xsl:for-each> </Row> "); #endregion #region <Row> var isDataSet = ds != null && ds.Tables.Contains("Значение1"); sb.AppendFormat(@"<xsl:for-each select=""{0}"">", source); sb.AppendLine(@"<Row>"); foreach (var item in Шаблон.Колонки) { var style = "s93"; var type = null as Configuration.Type; if (!string.IsNullOrEmpty(item.Формат)) { switch (item.Формат) { case "Int": type = new Configuration.Type() { MemberType = MemberTypes.Int }; break; case "Double": type = new Configuration.Type() { MemberType = MemberTypes.Double }; break; case "String": type = new Configuration.Type() { MemberType = MemberTypes.String }; break; } } if (type == null && isDataSet && ds.Tables["Значение1"].Columns.Contains(item.Атрибут)) { //определить тип из DataSet var typeofColumn = ds.Tables["Значение1"].Columns[item.Атрибут].DataType; if (typeofColumn == typeof(double) || typeofColumn == typeof(decimal)) { type = new Configuration.Type() { MemberType = MemberTypes.Double } } ; else if (typeofColumn == typeof(int) || typeofColumn == typeof(long)) { type = new Configuration.Type() { MemberType = MemberTypes.Int } } ; else if (typeofColumn == typeof(DateTime)) { type = new Configuration.Type() { MemberType = MemberTypes.DateTime } } ; else if (typeofColumn == typeof(bool)) { type = new Configuration.Type() { MemberType = MemberTypes.Bool } } ; else { type = new Configuration.Type() { MemberType = MemberTypes.String } }; } else { type = new ConfigurationClient().ПолучитьТип(item.Атрибут, domain); } #region set style if (type != null) { switch (type.MemberType) { case MemberTypes.Double: style = "s93Numeric"; break; case MemberTypes.Ссылка: case MemberTypes.Int: style = "s93Int"; break; } } #endregion sb.AppendFormat("<Cell ss:StyleID=\"{0}\">", style); sb.AppendLine(); if (!string.IsNullOrEmpty(item.Атрибут)) { var attr = item.Атрибут.Replace("/", "_x002F_").Replace("@", "_x0040_"); if (type != null) { switch (type.MemberType) { case MemberTypes.Double: case MemberTypes.Ссылка: case MemberTypes.Int: sb.Append(@"<Data ss:Type=""Number"">"); sb.AppendFormat(@"<xsl:value-of select=""{0}"" />", attr); //sb.AppendFormat(@"<xsl:value-of select=""format-number({0},'# ##0,00')"" />", item.Атрибут); break; case MemberTypes.DateTime: sb.Append(@"<Data ss:Type=""String"">"); switch ((item.Формат ?? "").ToUpper()) { case "G": sb.AppendFormat(@"<xsl:value-of select=""format-dateTime({0},'[D,2].[M,2].[Y,*-4] [H01]:[m01]')"" />", attr); break; case "HH:MM": sb.AppendFormat(@"<xsl:value-of select=""format-dateTime({0},'[H01]:[m01]')"" />", attr); break; default: sb.AppendFormat(@"<xsl:value-of select=""format-dateTime({0},'[D,2].[M,2].[Y,*-4]')"" />", attr); break; } break; //case MemberTypes.Bool: // sb.Append(@"<Data ss:Type=""String"">"); // sb.AppendFormat(@"<xsl:if test=""{0} = 'true'"">ДА</<xsl:if>", attr); // break; default: sb.Append(@"<Data ss:Type=""String"">"); sb.AppendFormat(@"<xsl:value-of select=""{0}"" />", attr); break; } } else { sb.AppendFormat(@"<Data ss:Type=""{0}"">", item.ТипЗначения.ToString()); sb.AppendFormat(@"<xsl:value-of select=""{0}"" />", attr); } sb.AppendLine(@"</Data>"); } sb.AppendLine(@"</Cell>"); } sb.AppendLine(@"</Row>"); sb.AppendLine(@"</xsl:for-each>"); sb.AppendLine(@"<Row />"); sb.AppendLine(@"<Row />"); #endregion if (Шаблон.Группировки != null) { foreach (var item in Шаблон.Группировки) { sb.AppendLine(@"</xsl:for-each-group>"); } } #endregion #region ИсходныйКод var ИсходныйКод = Regex.Replace(RosService.Properties.Resources.ReportExcel, "<r:Data />", sb.ToString()); #endregion return(ВыводОтчета( Шаблон.НазваниеОтчета, ИсходныйКод.ToString(), "Excel", Шаблон.ФорматОтчета, Шаблон.ОриентацияСтраницы, ds, Хранилище, user, domain)); }
public void RemoveConsole() { Trace.WriteLine("Installer::RemoveConsole"); SetOutput(_isPassive, _isPassive && _isForced); try { System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent(); System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity); if (!principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) { RemoveElevated(); return; } List <GitInstallation> installations = null; // use the custom installation path if supplied if (!String.IsNullOrEmpty(_customPath)) { if (!Directory.Exists(_customPath)) { Console.Out.WriteLine(); Console.Error.WriteLine($"Fatal: custom path does not exist: '{_customPath}'. U_U"); Pause(); Result = ResultValue.InvalidCustomPath; return; } Console.Out.WriteLine(); Console.Out.WriteLine($"Removing from custom path: '{_customPath}'."); // if the custom path points to a git location then treat it properly GitInstallation installation; if (Where.FindGitInstallation(_customPath, KnownGitDistribution.GitForWindows64v2, out installation) || Where.FindGitInstallation(_customPath, KnownGitDistribution.GitForWindows32v2, out installation) || Where.FindGitInstallation(_customPath, KnownGitDistribution.GitForWindows32v1, out installation)) { Trace.Write($" Git found: {installation.Path}"); // track known Git installations installations = new List <GitInstallation>(); installations.Add(installation); } } // since no custom installation path was supplied, use default logic else { Console.Out.WriteLine(); Console.Out.WriteLine("Looking for Git installation(s)..."); if (Where.FindGitInstallations(out installations)) { foreach (var installation in installations) { Console.Out.WriteLine($" {installation.Path}"); } } } if (installations == null) { Program.LogEvent($"Git was not detected, unable to continue with removal.", EventLogEntryType.Error); Console.Out.WriteLine(); Console.Error.WriteLine("Fatal: Git was not detected, unable to continue. U_U"); Pause(); Result = ResultValue.GitNotFound; return; } Configuration.Type types = Configuration.Type.Global | Configuration.Type.System; Configuration.Type updateTypes; if (SetGitConfig(installations, GitConfigAction.Unset, types, out updateTypes)) { if ((updateTypes & Configuration.Type.System) == Configuration.Type.System) { Console.Out.WriteLine(); Console.Out.WriteLine("Updated your /etc/gitconfig [git config --system]"); } else { Console.Out.WriteLine(); // updating /etc/gitconfig should not fail installation when forced if (!_isForced) { // only 'fatal' when not forced Console.Error.Write("Fatal: "); Result = ResultValue.GitConfigSystemFailed; return; } Console.Error.WriteLine("Unable to update your /etc/gitconfig correctly."); } if ((updateTypes & Configuration.Type.Global) == Configuration.Type.Global) { Console.Out.WriteLine("Updated your ~/.gitconfig [git config --global]"); } else { Console.Out.WriteLine(); Console.Error.WriteLine("Fatal: Unable to update your ~/.gitconfig correctly."); Result = ResultValue.GitConfigGlobalFailed; return; } } List <string> cleanedFiles; foreach (var installation in installations) { Console.Out.WriteLine(); Console.Out.WriteLine($"Removing from '{installation.Path}'."); if (CleanFiles(installation.Libexec, out cleanedFiles)) { foreach (var file in cleanedFiles) { Console.Out.WriteLine($" {file}"); } Console.Out.WriteLine($" {cleanedFiles.Count} file(s) cleaned"); } else if (_isForced) { Console.Error.WriteLine(" removal failed. U_U"); } else { Console.Error.WriteLine(" removal failed. U_U"); Pause(); Result = ResultValue.RemovalFailed; return; } } if (Directory.Exists(UserBinPath)) { Console.Out.WriteLine(); Console.Out.WriteLine($"Removing from '{UserBinPath}'."); if (CleanFiles(UserBinPath, out cleanedFiles)) { foreach (var file in cleanedFiles) { Console.Out.WriteLine($" {file}"); } Console.Out.WriteLine($" {cleanedFiles.Count} file(s) cleaned"); } else if (_isForced) { Console.Error.WriteLine(" removal failed. U_U"); } else { Console.Error.WriteLine(" removal failed. U_U"); Pause(); Result = ResultValue.RemovalFailed; return; } } if (CygwinPath != null && Directory.Exists(CygwinPath)) { if (CleanFiles(CygwinPath, out cleanedFiles)) { foreach (var file in cleanedFiles) { Console.Out.WriteLine($" {file}"); } Console.Out.WriteLine($" {cleanedFiles.Count} file(s) cleaned"); } } // all necissary content has been deployed to the system Result = ResultValue.Success; Program.LogEvent($"{Program.Title} successfully removed.", EventLogEntryType.Information); Console.Out.WriteLine(); Console.Out.WriteLine($"Success! {Program.Title} was removed! ^_^"); Pause(); } finally { SetOutput(true, true); } }
public void DeployConsole() { SetOutput(_isPassive, _isPassive && _isForced); try { System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent(); System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity); if (!principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) { DeployElevated(); return; } List <GitInstallation> installations = null; // use the custom installation path if supplied if (!String.IsNullOrEmpty(_customPath)) { if (!Directory.Exists(_customPath)) { Program.LogEvent("No Git installation found, unable to continue deployment.", EventLogEntryType.Error); Console.Out.WriteLine(); Program.WriteLine($"Fatal: custom path does not exist: '{_customPath}'. {FailFace}"); Pause(); Result = ResultValue.InvalidCustomPath; return; } Console.Out.WriteLine(); Console.Out.WriteLine($"Deploying to custom path: '{_customPath}'."); // if the custom path points to a git location then treat it properly GitInstallation installation; if (Where.FindGitInstallation(_customPath, KnownGitDistribution.GitForWindows64v2, out installation) || Where.FindGitInstallation(_customPath, KnownGitDistribution.GitForWindows32v2, out installation) || Where.FindGitInstallation(_customPath, KnownGitDistribution.GitForWindows32v1, out installation)) { Git.Trace.WriteLine($" Git found: '{installation.Path}'."); // track known Git installations installations = new List <GitInstallation>(); installations.Add(installation); } Program.LogEvent($"Custom path deployed to: '{_customPath}'", EventLogEntryType.Information); } // since no custom installation path was supplied, use default logic else { Console.Out.WriteLine(); Console.Out.WriteLine("Looking for Git installation(s)..."); if (Where.FindGitInstallations(out installations)) { foreach (var installation in installations) { Console.Out.WriteLine($" {installation.Path}"); } } } if (installations == null) { Program.LogEvent("No Git installation found, unable to continue.", EventLogEntryType.Error); Console.Out.WriteLine(); Program.WriteLine("Fatal: Git was not detected, unable to continue. {FailFace}"); Pause(); Result = ResultValue.GitNotFound; return; } List <string> copiedFiles; foreach (var installation in installations) { Console.Out.WriteLine(); Console.Out.WriteLine($"Deploying from '{Program.Location}' to '{installation.Path}'."); if (CopyFiles(Program.Location, installation.Libexec, FileList, out copiedFiles)) { int copiedCount = copiedFiles.Count; foreach (var file in copiedFiles) { Console.Out.WriteLine($" {file}"); } // copy help documents if (Directory.Exists(installation.Doc) && CopyFiles(Program.Location, installation.Doc, DocsList, out copiedFiles)) { copiedCount += copiedFiles.Count; foreach (var file in copiedFiles) { Console.Out.WriteLine($" {file}"); } } Program.LogEvent($"Deployment to '{installation.Path}' succeeded.", EventLogEntryType.Information); Console.Out.WriteLine($" {copiedCount} file(s) copied"); } else if (_isForced) { Program.LogEvent($"Deployment to '{installation.Path}' failed.", EventLogEntryType.Warning); Program.WriteLine($" deployment failed. {FailFace}"); } else { Program.LogEvent($"Deployment to '{installation.Path}' failed.", EventLogEntryType.Error); Program.WriteLine($" deployment failed. {FailFace}"); Pause(); Result = ResultValue.DeploymentFailed; return; } } Console.Out.WriteLine(); Console.Out.WriteLine($"Deploying from '{Program.Location}' to '{UserBinPath}'."); if (!Directory.Exists(UserBinPath)) { Directory.CreateDirectory(UserBinPath); } if (CopyFiles(Program.Location, UserBinPath, FileList, out copiedFiles)) { int copiedCount = copiedFiles.Count; foreach (var file in copiedFiles) { Console.Out.WriteLine($" {file}"); } if (CopyFiles(Program.Location, UserBinPath, DocsList, out copiedFiles)) { copiedCount = copiedFiles.Count; foreach (var file in copiedFiles) { Console.Out.WriteLine($" {file}"); } } Program.LogEvent($"Deployment to '{UserBinPath}' succeeded.", EventLogEntryType.Information); Console.Out.WriteLine($" {copiedCount} file(s) copied"); } else if (_isForced) { Program.LogEvent($"Deployment to '{UserBinPath}' failed.", EventLogEntryType.Warning); Program.WriteLine($" deployment failed. {FailFace}"); } else { Program.LogEvent($"Deployment to '{UserBinPath}' failed.", EventLogEntryType.Error); Program.WriteLine($" deployment failed. {FailFace}"); Pause(); Result = ResultValue.DeploymentFailed; return; } if (CygwinPath != null && Directory.Exists(CygwinPath)) { if (CopyFiles(Program.Location, CygwinPath, FileList, out copiedFiles)) { int copiedCount = copiedFiles.Count; foreach (var file in copiedFiles) { Console.Out.WriteLine($" {file}"); } if (CopyFiles(Program.Location, CygwinPath, DocsList, out copiedFiles)) { copiedCount = copiedFiles.Count; foreach (var file in copiedFiles) { Console.Out.WriteLine($" {file}"); } } Program.LogEvent($"Deployment to '{CygwinPath}' succeeded.", EventLogEntryType.Information); Console.Out.WriteLine($" {copiedCount} file(s) copied"); } else if (_isForced) { Program.LogEvent($"Deployment to '{CygwinPath}' failed.", EventLogEntryType.Warning); Program.WriteLine($" deployment failed. {FailFace}"); } else { Program.LogEvent($"Deployment to '{CygwinPath}' failed.", EventLogEntryType.Error); Program.WriteLine($" deployment failed. {FailFace}"); Pause(); Result = ResultValue.DeploymentFailed; return; } } Configuration.Type types = Configuration.Type.Global; Configuration.Type updateTypes; if (SetGitConfig(installations, GitConfigAction.Set, types, out updateTypes)) { if ((updateTypes & Configuration.Type.Global) == Configuration.Type.Global) { Console.Out.WriteLine("Updated your ~/.gitconfig [git config --global]"); } else { Console.Out.WriteLine(); Program.WriteLine("Fatal: Unable to update your ~/.gitconfig correctly."); Result = ResultValue.GitConfigGlobalFailed; return; } } // all necessary content has been deployed to the system Result = ResultValue.Success; Program.LogEvent($"{Program.Title} v{Program.Version.ToString(3)} successfully deployed.", EventLogEntryType.Information); Console.Out.WriteLine(); Console.Out.WriteLine($"Success! {Program.Title} was deployed! {TadaFace}"); Pause(); } finally { SetOutput(true, true); } }