private void DoDeviceStarted(Schema.Device device) { if (OnDeviceStarted != null) { OnDeviceStarted(this, device); } }
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"); }
private void DoDeviceStarting(Schema.Device device) { if (OnDeviceStarting != null) { OnDeviceStarting(this, device); } }
protected internal MemoryDeviceSession ( Schema.Device device, ServerProcess serverProcess, Schema.DeviceSessionInfo deviceSessionInfo ) : base(device, serverProcess, deviceSessionInfo) { }
private Statement SaveSystemDeviceSettings(Schema.Device device) { AlterDeviceStatement statement = new AlterDeviceStatement(); statement.DeviceName = device.Name; statement.AlterClassDefinition = new AlterClassDefinition(); statement.AlterClassDefinition.AlterAttributes.AddRange(device.ClassDefinition.Attributes); return(statement); }
public object DeviceExecute(Schema.Device device, PlanNode planNode) { if (_serverProcess.IsReconciliationEnabled() || (planNode.DataType != null)) { long startTicks = TimingUtility.CurrentTicks; try { EnsurePrepared(planNode); return(DeviceConnect(device).Execute(this, planNode)); } finally { _statistics.DeviceExecuteTime += TimingUtility.TimeSpanFromTicks(startTicks); } } return(null); }
// DeterminePotentialDevice public virtual void DeterminePotentialDevice(Plan plan) { // if child nodes are flagged with nodevice, or have more than one non-null device // this node is flagged as nodevice // otherwise // this node uses the same potential device as its children Schema.Device childDevice = null; Schema.Device currentChildDevice = null; NoDevice = !ShouldSupport; if (_nodes != null) { for (int index = 0; index < _nodes.Count; index++) { var node = _nodes[index]; node.DeterminePotentialDevice(plan); NoDevice = NoDevice || node.NoDevice; if (!NoDevice) { childDevice = node.PotentialDevice; if (childDevice != null) { if (currentChildDevice == null) { currentChildDevice = childDevice; } else if (currentChildDevice != childDevice) { NoDevice = true; } } } } } if (!NoDevice) { _potentialDevice = currentChildDevice; } }
public void StartDevice(ServerProcess process, Schema.Device device) { if (!device.Running) { // TODO: It's not at all clear that this would have had any effect. // //AProcess.Plan.PushSecurityContext(new SecurityContext(ADevice.Owner)); //try //{ DoDeviceStarting(device); try { process.CatalogDeviceSession.StartDevice(device); process.CatalogDeviceSession.RegisterDevice(device); } catch (Exception exception) { throw new ServerException(ServerException.Codes.DeviceStartupError, exception, device.Name); } if ((device.ReconcileMode & ReconcileMode.Startup) != 0) { try { device.Reconcile(process); } catch (Exception exception) { throw new ServerException(ServerException.Codes.StartupReconciliationError, exception, device.Name); } } DoDeviceStarted(device); //} //finally //{ // AProcess.Plan.PopSecurityContext(); //} } }
public virtual void SetDevice(Plan plan, Schema.Device device) { _device = device; //_deviceSupported = true; }
// DetermineDevice public virtual void DetermineDevice(Plan plan) { // Recheck the NoDevice flag, as it will be set directly when a device-painted node has indicated not supported if (_nodes != null) { for (int index = 0; index < _nodes.Count; index++) { if (_nodes[index].NoDevice) { NoDevice = true; break; } } } if (!NoDevice) { _device = _potentialDevice; if (_device != null) { Schema.DevicePlan devicePlan = null; if (ShouldSupport) { plan.EnsureDeviceStarted(_device); devicePlan = _device.Prepare(plan, this); } if (devicePlan != null) { _deviceMessages = devicePlan.TranslationMessages; } if ((devicePlan != null) && devicePlan.IsSupported) { // If the plan could be supported via parameterization, it is not actually supported by the device // and setting the device supported to false ensures that if this node is actually executed, the // device will not be asked to perform a useless parameterization. DeviceSupported = !CouldSupport; } else { if (!_device.IgnoreUnsupported && (DataType != null) && !IgnoreUnsupported && !plan.InTypeOfContext) { if ((devicePlan != null) && !plan.SuppressWarnings) { plan.Messages.Add(new CompilerException(CompilerException.Codes.UnsupportedPlan, CompilerErrorLevel.Warning, _device.Name, SafeEmitStatementAsString(), devicePlan.TranslationMessages.ToString())); } } DeviceSupported = false; NoDevice = true; } } else { DeviceSupported = false; } } else { DeviceSupported = false; } }
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()); }
// Devices public Schema.DeviceSession DeviceConnect(Schema.Device device) { return(_serverProcess.DeviceConnect(device)); }
public void EnsureDeviceStarted(Schema.Device device) { _serverProcess.EnsureDeviceStarted(device); }