예제 #1
0
        private dynamic ImportConfiguration(ModulesExportDto dto)
        {
            var state = _audioEngine.IsRunning;

            try
            {
                if (state)
                {
                    _audioEngine.Stop();
                }

                if (dto?.Modules == null)
                {
                    return(false);
                }

                if (!_connectionService.Truncate())
                {
                    _logger.Error("Could not truncate the connections table.");
                    return(false);
                }

                if (!_moduleService.Truncate())
                {
                    _logger.Error("Could not truncate the modules table.");
                    return(false);
                }

                var moduleIdMap = new Dictionary <long, long>();

                foreach (var moduleDto in dto.Modules)
                {
                    var oldId = moduleDto.Id;
                    _moduleService.Insert(moduleDto);
                    moduleIdMap.Add(oldId, moduleDto.Id);
                }

                foreach (var connectionDto in dto.Connections)
                {
                    if (moduleIdMap.TryGetValue(connectionDto.SourceId, out var newSourceId) &&
                        moduleIdMap.TryGetValue(connectionDto.TargetId, out var newTargetId))
                    {
                        connectionDto.SourceId = newSourceId;
                        connectionDto.TargetId = newTargetId;
                        _connectionService.Insert(connectionDto);
                    }
                }

                return(true);
            }
            finally
            {
                if (state)
                {
                    _audioEngine.Start();
                }
            }
        }
예제 #2
0
        private object InsertConnection(ModuleConnectionDto connectionDto)
        {
            if (connectionDto.SourceId <= 0 || connectionDto.TargetId <= 0)
            {
                return(false);
            }

            if (!_moduleConnectionService.Insert(connectionDto))
            {
                return(false);
            }

            _audioEngine.AddConnection(connectionDto.Id);

            return(connectionDto);
        }