コード例 #1
0
ファイル: AppViewModel.cs プロジェクト: MagmaWorks/SCaFFOLD
 public AppViewModel(List <CalcCore.CalcAssembly> calcs, List <PluginInfo> plugins)
 {
     Assemblies = calcs;
     _plugins   = plugins;
     CalcCore.ICalc calcInstance = (CalcCore.ICalc)Activator.CreateInstance(Assemblies[1].Class);
     ViewModels.Add(new CalculationViewModel(calcInstance, _plugins));
 }
コード例 #2
0
ファイル: AppViewModel.cs プロジェクト: MagmaWorks/SCaFFOLD
        private void copyCalc()
        {
            CalcCore.ICalc newCalc   = (CalcCore.ICalc)Activator.CreateInstance(ViewModel.Calc.GetType());
            var            oldInputs = ViewModel.Calc.GetInputs();
            var            newInputs = newCalc.GetInputs();

            for (int i = 0; i < oldInputs.Count; i++)
            {
                newInputs[i].ValueAsString = oldInputs[i].ValueAsString;
            }

            bool uniqueName   = false;
            var  proposedName = ViewModel.Calc.InstanceName + "_copy";

            while (!uniqueName)
            {
                if (ViewModels.Where(a => a.CalcInstanceName == proposedName).ToList().Count > 0)
                {
                    proposedName += "_copy";
                }
                else
                {
                    uniqueName = true;
                }
            }
            newCalc.InstanceName = proposedName;


            _viewModels.Add(new CalculationViewModel(newCalc, _plugins));
            RaisePropertyChanged(nameof(ViewModels));
            SelectedViewModel = _viewModels.Count - 1;
        }
コード例 #3
0
ファイル: AppViewModel.cs プロジェクト: MagmaWorks/SCaFFOLD
 private void addCalc(Type calcType)
 {
     CalcCore.ICalc calcInstance = (CalcCore.ICalc)Activator.CreateInstance(calcType);
     ViewModels.Add(new CalculationViewModel(calcInstance, _plugins));
     SelectedViewModel = ViewModels.Count - 1;
 }
コード例 #4
0
ファイル: AppViewModel.cs プロジェクト: MagmaWorks/SCaFFOLD
        private void openCalc()
        {
            try
            {
                var openDialog = new OpenFileDialog();
                openDialog.Filter           = @"Calc files |*.JSON";
                openDialog.InitialDirectory = activeDirectory != null ? activeDirectory : Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                //openDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                openDialog.Multiselect = true;
                if (openDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                activeDirectory = Path.GetDirectoryName(openDialog.FileName);
                foreach (var filePath in openDialog.FileNames)
                {
                    bool   inputMissing        = false;
                    string inputMissingMessage = "";
                    string openObj             = System.IO.File.ReadAllText(filePath);
                    var    deserialiseType     = new { InstanceName = "", TypeName = "", ClassName = "", Inputs = new List <deserialiseCalcValue>() };
                    var    deserialiseObj      = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(openObj, deserialiseType);

                    CalcAssembly calcType = Assemblies[0];
                    foreach (var assembly in Assemblies)
                    {
                        if (assembly.Name == deserialiseObj.ClassName)
                        {
                            calcType = assembly;
                        }
                        else if (assembly.AltNames != null)
                        {
                            foreach (var name in assembly.AltNames)
                            {
                                if (name == deserialiseObj.ClassName)
                                {
                                    calcType = assembly;
                                }
                            }
                        }
                    }
                    CalcCore.ICalc calcInstance = (CalcCore.ICalc)Activator.CreateInstance(calcType.Class);
                    foreach (var item in deserialiseObj.Inputs)
                    {
                        // Need to find a tidy way to do this...
                        var input = calcInstance.Inputs.Find(a => a.Name == item.Name);
                        if (input != null)
                        {
                            input.ValueAsString = item.ValueAsString;
                        }
                        else
                        {
                            inputMissing         = true;
                            inputMissingMessage += "The input \"" + item.Name + "\" in file does not exist in calc" + Environment.NewLine;
                        }
                    }
                    calcInstance.InstanceName = deserialiseObj.InstanceName;
                    calcInstance.UpdateCalc();
                    var newCalcVM = new CalculationViewModel(calcInstance, _plugins);
                    newCalcVM.Filepath = filePath;
                    ViewModels.Add(newCalcVM);
                    SelectedViewModel = ViewModels.Count - 1;
                    if (inputMissing)
                    {
                        System.Windows.MessageBox.Show(inputMissingMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show("Oops..." + Environment.NewLine + ex.Message);
                return;
            }
        }