Beispiel #1
0
        public static LicenseValidationState CheckLicenseState(ClientInfo clientInfo, out string message, out bool deleteVideo)
        {
            LicenseValidationState currentState = LicenseValidationState.Valid;

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

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

            lastAccessTime = sessionStartDate;

            //RegDate > CurrentDate
            if (sessionStartDate.CompareTo(currentDateTime) > 0)
            {
                currentState = LicenseValidationState.InvalidLicense;
                message      = invalidLicenseMessage;
            }
            // License is expired - Delete All Videos
            else if (clientInfo.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;
            }
            //// First Time Login Case -> Valid
            //if (lastAccessTime.Equals(clientInfo.RegistrationDate) && (registrationDate < currentDateTime && currentDateTime < clientInfo.ExpiryDate))
            //{
            //    currentState = LicenseValidationState.Valid;
            //}
            //// Normal Case -> Valid
            //else if (lastAccessTime <= currentDateTime && (registrationDate < currentDateTime && currentDateTime < clientInfo.ExpiryDate))
            //{
            //    currentState = LicenseValidationState.Valid;
            //}

            return(currentState);
        }
Beispiel #2
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);
        }