Esempio n. 1
0
        public bool Save(string filePath)
        {
            // workaround to save indices instead of ids
            var effectSelectorInCommands  = getCriticalEffectSelectorInCommands();
            var effectSelectorOutCommands = getCriticalEffectSelectorOutCommands();

            bool prepared = false;

            if (!_ignoreFx && (effectSelectorInCommands.Any() || effectSelectorOutCommands.Any()))
            {
                if (FxSettings == null)
                {
                    FxSettings = (TraktorSettings.Initialized) ? TraktorSettings.Instance.FxSettings : createDefaultFxSettings();
                }

                prepareFxForSave(effectSelectorInCommands, effectSelectorOutCommands);
                prepared = true;
            }

            // build controller config (binary)
            DeviceIoConfigController controllerConfig = null;

            try
            {
                string tsiData = getDataAsBase64String();
                controllerConfig       = new DeviceIoConfigController();
                controllerConfig.Value = tsiData;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error building controller config. Reason: " + ex.Message);
                return(false);
            }

            if (prepared)
            {
                restoreEffectSelectorCommands(effectSelectorInCommands, effectSelectorOutCommands);
            }

            // build xml document
            try
            {
                TsiXmlDocument xml = (Path != null) ? new TsiXmlDocument(Path) : new TsiXmlDocument();
                if (FxSettings != null && (effectSelectorInCommands.Any() || effectSelectorOutCommands.Any()))
                {
                    FxSettings.Save(xml);
                }
                xml.SaveEntry(controllerConfig);
                xml.Save(filePath);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error building xml document. Reason: " + ex.Message);
                return(false);
            }

            Path = filePath;
            return(true);
        }
Esempio n. 2
0
        public bool Save(string filePath, bool optimizeFXList, bool backup = false)
        {
            // workaround to save indices (position on a list) instead of ids (actual command)
            var effectSelectorInCommands  = getCriticalEffectSelectorInCommands();
            var effectSelectorOutCommands = getCriticalEffectSelectorOutCommands();

            OptimizeFXList = optimizeFXList;

            bool prepared = false;

            if (!_ignoreFx && (effectSelectorInCommands.Any() || effectSelectorOutCommands.Any()))
            {
                if (FxSettings == null)
                {
                    FxSettings = (TraktorSettings.Initialized) ? TraktorSettings.Instance.FxSettings : createDefaultFxSettings();
                }

                prepareFxForSave(effectSelectorInCommands, effectSelectorOutCommands);
                prepared = true;
            }

            // build controller config (binary)
            DeviceIoConfigController controllerConfigController = null;
            DeviceIoConfigKeyboard   controllerConfigKeyboard   = null;

            var all_devices      = _devices.Select(d => d).ToList();
            var only_keyboard    = _devices.Where(d => (d.IsKeyboard == true)).ToList();
            var only_controllers = _devices.Where(d => (d.IsKeyboard == false)).ToList();

            try {
                if (only_controllers.Any())
                {
                    string tsiDataController = getDataAsBase64String(false);
                    controllerConfigController       = new DeviceIoConfigController();
                    controllerConfigController.Value = tsiDataController;
                }

                if (only_keyboard.Any())
                {
                    string tsiDataKeyboard = getDataAsBase64String(true);
                    controllerConfigKeyboard       = new DeviceIoConfigKeyboard();
                    controllerConfigKeyboard.Value = tsiDataKeyboard;
                }
            }
            catch (Exception ex)
            {
                // FIXME: show this to the user somehow
                //   at least a show console option

                // Exception thrown: 'System.OutOfMemoryException' in mscorlib.dll
                // Error building controller config. Reason: Exception of type 'System.OutOfMemoryException' was thrown.

                Debug.WriteLine("Error building controller config. Reason: " + ex.Message);
                return(false);
            }

            if (prepared)
            {
                restoreEffectSelectorCommands(effectSelectorInCommands, effectSelectorOutCommands);
            }

            // build xml document
            try
            {
                TsiXmlDocument xml = (Path != null) ? new TsiXmlDocument(Path) : new TsiXmlDocument();
                if (FxSettings != null && (effectSelectorInCommands.Any() || effectSelectorOutCommands.Any()))
                {
                    FxSettings.Save(xml);
                }

                if (only_controllers.Any())
                {
                    xml.SaveEntry(controllerConfigController);
                }
                if (only_keyboard.Any())
                {
                    xml.SaveEntry(controllerConfigKeyboard);
                }

                xml.Save(filePath);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error building xml document. Reason: " + ex.Message);
                return(false);
            }

            if (!backup)
            {
                Path = filePath;
            }
            return(true);
        }