예제 #1
0
            /// <summary>
            /// Sets the channel-specific properties of the specified channel.
            /// </summary>
            /// <param name="request">The update channel properties by channel id data request.</param>
            /// <returns>A null response.</returns>
            private NullResponse UpdateChannelPropertiesByChannelId(UpdateChannelPropertiesByChannelIdDataRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.Null(request.ChannelProperties, "request.ChannelProperties");

                ChannelL2CacheDataStoreAccessor level2CacheDataAccessor = this.GetChannelL2CacheDataStoreAccessor(request.RequestContext);

                bool updateL2Cache = DataStoreManager.DataStores[DataStoreType.L2Cache].Policy.MustUpdateOnMiss &&
                                     request.ChannelProperties.Count() < MaxCachedCollectionSize;

                Stopwatch processTimer = Stopwatch.StartNew();

                foreach (ChannelProperty channelProperty in request.ChannelProperties)
                {
                    ParameterSet parameters = new ParameterSet();
                    parameters["@bi_ChannelId"]      = request.ChannelId;
                    parameters["@nvc_PropertyName"]  = channelProperty.Name;
                    parameters["@nvc_PropertyValue"] = channelProperty.Value;

                    int errorCode;

                    using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request))
                    {
                        errorCode = sqlServerDatabaseContext.ExecuteStoredProcedureNonQuery(SaveChannelPropertySprocName, parameters);
                    }

                    if (errorCode != (int)DatabaseErrorCodes.Success)
                    {
                        throw new StorageException(StorageErrors.Microsoft_Dynamics_Commerce_Runtime_CriticalStorageError, errorCode, "Unable to update channel properties.");
                    }
                }

                processTimer.Stop();
                NetTracer.Information("** timer info: UpdateChannelPropertiesByChannelId completed in {0} ms", processTimer.ElapsedMilliseconds);

                if (updateL2Cache)
                {
                    level2CacheDataAccessor.PutChannelPropertiesByChannelId(request.ChannelId, QueryResultSettings.AllRecords, request.ChannelProperties.AsPagedResult());
                }

                return(new NullResponse());
            }
예제 #2
0
            /// <summary>
            /// Gets the Income and expense accounts.
            /// </summary>
            /// <param name="request">Get income expense accounts data request.</param>
            /// <returns>Returns the collection of income expense account.</returns>
            private EntityDataServiceResponse <IncomeExpenseAccount> GetIncomeExpenseAccounts(GetIncomeExpenseAccountsDataRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.Null(request.QueryResultSettings, "request.QueryResultSettings");

                ChannelL2CacheDataStoreAccessor level2CacheDataAccessor = this.GetChannelL2CacheDataStoreAccessor(request.RequestContext);

                bool found;
                bool updateL2Cache;
                PagedResult <IncomeExpenseAccount> result = DataManager.GetDataFromCache(() => level2CacheDataAccessor.GetIncomeExpenseAccounts(request.IncomeExpenseType, request.QueryResultSettings), out found, out updateL2Cache);

                if (!found)
                {
                    string dataAreaId  = request.RequestContext.GetChannelConfiguration().InventLocationDataAreaId;
                    string storeNumber = request.RequestContext.GetOrgUnit().OrgUnitNumber;

                    var parameters = new ParameterSet();

                    parameters["@nvc_StoreId"]    = storeNumber;
                    parameters["@nvc_DataAreaId"] = dataAreaId;
                    parameters["@i_AccountType"]  = request.IncomeExpenseType;

                    using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request))
                    {
                        result = sqlServerDatabaseContext.ExecuteStoredProcedure <IncomeExpenseAccount>(GetRetailIncomeExpenseAccounts, parameters);
                    }

                    updateL2Cache &= result != null &&
                                     result.Results.Count < MaxCachedCollectionSize;
                }

                if (updateL2Cache)
                {
                    level2CacheDataAccessor.PutIncomeExpenseAccounts(request.IncomeExpenseType, request.QueryResultSettings, result);
                }

                return(new EntityDataServiceResponse <IncomeExpenseAccount>(result));
            }
예제 #3
0
            /// <summary>
            /// Resolves operating unit number.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>The channel Id corresponding to the Operating Unit Number.</returns>
            private SingleEntityDataServiceResponse <long> ResolveOperatingUnitNumber(ResolveOperatingUnitNumberDataRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.Null(request.QueryResultSettings, "request.QueryResultSettings");

                ChannelL2CacheDataStoreAccessor level2CacheDataAccessor = this.GetChannelL2CacheDataStoreAccessor(request.RequestContext);
                bool foundInCache;
                bool updateCache;

                const long InvalidChannelId = 0;
                long       channelId        = DataManager.GetDataFromCache(() => level2CacheDataAccessor.GetChannelIdByOperatingUnitNumber(request.OperatingUnitNumber), InvalidChannelId, out foundInCache, out updateCache);

                if (!foundInCache)
                {
                    var query = new SqlPagedQuery(request.QueryResultSettings)
                    {
                        Select = new ColumnSet(ChannelIdColumnName),
                        From   = StorageLookupView,
                        Where  = "ISPUBLISHED = 1 AND OPERATINGUNITNUMBER = @oun",
                    };

                    query.Parameters["@oun"] = request.OperatingUnitNumber;

                    using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request))
                    {
                        channelId = sqlServerDatabaseContext.ExecuteScalar <long>(query);
                    }
                }

                if (updateCache)
                {
                    level2CacheDataAccessor.PutChannelIdByOperatingUnitNumber(request.OperatingUnitNumber, channelId);
                }

                return(new SingleEntityDataServiceResponse <long>(channelId));
            }