internal static string getRemoteSdk(this CloverDeviceConfiguration config, CloverTransport transport)
        {
            string REG_KEY  = "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\CloverSDK";
            string receiver = "DLL";

            try
            {
                object rReceiver = Registry.GetValue(REG_KEY, "DisplayName", "unset");
                if (rReceiver != null && !rReceiver.ToString().Equals("unset"))
                {
                    receiver = rReceiver.ToString();
                }
            }
            catch (Exception e)
            {
                using (EventLog eventLog = new EventLog("Application"))
                {
                    eventLog.Source = "Application";
                    eventLog.WriteEntry($"{config.getMessagePackageName().GetType()}->{e.Message}");
                }
            }

            string shortTitle         = transport.ShortTitle();
            string shortTransportType = String.IsNullOrWhiteSpace(shortTitle) ? "UNKNOWN" : shortTitle;

            // Build SdkInfo string
            System.Reflection.Assembly assembly = System.Reflection.Assembly.Load("CloverConnector");
            string sdkInfoString = AssemblyUtils.GetAssemblyAttribute <System.Reflection.AssemblyDescriptionAttribute>(assembly).Description
                                   + "_" + receiver
                                   + "|" + shortTransportType
                                   + ":"
                                   + (assembly.GetAssemblyAttribute <System.Reflection.AssemblyFileVersionAttribute>()).Version
                                   + (assembly.GetAssemblyAttribute <System.Reflection.AssemblyInformationalVersionAttribute>()).InformationalVersion;

            using (EventLog eventLog = new EventLog("Application"))
            {
                eventLog.Source = "Application";
                eventLog.WriteEntry($"{config.getMessagePackageName().GetType()}->SDKInfo from assembly and registry = {sdkInfoString}");
            }

            return(sdkInfoString);
        }
示例#2
0
        /// <summary>
        /// Initialize the Clover Device for use
        /// </summary>
        /// <param name="configuration"></param>
        public virtual void Initialize(CloverDeviceConfiguration configuration)
        {
            string logSource = "_TransportEventLog";

            if (!EventLog.SourceExists(logSource))
            {
                EventLog.CreateEventSource(logSource, logSource);
            }

            // Add the event log trace listener to the collection.
            EventLogTraceListener myTraceListener = new EventLogTraceListener(logSource);

            Trace.Listeners.Add(myTraceListener);

            transport = configuration.getCloverTransport();

            shortTransportType = !string.IsNullOrWhiteSpace(transport.ShortTitle()) ? transport.ShortTitle() : shortTransportType;
            packageName        = configuration.getMessagePackageName();
            remoteSourceSDK    = getSDKInfoString();
            deviceInfo         = new DeviceInfo();
        }
        /// <summary>
        /// Initialize the Clover Device for use
        /// </summary>
        /// <param name="configuration"></param>
        public virtual void Initialize(CloverDeviceConfiguration configuration)
        {
            string logSource = "_TransportEventLog";

            try
            {
                // If this EventLog code crashes, you don't have the Windows Event Log Source setup, and this code isn't running with sufficient credentials to create it.
                // See https://github.com/clover/remote-pay-windows/wiki/ "Setting up the Windows Event Log" article for details.
                //
                // Quickfixs: run this app _once_ as admin so this code can perform setup, or just run this in an admin PowerShell> New-EventLog -LogName "Application" -Source "_TransportEventLog"
                //            Other fixes available in the project's wiki article.
                //
                // When this app is deployed into production, the installer or deploy script should ensure the EventLog is created.

                if (!EventLog.SourceExists(logSource))
                {
                    EventLog.CreateEventSource(logSource, logSource);
                }

                // Add the event log trace listener to the collection.
                EventLogTraceListener eventlog = new EventLogTraceListener(logSource);
                Trace.Listeners.Add(eventlog);
            }
            catch (Exception exception)
            {
                // If this has crashed, see the comment just above at the top of the EventLog try for details and quick fixes.
                throw new CloverException($"Aborting Clover Connector SDK because the Windows Event Log Source \"{logSource}\" does not exist or cannot be accessed.\nSee the https://github.com/clover/remote-pay-windows/wiki article for more information.\n\nref# CLOVER-W230\nDetail Message: {exception.Message}", "CLOVER-W230", exception);
            }

            Log(MessageLevel.Detailed, $"CloverDevice.{nameof(Initialize)} {configuration.getName()}, raid: {configuration.getRemoteApplicationID()}");

            transport = configuration.getCloverTransport();
            transport?.SetLogLevel(logLevel);

            shortTransportType = !string.IsNullOrWhiteSpace(transport.ShortTitle()) ? transport.ShortTitle() : shortTransportType;
            packageName        = configuration.getMessagePackageName();
            remoteSourceSDK    = getSDKInfoString();
            deviceInfo         = new DeviceInfo();
        }