예제 #1
0
 private void TRHandler()         // separated to method expecting reuse, may not be necessary
 {
     if (!tr)
     {
         tr = DictionaryManager.GetTrackResourceForVessel(vessel);
     }
 }
예제 #2
0
        public override void OnStart(PartModule.StartState state)
        {
            reagent1.definition = PartResourceLibrary.Instance.GetDefinition(resource1);
            reagent1.definition = PartResourceLibrary.Instance.GetDefinition(resource2);
            electric.definition = PartResourceLibrary.Instance.GetDefinition("ElectricCharge");

            tr = DictionaryManager.GetTrackResourceForVessel(vessel);

            BuildResourceDirectory();

            checkTimer.Setup(100);
        }
예제 #3
0
        private static Track MapTrack(TrackResource resource, Dictionary <string, ArtistMetadata> artistDict)
        {
            Track track = new Track
            {
                ArtistMetadata         = artistDict[resource.ArtistId],
                Title                  = resource.TrackName,
                ForeignTrackId         = resource.Id,
                OldForeignTrackIds     = resource.OldIds,
                ForeignRecordingId     = resource.RecordingId,
                OldForeignRecordingIds = resource.OldRecordingIds,
                TrackNumber            = resource.TrackNumber,
                AbsoluteTrackNumber    = resource.TrackPosition,
                Duration               = resource.DurationMs,
                MediumNumber           = resource.MediumNumber
            };

            return(track);
        }
예제 #4
0
        private void UpdateAudioResources(IList <TrackRecordingData> trackRecordings, Dictionary <long, List <AudioResource> > dbAudioGroups,
                                          TrackResource dbTrack, Project project, User user, DateTime now, Dictionary <string, FileResource> fileNameMapping,
                                          List <long> updatedAudioResourceIds)
        {
            List <AudioResource> dbAudioResources;

            if (!dbAudioGroups.TryGetValue(dbTrack.Resource.Id, out dbAudioResources))
            {
                dbAudioResources = new List <AudioResource>();
            }

            if (trackRecordings != null)
            {
                foreach (var trackRecordingData in trackRecordings)
                {
                    var dbAudioResource = dbAudioResources.FirstOrDefault(x => x.FileName == trackRecordingData.FileName);
                    if (dbAudioResource == null)
                    {
                        var newDbResource = new Resource
                        {
                            Name         = trackRecordingData.FileName,
                            ContentType  = ContentTypeEnum.AudioTrack,
                            ResourceType = ResourceTypeEnum.Audio,
                            Project      = project,
                        };

                        CreateAudioResource(newDbResource, dbTrack.Resource, 1, trackRecordingData, user, now, fileNameMapping);
                    }
                    else
                    {
                        CreateAudioResource(dbAudioResource.Resource, dbTrack.Resource, dbAudioResource.VersionNumber + 1, trackRecordingData, user, now, fileNameMapping);
                        updatedAudioResourceIds.Add(dbAudioResource.Id);
                    }
                }
            }
        }
예제 #5
0
        protected override void ExecuteWorkImplementation()
        {
            var now  = DateTime.UtcNow;
            var user = m_resourceRepository.Load <User>(m_userId);
            var resourceBeginningPage = m_trackData.BeginningPageId != null
                ? m_resourceRepository.Load <Resource>(m_trackData.BeginningPageId.Value)
                : null;

            var resourceChapter = m_trackData.ChapterId != null
                ? m_resourceRepository.Load <Resource>(m_trackData.ChapterId.Value)
                : null;

            if ((m_projectId == null && m_resourceId == null) || (m_projectId != null && m_resourceId != null))
            {
                throw new MainServiceException(MainServiceErrorCode.ProjectIdOrResourceId, "Exactly one parameter (ProjectId or ResourceId) has to be specified");
            }

            var trackResource = new TrackResource
            {
                Name                  = m_trackData.Name,
                Text                  = m_trackData.Text,
                Comment               = m_trackData.Comment,
                Position              = m_trackData.Position,
                ResourceChapter       = resourceChapter,
                ResourceBeginningPage = resourceBeginningPage,
                Resource              = null,
                VersionNumber         = 0,
                CreateTime            = now,
                CreatedByUser         = user,
            };

            if (m_resourceId != null)
            {
                var latestTrackResource = m_resourceRepository.GetLatestResourceVersion <TrackResource>(m_resourceId.Value);
                if (latestTrackResource == null)
                {
                    throw new MainServiceException(MainServiceErrorCode.EntityNotFound, "The entity was not found.");
                }

                trackResource.Resource      = latestTrackResource.Resource;
                trackResource.VersionNumber = latestTrackResource.VersionNumber + 1;
            }
            else
            {
                var resource = new Resource
                {
                    ContentType  = ContentTypeEnum.AudioTrack,
                    ResourceType = ResourceTypeEnum.AudioTrack,
                    Project      = m_resourceRepository.Load <Project>(m_projectId),
                };

                trackResource.Resource      = resource;
                trackResource.VersionNumber = 1;
            }

            trackResource.Resource.Name          = m_trackData.Name;
            trackResource.Resource.LatestVersion = trackResource;

            m_resourceRepository.Create(trackResource);

            ResourceId = trackResource.Resource.Id;
            VersionId  = trackResource.Id;
        }
        public override void OnStart(PartModule.StartState state)
        {
            reagent1.definition = PartResourceLibrary.Instance.GetDefinition(resource1);
            reagent1.definition = PartResourceLibrary.Instance.GetDefinition(resource2);
            electric.definition = PartResourceLibrary.Instance.GetDefinition("ElectricCharge");

            tr = DictionaryManager.GetTrackResourceForVessel(vessel);

            BuildResourceDirectory();

            checkTimer.Setup(100);
        }
 // separated to method expecting reuse, may not be necessary
 private void TRHandler()
 {
     if (!tr)
     {
         tr = DictionaryManager.GetTrackResourceForVessel (vessel);
     }
 }
예제 #8
0
        public void UpdateTracks(long projectId, int userId, BookData bookData)
        {
            if (bookData.Tracks == null)
            {
                return;
            }

            var updatedTrackResourceIds = new List <long>();
            var updatedAudioResourceIds = new List <long>();
            var now     = DateTime.UtcNow;
            var project = m_resourceRepository.Load <Project>(projectId);
            var user    = m_resourceRepository.Load <User>(userId);

            var dbTracks    = m_resourceRepository.GetProjectLatestTracks(projectId);
            var dbAudioList = m_resourceRepository.GetProjectLatestAudioResources(projectId)
                              .Where(x => x.ResourceTrack != null)
                              .ToList();
            var dbAudioGroups = dbAudioList
                                .GroupBy(x => x.ResourceTrack.Id)
                                .ToDictionary(x => x.Key, x => x.ToList());

            foreach (var track in bookData.Tracks)
            {
                var dbTrack = dbTracks.FirstOrDefault(x => x.Name == track.Name);

                var newDbTrack = new TrackResource
                {
                    VersionNumber = 0,
                    Resource      = null,
                    Comment       = string.Empty,
                    CreatedByUser = user,
                    CreateTime    = now,
                    Name          = track.Name,
                    Text          = track.Text,
                    Position      = track.Position,
                };

                if (dbTrack == null)
                {
                    var newResource = new Resource
                    {
                        Project      = project,
                        Name         = track.Name,
                        ContentType  = ContentTypeEnum.AudioTrack,
                        ResourceType = ResourceTypeEnum.AudioTrack,
                    };

                    newDbTrack.Resource      = newResource;
                    newDbTrack.VersionNumber = 1;
                }
                else
                {
                    newDbTrack.Resource      = dbTrack.Resource;
                    newDbTrack.VersionNumber = dbTrack.VersionNumber + 1;

                    updatedTrackResourceIds.Add(dbTrack.Id);
                }

                newDbTrack.Resource.LatestVersion = newDbTrack;

                m_resourceRepository.Create(newDbTrack);


                m_allImportedResourceVersionIds.Add(newDbTrack.Id);
                UpdateAudioResources(track.Recordings, dbAudioGroups, newDbTrack, project, user, now, bookData.FileNameMapping, updatedAudioResourceIds);
            }

            // Remove unused resources
            var unusedDbTracks = dbTracks.Where(x => !updatedTrackResourceIds.Contains(x.Id));

            RemoveResourceVersions(unusedDbTracks);

            var unusedDbAudioList = dbAudioList.Where(x => !updatedAudioResourceIds.Contains(x.Id));

            RemoveResourceVersions(unusedDbAudioList);
        }
예제 #9
0
 private bool IsTrackUpdated(TrackResource dbTrack, TrackData trackData)
 {
     return(dbTrack.Name != trackData.Name ||
            dbTrack.Text != trackData.Text ||
            dbTrack.Position != trackData.Position);
 }