public ResourceReportViewModel(BaseViewModel parentViewModel, ResourceReportModel dataModel, IDialogService dialogService, Func<ISaveFileDialog> saveFileDialogFactory)
            : base(parentViewModel)
        {
            Contract.Requires(dialogService != null);
            Contract.Requires(saveFileDialogFactory != null);

            _dialogService = dialogService;
            _saveFileDialogFactory = saveFileDialogFactory;
            _dataModel = dataModel;
            // Will bubble property change events from the Model to the ViewModel.
            _dataModel.PropertyChanged += (sender, e) => OnPropertyChanged(e.PropertyName);
        }
Beispiel #2
0
        /// <summary>
        /// Command line driven method.
        /// <example>
        /// /WR "Easy Start Report" "c:\temp\Easy Start Report.txt"
        /// /WR "C:\Users\%USERNAME%\AppData\Roaming\SpaceEngineersDedicated\Saves\Super Excellent Map\sandbox.sbc" "c:\temp\Super Excellent Map.txt"
        /// /WR "C:\Users\%USERNAME%\AppData\Roaming\SpaceEngineersDedicated\Saves\Super Excellent Map" "c:\temp\Super Excellent Map.txt"
        /// /WR "\\SERVER\Dedicated Saves\Super Excellent Map" "\\SERVER\Reports\Super Excellent Map.txt"
        /// </example>
        /// </summary>
        /// <param name="baseModel"></param>
        /// <param name="args"></param>
        public static void GenerateOfflineReport(ExplorerModel baseModel, string[] args)
        {
            var argList = args.ToList();
            var comArgs = args.Where(a => a.ToUpper() == "/WR" || a.ToUpper() == "-WR").Select(a => { return a; }).ToArray();
            foreach (var a in comArgs) argList.Remove(a);

            if (argList.Count < 2)
            {
                Environment.Exit(2);
                return;
            }

            var findSession = argList[0].ToUpper();
            var reportFile = argList[1];
            var reportExtension = Path.GetExtension(reportFile).ToUpper();

            if (reportExtension != ".HTM" &&
                reportExtension != ".HTML" &&
                reportExtension != ".TXT" &&
                reportExtension != ".XML")
            {
                Environment.Exit(1);
                return;
            }

            if (File.Exists(findSession))
            {
                findSession = Path.GetDirectoryName(findSession);
            }

            WorldResource world;

            if (Directory.Exists(findSession))
            {
                world = SelectWorldModel.LoadSession(findSession);
            }
            else
            {
                world = SelectWorldModel.FindSaveSession(SpaceEngineersConsts.BaseLocalPath.SavesPath, findSession);
            }

            if (world == null)
            {
                Environment.Exit(3);
                return;
            }

            baseModel.ActiveWorld = world;
            baseModel.ActiveWorld.LoadDefinitionsAndMods();
            baseModel.ActiveWorld.LoadSector(true);
            baseModel.ParseSandBox();

            var model = new ResourceReportModel();
            model.Load(baseModel.ActiveWorld.Savename, baseModel.Structures);
            model.GenerateReport();
            TempfileUtil.Dispose();

            if (reportExtension == ".HTM" || reportExtension == ".HTML")
                File.WriteAllText(reportFile, model.CreateHtmlReport());

            if (reportExtension == ".TXT")
                File.WriteAllText(reportFile, model.CreateTextReport());

            if (reportExtension == ".XML")
                File.WriteAllText(reportFile, model.CreateXmlReport());

            Environment.Exit(0);
        }
 public ResourceReportViewModel(BaseViewModel parentViewModel, ResourceReportModel dataModel)
     : this(parentViewModel, dataModel, ServiceLocator.Resolve<IDialogService>(), ServiceLocator.Resolve<ISaveFileDialog>)
 {
 }
Beispiel #4
0
 public void WorldReportExecuted()
 {
     var model = new ResourceReportModel();
     model.Load(_dataModel.ActiveWorld.Savename, _dataModel.Structures);
     var loadVm = new ResourceReportViewModel(this, model);
     _dialogService.ShowDialog<WindowResourceReport>(this, loadVm);
 }