private string SaveDeviceSettings(ServerProcess process) { D4TextEmitter emitter = new D4TextEmitter(); Block block = new Block(); IServerProcess localProcess = (IServerProcess)process; IServerCursor cursor = localProcess.OpenCursor("select Devices { ID }", null); try { using (IRow row = cursor.Plan.RequestRow()) { while (cursor.Next()) { cursor.Select(row); Schema.Device device = process.CatalogDeviceSession.ResolveCatalogObject((int)row[0 /*"ID"*/]) as Schema.Device; if ((device != null) && (device.ClassDefinition.Attributes.Count > 0)) { block.Statements.Add(SaveSystemDeviceSettings(device)); } } } } finally { localProcess.CloseCursor(cursor); } return(new D4TextEmitter().Emit(block) + "\r\n"); }
public void Open() { if (_shouldOpen && (_cursor == null)) { if (_plan == null) { try { _cursor = _process.OpenCursor(_expression, _params); } catch (Exception exception) { CompilerMessages messages = new CompilerMessages(); messages.Add(exception); ErrorsOccurred(messages); throw exception; } _plan = _cursor.Plan; _tableVar = _plan.TableVar; ErrorsOccurred(_plan.Messages); } else { _cursor = _plan.Open(_params); } } }
public void TestDeleteAtBOF() { IServerProcess LProcess = DataSession.ServerSession.StartProcess(new ProcessInfo(DataSession.SessionInfo)); try { var LFetchCount = DataSession.ServerSession.SessionInfo.FetchCount; LProcess.Execute("create table TestDeleteAtBOF { ID : Integer, Name : String, key { ID } };", null); LProcess.Execute("insert row { 1 ID, 'Joe' Name } into TestDeleteAtBOF;", null); LProcess.Execute("insert row { 2 ID, 'John' Name } into TestDeleteAtBOF;", null); IServerCursor LCursor = LProcess.OpenCursor("select TestDeleteAtBOF browse by { ID } capabilities { navigable, backwardsnavigable, bookmarkable, searchable, updateable } isolation browse", null); try { var LRow = LCursor.Plan.RequestRow(); try { LCursor.Last(); LCursor.Prior(); LCursor.Prior(); LCursor.Delete(); if (LCursor.BOF() && !LCursor.Next()) { throw new Exception("Delete At BOF failed"); } } finally { LCursor.Plan.ReleaseRow(LRow); } } finally { LProcess.CloseCursor(LCursor); } } finally { DataSession.ServerSession.StopProcess(LProcess); } }
public void TestCLI() { IServerProcess LProcess = DataSession.ServerSession.StartProcess(new ProcessInfo(DataSession.SessionInfo)); try { var LFetchCount = DataSession.ServerSession.SessionInfo.FetchCount; LProcess.Execute("create table Test { ID : Integer, key { ID } };", null); LProcess.Execute(String.Format("for var LIndex := 1 to {0} do insert row {{ LIndex ID }} into Test;", LFetchCount.ToString()), null); IServerCursor LCursor = LProcess.OpenCursor("select Test order by { ID } capabilities { navigable, backwardsnavigable, bookmarkable, searchable, updateable }", null); try { var LCounter = 0; while (LCursor.Next()) { using (IRow LRow = LCursor.Select()) { LCounter += (int)LRow[0]; } } if (LCounter != (LFetchCount * (LFetchCount + 1)) / 2) { throw new Exception("Fetch count summation failed"); } LCursor.Reset(); LCounter = 0; while (LCursor.Next()) { using (IRow LRow = LCursor.Select()) { LCounter++; if (LCounter != (int)LRow[0]) { throw new Exception("Select failed"); } } } LCursor.Reset(); LCounter = 0; LCursor.Next(); LCursor.Next(); using (IRow LRow = LCursor.Select()) { LRow[0] = -1; LCursor.Update(LRow); } using (IRow LRow = LCursor.Select()) { if ((int)LRow[0] != -1) { throw new Exception("Update failed"); } } LCursor.Delete(); using (IRow LRow = LCursor.Select()) { if ((int)LRow[0] != 1) { throw new Exception("Delete failed"); } LRow[0] = 2; LCursor.Insert(LRow); } using (IRow LRow = LCursor.Select()) { if ((int)LRow[0] != 2) { throw new Exception("Insert failed"); } } LCursor.Reset(); LCounter = 0; Guid LBookmark = Guid.Empty; while (LCursor.Next()) { using (IRow LRow = LCursor.Select()) { LCounter++; if (LCounter == 5) { LBookmark = LCursor.GetBookmark(); } } } if (!LCursor.GotoBookmark(LBookmark, true)) { throw new Exception("GotoBookmark failed"); } using (IRow LRow = LCursor.Select()) { if ((int)LRow[0] != 5) { throw new Exception("GotoBookmark failed"); } } LCursor.DisposeBookmark(LBookmark); } finally { LProcess.CloseCursor(LCursor); } LProcess.Execute("delete Test;", null); LFetchCount *= 10; LProcess.Execute(String.Format("for var LIndex := 1 to {0} do insert row {{ LIndex ID }} into Test;", LFetchCount.ToString()), null); LCursor = LProcess.OpenCursor("select Test order by { ID } capabilities { navigable, backwardsnavigable, bookmarkable, searchable, updateable }", null); try { var LCounter = 0; while (LCursor.Next()) { using (IRow LRow = LCursor.Select()) { LCounter += (int)LRow[0]; } } if (LCounter != (LFetchCount * (LFetchCount + 1)) / 2) { throw new Exception("Fetch count summation failed"); } LCursor.Reset(); LCounter = 0; while (LCursor.Next()) { using (IRow LRow = LCursor.Select()) { LCounter++; if (LCounter != (int)LRow[0]) { throw new Exception("Select failed"); } } } } finally { LProcess.CloseCursor(LCursor); } } finally { DataSession.ServerSession.StopProcess(LProcess); } }
private string SaveSecurity(ServerProcess process) { StringBuilder result = new StringBuilder(); IServerProcess localProcess = (IServerProcess)process; IServerCursor cursor; // Users result.Append("// Users\r\n"); cursor = localProcess.OpenCursor("select Users { ID }", null); try { using (IRow row = cursor.Plan.RequestRow()) { while (cursor.Next()) { cursor.Select(row); switch ((string)row[0 /*"ID"*/]) { case Engine.SystemUserID: break; case Engine.AdminUserID: if (_adminUser.Password != String.Empty) { result.AppendFormat("SetEncryptedPassword('{0}', '{1}');\r\n", _adminUser.ID, _adminUser.Password); } break; default: Schema.User user = process.CatalogDeviceSession.ResolveUser((string)row[0 /*"ID"*/]); result.AppendFormat("CreateUserWithEncryptedPassword('{0}', '{1}', '{2}');\r\n", user.ID, user.Name, user.Password); break; } } } } finally { localProcess.CloseCursor(cursor); } result.Append("\r\n"); result.Append("// Device Users\r\n"); // DeviceUsers cursor = localProcess.OpenCursor("select DeviceUsers join (Devices { ID Device_ID, Name Device_Name }) { User_ID, Device_ID }", null); try { using (IRow row = cursor.Plan.RequestRow()) { while (cursor.Next()) { cursor.Select(row); Schema.User user = process.CatalogDeviceSession.ResolveUser((string)row[0 /*"User_ID"*/]); Schema.Device device = (Schema.Device)process.CatalogDeviceSession.ResolveCatalogObject((int)row[1 /*"Device_ID"*/]); Schema.DeviceUser deviceUser = process.CatalogDeviceSession.ResolveDeviceUser(device, user); result.AppendFormat("CreateDeviceUserWithEncryptedPassword('{0}', '{1}', '{2}', '{3}', '{4}');\r\n", deviceUser.User.ID, deviceUser.Device.Name, deviceUser.DeviceUserID, deviceUser.DevicePassword, deviceUser.ConnectionParameters); } } } finally { localProcess.CloseCursor(cursor); } result.Append("\r\n"); result.Append("// User Roles\r\n"); // UserRoles cursor = localProcess.OpenCursor("select UserRoles where Role_Name <> 'System.User'", null); try { using (IRow row = cursor.Plan.RequestRow()) { while (cursor.Next()) { cursor.Select(row); result.AppendFormat("AddUserToRole('{0}', '{1}');\r\n", (string)row[0 /*"User_ID"*/], (string)row[1 /*"Role_Name"*/]); } } } finally { localProcess.CloseCursor(cursor); } result.Append("\r\n"); result.Append("// User Right Assignments\r\n"); // UserRightAssignments cursor = localProcess.OpenCursor("select UserRightAssignments", null); try { using (IRow row = cursor.Plan.RequestRow()) { while (cursor.Next()) { cursor.Select(row); if ((bool)row[2 /*"IsGranted"*/]) { result.AppendFormat("GrantRightToUser('{0}', '{1}');\r\n", (string)row[1 /*"Right_Name"*/], (string)row[0 /*"User_ID"*/]); } else { result.AppendFormat("RevokeRightFromUser('{0}', '{1}');\r\n", (string)row[1 /*"Right_Name"*/], (string)row[0 /*"User_ID"*/]); } } } } finally { localProcess.CloseCursor(cursor); } result.Append("\r\n"); return(result.ToString()); }