public void EvaluatePassedNullOrEmptyStringShouldThrow(
            [Values("", null)] string command)
        {
            COMMapinfo mapinfo = new COMMapinfo(mockmapinfo.Object);

            Assert.Throws <ArgumentNullException>(() => mapinfo.Evaluate(command));
        }
        public void EvaluateWithInvaildArgRethrowsMapinfoExceptionFromCOMException()
        {
            mockmapinfo.Setup(m => m.Eval("InvailedArg"))
            .Throws <COMException>();

            COMMapinfo mapinfo = new COMMapinfo(mockmapinfo.Object);

            Assert.Throws <MapinfoException>(() => mapinfo.Evaluate("InvailedArg"));
        }
        public void RunCommandWithInvaildArgRethrowsMapinfoExceptionFromCOMException()
        {
            mockmapinfo.Setup(m => m.Do("InvailedArg"))
            .Throws <COMException>();

            COMMapinfo mapinfo = new COMMapinfo(mockmapinfo.Object);

            Assert.Throws <MapinfoException>(() => mapinfo.RunCommand("InvailedArg"));
        }
        public void MapinfoWithNoErrorCodeNotThrow()
        {
            mockmapinfo.Setup(m => m.LastErrorCode)
            .Returns(0);

            COMMapinfo mapinfo = new COMMapinfo(mockmapinfo.Object);

            Assert.DoesNotThrow(() => mapinfo.RunCommand("DummyArg"), "RunCommand threw an Exception");
            Assert.DoesNotThrow(() => mapinfo.Evaluate("DummyArg"), "Evaluate threw an Exception");
        }
        public void MapinfoWithErrorCodeGreaterThenZeroShouldThrow()
        {
            mockmapinfo.Setup(m => m.LastErrorCode)
            .Returns(1);

            COMMapinfo mapinfo = new COMMapinfo(mockmapinfo.Object);

            Assert.Throws <MapinfoException>(() => mapinfo.RunCommand("DummyArg"), "RunCommand didn't throw a MapinfoException");
            Assert.Throws <MapinfoException>(() => mapinfo.Evaluate("DummyArg"), "Evaluate didn't throw a MapinfoException");
        }
        public void GetUnderlyingInstanceReturnsAssignedInstance()
        {
            DMapInfo expected = mockmapinfo.Object;

            COMMapinfo mapinfo = new COMMapinfo(expected);

            object result = mapinfo.GetUnderlyingMapinfoInstance();

            Assert.IsInstanceOf(typeof(DMapInfo), result);
            Assert.AreSame(expected, result);
        }
Exemple #7
0
        private void InitializeComObject()
        {
            // Create the MapInfo Professional object, this will create an instance of
            // Mapinfo and return a the instance as wrapped in a IMapinfoWrapper which provides basic
            // Mapinfo OLE commnds like Do and Eval.
            this.MapInfoApp = COMMapinfo.CreateInstance();

            // Set the parent window for Mapinfo Professional dialogs to this form.
            this.SetAsMapinfoApplicationWindow();

            // Create a new callback object.
            CustomCallback callback = new CustomCallback();

            // Sink the events to the form.
            callback.OnStatusChanged += new Action <string>(callback_OnStatusChanged);
            callback.OnMenuItemClick += new Action <string>(callback_OnMenuItemClick);

            // Register the callback with Mapinfo.
            // At the moment we have to cast the IMapinfoWrapper object to COMMapinfo to set the
            // callback object.  This will change in the future.
            ((COMMapinfo)this.MapInfoApp).Callback = callback;
        }
Exemple #8
0
 public override bool Close()
 {
     try
     {
         if (_mapInfoApp != null)
         {
             _mapInfoApp.RunMenuCommand((int)MapInfoConstants.MenuDef95File.M_FILE_EXIT);
             _mapInfoApp = null;
             _mapInfoComObj = null;
         }
         return true;
     }
     catch { return false; }
 }
Exemple #9
0
        public override bool Start(ProcessWindowStyle windowStyle)
        {
            try
            {
                // get any running MapInfo processes
                _mapInfoProcsPreStart = GetMapInfoProcesses();

                // create a MapInfo instance
                _mapInfoComObj = COMMapinfo.CreateInstance();
                _mapInfoApp = (DMapInfo)_mapInfoComObj.GetUnderlyingMapinfoInstance();
                //_mapInfoApp = (DMapInfo)Activator.CreateInstance(Type.GetTypeFromProgID("MapInfo.Application"));

                // wire up callback
                MapInfoCustomCallback miCallback = new MapInfoCustomCallback();
                miCallback.OnStatusChanged += new Action<string>(miCallback_OnStatusChanged);
                miCallback.OnMenuItemClick += new Action<string>(miCallback_OnMenuItemClick);
                miCallback.OnWindowChanged += new Action<int>(miCallback_OnWindowChanged);
                _mapInfoComObj.Callback = miCallback;

                double mapInfoVersion;
                double.TryParse(_mapInfoApp.Version, NumberStyles.AllowDecimalPoint, CultureInfo.CurrentCulture, out mapInfoVersion);

                // open the HLU workspace
                if (!OpenWorkspace(_mapPath)) return false;

                // size MapInfo window
                Window(windowStyle, IntPtr.Zero);

                // MapInfo 10 won't display toolbars when started programmatically
                if (mapInfoVersion >= 1000)
                {
                    if (!File.Exists(String.Format("{0}{1}MapInfo{1}MapInfo{1}Professional{1}{2}{1}MICommandBarStateAutomation.xml",
                        Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Path.DirectorySeparatorChar, _mapInfoApp.Version)))
                    {
                        EnableStandardTools();
                    }
                }
                else
                {
                    try
                    {
                        string prefFolder = _mapInfoApp.Eval(String.Format("GetFolderPath$({0})",
                            (int)MapInfoConstants.GetFolderPath.FOLDER_MI_PREFERENCE));
                        string startupWS = Path.Combine(prefFolder, "Startup.wor"); // "MAPINFOW.WOR");
                        if (File.Exists(startupWS))
                        {
                            _mapInfoApp.Do(String.Format("Run Application {0}", QuoteValue(startupWS)));
                        }
                    }
                    catch { }
                    EnableStandardTools();
                    SizeWindow(_hluMapWindowID, false);
                }

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error Starting MapInfo", MessageBoxButton.OK, MessageBoxImage.Error);
                return false;
            }
        }