示例#1
0
        private void InitializeConsole()
        {
            using (_logger.CreateCallstack())
            {
                int    attempts = 0;
                Random random   = new Random();
                int    process  = Process.GetCurrentProcess().Id;

                do
                {
                    if (attempts > MaxAttempts)
                    {
                        throw _logger.WriteException(new SessionLocalException(_session, "Cannot find unique name for event object."));
                    }

                    int instanceNumber = random.Next(1000);

                    _instanceName = string.Format(CultureInfo.InvariantCulture, "_{0}_{1}_{2}", process, GetHashCode(), instanceNumber);
                    _logger.WriteLine("Trying event {0}", _instanceName);
                    if (!TryCreateEvent(ConsoleEventRequest + _instanceName, out _requestEvent))
                    {
                        _logger.WriteLine("Event {0} is not unique", _instanceName);
                        _requestEvent.Close();
                        _requestEvent = null;
                    }
                    else
                    {
                        _logger.WriteLine("Event {0} is unique", _instanceName);
                        _responseEvent = CreateEvent(ConsoleEventResponse + _instanceName);
                        _cancelEvent   = CreateEvent(ConsoleEventCancel + _instanceName);
                        string fileMappingName = ConsoleMapping + _instanceName;
                        _fileMapping = CreateFileMapping(fileMappingName);
                        if (Marshal.GetLastWin32Error() == UnsafeNativeMethods.ERROR_ALREADY_EXISTS)
                        {
                            throw _logger.WriteException(new SessionLocalException(_session, string.Format(CultureInfo.InvariantCulture, "File mapping {0} already exists", fileMappingName)));
                        }
                        if (_fileMapping.IsInvalid)
                        {
                            throw _logger.WriteException(new SessionLocalException(_session, string.Format(CultureInfo.InvariantCulture, "Cannot create file mapping {0}", fileMappingName)));
                        }
                    }
                    ++attempts;
                }while (_requestEvent == null);

                using (ConsoleCommStruct commStruct = AcquireCommStruct())
                {
                    commStruct.InitHeader();
                }

                if (_session.GuardProcessWithJobInternal)
                {
                    string jobName = ConsoleJob + _instanceName;
                    _job = new Job(_logger, jobName);
                }
            }
        }
示例#2
0
        private void ProcessEvent()
        {
            using (_logger.CreateCallstack())
            {
                using (ConsoleCommStruct commStruct = AcquireCommStruct())
                {
                    switch (commStruct.Event)
                    {
                    case ConsoleEvent.Print:
                        ProcessPrintEvent(commStruct.PrintEvent);
                        break;

                    case ConsoleEvent.Input:
                        ProcessInputEvent(commStruct.InputEvent);
                        break;

                    case ConsoleEvent.Choice:
                        ProcessChoiceEvent(commStruct.ChoiceEvent);
                        break;

                    case ConsoleEvent.Title:
                        ProcessTitleEvent(commStruct.TitleEvent);
                        break;

                    case ConsoleEvent.Init:
                        ProcessInitEvent(commStruct.InitEvent);
                        break;

                    case ConsoleEvent.Progress:
                        ProcessProgressEvent(commStruct.ProgressEvent);
                        break;

                    case ConsoleEvent.TransferOut:
                        ProcessTransferOutEvent(commStruct.TransferOutEvent);
                        break;

                    case ConsoleEvent.TransferIn:
                        ProcessTransferInEvent(commStruct.TransferInEvent);
                        break;

                    default:
                        throw _logger.WriteException(new NotImplementedException());
                    }
                }

                _responseEvent.Set();
                _logger.WriteLineLevel(1, "Response event set");
            }
        }
示例#3
0
        private void ProcessEvent()
        {
            using (_logger.CreateCallstack())
            {
                using (ConsoleCommStruct commStruct = AcquireCommStruct())
                {
                    switch (commStruct.Event)
                    {
                    case ConsoleEvent.Print:
                        ProcessPrintEvent(commStruct.PrintEvent);
                        break;

                    case ConsoleEvent.Input:
                        ProcessInputEvent(commStruct.InputEvent);
                        break;

                    case ConsoleEvent.Choice:
                        ProcessChoiceEvent(commStruct.ChoiceEvent);
                        break;

                    case ConsoleEvent.Title:
                        ProcessTitleEvent(commStruct.TitleEvent);
                        break;

                    case ConsoleEvent.Init:
                        ProcessInitEvent(commStruct.InitEvent);
                        break;

                    case ConsoleEvent.Progress:
                        ProcessProgressEvent(commStruct.ProgressEvent);
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }

                _responseEvent.Set();
            }
        }