Example #1
0
 public PagedList<KeyInfo> SearchKeys(KeySearchCriteria searchCriteria)
 {
     var headSearchCriteria = ConvertSearchCriteria(searchCriteria);
     headSearchCriteria.HqId = CurrentHeadQuarterId;
     if (Constants.InstallType == InstallType.Oem)
     {
         headSearchCriteria.ShouldCarbonCopy = true;
     }
     return keyRepository.SearchKeys(headSearchCriteria);
 }
Example #2
0
        private KeySearchCriteria[] GetBoundKeyToMsSearchCriteria(KeySearchCriteria searchCriteria)
        {
            var myCriteria = ConvertSearchCriteria(searchCriteria);
            myCriteria.HasHardwareHash = true;
            myCriteria.KeyType = KeyType.Standard;
            myCriteria.KeyState = KeyState.Bound;
            myCriteria.HqId = CurrentHeadQuarterId;
            myCriteria.IsInProgress = false;

            return new KeySearchCriteria[] { myCriteria };
        }
Example #3
0
        public List<KeyInfo> SearchUnassignKeys(KeySearchCriteria searchCriteria)
        {
            if (searchCriteria.SsId == null)
                throw new ArgumentException("SsId is null.");

            KeySearchCriteria searchCriteriaMe = ConvertSearchCriteria(searchCriteria);
            searchCriteriaMe.KeyState = KeyState.Assigned;
            searchCriteriaMe.IsInProgress = false;
            if (CurrentHeadQuarterId != null)
                searchCriteriaMe.HqId = CurrentHeadQuarterId;
            searchCriteriaMe.PageSize = Constants.BatchLimit;
            return keyRepository.SearchKeys(searchCriteriaMe);
        }
Example #4
0
        /// <summary>
        /// search keys to revert 
        /// </summary>
        /// <param name="searchCriteria"></param>
        /// <returns></returns>
        public List<KeyInfo> SearchKeysToRevert(KeySearchCriteria searchCriteria)
        {
            if (searchCriteria.KeyType == null)
                throw new NotSupportedException();

            searchCriteria.HqId = CurrentHeadQuarterId;
            if (searchCriteria.KeyType == KeyType.All)
            {
                if (searchCriteria.KeyStateIds != null)
                    throw new DisException("SearchKey_InvalidKeyType");
                else
                {
                    var searchCriteriaStandard = ConvertSearchCriteria(searchCriteria);
                    var searchCriteriaMBR = ConvertSearchCriteria(searchCriteria);
                    searchCriteriaStandard.KeyType = KeyType.Standard;
                    searchCriteriaStandard.KeyStates = new List<KeyState> { KeyState.Consumed, KeyState.Bound };
                    searchCriteriaMBR.KeyType = KeyType.MBR;
                    searchCriteriaMBR.KeyStates = new List<KeyState> { KeyState.ActivationEnabled };
                    return keyRepository.SearchKeys(new KeySearchCriteria[] { searchCriteriaStandard, searchCriteriaMBR });
                }
            }
            else
            {
                switch (searchCriteria.KeyType)
                {
                    case KeyType.Standard:
                        if (searchCriteria.KeyStateIds == null || searchCriteria.KeyStateIds.Count <= 0)
                            searchCriteria.KeyStates = new List<KeyState> { KeyState.Consumed, KeyState.Bound };
                        break;
                    case KeyType.MBR:
                        if (searchCriteria.KeyStateIds == null || searchCriteria.KeyStateIds.Count <= 0)
                            searchCriteria.KeyStates = new List<KeyState> { KeyState.ActivationEnabled };
                        break;
                    default:
                        break;
                }
                return keyRepository.SearchKeys(searchCriteria);
            }
        }
Example #5
0
        /// <summary>
        /// get keys search criteria to return
        /// </summary>
        /// <param name="searchCriteria">KeySearchCriteria</param>
        /// <returns></returns>
        private KeySearchCriteria[] GetToReturnKeysSearchCriteria(KeySearchCriteria searchCriteria)
        {
            if (searchCriteria.KeyType == null)
                throw new NotSupportedException();

            searchCriteria.HqId = CurrentHeadQuarterId;
            searchCriteria.IsInProgress = false;
            if (searchCriteria.KeyType == KeyType.All)
            {
                if (searchCriteria.KeyStateIds != null)
                    throw new DisException("SearchKey_InvalidKeyType");
                else
                {
                    var searchCriteriaStandard = ConvertSearchCriteria(searchCriteria);
                    var searchCriteriaMBR = ConvertSearchCriteria(searchCriteria);
                    var searchCriteriaMAT = ConvertSearchCriteria(searchCriteria);

                    searchCriteriaStandard.KeyType = KeyType.Standard;
                    searchCriteriaStandard.KeyStates = new List<KeyState> { KeyState.Fulfilled, KeyState.Bound, KeyState.ActivationEnabled, KeyState.ActivationDenied };
                    searchCriteriaMBR.KeyType = KeyType.MBR;
                    searchCriteriaMBR.KeyStates = new List<KeyState> { KeyState.Fulfilled, KeyState.ActivationEnabled };
                    searchCriteriaMAT.KeyType = KeyType.MAT;
                    searchCriteriaMAT.KeyStates = new List<KeyState> { KeyState.Fulfilled };
                    return new KeySearchCriteria[] { searchCriteriaStandard, searchCriteriaMBR, searchCriteriaMAT };
                }
            }
            else
            {
                switch (searchCriteria.KeyType)
                {
                    case KeyType.Standard:
                        if (searchCriteria.KeyStateIds == null || searchCriteria.KeyStateIds.Count <= 0)
                            searchCriteria.KeyStates = new List<KeyState> { KeyState.Fulfilled, KeyState.Bound, KeyState.ActivationEnabled, KeyState.ActivationDenied };
                        break;
                    case KeyType.MBR:
                        if (searchCriteria.KeyStateIds == null || searchCriteria.KeyStateIds.Count <= 0)
                            searchCriteria.KeyStates = new List<KeyState> { KeyState.Fulfilled, KeyState.ActivationEnabled };
                        break;
                    case KeyType.MAT:
                        if (searchCriteria.KeyStateIds == null || searchCriteria.KeyStateIds.Count <= 0)
                            searchCriteria.KeyStates = new List<KeyState> { KeyState.Fulfilled };
                        break;
                    default:
                        break;
                }
                return new KeySearchCriteria[] { searchCriteria };
            }
        }
Example #6
0
 public List<KeyInfo> SearchToReturnKeys(KeySearchCriteria searchCriteria)
 {
     return keyRepository.SearchKeys(GetToReturnKeysSearchCriteria(searchCriteria));
 }
Example #7
0
        private KeySearchCriteria[] GetNotBeenSendReturnKeysSearchCriteria()
        {
            KeySearchCriteria searchCriteria = new KeySearchCriteria()
            {
                HqId = CurrentHeadQuarterId,
                ShouldIncludeReturnReport = true,
                IsInProgress = true,
                ReturnReportStatus = ReturnReportStatus.Generated
            };
            var searchCriteriaStandard = ConvertSearchCriteria(searchCriteria);
            var searchCriteriaMBR = ConvertSearchCriteria(searchCriteria);
            var searchCriteriaMAT = ConvertSearchCriteria(searchCriteria);

            searchCriteriaStandard.KeyType = KeyType.Standard;
            searchCriteriaStandard.KeyStates = new List<KeyState> { KeyState.Fulfilled, KeyState.Bound, KeyState.ActivationEnabled, KeyState.ActivationDenied };
            searchCriteriaMBR.KeyType = KeyType.MBR;
            searchCriteriaMBR.KeyStates = new List<KeyState> { KeyState.Fulfilled, KeyState.ActivationEnabled };
            searchCriteriaMAT.KeyType = KeyType.MAT;
            searchCriteriaMAT.KeyStates = new List<KeyState> { KeyState.Fulfilled };
            return new KeySearchCriteria[] { searchCriteriaStandard, searchCriteriaMBR, searchCriteriaMAT };
        }
Example #8
0
 public List<KeyOperationHistory> SearchOperationHistories(KeySearchCriteria criteria)
 {
     throw new NotImplementedException();
 }
Example #9
0
 private KeySearchCriteria GetRecallKeySearchCriteria(KeySearchCriteria criteria)
 {
     criteria.KeyState = KeyState.Fulfilled;
     criteria.HqId = CurrentHeadQuarterId; ;
     return ConvertSearchCriteria(criteria);
 }
 private void SearchKeys(object sender, EventArgs e)
 {
     crit = SCVM.FillSearchCriteria();
     crit.KeyState = KeyState.Bound;
     if (!ValidationHelper.ValidateDateRange(crit.DateFrom, crit.DateTo))
         return;
     if (Keys == null)
         this.Keys = new ObservableCollection<KeyInfoModel>();
     this.Keys.Clear();
     this.LoadNextPage();
 }
Example #11
0
        /// <summary>
        /// Set product key info from key store, called from KeyProviderListener.
        /// </summary>
        /// <param name="parameters">Optional parameter for use by OEMs</param>
        /// <param name="productKeyInfo">XML with product key info to store</param>
        /// <returns></returns>
        public int UpdateKey(string parameters, string productKeyInfo)
        {
            try
            {
                MessageLogger.LogSystemRunning("UpdateKey", "Parameters = " + parameters);

                XDocument param = ParseAndValidateXML(parameters, parameterSchema);

                if (param == null)
                {
                    return Convert.ToInt32(
                        ReturnValue.MSG_KEYPROVIDER_XML_SCHEMA_FORMAT_VIOLATION);
                }

                XDocument dm = ParseAndValidateXML(productKeyInfo, productKeyInfoSchema);

                if (dm == null)
                {
                    return Convert.ToInt32(
                        ReturnValue.MSG_KEYPROVIDER_XML_SCHEMA_FORMAT_VIOLATION);
                }

                // Get XML bound by DMTool.
                foreach (XElement element in dm.Descendants("Key"))
                {
                    long productKeyId = Convert.ToInt64(GetXElementValue(element, "ProductKeyID"));

                    KeySearchCriteria query = new KeySearchCriteria();
                    query.PageSize = 1;
                    query.KeyId = productKeyId;

                    query = AttachParameters(query, param);

                    var keys = keyProxy.SearchKeys(query);

                    if (keys == null || keys.Count <= 0)
                    {
                        return Convert.ToInt32(
                           ReturnValue.MSG_KEYPROVIDER_NO_KEYS_AVAILABLE_FOR_SPECIFIED_PARAMETERS);
                    }
                    var key = keys.FirstOrDefault();

                    if (key == null)
                    {
                        return Convert.ToInt32(
                           ReturnValue.MSG_KEYPROVIDER_NO_KEYS_AVAILABLE_FOR_SPECIFIED_PARAMETERS);
                    }

                    var newHardwareId = GetXElementValue(element, "HardwareHash");
                    var newOEMOptionalInfo = new OemOptionalInfo(GetXElementValue(element, "OEMOptionalInfo"));
                    var newKeyState = (KeyState)Convert.ToByte(GetXElementValue(element, "ProductKeyState"));
                    if (!keyProxy.UpdateReportKey(key, newKeyState, newHardwareId, newOEMOptionalInfo))
                        return Convert.ToInt32(ReturnValue.MSG_KEYPROVIDER_INVALID_PRODUCT_KEY_STATE_TRANSITION);
                }

            }
            catch (Exception ex)
            {
                ExceptionHandler.HandleException(ex);

                if (ex.GetType() == typeof(EntityException))
                {
                    return Convert.ToInt32(ReturnValue.MSG_KEYPROVIDER_FAILED_DB_CONNECTION);
                }

                return Convert.ToInt32(ReturnValue.MSG_KEYPROVIDER_FAILED);
            }

            return Convert.ToInt32(ReturnValue.MSG_KEYPROVIDER_SUCCESS);
        }
Example #12
0
 private KeySearchCriteria[] GetAssignkeysSearchCriteria(KeySearchCriteria searchCriteria)
 {
     KeySearchCriteria searchCriteriaUp = ConvertSearchCriteria(searchCriteria);
     searchCriteriaUp.KeyState = KeyState.Fulfilled;
     searchCriteriaUp.IsInProgress = false;
     searchCriteriaUp.IsAssign = false;
     searchCriteriaUp.SsId = null;
     searchCriteriaUp.HqId = CurrentHeadQuarterId;
     return new KeySearchCriteria[] { searchCriteriaUp };
 }
Example #13
0
 public List<KeyGroup> SearchAssignKeyGroups(KeySearchCriteria searchCriteria)
 {
     return keyRepository.SearchKeyGroups(GetAssignkeysSearchCriteria(searchCriteria));
 }
Example #14
0
 private KeySearchCriteria GetBoundKeysSearchCriteria(KeySearchCriteria searchCriteria)
 {
     var searchCriteriaUp = ConvertSearchCriteria(searchCriteria);
     searchCriteriaUp.KeyType = KeyType.Standard;
     searchCriteriaUp.KeyState = KeyState.Bound;
     searchCriteriaUp.HqId = CurrentHeadQuarterId;
     searchCriteriaUp.IsInProgress = false;
     searchCriteriaUp.HasHardwareHash = true;
     return searchCriteriaUp;
 }
Example #15
0
        protected KeySearchCriteria ConvertSearchCriteria(KeySearchCriteria searchCriteria)
        {
            if (searchCriteria == null)
                throw new ApplicationException("Search criteria is null.");

            var criteria = (KeySearchCriteria)searchCriteria.Clone();
            criteria.HqId = CurrentHeadQuarterId;
            if (criteria.DateFrom.HasValue && criteria.DateFrom.Value < SqlDateTime.MinValue.Value)
                criteria.DateFrom = SqlDateTime.MinValue.Value;
            if (criteria.DateTo.HasValue)
                criteria.DateTo = (criteria.DateTo.Value > SqlDateTime.MaxValue.Value ?
                    SqlDateTime.MaxValue.Value : criteria.DateTo.Value.AddDays(1));
            if (criteria.OemRmaDateTo.HasValue)
                criteria.OemRmaDateTo = (criteria.OemRmaDateTo.Value > SqlDateTime.MaxValue.Value ?
                    SqlDateTime.MaxValue.Value : criteria.OemRmaDateTo.Value.AddDays(1));
            if (criteria.PageSize < 0)
                criteria.PageSize = KeySearchCriteria.DefaultPageSize;
            else if (criteria.PageSize == 0)
                criteria.PageSize = int.MaxValue;
            return criteria;
        }
Example #16
0
 public List<KeyInfo> SearchFulfilledKeys(KeySearchCriteria searchCriteria)
 {
     return keyRepository.SearchKeys(GetFulfilledkeysSearchCriteria(searchCriteria));
 }
Example #17
0
 public List<KeyGroup> SearchBoundKeyGroups(KeySearchCriteria searchCriteria)
 {
     return keyRepository.SearchKeyGroups(GetBoundKeysSearchCriteria(searchCriteria));
 }
Example #18
0
        /// <summary>
        /// Method to get OrderList data based on OrderStatusId
        /// </summary>
        private void Search(int pageNumber)
        {
            if (ValidationHelper.ValidateDateRange(StartChangeStateDate, EndChangeStateDate))
            {
                IsBusy = true;
                WorkInBackground((s, e) =>
                {
                    try
                    {
                        //Manage Search Criteria
                        KeySearchCriteria searchCriteria = new KeySearchCriteria();
                        searchCriteria.ShouldIncludeHistories = true;
                        searchCriteria.PageSize = PageSize;
                        searchCriteria.PageNumber = pageNumber;
                        searchCriteria.OemPoNumber = OEMPoNumber;
                        searchCriteria.DateFrom = StartChangeStateDate;
                        searchCriteria.DateTo = EndChangeStateDate;
                        searchCriteria.OemRmaDateFrom = StartOemRMADate;
                        searchCriteria.OemRmaDateTo = EndOemRMADate;
                        searchCriteria.MsOrderNumber = OrderNumber;
                        searchCriteria.MsPartNumber = MsPartNumber;
                        searchCriteria.OemPartNumber = OEMPartNumber;
                        searchCriteria.ProductKeyID = ProductKeyID;
                        if (!string.IsNullOrEmpty(ProductKeyIDFrom))
                            searchCriteria.ProductKeyIDFrom = long.Parse(ProductKeyIDFrom);
                        if (!string.IsNullOrEmpty(ProductKeyIDTo))
                            searchCriteria.ProductKeyIDTo = long.Parse(ProductKeyIDTo);
                        searchCriteria.ProductKey = ProductKey;
                        searchCriteria.HardwareHash = HardWareHash;
                        searchCriteria.ReferenceNumber = ReferenceNumber;
                        searchCriteria.ZPC_MODEL_SKU = ZPC_MODEL_SKU;
                        searchCriteria.ZCHANNEL_REL_ID = ZCHANNEL_REL_ID;
                        searchCriteria.ZMAUF_GEO_LOC = ZMAUF_GEO_LOC;
                        searchCriteria.ZOEM_EXT_ID = ZOEM_EXT_ID;
                        searchCriteria.ZPGM_ELIG_VALUES = ZPGM_ELIG_VALUES;
                        searchCriteria.TrakingInfo = TrakingInfo;
                        searchCriteria.ShouldIncludeReturnReport = true;
                        searchCriteria.OemRmaNumber = OemRmaNumber;

                        if (!string.IsNullOrEmpty(sortColumn))
                        {
                            searchCriteria.SortBy = sortColumn;
                            searchCriteria.SortByDesc = isDesc;
                        }
                        if (!string.IsNullOrEmpty(selectedKeyState))
                        {
                            if (selectedKeyState != MergedResources.Common_All)
                                searchCriteria.KeyState = (KeyState)Enum.Parse(typeof(KeyState), selectedKeyState, true);
                        }
                        if (SelectedSubSidiary != null && SelectedSubSidiary.SsId != 0)
                        {
                            searchCriteria.SsId = SelectedSubSidiary.SsId;
                        }
                        if (!string.IsNullOrEmpty(SelectedKeyType) && SelectedKeyType != MergedResources.Common_All)
                        {
                            searchCriteria.KeyType = (KeyType)Enum.Parse(typeof(KeyType), SelectedKeyType, true);
                        }
                        if (SelectedKeyType == MergedResources.Common_All)
                            searchCriteria.KeyType = null;

                        if (!string.IsNullOrEmpty(SelectReturnState) && SelectReturnState != ResourcesOfR6.Common_AllReturnedKeys && ReturnSelectVisibility == Visibility.Visible)
                        {
                            if (SelectReturnState == ResourcesOfR6.Common_ReturnedWithNoCredit)
                                searchCriteria.HasNoCredit = true;
                            else
                                searchCriteria.HasNoCredit = false;
                        }

                        //Search keys by search criteria
                        PagedList<KeyInfo> keyCollection = keyProxy.SearchKeys(searchCriteria);
                        if (keyCollection.PageCount > 0 && pageNumber > keyCollection.PageCount)
                        {
                            Dispatch(() =>
                            {
                                Search(keyCollection.PageCount);
                            });
                            return;
                        }
                        else
                        {
                            //Set Page Count from search
                            CurrentPage = pageNumber;
                            PageCount = keyCollection.PageCount;
                            TotalCount = keyCollection.TotalCount;

                            //Fill key collection
                            KeyInfoCollection = new ObservableCollection<KeyInfoModel>(keyCollection.Select(k => new KeyInfoModel() { keyInfo = k }));
                        }

                        //Notify UI
                        KeysDetailsValueCollection = null;
                        KeyHistoryInformation = null;

                        IsBusy = false;
                    }
                    catch (Exception ex)
                    {
                        IsBusy = false;
                        ex.ShowDialog();
                        ExceptionHandler.HandleException(ex);
                    }
                });
            }
        }
Example #19
0
        /// <summary>
        /// Get product key info from key store, called from KeyProviderListener.
        /// </summary>
        /// <param name="productKeyInfo">product key info BLOB</param>
        /// <returns></returns>
        public int GetKey(string parameters, ref string productKeyInfo)
        {
            try
            {
                XDocument param = ParseAndValidateXML(parameters, parameterSchema);

                if (param == null)
                {
                    return Convert.ToInt32(
                        ReturnValue.MSG_KEYPROVIDER_XML_SCHEMA_FORMAT_VIOLATION);
                }

                // Get allocated key in store.
                KeySearchCriteria query = new KeySearchCriteria();
                query.KeyState = KeyState.Fulfilled;
                query.SortBy = "FulfilledDateUTC";
                query.SortByDesc = false;
                query.PageSize = 1;

                query = AttachParameters(query, param);
                if (query == null)
                {
                    return Convert.ToInt32(ReturnValue.MSG_KEYPROVIDER_XML_INVALID_PARAMETER);
                }

                KeyInfo key = null;
                try
                {
                    key = GetKeyTransaction(query);
                    MessageLogger.LogSystemRunning("GetKey", string.Format("{0} key {1}/{2} was consumed to {3}.\r\n{4}",
                        key.KeyInfoEx.KeyType.ToString(), key.KeyId, key.ProductKey, key.KeyStateName, parameters));
                }
                catch (ApplicationException)
                {
                    return Convert.ToInt32(
                        ReturnValue.MSG_KEYPROVIDER_NO_KEYS_AVAILABLE_FOR_SPECIFIED_PARAMETERS);
                }

                // Compose and return XML to DMTool.
                XElement dm = new XElement("Key",
                    new XElement("ProductKey", key.ProductKey),
                    new XElement("ProductKeyID", key.KeyId.ToString()),
                    new XElement("ProductKeyState", (byte)KeyState.Consumed),
                    new XElement("ProductKeyPartNumber", key.SkuId)
                );
                productKeyInfo = dm.ToString();
            }
            catch (Exception ex)
            {
                ExceptionHandler.HandleException(ex);

                if (ex.GetType() == typeof(EntityException))
                {
                    return Convert.ToInt32(ReturnValue.MSG_KEYPROVIDER_FAILED_DB_CONNECTION);
                }

                return Convert.ToInt32(ReturnValue.MSG_KEYPROVIDER_FAILED);
            }

            return Convert.ToInt32(ReturnValue.MSG_KEYPROVIDER_SUCCESS);
        }
Example #20
0
        /// <summary>
        /// Get product key info from key store, called from KeyProviderListener.
        /// </summary>
        /// <param name="parameters">Optional parameter for use by OEMs</param>
        /// <param name="productKeyInfo">product key info BLOB</param>
        /// <returns></returns>
        public int GetKey(string parameters, ref string productKeyInfo)
        {
            try
            {
                MessageLogger.LogSystemRunning("GetKey", "Parameters = " + parameters);

                XDocument param = ParseAndValidateXML(parameters, parameterSchema);

                if (param == null)
                {
                    return Convert.ToInt32(
                        ReturnValue.MSG_KEYPROVIDER_XML_SCHEMA_FORMAT_VIOLATION);
                }
                KeyInfo key = null;

                // Get allocated key in store.
                KeySearchCriteria query = new KeySearchCriteria();
                query.KeyStates = new List<KeyState> { KeyState.Fulfilled };
                query.SortBy = "FulfilledDateUTC";
                query.SortByDesc = false;
                query.PageSize = 1;

                query = AttachParameters(query, param);
                if (query == null)
                {
                    return Convert.ToInt32(ReturnValue.MSG_KEYPROVIDER_XML_INVALID_PARAMETER);
                }
                var keys = keyProxy.SearchKeys(query);

                if (keys == null || keys.Count <= 0)
                {
                    return Convert.ToInt32(
                       ReturnValue.MSG_KEYPROVIDER_NO_KEYS_AVAILABLE_FOR_SPECIFIED_PARAMETERS);
                }
                key = keys.FirstOrDefault();

                keyProxy.UpdateKeyState(key, KeyState.Consumed);

                var updatedKey = keyProxy.SearchKeys(new KeySearchCriteria() { PageSize = 1, KeyId = key.ProductKeyId }).Keys.FirstOrDefault();

                // Compose and return XML to DMTool.
                XElement dm = new XElement("Key",
                    new XElement("ProductKey", updatedKey.ProductKey),
                    new XElement("ProductKeyID", updatedKey.ProductKeyId.ToString()),
                    new XElement("ProductKeyState", (byte)updatedKey.ProductKeyState),
                    new XElement("ProductKeyPartNumber", updatedKey.SKUID)
                );

                productKeyInfo = dm.ToString();
            }
            catch (Exception ex)
            {
                ExceptionHandler.HandleException(ex);

                if (ex.GetType() == typeof(EntityException))
                {
                    return Convert.ToInt32(ReturnValue.MSG_KEYPROVIDER_FAILED_DB_CONNECTION);
                }

                return Convert.ToInt32(ReturnValue.MSG_KEYPROVIDER_FAILED);
            }

            return Convert.ToInt32(ReturnValue.MSG_KEYPROVIDER_SUCCESS);
        }
Example #21
0
        private KeyInfo GetKeyTransaction(KeySearchCriteria criteria)
        {
            KeyInfo key = null;

            bool failed = false;
            using (KeyStoreContext context = new KeyStoreContext(false))
            {
                ObjectContext oCtx = ((IObjectContextAdapter)context).ObjectContext;
                oCtx.Connection.Open();
                DbTransaction trans = oCtx.Connection.BeginTransaction(System.Data.IsolationLevel.Serializable);
                try
                {
                    IQueryable<KeyInfo> query = context.KeyInfoes.Include("KeyInfoEx").OrderBy(k => k.FulfilledDateUtc);
                    if (!string.IsNullOrEmpty(criteria.MsPartNumber))
                        query = query.Where(k => k.LicensablePartNumber.Contains(criteria.MsPartNumber));
                    if (!string.IsNullOrEmpty(criteria.OemPoNumber))
                        query = query.Where(k => k.OemPoNumber.Contains(criteria.OemPoNumber));
                    if (criteria.HasOemPartNumberNull && string.IsNullOrEmpty(criteria.OemPartNumber))
                        query = query.Where(k => k.OemPartNumber == null || k.OemPartNumber == string.Empty);
                    if (!string.IsNullOrEmpty(criteria.OemPartNumber))
                        query = query.Where(k => k.OemPartNumber.Contains(criteria.OemPartNumber));
                    key = query.FirstOrDefault(k => k.KeyStateId == (int)KeyState.Fulfilled && !k.KeyInfoEx.IsInProgress);

                    if (key == null)
                        throw new ApplicationException("No key available.");

                    key.FactoryFloorAssembleKey();
                    if (key.KeyStateChanged)
                        context.KeyHistories.Add(new KeyHistory()
                        {
                            KeyId = key.KeyId,
                            KeyStateId = key.KeyStateId,
                            StateChangeDate = DateTime.Now
                        });
                    context.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    failed = true;
                }
                if (!failed)
                    trans.Commit();

                oCtx.Connection.Close();
            }
            if (failed)
                key = GetKeyTransaction(criteria);

            return key;
        }
Example #22
0
        private KeySearchCriteria[] GetBoundKeyToReportSearchCriteria(KeySearchCriteria searchCriteria)
        {
            var myCriteria = ConvertSearchCriteria(searchCriteria);
            var headQuarterCriteria = ConvertSearchCriteria(searchCriteria);

            myCriteria.HasHardwareHash = true;
            myCriteria.KeyType = KeyType.Standard;
            myCriteria.KeyState = KeyState.Bound;
            myCriteria.HqId = CurrentHeadQuarterId;
            if (Constants.InstallType == InstallType.Tpi)
            {
                if (!CurrentHeadQuarter.IsCentralizedMode)
                    myCriteria.IsInProgress = false;
            }
            else if (Constants.InstallType == InstallType.Oem)
                myCriteria.IsInProgress = false;
            return new KeySearchCriteria[] { myCriteria };
        }
Example #23
0
        /// <summary>
        /// Test function to validate the client to server connection, called from KeyProviderListener.
        /// </summary>
        /// <param name="message">Text output</param>
        /// <returns></returns>
        public int Ping(ref string productKeyInfo)
        {
            try
            {
                string parameters = ConfigurationManager.AppSettings["PingTestParameters"];

                MessageLogger.LogSystemRunning("Ping", "Parameters = " + parameters);

                XDocument param = ParseAndValidateXML(parameters, parameterSchema);

                // Get allocated key in store.
                KeySearchCriteria query = new KeySearchCriteria();
                query.PageSize = 1;
                query.KeyStates = new List<KeyState> { KeyState.Fulfilled };

                query = AttachParameters(query, param);
                if (query == null)
                {
                    return Convert.ToInt32(ReturnValue.MSG_KEYPROVIDER_XML_INVALID_PARAMETER);
                }

                var keys = keyProxy.SearchKeys(query);

                if (keys == null || keys.Count <= 0)
                {
                    return Convert.ToInt32(
                       ReturnValue.MSG_KEYPROVIDER_NO_KEYS_AVAILABLE_FOR_SPECIFIED_PARAMETERS);
                }
                KeyInfo key = keys.FirstOrDefault();

                XElement dm = new XElement("Key",
                    new XElement("ProductKey", key.ProductKey.ToString()),
                    new XElement("ProductKeyID", key.KeyId.ToString()),
                    new XElement("ProductKeyState", key.KeyState.ToString()),
                    new XElement("ProductKeyPartNumber", key.SkuId)
                );

                productKeyInfo = dm.ToString();
            }
            catch (Exception ex)
            {
                ExceptionHandler.HandleException(ex);

                if (ex.GetType() == typeof(EntityException))
                {
                    return Convert.ToInt32(ReturnValue.MSG_KEYPROVIDER_FAILED_DB_CONNECTION);
                }

                return Convert.ToInt32(ReturnValue.MSG_KEYPROVIDER_FAILED);
            }

            return Convert.ToInt32(ReturnValue.MSG_KEYPROVIDER_SUCCESS);
        }
Example #24
0
 public List<KeyInfo> SearchRecallKeys(KeySearchCriteria criteria)
 {
     return keyRepository.SearchKeys(
         GetRecallKeySearchCriteria(criteria));
 }
Example #25
0
        private KeySearchCriteria AttachParameters(KeySearchCriteria searchCriteria, XDocument parameterXml)
        {
            var query = searchCriteria;
            foreach (XElement element in parameterXml.Elements("Parameters").Descendants())
            {
                string parameterName = element.Attribute("name").Value;

                if (!section.AllKeys.Contains(parameterName))
                {
                    MessageLogger.LogSystemRunning("AttachParameters", "Invalid Parameters = " +
                        parameterXml.ToString(), TraceEventType.Warning);
                    return null;
                }

                string value = element.Attribute("value").Value;

                IParameter processor = Activator.CreateInstance(System.Type.GetType(section[parameterName])) as IParameter;
                processor.Attach(query, value);
            }
            return query;
        }
Example #26
0
        /// <summary>
        /// 
        /// </summary>
        public KeySearchCriteria FillSearchCriteria()
        {
            KeySearchCriteria KeySearchCriteria = new KeySearchCriteria();
            KeySearchCriteria.PageSize = KeySearchCriteria.DefaultPageSize;
            KeySearchCriteria.MsPartNumber = SearchMSNumber;
            KeySearchCriteria.OemPartNumber = SearchOEMNumber;
            KeySearchCriteria.OemPoNumber = SearchPONumber;
            KeySearchCriteria.DateFrom = BeginMsFulfiledDate;
            KeySearchCriteria.DateTo = EndMsFulfiledDate;
            KeySearchCriteria.OemRmaDateFrom = StartOemRMADate;
            KeySearchCriteria.OemRmaDateTo = EndOemRMADate;
            if (SelectedKeyType == MergedResources.Common_All)
                KeySearchCriteria.KeyType = KeyType.All;
            else
                KeySearchCriteria.KeyType = (KeyType)Enum.Parse(typeof(KeyType), SelectedKeyType, true);

            if (this.SelectedKeyState != null && this.SelectedKeyState != MergedResources.Common_All)
                KeySearchCriteria.KeyStates = new List<KeyState>() { (KeyState)Enum.Parse(typeof(KeyState), this.SelectedKeyState, true) };

            KeySearchCriteria.ProductKey = ProductKey;
            KeySearchCriteria.ProductKeyID = ProductKeyID;
            if (!string.IsNullOrEmpty(ProductKeyIDFrom))
                KeySearchCriteria.ProductKeyIDFrom = long.Parse(ProductKeyIDFrom);
            if (!string.IsNullOrEmpty(ProductKeyIDTo))
                KeySearchCriteria.ProductKeyIDTo = long.Parse(ProductKeyIDTo);

            return KeySearchCriteria;
        }
 public void Attach(KeySearchCriteria searchCriteria, object value)
 {
     searchCriteria.MSPartNumber = value.ToString();
 }
Example #28
0
 public List<KeyInfo> SearchBoundKeysToReport(KeySearchCriteria searchCriteria)
 {
     return keyRepository.SearchKeys(
         GetBoundKeyToReportSearchCriteria(searchCriteria));
 }