/// <summary> /// /// </summary> public MQAdapter(HostType host) { #region Load MQ parameters from configuration file string mqManager = System.Configuration.ConfigurationManager.AppSettings[host.ToString() + ".MQ.Manager"]; string channel = System.Configuration.ConfigurationManager.AppSettings[host.ToString() + ".MQ.Channel"]; string ipAddress = System.Configuration.ConfigurationManager.AppSettings[host.ToString() + ".MQ.Server"]; string putQueue = System.Configuration.ConfigurationManager.AppSettings[host.ToString() + ".MQ.Put.Queue"]; string getQueue = System.Configuration.ConfigurationManager.AppSettings[host.ToString() + ".MQ.Get.Queue"]; int timeout = 30000; string _timeout = System.Configuration.ConfigurationManager.AppSettings[host.ToString() + ".MQ.Response.Timeout"]; if (_timeout != null) { timeout = int.Parse(_timeout); } int port = 1414; string _port = System.Configuration.ConfigurationManager.AppSettings[host.ToString() + ".MQ.Port"]; if (_port != null) { port = int.Parse(_port); } #endregion InitializeAdapter(mqManager, channel, ipAddress, putQueue, getQueue, timeout, 37, port); }
private static IFileMetadataStrategy GetMetadata(HostType hostType) { switch (hostType) { case HostType.GridFs: return(new GridFsMetadata()); default: throw new NotImplementedException(hostType.ToString()); } }
public static Host New(HostType hostType) { Host host = null; switch (hostType) { case HostType.GDI: host = HostGDI.Instance; break; case HostType.SDL: host = HostSdl.Instance; break; default: throw new Exception("Unexpected HostType: " + hostType.ToString()); } return host; }
/// <summary> /// page load (postback data is now available) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load( object sender, EventArgs e) { try { if (Session[HttpSessionStateVariables.EnterpriseSession.ToString()] == null) { throw new NullReferenceException(); } _enterpriseSession = (EnterpriseSession)Session[HttpSessionStateVariables.EnterpriseSession.ToString()]; try { if (!_enterpriseSession.IsAdmin) { Response.Redirect("~/", true); } if (Request["hostType"] == null || !Enum.TryParse(Request["hostType"], out _hostType)) { _hostType = HostType.RDP; } // retrieve the host, if any (create if empty) if (Request["hostId"] != null) { long hostId; if (!long.TryParse(Request["hostId"], out hostId)) { hostId = 0; } if (hostId != 0) { _hostId = hostId; if (!IsPostBack && Request["edit"] == null) { try { var host = _enterpriseClient.GetHost(_hostId.Value, _enterpriseSession.SessionID); if (host != null) { _hostType = host.HostType; hostType.Value = _hostType.ToString(); hostName.Value = host.HostName; hostAddress.Value = host.HostAddress; vmGuid.Value = host.VMGuid; vmEnhancedMode.Checked = host.VMEnhancedMode; groupsAccess.Value = host.DirectoryGroups; securityProtocol.SelectedIndex = (int)host.Protocol; promptCredentials.Checked = host.PromptForCredentials; startProgram.Value = host.StartRemoteProgram; } } catch (Exception exc) { System.Diagnostics.Trace.TraceError("Failed to retrieve host {0}, ({1})", _hostId, exc); } } createSessionUrl.Attributes["onclick"] = string.Format("parent.openPopup('editHostSessionPopup', 'EditHostSession.aspx?hostId={0}');", _hostId); } } else { createSessionUrl.Disabled = true; deleteHost.Disabled = true; } vmGuidInput.Visible = _hostType == HostType.RDP; vmEnhancedModeInput.Visible = _hostType == HostType.RDP; rdpSecurityInput.Visible = _hostType == HostType.RDP; startProgramInput.Visible = _hostType == HostType.RDP; // local admin groupsAccessInput.Visible = !string.IsNullOrEmpty(_enterpriseSession.Domain); if (string.IsNullOrEmpty(_enterpriseSession.Domain)) { promptCredentials.Checked = true; promptCredentials.Disabled = true; } } catch (ThreadAbortException) { // occurs because the response is ended after redirect } } catch (Exception exc) { System.Diagnostics.Trace.TraceError("Failed to retrieve the active enterprise session ({0})", exc); } }
/// <summary> /// IND$FILE file transfer, asynchronous version. /// </summary> /// <param name="localFile">Local file name.</param> /// <param name="hostFile">Host file name.</param> /// <param name="direction">Direction of transfer.</param> /// <param name="mode">Type of transfer (ASCII/binary).</param> /// <param name="hostType">Host type (TSO/VM/CICS).</param> /// <param name="parameters">Additional parameters.</param> /// <returns>Success/failure and failure text.</returns> /// <exception cref="InvalidOperationException">Session is not started.</exception> /// <exception cref="X3270ifCommandException"><see cref="ExceptionMode"/> is enabled and the command fails.</exception> public async Task <IoResult> TransferAsync( string localFile, string hostFile, Direction direction, Mode mode, HostType hostType, IEnumerable <Parameter> parameters) { // Check file names. if (string.IsNullOrEmpty(localFile)) { throw new ArgumentException("localFile"); } if (string.IsNullOrEmpty(hostFile)) { throw new ArgumentException("hostFile"); } // Build up the fixed arguments. var argd = new SortedDictionary <string, string>(); argd["localfile"] = localFile; argd["hostfile"] = hostFile; argd["direction"] = direction.ToString(); argd["mode"] = mode.ToString(); argd["host"] = hostType.ToString(); // Walk through the parameters and build up the optional agruments. if (parameters != null) { foreach (var p in parameters) { switch (p.Type) { case ParameterType.AsciiCr: if (mode != Mode.Ascii) { throw new ArgumentException("AsciiCr requires Ascii mode"); } argd["cr"] = ((ParameterAsciiCr)p).AddRemove ? "add" : "keep"; break; case ParameterType.AsciiRemap: if (mode != Mode.Ascii) { throw new ArgumentException("AsciiRemap requires Ascii mode"); } var remap = (ParameterAsciiRemap)p; argd["remap"] = remap.Remap ? "yes" : "no"; if (remap.CodePage.HasValue) { argd["windowscodepage"] = remap.CodePage.ToString(); } break; case ParameterType.BlockSize: if (hostType != HostType.Tso) { throw new ArgumentException("BlockSize only works on TSO hosts"); } argd["blocksize"] = ((ParameterBlockSize)p).BlockSize.ToString(); break; case ParameterType.ExistAction: argd["exist"] = ((ParameterExistAction)p).ExistAction.ToString(); break; case ParameterType.SendLogicalRecordLength: if (direction != Direction.Send) { throw new ArgumentException("SendLogicalRecordLength requires send"); } if (hostType == HostType.Cics) { throw new ArgumentException("SendLogicalRecordLength does not work on CICS"); } argd["lrecl"] = ((ParameterSendLogicalRecordLength)p).RecordLength.ToString(); break; case ParameterType.SendRecordFormat: if (direction != Direction.Send) { throw new ArgumentException("SendRecordFormat requires send"); } if (hostType == HostType.Cics) { throw new ArgumentException("SendRecordFormat does not work with CICS hosts"); } argd["recfm"] = ((ParameterSendRecordFormat)p).RecordFormat.ToString(); break; case ParameterType.TsoSendAllocation: if (direction != Direction.Send) { throw new ArgumentException("SendTsoAllocation requires send"); } if (hostType != HostType.Tso) { throw new ArgumentException("SendTsoAllocation requires Tso host"); } var alloc = (ParameterTsoSendAllocation)p; argd["allocation"] = alloc.AllocationUnits.ToString(); argd["primaryspace"] = alloc.PrimarySpace.ToString(); if (alloc.SecondarySpace.HasValue) { argd["secondaryspace"] = alloc.SecondarySpace.Value.ToString(); } if (alloc.AllocationUnits == TsoAllocationUnits.Avblock) { argd["avblock"] = alloc.Avblock.ToString(); } break; case ParameterType.BufferSize: argd["buffersize"] = ((ParameterBufferSize)p).BufferSize.ToString(); break; } } } // Check for parameter interference (that's why the keywords went into a Dictionary). string v; if (direction == Direction.Send && argd.TryGetValue("exist", out v) && v == ExistAction.Append.ToString() && (argd.TryGetValue("recfm", out v) || argd.TryGetValue("lrecl", out v) || argd.TryGetValue("allocation", out v))) { throw new ArgumentException("Host file creation properties do not work with append"); } // Join the dictionary of keywords and values together, quoting each argument as necessary. var arge = argd.Select(kv => QuoteString(kv.Key + "=" + kv.Value)); var result = await this.IoAsync("Transfer(" + string.Join(",", arge) + ")", isModify : true) .ConfigureAwait(continueOnCapturedContext: false); return(result); }
public HostContext(HostType hostType, string logFile = null) { // Validate args. if (hostType == HostType.Undefined) { throw new ArgumentException(message: $"HostType cannot be {HostType.Undefined}"); } _hostType = hostType; _loadContext = AssemblyLoadContext.GetLoadContext(typeof(HostContext).GetTypeInfo().Assembly); _loadContext.Unloading += LoadContext_Unloading; this.SecretMasker.AddValueEncoder(ValueEncoders.JsonStringEscape, $"HostContext_{WellKnownSecretAliases.JsonStringEscape}"); this.SecretMasker.AddValueEncoder(ValueEncoders.UriDataEscape, $"HostContext_{WellKnownSecretAliases.UriDataEscape}"); this.SecretMasker.AddValueEncoder(ValueEncoders.BackslashEscape, $"HostContext_{WellKnownSecretAliases.UriDataEscape}"); this.SecretMasker.AddRegex(AdditionalMaskingRegexes.UrlSecretPattern, $"HostContext_{WellKnownSecretAliases.UrlSecretPattern}"); if (AgentKnobs.MaskUsingCredScanRegexes.GetValue(this).AsBoolean()) { foreach (var pattern in AdditionalMaskingRegexes.CredScanPatterns) { this.SecretMasker.AddRegex(pattern, $"HostContext_{WellKnownSecretAliases.CredScanPatterns}"); } } // Create the trace manager. if (string.IsNullOrEmpty(logFile)) { int logPageSize; string logSizeEnv = Environment.GetEnvironmentVariable($"{_hostType.ToString().ToUpperInvariant()}_LOGSIZE"); if (!string.IsNullOrEmpty(logSizeEnv) || !int.TryParse(logSizeEnv, out logPageSize)) { logPageSize = _defaultLogPageSize; } int logRetentionDays; string logRetentionDaysEnv = Environment.GetEnvironmentVariable($"{_hostType.ToString().ToUpperInvariant()}_LOGRETENTION"); if (!string.IsNullOrEmpty(logRetentionDaysEnv) || !int.TryParse(logRetentionDaysEnv, out logRetentionDays)) { logRetentionDays = _defaultLogRetentionDays; } // this should give us _diag folder under agent root directory as default value for diagLogDirctory string diagLogPath = GetDiagDirectory(_hostType); _traceManager = new TraceManager(new HostTraceListener(diagLogPath, hostType.ToString(), logPageSize, logRetentionDays), this.SecretMasker); } else { _traceManager = new TraceManager(new HostTraceListener(logFile), this.SecretMasker); } _trace = GetTrace(nameof(HostContext)); this.SecretMasker.SetTrace(_trace); _vssTrace = GetTrace(nameof(VisualStudio) + nameof(VisualStudio.Services)); // VisualStudioService // Enable Http trace if (AgentKnobs.HttpTrace.GetValue(this).AsBoolean()) { _trace.Warning("*****************************************************************************************"); _trace.Warning("** **"); _trace.Warning("** Http trace is enabled, all your http traffic will be dumped into agent diag log. **"); _trace.Warning("** DO NOT share the log in public place! The trace may contains secrets in plain text. **"); _trace.Warning("** **"); _trace.Warning("*****************************************************************************************"); _httpTrace = GetTrace("HttpTrace"); _diagListenerSubscription = DiagnosticListener.AllListeners.Subscribe(this); } // Enable perf counter trace string perfCounterLocation = AgentKnobs.AgentPerflog.GetValue(this).AsString(); if (!string.IsNullOrEmpty(perfCounterLocation)) { try { Directory.CreateDirectory(perfCounterLocation); _perfFile = Path.Combine(perfCounterLocation, $"{hostType}.perf"); } catch (Exception ex) { _trace.Error(ex); } } }
public IPasswordChangerEx Create(HostType hostType) { throw new NotSupportedException(hostType.ToString()); }
public void StartConnect() { if (Connected) { return; } // 创建 switch (HostType) { case HostConnectionType.Machine: ConnectionInstance = MachineProxy.Create(RemoteHostAddress); break; case HostConnectionType.Process: ConnectionInstance = ProcessProxy.Create(RemoteHostAddress); break; case HostConnectionType.Resource: ConnectionInstance = ResourceProxy.Create(RemoteHostAddress); break; case HostConnectionType.Partner: ConnectionInstance = PartnerProxy.Create(RemoteHostAddress); break; case HostConnectionType.Admin: ConnectionInstance = AdminProxy.Create(RemoteHostAddress); break; default: throw new NotSupportedException(); } // 连接 ConnectionInstance?.Connect(); if (Connected) { //连接事件 ServerEventArg arg = new ServerEventArg("Unknown", ServerEventType.Connected); LOG.Info($"启动{HostType.ToString()}对方端口{RemoteHostAddress}成功"); OnConnectedHander?.BeginInvoke(arg, null, null); //启动心跳 //StartHeartbeat(); } else { //连接失败 ServerEventArg arg = new ServerEventArg("Unknown", ServerEventType.Fault); LOG.Debug($"启动{HostType.ToString()}对方端口{RemoteHostAddress}失败"); OnConnectFaultHander?.BeginInvoke(arg, null, null); ConnectionInstance = null; } }