示例#1
0
        public static LicenseValidationState CheckLicenseStateNew(DateTime registrationDate, DateTime sessionStartDate, DateTime sessionEndDate, out string message, out bool deleteVideo)
        {
            LicenseValidationState currentState = LicenseValidationState.Valid;

            deleteVideo = false;
            message     = "";
            DateTime startDate       = new DateTime();
            DateTime lastAccessTime  = new DateTime();
            DateTime currentDateTime = DateTime.Now;

            // if registration date is between SessionStart and SessionEnd date
            if (sessionStartDate.CompareTo(registrationDate) < 0 && sessionEndDate.CompareTo(registrationDate) > 0)
            {
                startDate = DateTime.Parse(registrationDate.AddSeconds(-registrationDate.Second).AddMinutes(-registrationDate.Minute).ToString("dd-MMM-yyyy hh:00 tt"), CultureInfo.InvariantCulture);
            }
            // Future registration date
            else if (sessionStartDate.CompareTo(registrationDate) > 0)
            {
                startDate = sessionStartDate;
            }
            // Expired license
            else if (sessionEndDate.CompareTo(registrationDate) < 0)
            {
                deleteVideo  = true;
                currentState = LicenseValidationState.Expired;
                message      = licenseExpiredMessage;
                return(currentState);
            }

            lastAccessTime = startDate;

            // RegDate > CurrentDate
            if (startDate.CompareTo(currentDateTime) > 0)
            {
                currentState = LicenseValidationState.InvalidLicense;
                message      = invalidLicenseMessage;
            }
            // License is expired - Delete All Videos
            else if (sessionEndDate < currentDateTime)
            {
                deleteVideo  = true;
                currentState = LicenseValidationState.Expired;
                message      = licenseExpiredMessage;
            }
            // Clock time is back from current time -> Invalid Clock
            else if (lastAccessTime > currentDateTime) // && (registrationDate < currentDateTime && currentDateTime > clientInfo.ExpiryDate))
            {
                currentState = LicenseValidationState.InvalidClock;
                message      = invalidClockMessage;
            }
            return(currentState);
        }
示例#2
0
        private LicenseValidationState ValidateLicenseNew(RegInfoFB firebaseRegistrationInfo, ClientInfo localClientInfo, string localMACAddress, out string errorMessage, out bool deleteVideos, out bool skipLoginScreen)
        {
            errorMessage = ""; deleteVideos = false; skipLoginScreen = false;
            LicenseValidationState licenseState = LicenseValidationState.None;

            // Licese already expired
            if (CommonAppStateDataHelper.ClientInfoObject.Expired)
            {
                deleteVideos = true;
                errorMessage = LicenseHelper.licenseExpiredMessage;
                licenseState = LicenseValidationState.Expired;
            }
            else if (firebaseRegistrationInfo == null && string.IsNullOrEmpty(localClientInfo.MacAddress) == true)
            {
                errorMessage = LicenseHelper.onlineConnectivityIsMust;
                licenseState = LicenseValidationState.ConnectivityRequiredForValidation;
            }
            else if (string.IsNullOrEmpty(localMACAddress) == true)
            {
                errorMessage = LicenseHelper.invalidLicenseMessage;
                licenseState = LicenseValidationState.EmptyMacAddress;
            }
            else
            {
                DateTime sessionEndDate = localClientInfo.SessionEndDate;

                if (firebaseRegistrationInfo != null)
                {
                    sessionEndDate = firebaseRegistrationInfo.ExpiryDate;
                }

                licenseState = LicenseHelper.CheckLicenseStateNew(localClientInfo.RegistrationDate, localClientInfo.SessionStartDate, sessionEndDate, out errorMessage, out deleteVideos);

                // Validate Firebase MacAddress Check
                if (licenseState == LicenseValidationState.Valid)
                {
                    licenseState = LicenseHelper.ValidateMacAddress(firebaseRegistrationInfo, localClientInfo, localMACAddress, out errorMessage, out deleteVideos, out skipLoginScreen);
                }
            }
            return(licenseState);
        }
示例#3
0
        private void OnAfterLicesseValidation(string message, bool deleteVideos, LicenseValidationState licenseState)
        {
            if (deleteVideos && licenseState == LicenseValidationState.Expired)
            {
                CommonAppStateDataHelper.ClientInfoObject.Expired = true;
                CommonAppStateDataHelper.LicenseError             = true;

                if (Directory.Exists(ClientHelper.GetClientVideoFilePath(_clientInfo.SchoolId, _clientInfo.SchoolCity)))
                {
                    Directory.Delete(ClientHelper.GetClientVideoFilePath(_clientInfo.SchoolId, _clientInfo.SchoolCity), true);
                }

                MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                this.Close();
            }
            else if (licenseState != LicenseValidationState.Valid)
            {
                CommonAppStateDataHelper.LicenseError = true;
                MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.Close();
            }
        }
示例#4
0
        private void ValidateLicense()
        {
            string message = ""; bool deleteVideos = false;
            LicenseValidationState licenseState = LicenseValidationState.None;

            if (CommonAppStateDataHelper.ClientInfoObject.Expired)
            {
                deleteVideos = true;
                message      = LicenseHelper.licenseExpiredMessage;
                licenseState = LicenseValidationState.Expired;
            }
            else
            {
                licenseState = LicenseHelper.CheckLicenseState(_clientInfo, out message, out deleteVideos);
            }

            if (deleteVideos && licenseState == LicenseValidationState.Expired)
            {
                CommonAppStateDataHelper.ClientInfoObject.Expired = true;
                CommonAppStateDataHelper.LicenseError             = true;

                if (Directory.Exists(ClientHelper.GetClientVideoFilePath(_clientInfo.SchoolId, _clientInfo.SchoolCity)))
                {
                    Directory.Delete(ClientHelper.GetClientVideoFilePath(_clientInfo.SchoolId, _clientInfo.SchoolCity), true);
                }

                MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                this.Close();
            }
            else if (licenseState != LicenseValidationState.Valid)
            {
                CommonAppStateDataHelper.LicenseError = true;
                MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.Close();
            }
        }
示例#5
0
        private void frmLogin_Load(object sender, EventArgs e)
        {
            try
            {
                label11.Location = new System.Drawing.Point(panel4.Width / 2 - 150, 11);
                label2.Location  = new System.Drawing.Point(panel4.Width / 2 - 75, 15);


                this.progressBar1.Visible = true;
                this.progressBar1.Enabled = true;
                this.progressBar1.Value   = 10;
                //ClientHelper.GetClientThumbanailPath();

                _clientInfoFilePath = ClientHelper.GetClientInfoFilePath();

                if (!File.Exists(_clientInfoFilePath))
                {
                    MessageBox.Show("Invalid Configuration", "Configuration Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;
                }

                this.progressBar1.Value = 30;

                CommonAppStateDataHelper.ClientInfoObject = Cryptograph.DecryptObject <ClientInfo>(_clientInfoFilePath);
                _clientInfo = CommonAppStateDataHelper.ClientInfoObject;

                this.progressBar1.Value = 70;

                if (_clientInfo != null)
                {
                    lblSessionYears.Text  = ClientHelper.GetSessionString(_clientInfo.SessionString);
                    lblSchoolWelcome.Text = ClientHelper.GetWelcomeString(_clientInfo.SchoolName, _clientInfo.SchoolCity, _clientInfo.SchoolId);
                    lblExpireDate.Text    = ClientHelper.GetExpiryDateString(_clientInfo.SessionEndDate);

                    _currentMacAddress = MacAddressHelper.GetMacAddress();
                    //_currentMacAddress = "B82A72A780B7";
                    _firebaseRegInfo = GetFirebaseRegistrationInformation();

                    string errorMessage    = "";
                    bool   deleteVideos    = false;
                    bool   skipLoginScreen = false;
                    // Check license session duraion
                    LicenseValidationState licenseState = ValidateLicenseNew(_firebaseRegInfo, _clientInfo, _currentMacAddress, out errorMessage, out deleteVideos, out skipLoginScreen);

                    TextFileLogger.Log("License State" + licenseState.ToString());

                    if (licenseState != LicenseValidationState.Valid)
                    {
                        OnAfterLicesseValidation(errorMessage, deleteVideos, licenseState);
                    }

                    _showLoginForm = !skipLoginScreen;

                    this.progressBar1.Value = 100;

                    //// update mac address in local client info file
                    //if (licenseState == LicenseValidationState.Valid)
                    //{
                    //    this.progressBar1.Value = 90;
                    //    //if (string.IsNullOrEmpty(CommonAppStateDataHelper.ClientInfoObject.MacAddress))
                    //    //{
                    //    //    _showLoginForm = true;
                    //    //}
                    //    //else
                    //    //{
                    //    //    _showLoginForm = false;
                    //    //}
                    //}
                    //else
                    //{
                    //    this.progressBar1.Value = 100;
                    //    Application.Exit();
                    //}
                }
                else
                {
                    throw new Exception("Invalid client info configuration.");
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.HandleException(ex);
                MessageBox.Show(ex.Message + "\n" + ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#6
0
        public static LicenseValidationState ValidateMacAddress(RegInfoFB firebaseRegistrationInfo, ClientInfo localClientInfo, string localMacAddress, out string message, out bool deleteVideo, out bool skipLoginScreen)
        {
            //bool firebaseLicenseValidation = false;

            LicenseValidationState licenseState = LicenseValidationState.None;

            skipLoginScreen = false;
            deleteVideo     = false;
            message         = "";

            // Device is online
            if (firebaseRegistrationInfo != null)
            {
                //1)    localClientInfo.MacAddress <> '' AND localClientInfo.MacAddress is in FirebaseMacAddressList == True
                //          Allow to login without authentication
                if (string.IsNullOrEmpty(localClientInfo.MacAddress) == false)
                {
                    // If local mac address is not matching with saved mac address.
                    if (localClientInfo.MacAddress.ToLower().Equals(localMacAddress.ToLower()) == false)
                    {
                        licenseState    = LicenseValidationState.SavedMacAddressMismatched;
                        skipLoginScreen = false;
                        message         = invalidLicenseMessage;
                        deleteVideo     = true;
                    }

                    else if (firebaseRegistrationInfo.MacAddresses.Contains(localClientInfo.MacAddress) == true)
                    {
                        // maxlicense is valid and user already authenticated
                        skipLoginScreen = true;
                        licenseState    = LicenseValidationState.Valid;
                    }
                    else if (firebaseRegistrationInfo.MacAddresses.Contains(localClientInfo.MacAddress) == false)
                    {
                        // 2.1) If FirebaseMacAddressList.Count >= MaxLicenseCount
                        //        Raise Error and Exit Application
                        if (firebaseRegistrationInfo.MacAddresses.Count >= firebaseRegistrationInfo.NoOfPcs)
                        {
                            licenseState    = LicenseValidationState.MaxMacAddressLimitExceed;
                            skipLoginScreen = false;
                            message         = maxLicenseOccupiedMessage;
                            deleteVideo     = true;
                        }

                        // 2.2) IF FirebaseMacAddressList.Count < MaxLicenseCount
                        //        Add current macaddress in FirebaseMacAddressList and allow login
                        if (firebaseRegistrationInfo.MacAddresses.Count < firebaseRegistrationInfo.NoOfPcs)
                        {
                            licenseState = LicenseValidationState.Valid;
                            // Add current macaddress in FirebaseMacAddressList
                            //_addMacAddressInFirebase = true;
                            skipLoginScreen = false;
                        }
                    }
                }
                // 3)   If localClientInfo.MacAddress == '' Then
                else if (string.IsNullOrEmpty(localClientInfo.MacAddress))
                {
                    //    3.1) If FirebaseMacAddressList.Count >= MaxLicenseCount
                    //        Raise Error and Exit Application
                    if (firebaseRegistrationInfo.MacAddresses.Count >= firebaseRegistrationInfo.NoOfPcs)
                    {
                        licenseState    = LicenseValidationState.MaxMacAddressLimitExceed;
                        skipLoginScreen = false;
                        message         = maxLicenseOccupiedMessage;
                        deleteVideo     = true;
                    }
                    // 3.2) If FirebaseMacAddressList.Count < MaxLicenseCount
                    else if (firebaseRegistrationInfo.MacAddresses.Count < firebaseRegistrationInfo.NoOfPcs)
                    {
                        licenseState = LicenseValidationState.Valid;

                        //      On sucessful authentication, save local mac address to Firebase.
                        //      Save local mac address to local client info file
                        //_addMacAddressInFirebase = true;
                        //      Ask user to enter login credentials
                        skipLoginScreen = false;
                    }
                }
            }
            // Device is offline
            else
            {
                // 1) localClientInfo.MacAddress == ''
                //      Ask user for autentication
                if (string.IsNullOrEmpty(localClientInfo.MacAddress))
                {
                    skipLoginScreen = false;
                }
                //    2) localClientInfo.MacAddress <> ''
                //            Allow user to use application without authentication
                else if (string.IsNullOrEmpty(localClientInfo.MacAddress) == false)
                {
                    if (localClientInfo.MacAddress.ToLower().Equals(localMacAddress.ToLower()))
                    {
                        skipLoginScreen = true;
                        licenseState    = LicenseValidationState.Valid;
                    }
                    else
                    {
                        skipLoginScreen = false;
                        licenseState    = LicenseValidationState.ConnectivityRequiredForValidation;
                        message         = invalidLicenseMessage;
                    }

                    // Validate license date;
                }
            }

            return(licenseState);
        }