/// <summary> /// Gets the Oid from a DataRow. The DataRow is a row of the DataTable. /// </summary> /// <param name="dataTable">DataTable the Oid is given from.</param> /// <param name="row">Row the Oid is requested.</param> /// <param name="alternateKeyName">Name of the alternate key, if proceed.</param> /// <returns>Returns the Oid corresponding to the DataRow.</returns> public static Oid GetOid(DataTable dataTable, DataRow row, string alternateKeyName) { Oid resultOid = null; List <DataColumn> oidFields = GetOidColumns(dataTable); if (oidFields != null) { resultOid = Oid.Create(dataTable.TableName); resultOid.Fields.Clear(); foreach (DataColumn lDataColumn in oidFields) { ModelType type = (ModelType)lDataColumn.ExtendedProperties[DataTableProperties.DataColumnProperties.ModelType]; object rowValue = row[lDataColumn.Ordinal]; if (rowValue == null || rowValue == DBNull.Value) { return(null); } if (type == ModelType.String && rowValue.ToString().Trim().Length == 0) { return(null); } IOidField oidField = FieldList.CreateField(string.Empty, type); oidField.Value = rowValue; resultOid.Fields.Add(oidField); } string lAlternateKeyName = alternateKeyName; if (lAlternateKeyName == string.Empty) { // If no alternateKeyName is specified, ask to the current oid. lAlternateKeyName = resultOid.AlternateKeyName; } if (lAlternateKeyName != string.Empty) { // Try to load the alternate key fields with the values contained in the row. IOid auxAlternateKey = resultOid.GetAlternateKey(lAlternateKeyName); if ((auxAlternateKey as AlternateKey) != null) { foreach (IOidField oidField in auxAlternateKey.Fields) { // It is not guaranteed if the alternate key field is in the datatable. if (dataTable.Columns.Contains(oidField.Name)) { oidField.Value = row[oidField.Name]; } } } } } return(resultOid); }
private void SendForm(FormAction trigger, ActionSet actionSet, Node sourceNode, BlockBase sourceBlock, long sourceViewID, bool expectResponse = false) { if (sourceNode != null) { WaveMessage msg = new WaveMessage(); Core.Navigation.Requests.Add(msg, sourceViewID, trigger.Transition, trigger.IsPopUp); if (Core.CSLVersion == WaveCSLVersion.Version5) { msg.AddInt16(NaviAgentFieldID.ActionTypeID, (short)trigger.ActionType); msg.AddBoolean(NaviAgentFieldID.FormRequiresNoWait, trigger.WaitForNode); } else { msg.AddByte(NaviAgentFieldID.ActionRef, (byte)trigger.FormID); } FieldList payload = FieldList.CreateField(NaviAgentFieldID.ActionPayload); payload.AddString(NaviAgentFieldID.FormRequestURL, trigger.FormURL); sourceNode.AttachFormData((short)trigger.FormID, payload); msg.AddFieldList(payload); Core.System.Location.AddLocationData(msg); if (sourceNode.CacheID != null) { msg.AddBinary(MessageOutFieldID.CacheItemID, sourceNode.CacheID.Value.ToByteArray()); } else { msg.AddString(MessageOutFieldID.ItemURI, sourceNode.URI); } if (Core.CSLVersion != WaveCSLVersion.Version5) { msg.AddInt32(NaviAgentFieldID.ActionSetID, actionSet.DefinitionID); } msg.Send(WaveServerComponent.NavigationAgent, NaviAgentMessageID.Action); if (expectResponse) { Core.UI.SignalViewNavigationStart(sourceViewID); } } }
public void OnMessageReceived(WaveServerComponent dest, Enum msgID, WaveMessage data) { if (msgID is UserManagerMessageID) { if (data != null) { switch ((UserManagerMessageID)msgID) { case UserManagerMessageID.Challenge: { bool createAccount = false; // check if there is login already (otherwise set defaults) if (!Core.Application.HasLogin) { createAccount = true; Core.Application.UpdateCredentials(GenerateNewUsername(), StringHelper.GetBytes(DefaultPassword)); } // get CSL version WaveCSLVersion serverCSL = (WaveCSLVersion)(data[UserManagerFieldID.CSLVersion].AsShort() ?? (short)WaveCSLVersion.Unknown); switch (serverCSL) { case WaveCSLVersion.Version5: case WaveCSLVersion.Version4: Core.CSLVersion = serverCSL; break; default: Core.CSLVersion = WaveCSLVersion.Version3; break; } // get maximum protocol version WaveProtocolVersion serverProto = (WaveProtocolVersion)(data[UserManagerFieldID.MaxWeMessageVersion].AsByte() ?? (byte)WaveProtocolVersion.Unknown); switch (serverProto) { case WaveProtocolVersion.Version4: Core.ProtocolVersion = WaveProtocolVersion.Version4; break; default: Core.ProtocolVersion = WaveProtocolVersion.Version3; break; } // get challenge BinaryField challenge = (BinaryField)data[UserManagerFieldID.Challenge]; // assemble login message WaveMessage msgOut = new WaveMessage(); msgOut.AddInt16(UserManagerFieldID.CSLVersion, (short)Core.CSLVersion); msgOut.AddBoolean(UserManagerFieldID.EncryptSession, Core.UseEncryption); msgOut.AddInt16(UserManagerFieldID.PriorityMask, NetworkAgent.PrioritiesActiveMask); msgOut.AddBinary(UserManagerFieldID.UserCredentials, ProcessChallenge(challenge.Data, Core.Application, createAccount)); msgOut.AddBoolean(UserManagerFieldID.CreateAccount, createAccount); // cache hash byte[] cacheHash = Core.Cache.CacheHash; msgOut.AddBinary(CacheAgentFieldID.CacheHashCompressed, (cacheHash.Length > 0) ? CompressionHelper.GZipBuffer(cacheHash) : cacheHash); // cache ID (if any) if (Core.Cache.CacheID.HasValue) { msgOut.AddBinary(MessageOutFieldID.CacheItemID, Core.Cache.CacheID.Value.ToByteArray()); } // compiling device settings FieldList deviceSettingsList = FieldList.CreateField(UserManagerFieldID.DeviceSettings); deviceSettingsList.AddString(UserManagerFieldID.DeviceBuildID, Core.BuildID); deviceSettingsList.AddBoolean(NaviAgentFieldID.DeviceSupportsTouch, true); deviceSettingsList.AddInt16(NaviAgentFieldID.DeviceScreenResolutionWidth, 480); deviceSettingsList.AddInt16(NaviAgentFieldID.DeviceScreenResolutionHeight, 800); DeviceGroup[] devs = Core.System.SupportedDeviceGroups; foreach (DeviceGroup dev in devs) { deviceSettingsList.AddInt16(NaviAgentFieldID.DeviceProfileGroup, (short)dev); } deviceSettingsList.AddString(UserManagerFieldID.LanguageID, CultureInfo.CurrentCulture.Name); deviceSettingsList.AddString(UserManagerFieldID.Timezone, Core.Settings.TimeZone); deviceSettingsList.AddBoolean(UserManagerFieldID.AlphaSupport, true); deviceSettingsList.AddBoolean(UserManagerFieldID.CompressionSupport, true); msgOut.AddFieldList(deviceSettingsList); // compiling application request list FieldList appRequestList = FieldList.CreateField(UserManagerFieldID.ApplicationRequest); appRequestList.AddString(NaviAgentFieldID.ApplicationURN, Core.Application.URI); appRequestList.AddInt16(NaviAgentFieldID.ApplicationRequestAction, (short)AppRequestAction.GetAppEntryPage); msgOut.AddFieldList(appRequestList); msgOut.Send(WaveServerComponent.UserManager, UserManagerMessageID.Login); Core.UI.SignalViewNavigationStart(Core.UI.RootViewID); break; } case UserManagerMessageID.EncryptionKeys: { // setting encryption (if allowed by build configuration) if (Core.UseEncryption && (sessionHandshakeFish != null)) { BinaryField sessionKeyField = (BinaryField)data[UserManagerFieldID.SessionKey]; byte[] sessionKey = (byte[])sessionKeyField.Data; sessionHandshakeFish.Decrypt(sessionKey, sessionKey.Length); BinaryField globalServerKeyField = (BinaryField)data[UserManagerFieldID.GlobalServerKey]; byte[] globalServerKey = (byte[])globalServerKeyField.Data; sessionHandshakeFish.Decrypt(globalServerKey, globalServerKey.Length); Core.NotifyEncryptionKeysChanged(this, sessionKey, globalServerKey); } else { Core.NotifyEncryptionKeysChanged(this, null, null); } // setting login data StringField userName = (StringField)data[UserManagerFieldID.CreatedAccountUserName]; if (userName != null) { BinaryField userPass = (BinaryField)data[UserManagerFieldID.CreatedAccountPasswordHash]; if ((userPass != null) && (sessionHandshakeFish != null)) { byte[] passBuffer = (byte[])userPass.Data.Clone(); sessionHandshakeFish.Decrypt(passBuffer, passBuffer.Length); Core.Application.UpdateCredentials(userName.Data, passBuffer); // no longer needed sessionHandshakeFish = null; } } break; } case UserManagerMessageID.LoginResponse: { if (!authenticated) { Int16Field loginStatus = (Int16Field)data[UserManagerFieldID.LoginStatus]; switch ((UserLoginStatus)loginStatus.Data) { case UserLoginStatus.Success: { // signal authentication success Core.NotifyAuthentication(this, data[UserManagerFieldID.SessionInfo].AsByteArray()); // preparing login data message FieldList appContext = (FieldList)data[UserManagerFieldID.ApplicationContext]; if (appContext != null) { int appID = appContext[MessageOutFieldID.ApplicationID].AsInteger() ?? 0; string unqualifiedAppURI = appContext[UserManagerFieldID.ApplicationUnqualifiedURI].AsText(); string fullyQualifiedAppURI = appContext[UserManagerFieldID.ApplicationFullyQualifiedURI].AsText(); Core.NotifySuccessfulLogin(this, appID, unqualifiedAppURI, fullyQualifiedAppURI); } authenticated = true; authenticatedEver = true; break; } case UserLoginStatus.FailedInvalidCredentials: Core.NotifyTerminateSession(this, SessionTerminationReasonCode.InvalidCredentials); break; case UserLoginStatus.FailedNoUser: Core.NotifyTerminateSession(this, SessionTerminationReasonCode.NoSuchUser); break; } } break; } } } } }