Пример #1
0
        public Int32 _Main()
        {
            Int32 returnValue = -1; //default to fail code

            try
            {
                ViewModel.StatusMessage = String.Format("{0} starting...", ViewName);

                //init settigns

                ViewModel.StatusMessage = String.Format("{0} started.", ViewName);

                _Run();

                ViewModel.StatusMessage = String.Format("{0} completing...", ViewName);

                DisposeSettings();

                ViewModel.StatusMessage = String.Format("{0} completed.", ViewName);

                //return success code
                returnValue = 0;
            }
            catch (Exception ex)
            {
                ViewModel.ErrorMessage = String.Format("{0} did NOT complete: '{1}'", ViewName, ViewModel.ErrorMessage);
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);
            }
            finally
            {
                ViewModel = null;
            }
            return(returnValue);
        }
Пример #2
0
        protected void InitViewModel()
        {
            Dictionary <String, String> d = default(Dictionary <String, String>);

            try
            {
                //tell controller how model should notify view about non-persisted properties AND including model properties that may be part of settings
                ModelController <MVCModel> .DefaultHandler = PropertyChangedEventHandlerDelegate;

                //tell controller how settings should notify view about persisted properties
                SettingsController <MVCSettings> .DefaultHandler = PropertyChangedEventHandlerDelegate;

                InitModelAndSettings();

#if USE_CUSTOM_VIEWMODEL
                //class to handle standard behaviors
                d = new Dictionary <String, String>();
                d.Add("New", "New");
                d.Add("Save", "Save");
                d.Add("Open", "Open");
                d.Add("Print", "Print");
                d.Add("Copy", "Copy");
                d.Add("Properties", "Properties");

                ViewModelController <String, MVCConsoleViewModel> .New
                (
                    ViewName,
                    new MVCConsoleViewModel
                    (
                        this.PropertyChangedEventHandlerDelegate,
                        d
                    )
                );

                //select a viewmodel by view name
                ViewModel =
                    ViewModelController <String, MVCConsoleViewModel> .ViewModel[ViewName];
#else
                //class to handle standard behaviors
                ViewModelController <String, ConsoleViewModel <String, MVCSettings, MVCModel> > .New
                (
                    ViewName,
                    new ConsoleViewModel <String, MVCSettings, MVCModel>
                    (
                        this.PropertyChangedEventHandlerDelegate,
                        new Dictionary <String, String>()
                {
                    { "New", "New" },
                    { "Save", "Save" },
                    { "Open", "Open" },
                    { "Print", "Print" },
                    { "Copy", "Copy" },
                    { "Properties", "Properties" }
                }
                    )
                );

                //select a viewmodel by view name
                ViewModel =
                    ViewModelController <String, ConsoleViewModel <String, MVCSettings, MVCModel> > .ViewModel[ViewName];
#endif

                //Init config parameters
                if (!LoadParameters())
                {
                    throw new Exception(String.Format("Unable to load config file parameter(s)."));
                }

                //DEBUG:filename coming in is being converted/passed as DOS 8.3 format equivalent
                //Load
                if ((SettingsController <MVCSettings> .FilePath == null) || (SettingsController <MVCSettings> .Filename == SettingsController <MVCSettings> .FILE_NEW))
                {
                    //NEW
                    ViewModel.FileNew();
                }
                else
                {
                    //OPEN
                    ViewModel.FileOpen();
                }
            }
            catch (Exception ex)
            {
                if (ViewModel != null)
                {
                    ViewModel.ErrorMessage = ex.Message;
                }
                Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error);
            }
        }