Ejemplo n.º 1
0
 public LoginAdapter(IProgressConnection connection)
 {
     _nLogLogger  = new NLogLogger("LoginAdapter");
     _nLogLoggerP = new NLogLogger("Performance", "LoginAdapter");
     try
     {
         this._asProxyAppObject = new SharedProxyAppObject(connection.Connection);
         this._pdsContext       = new pdsContextDataSet();
         this._poLoginproxy     = this._asProxyAppObject.CreatePO_loginproxy();
     }
     catch (Exception ex)
     {
         _nLogLogger.ErrorException("Failed in login adapter ", ex);
         // PMC 02/09/2018 - IBM AppScan - This has been manually reviewed and passed as being safe - Does not reveal error, logs securely
         ErrorReportingHelper.ReportProgramErrors($"Error in login constructor - {ex.Message}");
     }
 }
Ejemplo n.º 2
0
        protected virtual void Dispose(bool disposing)
        {
            if (this._disposed)
            {
                return;
            }
            if (!disposing)
            {
                return;
            }
            this._poLoginproxy?.Dispose();
            this._poLoginproxy = null;
            this._asProxyAppObject?.Dispose();
            this._asProxyAppObject = null;

            this._pdsContext?.Dispose();
            this._pdsContext = null;
            this._disposed   = true;
        }
Ejemplo n.º 3
0
        private static int Main(string[] args)
        {
            var errorLogPath = AppDomain.CurrentDomain.BaseDirectory + "\\ErrorLog.Txt";

            File.Delete(errorLogPath);
            var errorLines = new List <string> {
                "Build Version Error Log", "--------------------", string.Empty, "From Jenkins:"
            };
            // ----------------------------------
            // Pick up options from arguments
            // ----------------------------------
            var returnCode = 0;

            Parser.Default.ParseArguments <Options>(args)
            .WithParsed(opts =>
            {
                if (string.IsNullOrEmpty(opts.Password))
                {
                    opts.Password = opts.User;
                }
                var absolutePath = Environment.GetEnvironmentVariable(AbsolutePath);
                if (absolutePath == null)
                {
                    returnCode = -1;
                    return;
                }

                if (!opts.NoAppServerCall)
                {
                    if (string.IsNullOrEmpty(opts.AppServerUrl))
                    {
                        // ----------------------------
                        // Read the web.config and attempt to get the URL from there
                        // ----------------------------
                        var webConfigFullName = Path.Combine(absolutePath, opts.HomeForReport, WebConfigFile);
                        if (!File.Exists(webConfigFullName))
                        {
                            errorLines.Add("web.config not found");
                            File.WriteAllLines(errorLogPath, errorLines);
                            returnCode = -2;
                            return;
                        }
                        var webConfig      = XDocument.Load(webConfigFullName);
                        var firstOrDefault =
                            webConfig.Root?.Descendants("add")
                            .FirstOrDefault(x => x.Attribute("key")?.Value == "PROGRESS.Session.Url");
                        if (firstOrDefault != null)
                        {
                            opts.AppServerUrl = firstOrDefault.Attribute("value")?.Value;
                        }
                    }
                    if (string.IsNullOrEmpty(opts.AppServerUrl))
                    {
                        errorLines.Add("Never got an appserver url");
                        File.WriteAllLines(errorLogPath, errorLines);
                        returnCode = -2;
                        return;
                    }
                }

                // ----------------------------------
                // Jenkins Build Information
                // ----------------------------------
                var reportPathAndName = Path.Combine(absolutePath, opts.HomeForReport, ReportName);

                File.Delete(reportPathAndName);
                var lines = new List <string> {
                    $"Build Version Report {Assembly.GetEntryAssembly().GetName().Version}", "------------------------------", string.Empty, DateTime.Now.ToLongDateString(), string.Empty, opts.Identity, string.Empty, string.Empty, "From Jenkins:"
                };
                lines.AddRange(
                    from environmentVar in ListOfVariableToPull
                    let environmentValue = Environment.GetEnvironmentVariable(environmentVar)
                                           select $"  {environmentVar,-15}: {environmentValue ?? "Not set!"}");
                lines.Add(string.Empty);


                if (!opts.NoAppServerCall)
                {
                    // ----------------------------------
                    // DLL Processing
                    // ----------------------------------
                    lines.Add("From DLLs:");
                    var dlls           = Directory.GetFiles(Path.Combine(absolutePath, opts.DllLocation), "*ProxyAppObject.DLL");
                    var versionList    = new Dictionary <string, string>();
                    var defaultVersion = string.Empty;
                    var maxLength      = 0;
                    foreach (var dll in dlls)
                    {
                        var assembly = Assembly.LoadFrom(dll);
                        var version  = assembly.GetName().Version.ToString();
                        if (string.IsNullOrEmpty(defaultVersion))
                        {
                            defaultVersion = version;
                        }
                        var name = assembly.GetName().Name;
                        if (name.Length > maxLength)
                        {
                            maxLength = name.Length;
                        }
                        versionList.Add(name, version);
                    }
                    if (!string.IsNullOrEmpty(defaultVersion))
                    {
                        var countOfDefaultVersion = versionList.Count(d => d.Value.Equals(defaultVersion));
                        if (countOfDefaultVersion != versionList.Count)
                        {
                            lines.Add("  Warning not all DLL's contain the same version");
                            lines.AddRange(
                                versionList.Select(version => $"  {version.Key,-20}: {version.Value}"));
                        }
                        else
                        {
                            lines.Add($"  All DLLS are at version {defaultVersion}");
                        }
                    }
                    else
                    {
                        lines.Add("  Error getting SI version from DLL's");
                    }

                    // ----------------------------------------
                    // Progress SI Call to get more information
                    // ----------------------------------------
                    try
                    {
                        lines.Add(string.Empty);
                        lines.Add("From Sxe:");
                        var connection = new Connection(opts.AppServerUrl, "", "", "")
                        {
                            SessionModel = opts.SessionModel == "SL" ? 0 : 1
                        };
                        var sharedProxyAppObject = new SharedProxyAppObject(connection);
                        var pdsContextDataSet    = new pdsContextDataSet();
                        var loginproxy           = sharedProxyAppObject.CreatePO_loginproxy();

                        var pdsUserLoginDataSet = new pdsUserLoginDataSet();
                        pdsUserLoginDataSet.ttblUserLogin.AddttblUserLoginRow(
                            opts.User,
                            opts.Password,
                            opts.Cono,
                            string.Empty,
                            false,
                            !opts.Multitenant);
                        loginproxy.Login(ref pdsContextDataSet, ref pdsUserLoginDataSet, out var cErrorMessage);
                        var doRest = true;
                        if (pdsContextDataSet.HasErrors)
                        {
                            lines.Add(cErrorMessage);
                            doRest = false;
                        }
                        if (!string.IsNullOrEmpty(cErrorMessage) && !cErrorMessage.ToLower(CultureInfo.InvariantCulture).Contains(OperInUse.ToLower(CultureInfo.InvariantCulture)))
                        {
                            lines.Add(cErrorMessage);
                            doRest = false;
                        }
                        if (string.IsNullOrEmpty(cErrorMessage))
                        {
                            cErrorMessage = string.Empty;
                        }
                        if (doRest && cErrorMessage.ToLower(CultureInfo.InvariantCulture).Contains(OperInUse.ToLower(CultureInfo.InvariantCulture)))
                        {
                            loginproxy.ClearCoreSession(ref pdsContextDataSet, opts.Cono, opts.User, out cErrorMessage);
                            if (string.IsNullOrEmpty(cErrorMessage))
                            {
                                pdsUserLoginDataSet.ttblUserLogin.AddttblUserLoginRow(
                                    opts.User,
                                    opts.Password,
                                    opts.Cono,
                                    string.Empty,
                                    false,
                                    !opts.Multitenant);
                                loginproxy.Login(ref pdsContextDataSet, ref pdsUserLoginDataSet, out cErrorMessage);
                                if (!string.IsNullOrEmpty(cErrorMessage))
                                {
                                    lines.Add(cErrorMessage);
                                    doRest = false;
                                }
                            }
                            else
                            {
                                lines.Add(cErrorMessage);
                                doRest = false;
                            }
                        }
                        if (doRest)
                        {
                            string cDisplayVersion;
                            string cInternalVersion;
                            string cEsbVersion;
                            string cSiVersion;
                            using (var poAssharedinquiryproxy = sharedProxyAppObject.CreatePO_assharedinquiryproxy()
                                   )
                            {
                                poAssharedinquiryproxy.GetSXVersionNumbers(
                                    ref pdsContextDataSet,
                                    out cErrorMessage,
                                    out cDisplayVersion,
                                    out cInternalVersion,
                                    out cEsbVersion,
                                    out cSiVersion);
                            }
                            if (!string.IsNullOrEmpty(cErrorMessage))
                            {
                                lines.Add(cErrorMessage);
                            }
                            else
                            {
                                lines.Add(string.Format($"  {"DisplayVersion",-20}: {cDisplayVersion}"));
                                lines.Add(string.Format($"  {"InternalVersion",-20}: {cInternalVersion}"));
                                lines.Add(string.Format($"  {"ESBVersion",-20}: {cEsbVersion}"));
                                lines.Add(string.Format($"  {"SIVersion",-20}: {cSiVersion}"));
                            }
                            loginproxy.Logout(ref pdsContextDataSet, out cErrorMessage);
                        }
                    }
                    catch (Exception e)
                    {
                        errorLines.Add(e.Message);
                        File.WriteAllLines(errorLogPath, errorLines);
                        returnCode = -3;
                        return;
                    }
                }

                // ----------------------------------
                // Write Final Build Information
                // ----------------------------------

                File.WriteAllLines(reportPathAndName, lines);
                returnCode = 0;
            })
            .WithNotParsed <Options>(errs =>
            {
            });

            return(returnCode);
        }