Пример #1
0
        private bool _runStandAlone;         // debug mode, run with message boxes instead of connection to FLEx.
#endif
        /// <summary>
        /// Initialize the helper, setting up the local service endpoint and opening.
        /// </summary>
        /// <param name="commandLineArgs">The entire FieldWorks project folder path is in the '-p' option, if not 'obtain' operation.
        /// Must include the project folder and project name with "fwdata" extension.
        /// Empty is OK if not send_receive command.</param>
        public bool Init(Dictionary <string, string> commandLineArgs)
        {
#if DEBUG // this command line argument is only for debugging.
            if (commandLineArgs.ContainsKey("-runStandAlone"))
            {
                _runStandAlone = true;
                MessageBox.Show("connection opened");
                return(true);
            }
#else
            if (commandLineArgs.ContainsKey("-runStandAlone"))
            {
                throw new InvalidOperationException("The '-runStandAlone' command line option is not supported in a Release build.");
            }
#endif

            HostOpened = true;

            // The pipeID as set by FLEx to be used in setting the communication channels
            var pipeId = commandLineArgs["-pipeID"];

            _host = IPCHostFactory.Create();
            _host.VerbosityLevel = 1;
            var hostIsInitialized = _host.Initialize <FLExService, IFLExService>("FLExEndpoint" + pipeId, null, null);
            if (!hostIsInitialized)
            {
                HostOpened = false;
                // display messagebox and quit
                MessageBox.Show(CommonResources.kAlreadyRunning, CommonResources.kFLExBridge, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return(false);
            }
            //open host ready for business

            _client = IPCClientFactory.Create();
            _client.VerbosityLevel = 1;
            _client.Initialize <IFLExBridgeService>("FLExBridgeEndpoint" + pipeId, FLExService.WaitObject, null);
            if (!_client.RemoteCall("BridgeReady"))
            {
                _client = null;                 //FLEx isn't listening.
            }
            return(true);
        }
Пример #2
0
        public static bool LaunchFieldworksBridge(string projectFolder, string userName, string command, string projectGuid,
                                                  int fwmodelVersionNumber, string liftModelVersionNumber, string writingSystemId, Action onNonBlockerCommandComplete,
                                                  out bool changesReceived, out string projectName)
        {
            _pipeID = string.Format(@"SendReceive{0}{1}", projectFolder, command);
            _flexBridgeTerminated = false;
            changesReceived       = false;
            var args = "";

            projectName  = "";
            _projectName = "";
            var userNameActual = userName;

            if (string.IsNullOrEmpty(userName))
            {
                userNameActual = Environment.UserName; // default so we can always pass something.
            }
            if (userNameActual != null)                // Paranoia, hopefully never null
            {
                AddArg(ref args, "-u", userNameActual);
            }
            if (!string.IsNullOrEmpty(projectFolder))
            {                // can S/R multiple projects simultaneously
                AddArg(ref args, "-p", projectFolder);
            }

            AddArg(ref args, "-v", command);

            if (command == SendReceive && FixItAppExists)
            {
                AddArg(ref args, "-f", FixItAppPathname);
            }

            if (!String.IsNullOrEmpty(projectGuid))
            {
                AddArg(ref args, "-g", projectGuid);
            }

            // Add two paths: to FW projDir & FW apps folder. Then, FB won't have to look in a zillion registry entries
            AddArg(ref args, "-projDir", FwDirectoryFinder.ProjectsDirectory);
            AddArg(ref args, "-fwAppsDir", FieldWorksAppsDir);
            // Tell Flex Bridge which model version of data are expected by FLEx.
            AddArg(ref args, "-fwmodel", fwmodelVersionNumber.ToString());
            AddArg(ref args, "-liftmodel", liftModelVersionNumber);
            // current culture may have country etc info after a hyphen. FlexBridge just needs the main language ID.
            // It probably can't ever be null or empty, but let's be as robust as possible.
            var locale = Thread.CurrentThread.CurrentUICulture.Name;

#if __MonoCS__
            // Mono doesn't have a plain "zh" locale.  It needs the country code for Chinese.  See FWNX-1255.
            if (locale != "zh-CN")
#endif
            locale = string.IsNullOrWhiteSpace(locale) ? "en" : locale.Split('-')[0];
            AddArg(ref args, "-locale", locale);

            if (_noBlockerHostAndCallback != null)
            {
                return(false);
            }
            AddArg(ref args, "-pipeID", _pipeID);
            if (!String.IsNullOrEmpty(writingSystemId))
            {
                AddArg(ref args, "-ws", writingSystemId);
            }

            // make a new FLExBridge
            var host = IPCHostFactory.Create();
            host.VerbosityLevel = 1;
            if (!host.Initialize <FLExBridgeService, IFLExBridgeService>("FLExBridgeEndpoint" + _pipeID, AlertFlex, CleanupHost))
            {
                return(false);
            }

            LaunchFlexBridge(host, command, args, onNonBlockerCommandComplete, ref changesReceived, ref projectName);

            return(true);
        }