private LogonColumn GetSAPLogonData(string strColumnName, PwEntry pe)
        {
            if (strColumnName == null)
            {
                Debug.Assert(false);
                return(null);
            }

            if (pe == null)
            {
                Debug.Assert(false);
                return(null);
            }

            if (strColumnName == m_vColNames[0])
            {
                //detect SAP ID and SAP client
                string strSAPID          = pe.Strings.ReadSafe(KeeSAPLogon.Properties.Resources.FieldKeySAPID);
                string strSAPClient      = pe.Strings.ReadSafe(KeeSAPLogon.Properties.Resources.FieldKeySAPClient);
                string strSAPLanguage    = pe.Strings.ReadSafe(KeeSAPLogon.Properties.Resources.FieldKeyLanguage);
                string strSAPTransaction = pe.Strings.ReadSafe(KeeSAPLogon.Properties.Resources.FieldKeyTransaction);

                LogonColumn lc = new LogonColumn(strSAPID, strSAPClient, strSAPLanguage, strSAPTransaction);
                return(lc);
            }

            return(null);
        }
Example #2
0
        //---------------------------------------------------------------------------------------------------
        // Interface Implementation: IComparable
        //---------------------------------------------------------------------------------------------------
        #region IComparable implementation

        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }

            LogonColumn otherLC = obj as LogonColumn;

            if (otherLC != null)
            {
                if (this.SAPID.CompareTo(otherLC.SAPID) < 0)
                {
                    return(-1);
                }
                if (this.SAPID.CompareTo(otherLC.SAPID) > 0)
                {
                    return(1);
                }

                if (this.SAPID.CompareTo(otherLC.SAPID) == 0)
                {
                    if (this.SAPClient.CompareTo(otherLC.SAPClient) < 0)
                    {
                        return(-1);
                    }
                    if (this.SAPClient.CompareTo(otherLC.SAPClient) > 0)
                    {
                        return(1);
                    }

                    if (this.SAPClient.CompareTo(otherLC.SAPClient) == 0)
                    {
                        if (this.SAPLanguage.CompareTo(otherLC.SAPLanguage) < 0)
                        {
                            return(-1);
                        }
                        if (this.SAPLanguage.CompareTo(otherLC.SAPLanguage) > 0)
                        {
                            return(1);
                        }

                        if (this.SAPLanguage.CompareTo(otherLC.SAPLanguage) == 0)
                        {
                            return(this.SAPTransaction.CompareTo(otherLC.SAPTransaction));
                        }
                    }
                }
            }
            else
            {
                throw new ArgumentException("Object is not an object of type " + this.ToString());
            }

            return(1);
        }
        public override void PerformCellAction(string strColumnName, PwEntry pe)
        {
            LogonColumn lc = GetSAPLogonData(strColumnName, pe);

            if (lc.IsValid())
            {
                lc.ExtendWithDefaults(m_config.DefaultLng, m_config.DefaultTx);

                ProtectedString pUser = DerefValue(PwDefs.UserNameField, pe);
                ProtectedString pPw   = DerefValue(PwDefs.PasswordField, pe);

                SAPLogonHandler.SAPGUIPath = m_config.SAPGUIPath;
                SAPLogonHandler.DoLogon(lc, pUser, pPw);
            }
        }
        public override string GetCellData(string strColumnName, PwEntry pe)
        {
            if (strColumnName == null)
            {
                Debug.Assert(false);
                return(String.Empty);
            }

            if (strColumnName != m_vColNames[0])
            {
                return(String.Empty);
            }

            if (pe == null)
            {
                Debug.Assert(false);
                return(String.Empty);
            }


            if (!SAPLogonHandler.ValidateSAPGUIPath(m_config.SAPGUIPath))
            {
                return(Translatable.ColumnConfigFailure);
            }


            //detect SAP ID and SAP client
            string      strCellData = "";
            LogonColumn lc          = GetSAPLogonData(strColumnName, pe);

            if (lc.IsValid())
            {
                strCellData = FormattedCellData(lc);
            }
            else
            {
                if (lc.HasSAPID() || lc.HasSAPClient() || lc.HasSAPLanguage() || lc.HasSAPTransaction())
                {
                    strCellData = Translatable.ColumnInvalidData;
                }
                else
                {
                    strCellData = Translatable.ColumnNoneSAPData;
                }
            }

            return(strCellData);
        }
Example #5
0
        public static bool DoLogon(LogonColumn logonPoint, ProtectedString user, ProtectedString password)
        {
            if (ValidateSAPGUIPath(m_sapguiPath) && logonPoint.IsValid())
            {
                //Example:
                //
                // "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapshcut" -system=ABC -client=010 -user=username -pw=pass -language=EN -maxgui -command=SE10
                //

                string strArgs = "-maxgui";

                Dictionary <string, string> args = new Dictionary <string, string>();
                args.Add("-system", logonPoint.SAPID);
                args.Add("-client", logonPoint.SAPClient);
                args.Add("-user", user.ReadString());
                args.Add("-pw", password.ReadString());
                args.Add("-language", logonPoint.SAPLanguage);
                args.Add("-command", logonPoint.SAPTransaction);

                foreach (string key in args.Keys)
                {
                    string value;
                    args.TryGetValue(key, out value);
                    strArgs = strArgs + " ";
                    strArgs = strArgs + key + "=" + value;
                }

                string           fileLoc  = Path.Combine(m_sapguiPath, SAPLogonHandler.SAPGUIShortCutEXE);
                FileInfo         fileInfo = new FileInfo(fileLoc);
                ProcessStartInfo info     = new ProcessStartInfo(fileInfo.FullName);
                info.Arguments              = strArgs;
                info.CreateNoWindow         = false;
                info.UseShellExecute        = true;
                info.ErrorDialog            = true;
                info.RedirectStandardInput  = false;
                info.RedirectStandardOutput = false;

                Process process = Process.Start(info);

                return(!(process.HasExited));
            }

            return(false);
        }
        //---------------------------------------------------------------------------------------------------
        // Private Methods
        //---------------------------------------------------------------------------------------------------
        private string FormattedCellData(LogonColumn entry)
        {
            string result = "";

            if (entry.HasSAPID() && m_config.DisSystemID)
            {
                result = result + entry.SAPID;
                if (entry.HasSAPClient() && m_config.DisClient)
                {
                    result = result + ":";
                }
            }

            if (entry.HasSAPClient() && m_config.DisClient)
            {
                result = result + entry.SAPClient;
            }

            if (entry.HasSAPLanguage() && m_config.DisLanguage)
            {
                result = result + " [" + entry.SAPLanguage + "]";
            }

            if (entry.HasSAPTransaction() && m_config.DisTx)
            {
                if ((entry.HasSAPID() && m_config.DisSystemID) ||
                    (entry.HasSAPClient() && m_config.DisClient) ||
                    (entry.HasSAPLanguage() && m_config.DisLanguage))
                {
                    result = result + " - ";
                }

                result = result + entry.SAPTransaction;
            }

            return(result);
        }