public bool TypeExists(ObjectName typeName) { if (typesCache.ContainsKey(typeName)) { return(true); } var table = Transaction.GetTable(TypeTableName); var schemaName = typeName.ParentName; var name = typeName.Name; var schemaCol = table.GetResolvedColumnName(1); var nameCol = table.GetResolvedColumnName(2); using (var session = new SystemSession(Transaction)) { using (var query = session.CreateQuery()) { var t = table.SimpleSelect(query, schemaCol, SqlExpressionType.Equal, SqlExpression.Constant(schemaName)); t = t.ExhaustiveSelect(query, SqlExpression.Equal(SqlExpression.Reference(nameCol), SqlExpression.Constant(name))); if (t.RowCount > 1) { throw new InvalidOperationException(String.Format("Name '{0}' resolves to multiple types.", typeName)); } return(t.RowCount == 1); } } }
public bool DropTrigger(ObjectName triggerName) { if (triggerName == null) { throw new ArgumentNullException("triggerName"); } var table = transaction.GetMutableTable(TriggerTableName); var schemaName = triggerName.ParentName; var name = triggerName.Name; var schemaCol = table.GetResolvedColumnName(0); var nameCol = table.GetResolvedColumnName(1); using (var session = new SystemSession(transaction)) { using (var query = session.CreateQuery()) { var t = table.SimpleSelect(query, nameCol, SqlExpressionType.Equal, SqlExpression.Constant(name)); t = t.ExhaustiveSelect(query, SqlExpression.Equal(SqlExpression.Reference(schemaCol), SqlExpression.Constant(schemaName))); if (t.RowCount == 0) { return(false); } table.Delete(t); transaction.OnObjectDropped(DbObjectType.Trigger, triggerName); return(true); } } }
private ITable FindViewEntry(ObjectName viewName) { var table = Transaction.GetTable(SystemSchema.ViewTableName); var schemav = table.GetResolvedColumnName(0); var namev = table.GetResolvedColumnName(1); using (var session = new SystemSession(Transaction, SystemSchema.Name)) { using (var query = session.CreateQuery()) { var t = table.SimpleSelect(query, namev, SqlExpressionType.Equal, SqlExpression.Constant(DataObject.String(viewName.Name))); t = t.ExhaustiveSelect(query, SqlExpression.Equal(SqlExpression.Reference(schemav), SqlExpression.Constant(viewName.ParentName))); // This should be at most 1 row in size if (t.RowCount > 1) { throw new ArgumentException(String.Format("Multiple view entries for name '{0}' in the system.", viewName)); } // Return the entries found. return(t); } } }
private void CheckForRegSoftware(string SubKey, string[] RegSubKeyArray) { foreach (var item in RegSubKeyArray) { string TmpSubKey = SubKey + @"\" + item; CimMethodResult SoftwareData = SystemSession.InvokeMethod(new CimInstance(RegistryClassName, RegistryNameSpace), "EnumValues", SetRegParameters(RegHives.LOCAL_MACHINE, RegistryMethods.EnumValues, TmpSubKey)); string[] SoftWareDataFields = (string[])SoftwareData.OutParameters["sNames"].Value; if (SoftWareDataFields != null) { string DisplayName = ""; string DisplayVersion = ""; foreach (var DataField in SoftWareDataFields) { if (DataField == "DisplayName") { CimMethodResult NameResults = SystemSession.InvokeMethod(new CimInstance(RegistryClassName, RegistryNameSpace), "GetStringValue", SetRegParameters(RegHives.LOCAL_MACHINE, RegistryMethods.GetStringValue, TmpSubKey, "DisplayName")); DisplayName = NameResults.OutParameters["sValue"].Value.ToString(); } if (DataField == "DisplayVersion") { CimMethodResult VersionResults = SystemSession.InvokeMethod(new CimInstance(RegistryClassName, RegistryNameSpace), "GetStringValue", SetRegParameters(RegHives.LOCAL_MACHINE, RegistryMethods.GetStringValue, TmpSubKey, "DisplayVersion")); DisplayVersion = VersionResults.OutParameters["sValue"].Value.ToString(); } } } } }
private ITable FindEntry(ObjectName routineName) { var table = transaction.GetTable(RoutineTableName); var schemav = table.GetResolvedColumnName(1); var namev = table.GetResolvedColumnName(2); using (var session = new SystemSession(transaction)) { using (var context = session.CreateQuery()) { var t = table.SimpleSelect(context, namev, SqlExpressionType.Equal, SqlExpression.Constant(Field.String(routineName.Name))); t = t.ExhaustiveSelect(context, SqlExpression.Equal(SqlExpression.Reference(schemav), SqlExpression.Constant(Field.String(routineName.ParentName)))); // This should be at most 1 row in size if (t.RowCount > 1) { throw new Exception("Assert failed: multiple procedure names for " + routineName); } // Return the entries found. return(t); } } }
public CimMethodParametersCollection GetParametersForMethod(string NameSpace, string ClassName, string MethodName) { // Returns all In parameters for a given method. Note: Out parameters are not output as this will result in errors when a query is run. CimMethodParametersCollection CimParams = new CimMethodParametersCollection(); CimClass cimClass = SystemSession.GetClass(NameSpace, ClassName); foreach (CimMethodDeclaration CimMDItem in cimClass.CimClassMethods) { if (CimMDItem.Name == MethodName) { foreach (var ParaItem in CimMDItem.Parameters) { bool isInParam = false; foreach (var Qitem in ParaItem.Qualifiers) { if (Qitem.Name.ToLower() == "in") { isInParam = true; } } if (isInParam) { CimParams.Add(CimMethodParameter.Create(ParaItem.Name, null, ParaItem.CimType, CimFlags.In)); } } } } return(CimParams); }
public async Task <object> GetSettings(string groupId, SystemSession session) { var response = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject(Client.ChatGroupService.getSettings(session.UserName, groupId, session.GetSession()))).ConfigureAwait(false); //var result = response.Select(x => new KeyValuePair<string, string>(x.Key, x.Value)); return(response); }
/// <summary> /// Obtain current user's aggregated session information. /// </summary> /// <param name="request">Current request.</param> /// <returns>Current user's information stored in the user's session.</returns> public static SystemSession GetSession(this HttpRequestMessage request) { var currentSession = HttpContext.Current.Session; if (currentSession == null) { return(null); } var session = new SystemSession { UserId = Convert.ToInt32(currentSession[0]), UserName = currentSession[1].ToString(), UserTypeId = Convert.ToByte(currentSession[2]), DeviceTypeId = currentSession[3].ToString(), DeviceId = currentSession[4].ToString(), LoginToken = currentSession[5].ToString(), IUserId = Convert.ToInt32(currentSession[0]) }; if (session.DeviceTypeId.Equals("W", StringComparison.OrdinalIgnoreCase)) { session.Ip = HttpContext.Current.Request.UserHostAddress; } return(session); }
private WorkingDayFixed GetWorkingDayFixedList(long personEmploymentId, SystemSession session) { var workScheduleList = Client.UserService.getEmployeeWorkSchedule(personEmploymentId, session.GetSession()).Where(x => x.ScheduleType).ToList(); if (!workScheduleList.Any()) { return(null); } var wkDay = new List <SystemDayOfWeek>(); for (var i = 0; i <= 6; ++i) { if (workScheduleList.Any(x => x.Day == i)) { wkDay.Add((SystemDayOfWeek)i); } } var fixedSchedule = new WorkingDayFixed { WorkTime = new WorkingTime { From = workScheduleList.First().StartTime, To = workScheduleList.First().EndTime }, WeekDay = wkDay }; return(fixedSchedule); }
public View GetView(ObjectName viewName) { var viewTable = Transaction.GetTable(SystemSchema.ViewTableName); var e = viewTable.GetEnumerator(); while (e.MoveNext()) { int row = e.Current.RowId.RowNumber; var cSchema = viewTable.GetValue(row, 0).Value.ToString(); var cName = viewTable.GetValue(row, 1).Value.ToString(); if (viewName.ParentName.Equals(cSchema) && viewName.Name.Equals(cName)) { ViewInfo viewInfo; if (!viewCache.TryGetValue(row, out viewInfo)) { var blob = (SqlBinary)viewTable.GetValue(row, 3).Value; using (var session = new SystemSession(Transaction, SystemSchema.Name)) { using (var context = session.CreateQuery()) { viewInfo = ViewInfo.Deserialize(blob.GetInput()); } } viewCache[row] = viewInfo; } return(new View(viewInfo)); } } return(null); }
public async Task <UserSearchResponse> UserSearch(UserSearchRequest request, SystemSession session) { var serviceRequest = new UserSearchQuery { Query = request.Query, Cursor = request.Cursor, Limit = request.Limit }; var response = await Task.Factory.StartNew(() => Client.SearchService.userSearch(serviceRequest, session.GetSession())).ConfigureAwait(false); var result = new UserSearchResponse { Cursor = response.Cursor, Limit = response.Limit, Count = response.Count, User = response.Users != null?response.Users.Select(x => new UserInformationBaseExtendedResponse { FirstName = x.UserInfoPerson.FirstName, LastName = x.UserInfoPerson.LastName, Image = x.UserInfo.Picture, Title = x.UserInfo.Title, UserId = Convert.ToInt32(x.UserInfoPerson.UserId), UserName = x.UserName, UserTypeId = (SystemUserType)x.UserInfo.UserTypeId }) : null }; return(result); }
//public async Task<StatusData<int>> DeleteInbox(InboxRequest request, int folderId, SystemSession session) //{ // var inboxRequest = new Kauwa.Inbox { UserId = request.UserId, FolderId = folderId }; // var serviceResponse = await Task.Factory.StartNew(() => _client.InboxService.deleteInboxFolder(inboxRequest, session.GetSession())); // var response = serviceResponse.GetStatusData<int>(); // response.Data = folderId; // return response; //} public async Task <StatusData <string> > DeleteInbox(List <int> folderList, SystemSession session) { var serviceResponse = await Task.Factory.StartNew(() => Client.InboxService.deleteInboxFolder(string.Join(",", folderList), session.GetSession())).ConfigureAwait(false); var response = serviceResponse.GetStatusData <string>(); return(response); }
public async Task <StatusData <int> > GetMessageCount(SystemSession session) { var result = new StatusData <int>(); var response = await Task.Factory.StartNew(() => Client.NotificationService.messageCount(session.GetSession())).ConfigureAwait(false); result.Data = response; return(result); }
public async Task <SystemDbStatus> SaveFileName(string fileId, SystemSession session) { var status = await _unitOfWork.Media.SaveFileName(fileId, session); await _unitOfWork.CommitAsync(); return(status); }
public async Task <string> GetUrl(ImageRequest request, SystemSession session) { var serviceRequest = new Elif { FileId = request.FileId, AskWebp = request.AskWebp, IsProfilePic = request.IsProfilePicture, SizeCodes = (SizedCodes)request.SizeCode, Username = request.UserName }; var response = await Task.Factory.StartNew(() => Client.ElifService.getUrl(serviceRequest, session.GetSession())).ConfigureAwait(false); // return string.IsNullOrWhiteSpace(response) ? null : response; return(response); }
public async Task <StatusData <string> > RollBack(string fileId, SystemSession session) { var response = await Task.Factory.StartNew(() => Client.ElifService.rollback(fileId, session.GetSession())).ConfigureAwait(false); var result = new StatusData <string> { Status = response ? SystemDbStatus.Updated : SystemDbStatus.NotModified }; return(result); }
public void EnumerateBaseSoftwareKeys() { string SubKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"; CimMethodResult CimMR = SystemSession.InvokeMethod(new CimInstance(RegistryClassName, RegistryNameSpace), "EnumKey", SetRegParameters(RegHive.LOCAL_MACHINE, RegistryMethods.EnumKey, SubKey)); string[] RegSubKeyArray = (string[])CimMR.OutParameters["sNames"].Value; if (RegSubKeyArray != null) { CheckForRegSoftware(SubKey, RegSubKeyArray); } }
public async Task <SystemDbStatus> SaveFileName(string fileId, SystemSession session) { var user = await FirstOrDefaultAsync(x => x.UserID == session.UserId).ConfigureAwait(false); if (user != null) { user.Picture = fileId; return(SystemDbStatus.Updated); } return(SystemDbStatus.NotModified); }
public async Task <StatusData <string> > UpsertSkill(SkillRequest request, SystemSession session) { var serviceRequest = new Kauwa.Skill { UserId = session.UserId, Text = string.Join(",", request.Skills), UserIdOrName = session.UserName // ProfileUserId = request.ProfileUserId, }; var response = (await Task.Factory.StartNew(() => Client.UserService.upsertSkill(serviceRequest, session.GetSession())).ConfigureAwait(false)).GetStatusData <string>(); return(response); }
private List <CimInstance> GetClassListData(string NameSpace, string ClassName, string Query) { List <CimInstance> cimInstances = new List <CimInstance>(); try { cimInstances = SystemSession.QueryInstances(NameSpace, "WQL", Query).ToList(); } catch (Exception ex) { // Log error :ex.Message "Error while running method GetClassListData" } return(cimInstances); }
//public StatusData<GeneralKvPair<string, string>> SignOut(SystemSession sessionObject, SignOut request) //{ // var result = new StatusData<GeneralKvPair<string, string>> // { // Status = SystemDbStatus.Deleted, // Data = new GeneralKvPair<string, string>() // }; // var session = new Session { SessionToken = request.Token, DeviceId = request.DeviceId, UserId = request.UserName, Replay = true }; // //var user = new User { Session = new Session { UserId = request.UserId.ToString(), SessionToken = request.LoginToken, DeviceId = request.DeviceId, Replay = true }, UsernameEmail = request.UserName }; // //var aa = _client.Service.Kill(user); // _client.SessionService.killSession(session); // result.Data.Id = request.DeviceId; // result.Data.Value = request.Token; // return result; //} public async Task <StatusData <bool> > SignOut(SystemSession sessionObject, SignOut request) { var result = new StatusData <bool> { Status = SystemDbStatus.Deleted }; var session = new Session { SessionToken = request.Token, DeviceId = request.DeviceId, UserId = request.UserName, Replay = true }; result.Data = await Task.Factory.StartNew(() => Client.SessionService.killSession(session)).ConfigureAwait(false); return(result); }
/// <summary> /// Returns Session object as required by JService. /// </summary> /// <param name="session">Current user's session containing all information.</param> /// <returns>Session object.</returns> public static Session GetSession(this SystemSession session) { var userSession = new Session { SessionToken = session.LoginToken, DeviceId = session.DeviceId, UserId = session.UserName, Replay = true, IUserId = session.UserId, TransportIp = session.Ip }; return(userSession); }
public async Task <IEnumerable <CategoryResponse> > GetUserCategoryList(SystemSession session) { var result = await Task.Factory.StartNew(() => Client.UserService.categoryList(session.UserId, session.GetSession())).ConfigureAwait(false); return(result.Select(c => new CategoryResponse { Name = c.Name, CategoryId = c.UserCategoryTypeId, Description = c.Description, // Users = c.Friends.ToList().Select(x => Convert.ToInt32(x)), Friends = c.Friends == null ? new List <int>() : c.Friends.ToList().Select(x => Convert.ToInt32(x)), IsSystemDefaultCategory = c.IsSystemDefault })); }
public async Task <AboutResponse> GetUserAbout(string targetUser, SystemSession session) { AboutResponse response = null; var result = await Task.Factory.StartNew(() => Client.UserService.getUserAbout(targetUser, session.GetSession())).ConfigureAwait(false); if (result != null) { response = new AboutResponse { Headline = result.HeadLine, About = result.About }; } return(response); }
public async Task <IEnumerable <SettingResponse> > ActiveDeviceList(SystemSession session) { var response = await Task.Factory.StartNew(() => Client.SessionService.getSession(session.GetSession())).ConfigureAwait(false); var result = response.Select(x => new SettingResponse { LastActivity = x.LastActivity, DeviceId = x.DeviceId, ModelName = x.ModelName, Token = x.SessionToken, DeviceType = x.DeviceType }); return(result); }
public async Task <IEnumerable <InboxResponse> > GetInboxFolder(SystemSession session) { var response = await Task.Factory.StartNew(() => Client.InboxService.listInboxFolders(session.UserId, session.GetSession())).ConfigureAwait(false); var result = response.Select(x => new InboxResponse { FolderId = x.FolderId, Name = x.Name, Created = Convert.ToDateTime(x.CreatedDate), RuleCount = x.RuleCount, Mute = x.Muted == 1 }); return(result); }
private ITable FindTrigger(ITable table, string schema, string name) { // Find all the trigger entries with this name var schemaColumn = table.GetResolvedColumnName(0); var nameColumn = table.GetResolvedColumnName(1); using (var session = new SystemSession(transaction, SystemSchema.Name)) { using (var context = session.CreateQuery()) { var t = table.SimpleSelect(context, nameColumn, SqlExpressionType.Equal, SqlExpression.Constant(DataObject.String(name))); return(t.ExhaustiveSelect(context, SqlExpression.Equal(SqlExpression.Reference(schemaColumn), SqlExpression.Constant(DataObject.String(schema))))); } } }
////public async Task<StatusData<bool>> Crop(ImageCropRequest cropRequest, SystemSession session) ////{ //// var serviceRequest = new Elif { FileId = cropRequest.FileId, AskWebp = cropRequest.AskWebp, Username = cropRequest.UserName }; //// var serviceCropRequest = new ElifImageCrop { Width = cropRequest.CropDetail.Width, Height = cropRequest.CropDetail.Height, Top = cropRequest.CropDetail.Top, Bottom = cropRequest.CropDetail.Bottom, Left = cropRequest.CropDetail.Left, Right = cropRequest.CropDetail.Right, SizeCodes = (SizedCodes)cropRequest.CropDetail.SizeCode }; //// var response = await Task.Factory.StartNew(() => Client.ElifService.doCrop(serviceRequest, serviceCropRequest, session.GetSession())).ConfigureAwait(false); //// var result = new StatusData<bool> { Status = response ? SystemDbStatus.Updated : SystemDbStatus.NotModified, Data = response }; //// return result; ////} public async Task <StatusData <bool> > Crop(ImageCropRequest cropRequest, SystemSession session) { var result = new StatusData <bool> { Status = SystemDbStatus.Updated }; var serviceRequest = new Elif { FileId = cropRequest.FileId, AskWebp = cropRequest.AskWebp, Username = cropRequest.UserName }; var serviceCropRequest = new ElifImageCrop { Width = cropRequest.CropDetail.Width, Height = cropRequest.CropDetail.Height, Top = cropRequest.CropDetail.Top, Bottom = cropRequest.CropDetail.Bottom, Left = cropRequest.CropDetail.Left, Right = cropRequest.CropDetail.Right, SizeCodes = (SizedCodes)cropRequest.CropDetail.SizeCode }; result.Data = await Task.Factory.StartNew(() => Client.ElifService.doCrop(serviceRequest, serviceCropRequest, session.GetSession())).ConfigureAwait(false); return(result); }
private IEnumerable <TriggerInfo> FindTriggers(ObjectName tableName, TriggerEventType eventType) { var fullTableName = tableName.FullName; var eventTypeCode = (int)eventType; var table = transaction.GetTable(SystemSchema.TriggerTableName); if (table == null) { return(new TriggerInfo[0]); } var tableColumn = table.GetResolvedColumnName(3); var eventTypeColumn = table.GetResolvedColumnName(4); ITable result; using (var session = new SystemSession(transaction, SystemSchema.Name)) { using (var context = session.CreateQuery()) { var t = table.SimpleSelect(context, tableColumn, SqlExpressionType.Equal, SqlExpression.Constant(DataObject.String(fullTableName))); result = t.ExhaustiveSelect(context, SqlExpression.Equal(SqlExpression.Reference(eventTypeColumn), SqlExpression.Constant(eventTypeCode))); } } if (result.RowCount == 0) { return(new TriggerInfo[0]); } var list = new List <TriggerInfo>(); foreach (var row in result) { var triggerInfo = FormTrigger(row); //TODO: get the other information such has the body, the external method or the procedure // if this is a non-callback list.Add(triggerInfo); } return(list.AsEnumerable()); }
private View GetViewAt(int offset) { var table = Transaction.GetTable(SystemSchema.ViewTableName); if (table == null) { throw new DatabaseSystemException(String.Format("System table '{0}' was not defined.", SystemSchema.ViewTableName)); } var e = table.GetEnumerator(); int i = 0; while (e.MoveNext()) { var row = e.Current.RowId.RowNumber; if (i == offset) { ViewInfo viewInfo; if (!viewCache.TryGetValue(row, out viewInfo)) { var binary = (ISqlBinary)table.GetValue(row, 3).Value; using (var session = new SystemSession(Transaction, SystemSchema.Name)) { using (var context = session.CreateQuery()) { viewInfo = ViewInfo.Deserialize(binary.GetInput()); } } viewCache[row] = viewInfo; } return(new View(viewInfo)); } ++i; } throw new ArgumentOutOfRangeException("offset"); }
private View GetViewAt(int offset) { var table = Transaction.GetTable(SystemSchema.ViewTableName); if (table == null) throw new DatabaseSystemException(String.Format("System table '{0}' was not defined.", SystemSchema.ViewTableName)); var e = table.GetEnumerator(); int i = 0; while (e.MoveNext()) { var row = e.Current.RowId.RowNumber; if (i == offset) { ViewInfo viewInfo; if (!viewCache.TryGetValue(row, out viewInfo)) { var binary = (ISqlBinary)table.GetValue(row, 3).Value; using (var session = new SystemSession(Transaction, SystemSchema.Name)) { using (var context = session.CreateQuery()) { viewInfo = ViewInfo.Deserialize(binary.GetInput()); } } viewCache[row] = viewInfo; } return new View(viewInfo); } ++i; } throw new ArgumentOutOfRangeException("offset"); }
public View GetView(ObjectName viewName) { var viewTable = Transaction.GetTable(SystemSchema.ViewTableName); var e = viewTable.GetEnumerator(); while (e.MoveNext()) { int row = e.Current.RowId.RowNumber; var cSchema = viewTable.GetValue(row, 0).Value.ToString(); var cName = viewTable.GetValue(row, 1).Value.ToString(); if (viewName.ParentName.Equals(cSchema) && viewName.Name.Equals(cName)) { ViewInfo viewInfo; if (!viewCache.TryGetValue(row, out viewInfo)) { var blob = (SqlBinary)viewTable.GetValue(row, 3).Value; using (var session = new SystemSession(Transaction, SystemSchema.Name)) { using (var context = session.CreateQuery()) { viewInfo = ViewInfo.Deserialize(blob.GetInput()); } } viewCache[row] = viewInfo; } return new View(viewInfo); } } return null; }
public bool AlterTable(TableInfo tableInfo) { tableInfo = tableInfo.AsReadOnly(); var tableName = tableInfo.TableName; // The current schema context is the schema of the table name string currentSchema = tableName.Parent.Name; using (var session = new SystemSession(Transaction, currentSchema)) { using (var context = session.CreateQuery()) { // Get the next unique id of the unaltered table. var nextId = NextUniqueId(tableName); // Drop the current table var cTable = GetTable(tableName); var droppedTableId = cTable.TableInfo.Id; DropTable(tableName); // And create the table table CreateTable(tableInfo); var alteredTable = GetMutableTable(tableName); var source = FindVisibleTable(tableName, false); int alteredTableId = source.TableId; // Set the sequence id of the table source.SetUniqueId(nextId.ToInt64()); // Work out which columns we have to copy to where int[] colMap = new int[tableInfo.ColumnCount]; var origTd = cTable.TableInfo; for (int i = 0; i < colMap.Length; ++i) { string colName = tableInfo[i].ColumnName; colMap[i] = origTd.IndexOfColumn(colName); } // First move all the rows from the old table to the new table, // This does NOT update the indexes. var e = cTable.GetEnumerator(); while (e.MoveNext()) { int rowIndex = e.Current.RowId.RowNumber; var dataRow = alteredTable.NewRow(); for (int i = 0; i < colMap.Length; ++i) { int col = colMap[i]; if (col != -1) { dataRow.SetValue(i, cTable.GetValue(rowIndex, col)); } } dataRow.SetDefault(context); // Note we use a low level 'AddRow' method on the master table // here. This does not touch the table indexes. The indexes are // built later. int newRowNumber = source.AddRow(dataRow); // Set the record as committed added source.WriteRecordState(newRowNumber, RecordState.CommittedAdded); } // TODO: We need to copy any existing index definitions that might // have been set on the table being altered. // Rebuild the indexes in the new master table, source.BuildIndexes(); // Get the snapshot index set on the new table and set it here SetIndexSetForTable(source, source.CreateIndexSet()); // Flush this out of the table cache FlushTableCache(tableName); // Ensure the native sequence generator exists... Transaction.RemoveNativeSequence(tableName); Transaction.CreateNativeSequence(tableName); // Notify that this database object has been successfully dropped and // created. Transaction.Registry.RegisterEvent(new TableDroppedEvent(droppedTableId, tableName)); Transaction.Registry.RegisterEvent(new TableCreatedEvent(alteredTableId, tableName)); return true; } } }
private IEnumerable<TriggerInfo> FindTriggers(ObjectName tableName, TriggerEventType eventType) { var fullTableName = tableName.FullName; var eventTypeCode = (int)eventType; var table = transaction.GetTable(SystemSchema.TriggerTableName); if (table == null) return new TriggerInfo[0]; var tableColumn = table.GetResolvedColumnName(3); var eventTypeColumn = table.GetResolvedColumnName(4); ITable result; using (var session = new SystemSession(transaction, SystemSchema.Name)) { using (var context = session.CreateQuery()) { var t = table.SimpleSelect(context, tableColumn, SqlExpressionType.Equal, SqlExpression.Constant(DataObject.String(fullTableName))); result = t.ExhaustiveSelect(context, SqlExpression.Equal(SqlExpression.Reference(eventTypeColumn), SqlExpression.Constant(eventTypeCode))); } } if (result.RowCount == 0) return new TriggerInfo[0]; var list = new List<TriggerInfo>(); foreach (var row in result) { var triggerInfo = FormTrigger(row); //TODO: get the other information such has the body, the external method or the procedure // if this is a non-callback list.Add(triggerInfo); } return list.AsEnumerable(); }
public bool TypeExists(ObjectName typeName) { if (typesCache.ContainsKey(typeName)) return true; var table = Transaction.GetTable(TypeTableName); var schemaName = typeName.ParentName; var name = typeName.Name; var schemaCol = table.GetResolvedColumnName(1); var nameCol = table.GetResolvedColumnName(2); using (var session = new SystemSession(Transaction)) { using (var query = session.CreateQuery()) { var t = table.SimpleSelect(query, schemaCol, SqlExpressionType.Equal, SqlExpression.Constant(schemaName)); t = t.ExhaustiveSelect(query, SqlExpression.Equal(SqlExpression.Reference(nameCol), SqlExpression.Constant(name))); if (t.RowCount > 1) throw new InvalidOperationException(String.Format("Name '{0}' resolves to multiple types.", typeName)); return t.RowCount == 1; } } }
public bool DropTrigger(ObjectName triggerName) { if (triggerName == null) throw new ArgumentNullException("triggerName"); var table = transaction.GetMutableTable(TriggerTableName); var schemaName = triggerName.ParentName; var name = triggerName.Name; var schemaCol = table.GetResolvedColumnName(0); var nameCol = table.GetResolvedColumnName(1); using (var session = new SystemSession(transaction)) { using (var query = session.CreateQuery()) { var t = table.SimpleSelect(query, nameCol, SqlExpressionType.Equal, SqlExpression.Constant(name)); t = t.ExhaustiveSelect(query, SqlExpression.Equal(SqlExpression.Reference(schemaCol), SqlExpression.Constant(schemaName))); if (t.RowCount == 0) return false; table.Delete(t); transaction.OnObjectDropped(DbObjectType.Trigger, triggerName); return true; } } }
public UserType GetUserType(ObjectName typeName) { UserType userType; if (!typesCache.TryGetValue(typeName, out userType)) { var typeTable = Transaction.GetTable(TypeTableName); var membersTable = Transaction.GetTable(TypeMemberTableName); var schemaName = typeName.ParentName; var name = typeName.Name; var schemaColumn = typeTable.GetResolvedColumnName(1); var nameColumn = typeTable.GetResolvedColumnName(2); var idColumn = membersTable.GetResolvedColumnName(0); UserTypeInfo typeInfo; using (var session = new SystemSession(Transaction)) { using (var query = session.CreateQuery()) { var t = typeTable.SimpleSelect(query, schemaColumn, SqlExpressionType.Equal, SqlExpression.Constant(schemaName)); t = t.ExhaustiveSelect(query, SqlExpression.Equal(SqlExpression.Reference(nameColumn), SqlExpression.Constant(name))); if (t.RowCount == 0) return null; var id = t.GetValue(0, 0); var parentField = t.GetValue(0, 3); ObjectName parentType = null; if (!Field.IsNullField(parentField)) { parentType = ObjectName.Parse(parentField.Value.ToString()); } typeInfo = new UserTypeInfo(typeName, parentType); var isSealedField = t.GetValue(0, 4); var isAbstractField = t.GetValue(0, 5); if (!Field.IsNullField(isSealedField)) { typeInfo.IsSealed = (SqlBoolean) isSealedField.AsBoolean().Value; } if (!Field.IsNullField(isAbstractField)) { typeInfo.IsAbstract = (SqlBoolean) isAbstractField.AsBoolean().Value; } var owner = t.GetValue(0, 6).Value.ToString(); typeInfo.Owner = owner; var t2 = membersTable.SimpleSelect(query, idColumn, SqlExpressionType.Equal, SqlExpression.Constant(id)); foreach (var row in t2) { var memberName = row.GetValue(1).Value.ToString(); var memberTypeString = row.GetValue(2).Value.ToString(); var memberType = SqlType.Parse(Transaction.Context, memberTypeString); if (memberType == null) throw new InvalidOperationException(String.Format("Cannot find the type '{0}' for member '{1}' of type '{2}'.", memberTypeString, memberName, typeName)); typeInfo.AddMember(memberName, memberType); } } } userType = new UserType(typeInfo); typesCache[typeName] = userType; } return userType; }
private ITable FindTrigger(ITable table, string schema, string name) { // Find all the trigger entries with this name var schemaColumn = table.GetResolvedColumnName(0); var nameColumn = table.GetResolvedColumnName(1); using (var session = new SystemSession(transaction, SystemSchema.Name)) { using (var context = session.CreateQuery()) { var t = table.SimpleSelect(context, nameColumn, SqlExpressionType.Equal, SqlExpression.Constant(Field.String(name))); return t.ExhaustiveSelect(context, SqlExpression.Equal(SqlExpression.Reference(schemaColumn), SqlExpression.Constant(Field.String(schema)))); } } }
public bool RoutineExists(ObjectName routineName) { if (routinesCache.ContainsKey(routineName)) return true; var table = transaction.GetTable(RoutineTableName); var schemav = table.GetResolvedColumnName(1); var namev = table.GetResolvedColumnName(2); using (var session = new SystemSession(transaction)) { using (var context = session.CreateQuery()) { var t = table.SimpleSelect(context, namev, SqlExpressionType.Equal, SqlExpression.Constant(Field.String(routineName.Name))); t = t.ExhaustiveSelect(context, SqlExpression.Equal(SqlExpression.Reference(schemav), SqlExpression.Constant(Field.String(routineName.ParentName)))); return t.RowCount == 1; } } }
private ITable FindEntry(ObjectName routineName) { var table = transaction.GetTable(RoutineTableName); var schemav = table.GetResolvedColumnName(1); var namev = table.GetResolvedColumnName(2); using (var session = new SystemSession(transaction)) { using (var context = session.CreateQuery()) { var t = table.SimpleSelect(context, namev, SqlExpressionType.Equal, SqlExpression.Constant(Field.String(routineName.Name))); t = t.ExhaustiveSelect(context, SqlExpression.Equal(SqlExpression.Reference(schemav), SqlExpression.Constant(Field.String(routineName.ParentName)))); // This should be at most 1 row in size if (t.RowCount > 1) throw new Exception("Assert failed: multiple procedure names for " + routineName); // Return the entries found. return t; } } }
private ITable FindViewEntry(ObjectName viewName) { var table = Transaction.GetTable(SystemSchema.ViewTableName); var schemav = table.GetResolvedColumnName(0); var namev = table.GetResolvedColumnName(1); using (var session = new SystemSession(Transaction, SystemSchema.Name)) { using (var query =session.CreateQuery()) { var t = table.SimpleSelect(query, namev, SqlExpressionType.Equal, SqlExpression.Constant(DataObject.String(viewName.Name))); t = t.ExhaustiveSelect(query, SqlExpression.Equal(SqlExpression.Reference(schemav), SqlExpression.Constant(viewName.ParentName))); // This should be at most 1 row in size if (t.RowCount > 1) throw new ArgumentException(String.Format("Multiple view entries for name '{0}' in the system.", viewName)); // Return the entries found. return t; } } }