private static T SetFieldValue <T>(int mediaId, EListType listType, int atom, T newValue)
 {
     int[]    columnIndexes = new int[] { atom };
     object[] fieldValues   = new object[] { newValue };
     ZuneLibrary.SetFieldValues(mediaId, listType, 1, columnIndexes, fieldValues, new QueryPropertyBag());
     return((T)fieldValues[0]);
 }
 public UpdatePlayedStatesTask(
     bool markPlayed,
     bool incrementPlayCount,
     bool incrementSkipCount,
     int mediaID,
     EListType listType,
     ContainerPlayMarker containerPlayMarker)
 {
     this.MarkPlayed          = markPlayed;
     this.IncrementPlayCount  = incrementPlayCount;
     this.IncrementSkipCount  = incrementSkipCount;
     this.MediaID             = mediaID;
     this.ListType            = listType;
     this.ContainerPlayMarker = containerPlayMarker;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Automatically wires up the indicated repository to return the collection
        /// of mock/stub objects for all methods of type EListType.  Additionally,
        /// any methods of type EType will return the first item in the collection
        /// </summary>
        /// <typeparam name="RepositoryType">The repository type to wire up</typeparam>
        /// <typeparam name="EType">BO type of the repository</typeparam>
        /// <typeparam name="EListType">BO collection type</typeparam>
        /// <param name="entitiesToReturn">Mock/stub objects already configured</param>
        /// <returns>The mock repository wrapper for further configuration</returns>
        protected Mock <RepositoryType> AutoWireUpMockRepository <RepositoryType, EType, EListType>(params EType[] entitiesToReturn)
            where RepositoryType : class
            where EType : class
            where EListType : List <EType>, new()
        {
            //Use the MockingKernel to get a Mock repository object from the DI container
            Mock <RepositoryType> mockRepo = _mockContainer.GetMock <RepositoryType>();

            //Search for repo accessor methods
            typeof(RepositoryType).GetMethods()
            .Where(mi => mi.Name.StartsWith("Get"))
            .ForEach(mi =>
            {
                //Build a lamba expression in the format expected by the Moq, e.g.
                //  mockRepo.Setup(repo => repo.Getxxxxx(It.IsAny<T>, It.IsAny<T>, etc...))

                //the parameter for the lambda will therefore be a repository
                var parameter = Expression.Parameter(typeof(RepositoryType));

                //The body will be a function call on the repo that matches this particular method
                var body = Expression.Call(parameter, mi,

                                           //Since we don't care what parameters are passed (for this simple repo mock)
                                           //match each parameter to a generic call of It.IsAny<ParamType>
                                           mi.GetParameters().Select(pi =>
                                                                     Expression.Call(typeof(It), "IsAny", new Type[] { pi.ParameterType })));

                if (mi.ReturnType.Equals(typeof(EListType)))
                {
                    //For collection types, return all indicated items
                    var lambdaExpression    = Expression.Lambda <Func <RepositoryType, EListType> >(body, parameter);
                    EListType newCollection = new EListType();
                    newCollection.AddRange(entitiesToReturn);
                    mockRepo.Setup(lambdaExpression).Returns(newCollection);
                }
                else if (mi.ReturnType.Equals(typeof(EType)))
                {
                    //For accessors returning a single item, pick the first item in the collection
                    var lambdaExpression = Expression.Lambda <Func <RepositoryType, EType> >(body, parameter);
                    mockRepo.Setup(lambdaExpression).Returns(
                        entitiesToReturn.Length == 0
                            ? (EType)null
                            : entitiesToReturn.First());
                }
            });

            return(mockRepo);
        }
 public LibraryPlaybackTrack(
     int mediaId,
     MediaType mediaType,
     ContainerPlayMarker containerPlayMarker)
 {
     this._mediaId             = mediaId;
     this._mediaType           = mediaType;
     this._listType            = PlaylistManager.MediaTypeToListType(mediaType);
     this._containerPlayMarker = containerPlayMarker;
     ThreadPool.QueueUserWorkItem(args =>
     {
         this._isInCollection = PlaylistManager.IsInCollection(this._mediaId, this._mediaType);
         Application.DeferredInvoke(delegate
         {
             this.RatingChanged.Invoke();
         }, null);
     }, null);
 }
        private void UpdatePlayedStates(
            bool markPlayed,
            bool incrementPlayCount,
            bool incrementSkipCount)
        {
            int mediaId = this.MediaId;

            if (mediaId == -1)
            {
                return;
            }
            EListType           listType            = this.ListType;
            ContainerPlayMarker containerPlayMarker = this._containerPlayMarker;

            ThreadPool.QueueUserWorkItem(new WaitCallback(UpdatePlayedStatesWorker), new UpdatePlayedStatesTask(markPlayed, incrementPlayCount, incrementSkipCount, mediaId, listType, containerPlayMarker));
            bool flag = this._containerPlayMarker != null && this._containerPlayMarker.PlaylistType == PlaylistType.QuickMix;

            if (incrementPlayCount)
            {
                if (this._mediaType == MediaType.Track)
                {
                    ++Shell.MainFrame.Social.PlayCount;
                }
                if (flag)
                {
                    SQMLog.Log(SQMDataId.QuickMixTrackPlays, 1);
                }
            }
            if (!incrementSkipCount || !flag)
            {
                return;
            }
            if (this.IsInVisibleCollection)
            {
                SQMLog.Log(SQMDataId.QuickMixLocalSkips, 1);
            }
            else
            {
                SQMLog.Log(SQMDataId.QuickMixRemoteSkips, 1);
            }
        }
 /// <inheritdoc />
 public CList(EListType listType, IEnumerable <object> elements) : base(listType, elements)
 {
     CachingType = ECachingType.Cacheable;
 }
 /// <inheritdoc />
 public CList(EListType listType, params object[] elements) : base(listType, elements)
 {
     CachingType = ECachingType.Cacheable;
 }
 /// <inheritdoc />
 public CList(EListType listType) : base(listType)
 {
     CachingType = ECachingType.Cacheable;
 }
        private static void UpdatePlayedStatesWorker(object o)
        {
            if (!(o is UpdatePlayedStatesTask playedStatesTask))
            {
                return;
            }
            int num1 = 0;
            int num2 = 0;
            int num3 = 0;

            int[]    columnIndexes = new int[7];
            object[] fieldValues   = new object[7];
            if (playedStatesTask.IncrementPlayCount)
            {
                columnIndexes[0] = 367;
                fieldValues[0]   = 0;
                ZuneLibrary.GetFieldValues(playedStatesTask.MediaID, playedStatesTask.ListType, 1, columnIndexes, fieldValues, PlaylistManager.Instance.QueryContext);
                num2             = (int)fieldValues[0];
                columnIndexes[0] = 366;
                fieldValues[0]   = 0;
                ZuneLibrary.GetFieldValues(playedStatesTask.MediaID, playedStatesTask.ListType, 1, columnIndexes, fieldValues, PlaylistManager.Instance.QueryContext);
                num1 = (int)fieldValues[0];
            }
            if (playedStatesTask.IncrementSkipCount)
            {
                columnIndexes[0] = 374;
                fieldValues[0]   = 0;
                ZuneLibrary.GetFieldValues(playedStatesTask.MediaID, playedStatesTask.ListType, 1, columnIndexes, fieldValues, PlaylistManager.Instance.QueryContext);
                num3 = (int)fieldValues[0];
            }
            int cValues = 0;

            if (playedStatesTask.MarkPlayed)
            {
                columnIndexes[cValues] = 262;
                fieldValues[cValues]   = 1;
                ++cValues;
            }
            if (playedStatesTask.IncrementPlayCount)
            {
                int num4 = num2 + 1;
                columnIndexes[cValues] = 367;
                fieldValues[cValues]   = num4;
                int index1 = cValues + 1;
                int num5   = num1 + 1;
                columnIndexes[index1] = 366;
                fieldValues[index1]   = num5;
                int index2 = index1 + 1;
                columnIndexes[index2] = 363;
                fieldValues[index2]   = DateTime.UtcNow;
                cValues = index2 + 1;
            }
            if (playedStatesTask.IncrementSkipCount)
            {
                int num4 = num3 + 1;
                columnIndexes[cValues] = 374;
                fieldValues[cValues]   = num4;
                int index = cValues + 1;
                columnIndexes[index] = 365;
                fieldValues[index]   = DateTime.UtcNow;
                cValues = index + 1;
            }
            if (cValues > 0)
            {
                ZuneLibrary.SetFieldValues(playedStatesTask.MediaID, playedStatesTask.ListType, cValues, columnIndexes, fieldValues, PlaylistManager.Instance.QueryContext);
            }
            if (!playedStatesTask.IncrementPlayCount || playedStatesTask.ContainerPlayMarker == null)
            {
                return;
            }
            bool flag = false;

            lock (playedStatesTask.ContainerPlayMarker)
            {
                if (!playedStatesTask.ContainerPlayMarker.Marked)
                {
                    playedStatesTask.ContainerPlayMarker.Marked = true;
                    flag = true;
                }
            }
            if (!flag)
            {
                return;
            }
            if (playedStatesTask.ContainerPlayMarker.LibraryId == -1 && playedStatesTask.ListType == EListType.eTrackList)
            {
                fieldValues[0] = -1;
                if (playedStatesTask.ContainerPlayMarker.MediaType == MediaType.Album)
                {
                    columnIndexes[0] = 11;
                    ZuneLibrary.GetFieldValues(playedStatesTask.MediaID, playedStatesTask.ListType, 1, columnIndexes, fieldValues, PlaylistManager.Instance.QueryContext);
                    playedStatesTask.ContainerPlayMarker.LibraryId = (int)fieldValues[0];
                }
                else if (playedStatesTask.ContainerPlayMarker.MediaType == MediaType.Genre)
                {
                    columnIndexes[0] = 399;
                    ZuneLibrary.GetFieldValues(playedStatesTask.MediaID, playedStatesTask.ListType, 1, columnIndexes, fieldValues, PlaylistManager.Instance.QueryContext);
                    playedStatesTask.ContainerPlayMarker.LibraryId = (int)fieldValues[0];
                }
                else if (playedStatesTask.ContainerPlayMarker.MediaType == MediaType.Artist)
                {
                    columnIndexes[0] = 11;
                    ZuneLibrary.GetFieldValues(playedStatesTask.MediaID, playedStatesTask.ListType, 1, columnIndexes, fieldValues, PlaylistManager.Instance.QueryContext);
                    int iMediaId = (int)fieldValues[0];
                    fieldValues[0]   = -1;
                    columnIndexes[0] = 78;
                    ZuneLibrary.GetFieldValues(iMediaId, EListType.eAlbumList, 1, columnIndexes, fieldValues, PlaylistManager.Instance.QueryContext);
                    playedStatesTask.ContainerPlayMarker.LibraryId = (int)fieldValues[0];
                }
            }
            if (playedStatesTask.ContainerPlayMarker.LibraryId == -1)
            {
                return;
            }
            columnIndexes[0] = 363;
            fieldValues[0]   = DateTime.UtcNow;
            EListType listType = PlaylistManager.MediaTypeToListType(playedStatesTask.ContainerPlayMarker.MediaType);

            ZuneLibrary.SetFieldValues(playedStatesTask.ContainerPlayMarker.LibraryId, listType, 1, columnIndexes, fieldValues, PlaylistManager.Instance.QueryContext);
        }