public StartApplicationSession NewStartApplicationSession(string username, string password, int sessionDuration = 180, int sessionCleanUpDelay = 60, string applicationId = "Ratcow.Csta") { var result = new StartApplicationSession { applicationInfo = new StartApplicationSessionApplicationInfo { applicationID = applicationId, applicationSpecificInfo = new StartApplicationSessionApplicationInfoApplicationSpecificInfo { Any = new XmlElement[] { NewSessionLoginInfo(username, password, sessionCleanUpDelay) } } }, requestedProtocolVersions = new string[] { DmccProtocols.ToString(DmccProtocolType.v63) }, requestedSessionDuration = sessionDuration.ToString() }; return(result); }
void InternalEventListenerLoop() { while (Running) { if (!HasData) { Task.Delay(200); continue; } { var(Request, InvokeId) = ReadXMLMessage(); var root = XmlHelper.GetRootElementName(Request); switch (root) { case nameof(StartApplicationSession): //TODO - we in no way validate the login credentials here, mainly because we don't //really care about them for this simple simulation - we are trying to simulate //a switch, so the login security as not really important till the bulk of the //functions are implemented. var startApplicationSession = SerializationHelper.Deserialize <StartApplicationSession>(Request); var requestedProtocol = startApplicationSession.requestedProtocolVersions?.Length > 0 ? startApplicationSession.requestedProtocolVersions[0]: string.Empty; logger.Debug($"requested protocol was {requestedProtocol}"); //set the protocol: if (EventProcessor?.Protocols?.Length > 0) { var requestedProtocolType = DmccProtocols.ToDmccProtocolType(requestedProtocol); protocol = EventProcessor.Protocols.FirstOrDefault(p => p.Protocol == requestedProtocolType); } else { //fall back... protocol = DmccServerDataProtocolFactory.Create(requestedProtocol); //TODO - remove this.. we should not fall back } if (protocol != null) { //we just respond that we are happy //var startApplicationResponse = $"<?xml version=\"1.0\" encoding=\"UTF-8\" ?><StartApplicationSessionPosResponse xmlns=\"http://www.ecma-international.org/standards/ecma-354/appl_session\"><sessionID>{sessionId}</sessionID><actualProtocolVersion>http://www.ecma-international.org/standards/ecma-323/csta/ed3/priv2</actualProtocolVersion><actualSessionDuration>{startApplicationSession.requestedSessionDuration}</actualSessionDuration></StartApplicationSessionPosResponse>"; //var startApplicationPositiveResponse = new StartApplicationSessionPosResponse //{ // actualProtocolVersion = requestedProtocol, // actualSessionDuration = startApplicationSession.requestedSessionDuration, // sessionID = sessionId, //}; var startApplicationPositiveResponse = protocol.NewStartApplicationSessionPosResponse(sessionId, requestedProtocol, startApplicationSession.requestedSessionDuration); SendResponse(InvokeId, startApplicationPositiveResponse); } else { //because we have no protocol at this point, we use a common static helper function. var startApplicationNegativeResponse = DmccServerDataProtocolBase.NewStartApplicationSessionNegResponse(StartApplicationSessionNegResponseErrorCodeDefinedError.requestedProtocolVersionNotSupported); SendResponse(InvokeId, startApplicationNegativeResponse); } break; case nameof(SystemRegister): /*<?xml version="1.0" encoding="UTF-8"?> * <SystemRegisterResponse * xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed3"> * <sysStatRegisterID>500046</sysStatRegisterID> * <actualStatusFilter> * <initializing>false</initializing> * <enabled>false</enabled> * <normal>true</normal> * <messageLost>false</messageLost> * <disabled>true</disabled> * <partiallyDisabled>false</partiallyDisabled> * <overloadImminent>false</overloadImminent> * <overloadReached>false</overloadReached> * <overloadRelieved>false</overloadRelieved> * </actualStatusFilter> * <extensions> * <privateData> * <private> * <ns1:SystemRegisterPrivateData * xmlns:ns1="http://www.avaya.com/csta" * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" * xsi:type="ns1:SystemRegisterPrivateData"> * <ns1:invertFilter>true</ns1:invertFilter> * </ns1:SystemRegisterPrivateData> * </private> * </privateData> * </extensions> * </SystemRegisterResponse> */ var systemRegister = SerializationHelper.Deserialize <SystemRegister>(Request); //let's just check the sessionId is what we previously sent if (systemRegister.extensions.privateData.Item is CSTAPrivateDataPrivate cpd) { var any = cpd.Any[0].OuterXml; var systemRegisterPrivateData = SerializationHelper.Deserialize <SystemRegisterPrivateData>(any); if (string.Compare(Parent.CallServerName, systemRegisterPrivateData.switchName) == 0) { var systemRegisterResponse = protocol.NewSystemRegisterResponse(systemRegisterResponseId); SendResponse(InvokeId, systemRegisterResponse); } else { SendUniversalFailure(InvokeId, OperationErrors.generic); //TODO - this should be better } } break; case nameof(GetDeviceId): var getDeviceId = SerializationHelper.Deserialize <GetDeviceId>(Request); if (ResourceManager.Devices.ContainsKey(getDeviceId.extension)) { var device = ResourceManager.Devices[getDeviceId.extension]; //TODO - should we ever be using the ManagingSwitchName here? I've thrown it in for good measure as a valid // alternative... but I've only ever used the switchIPInterface if (device?.ManagingSwitchIpAddress == getDeviceId.switchIPInterface || device?.ManagingSwitchName == getDeviceId.switchName) { if (device.Alocated) { SendUniversalFailure(InvokeId, OperationErrors.generic); //TODO - what do we actually get here? } else { device.Alocated = true; var getDeviceIdResponse = protocol.NewGetDeviceIdResponse(device.Device); SendResponse(InvokeId, getDeviceIdResponse); } } else { SendUniversalFailure(InvokeId, OperationErrors.invalidDeviceID); } } else { SendUniversalFailure(InvokeId, OperationErrors.invalidDeviceID); } break; case nameof(GetThirdPartyDeviceId): var getThirdPartyDeviceId = SerializationHelper.Deserialize <GetThirdPartyDeviceId>(Request); if (ResourceManager.Devices.ContainsKey(getThirdPartyDeviceId.extension)) { var device = ResourceManager.Devices[getThirdPartyDeviceId.extension]; if (device?.ManagingSwitchName == getThirdPartyDeviceId.switchName) { if (device.Alocated) { SendUniversalFailure(InvokeId, OperationErrors.generic); //TODO - what do we actually get here? } else { device.Alocated = true; var getDeviceIdResponse = protocol.NewGetThirdPartyDeviceIdResponse(device.Device); SendResponse(InvokeId, getDeviceIdResponse); } } else { SendUniversalFailure(InvokeId, OperationErrors.invalidDeviceID); } } else { SendUniversalFailure(InvokeId, OperationErrors.invalidDeviceID); } break; case nameof(ReleaseDeviceId): var releaseDeviceId = SerializationHelper.Deserialize <ReleaseDeviceId>(Request); var deviceId = releaseDeviceId?.device?.Value ?? string.Empty; if (ResourceManager.Devices.Values.Any(d => d?.Device?.Value == deviceId)) { var device = ResourceManager.Devices.Values.FirstOrDefault(d => d?.Device?.Value == deviceId); if (device != null) { device.Alocated = false; } var response = protocol.NewReleaseDeviceIdResponse(); SendResponse(InvokeId, response); } else { SendUniversalFailure(InvokeId, OperationErrors.invalidDeviceID); } break; default: logger.Debug(Request); break; } } } }
public static IDmccServerDataProtocol Create(string protocol) { return(Create(DmccProtocols.ToDmccProtocolType(protocol))); }
public static IDmccClientDataProtocol Create(string protocol) { return Create(DmccProtocols.ToDmccProtocolType(protocol)); }