示例#1
0
文件: App.cs 项目: ian2009/OpenBVE
        internal void SaveFile()
        {
            if (string.IsNullOrEmpty(SaveLocation))
            {
                SaveAsFile();
                return;
            }

            try
            {
                IntermediateFile.Write(saveLocation, Train, Panel, Sound);

                SystemSounds.Asterisk.Play();
            }
            catch (Exception e)
            {
                MessageBox = new MessageBox
                {
                    Title  = Utilities.GetInterfaceString("menu", "file", "save"),
                    Icon   = BaseDialog.DialogIcon.Error,
                    Button = BaseDialog.DialogButton.Ok,
                    Text   = e.Message,
                    IsOpen = true
                };
            }
        }
示例#2
0
文件: App.cs 项目: ian2009/OpenBVE
        internal void SaveAsFile()
        {
            SaveFileDialog = new SaveFileDialog
            {
                Filter          = @"Intermediate files (*.te)|*.te|All files (*.*)|*",
                OverwritePrompt = true,
                IsOpen          = true
            };

            if (SaveFileDialog.DialogResult != true)
            {
                return;
            }

            SaveLocation = SaveFileDialog.FileName;

            try
            {
                IntermediateFile.Write(saveLocation, Train, Panel, Sound);
            }
            catch (Exception e)
            {
                MessageBox = new MessageBox
                {
                    Title  = Utilities.GetInterfaceString("menu", "file", "save_as"),
                    Icon   = BaseDialog.DialogIcon.Error,
                    Button = BaseDialog.DialogButton.Ok,
                    Text   = e.Message,
                    IsOpen = true
                };

                SaveLocation = string.Empty;
            }
        }
示例#3
0
        /// <summary>
        /// Spills the In-Memory store to the disk if needed.
        /// The spill condition is dependant on the combine store's content volume and maximum intermediate pairs to spill.
        /// </summary>
        /// <param name="final_spill">is this the final spill? means data must be spilled even if there is a little data</param>
        /// <param name="thread_num">number of threads to use for soritng. The default is to use all cores.</param>
        /// <returns>a string containing the name of resulted file.</returns>
        public string doSpillIfNeeded(bool final_spill = false, int thread_num = -1)
        {
            if (combinedDictionary.Count > 0 && (intermediatePairCount + combinedDictionary.Count > maxIntermediatePairsToSpill || final_spill))
            {
                Stopwatch watch = new Stopwatch();
                watch.Restart();
                KeyValuePair <InterKey, List <InterValue> >[] sorted_pairs;
                if (thread_num <= 0)
                {
                    sorted_pairs = combinedDictionary.AsParallel().OrderBy(t => t.Key).ToArray();
                }
                else
                {
                    sorted_pairs = combinedDictionary.AsParallel().WithDegreeOfParallelism(thread_num).OrderBy(t => t.Key).ToArray();
                }
                combinedDictionary.Clear();
                intermediatePairCount = 0;

                mapperInfo.SpilledRecords += sorted_pairs.Count();
                watch.Stop();
                logger.Debug("Sorted {0} records in {1}.", StringFormatter.DigitGrouped(sorted_pairs.Count()), watch.Elapsed);
                IntermediateFile <InterKey, InterValue> inter_file = new IntermediateFile <InterKey, InterValue>(tempDirectory, mapperID);
                long written_bytes = 0;
                written_bytes            = inter_file.WriteRecords(sorted_pairs);
                mapperInfo.SpilledBytes += written_bytes;
                inter_file.Close();

                if (!final_spill && written_bytes > 0)
                {
                    if (written_bytes < maxIntermediateFileSize)
                    {
                        maxIntermediatePairsToSpill = (int)(maxIntermediatePairsToSpill * (double)(maxIntermediateFileSize) / written_bytes);
                        logger.Debug("maxIntermediatePairsToSpill was set to {0} records.", StringFormatter.DigitGrouped(maxIntermediatePairsToSpill));
                    }
                    if (written_bytes > 1.5 * maxIntermediateFileSize)
                    {
                        maxIntermediatePairsToSpill /= 2;
                        logger.Debug("maxIntermediatePairsToSpill was set to {0} records.", StringFormatter.DigitGrouped(maxIntermediatePairsToSpill));
                    }
                }

                return(inter_file.Path);
            }
            return(null);
        }
示例#4
0
文件: App.cs 项目: ian2009/OpenBVE
        internal void OpenFile()
        {
            MessageBox = new MessageBox
            {
                Title  = Utilities.GetInterfaceString("menu", "file", "open"),
                Icon   = BaseDialog.DialogIcon.Question,
                Button = BaseDialog.DialogButton.YesNoCancel,
                Text   = Utilities.GetInterfaceString("menu", "message", "open"),
                IsOpen = true
            };

            if (MessageBox.DialogResult == null)
            {
                return;
            }

            if (MessageBox.DialogResult == true)
            {
                SaveFile();
            }

            Interface.LogMessages.Clear();

            OpenFileDialog = new OpenFileDialog
            {
                Filter          = @"Intermediate files (*.te)|*.te|All files (*.*)|*",
                CheckFileExists = true,
                IsOpen          = true
            };

            if (OpenFileDialog.DialogResult != true)
            {
                return;
            }

            SaveLocation = OpenFileDialog.FileName;

            try
            {
                IntermediateFile.Parse(SaveLocation, out train, out panel, out sound);

                OnPropertyChanged(new PropertyChangedEventArgs(nameof(Train)));
                OnPropertyChanged(new PropertyChangedEventArgs(nameof(Panel)));
                OnPropertyChanged(new PropertyChangedEventArgs(nameof(Sound)));

                CreateItem();
            }
            catch (Exception e)
            {
                if (e is XmlException && SaveLocation.ToLowerInvariant().EndsWith(".dat") || e is InvalidDataException)
                {
                    /* At the minute, we need to use the import function to get existing trains into TrainEditor2
                     * Detect this is actually an existing train format and show a more useful error message
                     */
                    MessageBox = new MessageBox
                    {
                        Title  = Utilities.GetInterfaceString("menu", "file", "open"),
                        Icon   = BaseDialog.DialogIcon.Error,
                        Button = BaseDialog.DialogButton.Ok,
                        Text   = Utilities.GetInterfaceString("menu", "file", "wrongtype"),
                        IsOpen = true
                    };
                }
                else
                {
                    /* Generic error message-
                     * This isn't a file we recognise
                     */
                    MessageBox = new MessageBox
                    {
                        Title  = Utilities.GetInterfaceString("menu", "file", "open"),
                        Icon   = BaseDialog.DialogIcon.Error,
                        Button = BaseDialog.DialogButton.Ok,
                        Text   = e.Message,
                        IsOpen = true
                    };
                }


                SaveLocation = string.Empty;

                train = null;
                panel = null;
                sound = null;

                CreateNewFile();
            }
        }