Beispiel #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();
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Serializes the <paramref name="data"/> to a file.
        /// </summary>
        /// <param name="fileName">The full file name to serialize the data to.</param>
        /// <param name="data">The data to serialize.</param>
        public bool Export(string fileName, ModulesExportDto data)
        {
            try
            {
                using (var fs = new StreamWriter(fileName))
                    using (var jsonWriter = new JsonTextWriter(fs))
                    {
                        var serializer = JsonSerializer.CreateDefault();
                        serializer.Serialize(jsonWriter, data);
                    }

                return(true);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                return(false);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Stops the engine if it is running, deletes all existing modules and connections,
        /// imports all modules and connections from the specified data and then restarts the engine if it was running before the import.
        /// </summary>
        public async Task <bool> ImportConfigurationAsync(ModulesExportDto dto)
        {
            var response = await _apiClient.SendMessageAsync(ResourceName, "import", dto).ConfigureAwait(false);

            return(response.IsSuccess);
        }