Exemple #1
0
        private void btnGetDataFile_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.FileName   = "sxu.dll";
            dialog.DefaultExt = ".dll";
            dialog.Filter     = "DLL Files (.dll)|*.dll";

            dialog.ShowDialog();
            if (!String.IsNullOrEmpty(dialog.FileName))
            {
                ClientLicense cl = new ClientLicense(UIContext.License);

                string fileName = System.IO.Path.GetFileName(dialog.FileName);

                if (fileName != "sxu.dll")
                {
                    MessageBox.Show("This version of Scutex only supports a data file with the name of sxu.dll.");
                    return;
                }

                IClientLicenseService clientLicenseService = ObjectLocator.GetInstance <IClientLicenseService>();
                clientLicenseService.SaveClientLicense(cl, dialog.FileName);
            }
        }
Exemple #2
0
        private static void Demo(object sender, ExecutedRoutedEventArgs e)
        {
            if (UIContext.License != null)
            {
                DemoHostHelper helper = new DemoHostHelper();
                helper.CleanPreviousHost();

                string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
                path = path.Replace("file:\\", "");

                ClientLicense cl = new ClientLicense(UIContext.License);

                IClientLicenseService clientLicenseService = ObjectLocator.GetInstance <IClientLicenseService>();
                clientLicenseService.SaveClientLicense(cl, path + @"\sxu.dll");

                IHashingProvider hashingProvider = ObjectLocator.GetInstance <IHashingProvider>();
                IEncodingService encodingService = ObjectLocator.GetInstance <IEncodingService>();

                string dllCheckHash = encodingService.Encode(hashingProvider.HashFile(Directory.GetCurrentDirectory() + "\\lib\\WaveTech.Scutex.Licensing.dll"));
                string publicKey    = encodingService.Encode(UIContext.License.KeyPair.PublicKey);

                try
                {
                    File.Copy(Directory.GetCurrentDirectory() + "\\lib\\WaveTech.Scutex.Licensing.dll", Directory.GetCurrentDirectory() + "\\WaveTech.Scutex.Licensing.dll");
                }
                catch { }

                helper.CreateAssembly(publicKey, dllCheckHash);

                helper.ExecuteAssembly();
                helper = null;
            }
            else
            {
                MessageBox.Show("You must have an open licensing project to view the demo trial form.");
            }
        }
        public ScutexLicense GetScutexLicense(ClientLicense clientLicense)
        {
            ScutexLicense scutexLicense = new ScutexLicense();

            scutexLicense.TrialFaultReason          = TrialFaultReasons.None;
            scutexLicense.IsTrialValid              = true;
            scutexLicense.LastRun                   = clientLicense.LastRun;
            scutexLicense.TrialSettings             = clientLicense.TrialSettings;
            scutexLicense.TrailNotificationSettings = clientLicense.TrailNotificationSettings;
            scutexLicense.IsCommunityEdition        = ApplicationConstants.IsCommunityEdition;

            if (!clientLicense.FirstRun.HasValue)
            {
                Logging.LogDebug(string.Format("Is First Run!"));
                clientLicense.FirstRun         = _networkTimeProvider.GetNetworkTime();
                scutexLicense.WasTrialFristRun = true;

                Logging.LogDebug(string.Format("FirstRun SetTo: {0}", clientLicense.FirstRun.Value));
            }
            else
            {
                Logging.LogDebug(string.Format("Is Existing Run!"));
                Logging.LogDebug(string.Format("FirstRun Date: {0}", clientLicense.FirstRun.Value));
                Logging.LogDebug(string.Format("NetTime Date: {0}", _networkTimeProvider.GetNetworkTime()));
            }

            if (clientLicense.LastRun.HasValue && _networkTimeProvider.GetNetworkTime() < clientLicense.LastRun)
            {
                Logging.LogDebug(string.Format("TIME FAULT"));
                Logging.LogDebug(string.Format("LastRun Date: {0}", clientLicense.LastRun.Value));
                Logging.LogDebug(string.Format("NetRun Date: {0}", _networkTimeProvider.GetNetworkTime()));
                Logging.LogDebug(string.Format("Delta: {0}", (_networkTimeProvider.GetNetworkTime() - clientLicense.LastRun.Value)));

                scutexLicense.IsTrialValid     = false;
                scutexLicense.TrialFaultReason = TrialFaultReasons.TimeFault;
            }

            clientLicense.LastRun = _networkTimeProvider.GetNetworkTime();

            Logging.LogDebug(string.Format("Old Run Count: {0}", clientLicense.RunCount));
            clientLicense.RunCount++;
            Logging.LogDebug(string.Format("New Run Count: {0}", clientLicense.RunCount));

            scutexLicense.FirstRun = clientLicense.FirstRun;

            switch (clientLicense.TrialSettings.ExpirationOptions)
            {
            case TrialExpirationOptions.Days:
                TimeSpan ts = clientLicense.FirstRun.Value -
                              _networkTimeProvider.GetNetworkTime().AddDays(-int.Parse(clientLicense.TrialSettings.ExpirationData));

                scutexLicense.TrialRemaining = ts.Days;

                if (ts.Days <= 0)
                {
                    scutexLicense.IsTrialExpired = true;
                    Logging.LogDebug(string.Format("Trial Expired"));
                }
                else
                {
                    scutexLicense.IsTrialExpired = false;
                    Logging.LogDebug(string.Format("Trial Not Expired"));
                }

                break;
            }

            // TODO: Need to set a fair amount of data here, like licensed edition, level, etc
            if (clientLicense.IsLicensed)
            {
                scutexLicense.IsLicensed = clientLicense.IsLicensed;
                Logging.LogDebug(string.Format("Product is licensed"));
            }
            else
            {
                Logging.LogDebug(string.Format("Product is not licensed"));
            }

            Logging.LogDebug(string.Format("Saving client license"));
            _clientLicenseService.SaveClientLicense(clientLicense);

            return(scutexLicense);
        }
        public ClientLicense ActivateLicenseKey(string licenseKey, Guid?token, bool isOffline, ClientLicense scutexLicense, string hardwareFingerprint)
        {
            /* This method used to live in the LicenseKeyService class, where it should be
             *  but because of a circular reference in the WebServicesProvider and the ServicesLibrary
             *  project requiring the LicenseKeyService to valid keys it was causing and error and had
             *  to be moved here.
             */

            if (_licenseKeyService.ValidateLicenseKey(licenseKey, scutexLicense, true))
            {
                Token t = new Token();
                t.Data      = scutexLicense.ServiceToken;
                t.Timestamp = DateTime.Now;

                string packedToken = _packingService.PackToken(t);

                LicenseActivationPayload payload = new LicenseActivationPayload();
                payload.LicenseKey     = licenseKey;
                payload.ServiceLicense = new ServiceLicense(scutexLicense);
                payload.Token          = token;

                if (!String.IsNullOrEmpty(hardwareFingerprint))
                {
                    payload.HardwareFingerprint = hardwareFingerprint;
                }

                if (!isOffline)
                {
                    ActivationResult result = _licenseActiviationProvider.ActivateLicense(scutexLicense.ServiceAddress, packedToken,
                                                                                          GetClientStandardEncryptionInfo(scutexLicense),
                                                                                          payload, scutexLicense);

                    if (result != null && result.WasRequestValid && result.ActivationSuccessful)
                    {
                        scutexLicense.IsLicensed              = true;
                        scutexLicense.IsActivated             = true;
                        scutexLicense.ActivatingServiceId     = result.ServiceId;
                        scutexLicense.ActivationToken         = result.ActivationToken;
                        scutexLicense.ActivatedOn             = DateTime.Now;
                        scutexLicense.ActivationLastCheckedOn = DateTime.Now;

                        _clientLicenseService.SaveClientLicense(scutexLicense);

                        return(scutexLicense);
                    }
                }
                else
                {
                    scutexLicense.IsLicensed              = true;
                    scutexLicense.IsActivated             = false;
                    scutexLicense.ActivatingServiceId     = null;
                    scutexLicense.ActivationToken         = null;
                    scutexLicense.ActivatedOn             = DateTime.Now;
                    scutexLicense.ActivationLastCheckedOn = DateTime.Now;

                    _clientLicenseService.SaveClientLicense(scutexLicense);

                    return(scutexLicense);
                }
            }

            return(scutexLicense);
        }