/// <summary> Executes a D4 script. </summary> public static void ExecuteScript(string script, IServer server, SessionInfo sessionInfo) { IServerSession session = server.Connect(sessionInfo); try { IServerProcess process = session.StartProcess(new ProcessInfo(sessionInfo)); try { IServerScript localScript = process.PrepareScript(script); try { localScript.Execute(null); } finally { process.UnprepareScript(localScript); } } finally { session.StopProcess(process); } } finally { server.Disconnect(session); } }
protected internal void SetCacheTimeStamp(IServerProcess process, long clientCacheTimeStamp) { #if LOGCACHEEVENTS FInternalServer.LogMessage(LogEntryType.Information, String.Format("Thread {0} updating cache time stamp to {1}", Thread.CurrentThread.GetHashCode(), AClientCacheTimeStamp.ToString())); #endif #if USESPINLOCK while (Interlocked.CompareExchange(ref _cacheSyncRoot, 1, 0) == 1) { Thread.SpinWait(100); } try #else lock (FCacheSyncRoot) #endif { _clientCacheTimeStamp = clientCacheTimeStamp; ManualResetEvent signal; if (_cacheSignals.TryGetValue(clientCacheTimeStamp, out signal)) { signal.Set(); } } #if USESPINLOCK finally { Interlocked.Decrement(ref _cacheSyncRoot); } #endif }
private static void RunProcess(IServerProcess process, BackgroundProcessContext context) { // Long-running tasks are based on custom threads (not threadpool ones) as in // .NET Framework 4.5, so we can try to set custom thread name to simplify the // debugging experience. TrySetThreadName(process.ToString()); // LogProvider.GetLogger does not throw any exception, that is why we are not // using the `try` statement here. It does not return `null` value as well. var logger = LogProvider.GetLogger(process.GetProcessType()); logger.DebugFormat("Background process '{0}' started.", process); try { process.Execute(context); } catch (OperationCanceledException) { } catch (Exception ex) { logger.FatalException( String.Format( "Fatal error occurred during execution of '{0}' process. It will be stopped. See the exception for details.", process), ex); } logger.DebugFormat("Background process '{0}' stopped.", process); }
public void SetUpFixture() { FServerConfigurationManager = new SQLCEServerConfigurationManager(); FConfiguration = FServerConfigurationManager.GetTestConfiguration("TestInstance"); FServerConfigurationManager.ResetInstance(); FServer = FServerConfigurationManager.GetServer(); FServer.Start(); IServerSession LSession = FServer.Connect(new SessionInfo("Admin", "")); try { IServerProcess LProcess = LSession.StartProcess(new ProcessInfo(LSession.SessionInfo)); try { LProcess.ExecuteScript("EnsureLibraryRegistered('Frontend');"); LProcess.ExecuteScript("EnsureLibraryRegistered('TestFramework.Coverage.Base');"); } finally { LSession.StopProcess(LProcess); } } finally { FServer.Disconnect(LSession); } }
private static void RunProcess(IServerProcess process, BackgroundProcessContext context) { // Long-running tasks are based on custom threads (not threadpool ones) as in // .NET Framework 4.5, so we can try to set custom thread name to simplify the // debugging experience. TrySetThreadName(process.ToString()); // LogProvider.GetLogger does not throw any exception, that is why we are not // using the `try` statement here. It does not return `null` value as well. var logger = LogProvider.GetLogger(process.GetProcessType()); logger.Debug($"Background process '{process}' started."); try { process.Execute(context); } catch (Exception ex) { if (ex is OperationCanceledException && context.IsShutdownRequested) { // Graceful shutdown logger.Trace($"Background process '{process}' was stopped due to a shutdown request."); } else { logger.FatalException( $"Fatal error occurred during execution of '{process}' process. It will be stopped. See the exception for details.", ex); } } logger.Debug($"Background process '{process}' stopped."); }
private async Task <IKeyValueStore> InitializeKeyValueStoreAsync( [NotNull] IEnumerable <IManagedProcess> managedProcesses, [NotNull] ClusterHeartBeat heartbeat) { string etcdAgentType = WellKnownAgentType.KeyValueStore.ToString(); IEnumerable <IManagedProcess> kvsProcesses = managedProcesses.Where(m => m.AgentType.Equals(etcdAgentType)); // For all well-known KVS agent processes... foreach (var kvsProcess in kvsProcesses) { // Check if they live (reviving them, if necessary): bool started = await heartbeat.CheckHeartBeatAsync(kvsProcess); if (started) { // ... and try making contact IServerProcess serverProcess = (IServerProcess)kvsProcess; var keyValueStore = await EtcdKeyValueStore.TryConnectAsync( serverProcess.HostName, serverProcess.Port, serverProcess.UseTls); if (keyValueStore != null) { _logger.LogInformation("Using etcd based key-value store..."); return(keyValueStore); } } } // None is configured or none is running or none is responding: _logger.LogInformation("Using in-memory key-value store..."); return(new LocalKeyValueStore()); }
/// <summary> /// Initializes a new instance of the <see cref="NetworkServer{TServerOperator}"/> type. /// </summary> /// <param name="serverProcess">The <see cref="IServerProcess"/> to use for this server.</param> /// <param name="serverOperator">The <see cref="IServerOperator"/> to use for this server.</param> protected NetworkServer(IServerProcess serverProcess, TServerOperator serverOperator) { Process = serverProcess; Operator = serverOperator; Process.ConnectionOpened += OnConnectionOpened; }
/// <summary>Returns the equivalent D4 type for the given native (CLR) type. Will throw a ClientException if there is no mapping for the given native (CLR) type.</summary> public static DAE.Schema.IScalarType ScalarTypeFromNativeType(IServerProcess process, Type type) { if (type == null) { return(process.DataTypes.SystemScalar); } switch (type.Name) { case "Int32": return(process.DataTypes.SystemInteger); case "Int64": return(process.DataTypes.SystemLong); case "Int16": return(process.DataTypes.SystemShort); case "Byte": return(process.DataTypes.SystemByte); case "Boolean": return(process.DataTypes.SystemBoolean); case "String": return(process.DataTypes.SystemString); case "Decimal": return(process.DataTypes.SystemDecimal); case "DateTime": return(process.DataTypes.SystemDateTime); case "TimeSpan": return(process.DataTypes.SystemTimeSpan); case "Guid": return(process.DataTypes.SystemGuid); case "System.Exception": return(process.DataTypes.SystemError); default: throw new ClientException(ClientException.Codes.InvalidParamType, type.Name); } }
private void StopProcess() { if (_process != null) { try { if (_cursor != null) { try { _cursor.OnErrors -= new CursorErrorsOccurredHandler(CursorOnErrors); _cursor.Dispose(); } catch { // Errors closing the cursor should not prevent the process from stopping _cursor = null; } } #if USEASYNCSTOPPROCESS new StopProcessHandler(FSession.ServerSession.StopProcess).BeginInvoke(FProcess, null, null); #else _session.ServerSession.StopProcess(_process); #endif } finally { _process = null; } } }
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 override void Open() { if (_server == null) { _foreignServer = false; OnBeforeOpen(); if (_alias == null) { throw new ProviderException(ProviderException.Codes.NoAliasSpecified); } _connection = new ServerConnection(_alias, true); _server = _connection.Server; try { _alias.SessionInfo.Environment = "ADO.NET"; _session = _server.Connect(_alias.SessionInfo); _serverProcess = _session.StartProcess(new ProcessInfo(_alias.SessionInfo)); } catch { _server = null; _session = null; _serverProcess = null; _connection.Dispose(); _connection = null; throw; } OnAfterOpen(); } }
public Row RequestRow(IServerProcess AProcess, Schema.IRowType ARowType, Stream AStream) { Row LRow = GetRow(); LRow.Open(AProcess, ARowType, AStream); return(LRow); }
public Row RequestRow(IServerProcess AProcess, Schema.IRowType ARowType, NativeRow ARow) { Row LRow = GetRow(); LRow.Open(AProcess, ARowType, ARow); return(LRow); }
public InfiniteLoopProcess([NotNull] IServerProcess innerProcess) { if (innerProcess == null) { throw new ArgumentNullException("innerProcess"); } InnerProcess = innerProcess; }
public void ExecuteScript(IServerProcess process, string script, DAE.Runtime.DataParams paramsValue) { if (process == null) { process = DataSession.UtilityProcess; } DAE.IServerScript localScript = process.PrepareScript(script); try { foreach (DAE.IServerBatch batch in localScript.Batches) { if (batch.IsExpression()) { DAE.IServerExpressionPlan plan = batch.PrepareExpression(paramsValue); try { ErrorList errors = new ErrorList(); errors.AddRange(plan.Messages); ReportErrors(null, errors); if (plan.DataType is DAE.Schema.TableType) { plan.Close(plan.Open(paramsValue)); } else { plan.Evaluate(paramsValue).Dispose(); } } finally { batch.UnprepareExpression(plan); } } else { DAE.IServerStatementPlan plan = batch.PrepareStatement(paramsValue); try { ErrorList errors = new ErrorList(); errors.AddRange(plan.Messages); ReportErrors(null, errors); plan.Execute(paramsValue); } finally { batch.UnprepareStatement(plan); } } } } finally { process.UnprepareScript(localScript); } }
/// <summary>Evaluates the given expression on the given process using the given parameter names and values and returns the result.</summary> public DAE.Runtime.Data.IDataValue EvaluateRaw(IServerProcess process, string expression, string[] paramNames, object[] paramsValue) { if (process == null) { process = UtilityProcess; } return(EvaluateRaw(process, expression, DataParamsFromNativeParams(process, paramNames, paramsValue))); }
/// <summary> Executes the given statement on the given process and using the given parameter values (auto numbered A0..An-1). </summary> public void Execute(IServerProcess process, string statement, params object[] paramsValue) { if (process == null) { process = UtilityProcess; } Execute(process, statement, DataParamsFromNativeParams(process, paramsValue)); }
/// <summary>EvaluateScalars the given expression on the given process and using the given parameter names and values.</summary> public DAE.Runtime.Data.Scalar EvaluateScalar(IServerProcess process, string expression, string[] paramNames, object[] paramsValue) { if (process == null) { process = DataSession.UtilityProcess; } return(EvaluateScalar(process, expression, DAE.Client.DataSession.DataParamsFromNativeParams(process, paramNames, paramsValue))); }
public IServerCursor OpenCursor(IServerProcess process, string expression, string[] paramNames, object[] paramsValue) { if (process == null) { process = UtilityProcess; } return(OpenCursor(process, expression, DataParamsFromNativeParams(process, paramNames, paramsValue))); }
/// <summary> Executes the given statement on the given process and using the given parameter names and values. </summary> public void Execute(IServerProcess process, string expression, string[] paramNames, object[] paramsValue) { if (process == null) { process = UtilityProcess; } Execute(process, expression, DataParamsFromNativeParams(process, paramNames, paramsValue)); }
private DAE.Schema.RowType _cacheRowType; // shared across threads (synced using the pipe instance) private DAE.Schema.RowType GetCacheRowType(IServerProcess process) { if (_cacheRowType == null) { _cacheRowType = new DAE.Schema.RowType(); _cacheRowType.Columns.Add(new DAE.Schema.Column("Value", process.DataTypes.SystemScalar)); } return(_cacheRowType); }
private void StartProcess() { ProcessInfo processInfo = new ProcessInfo(_session.SessionInfo); processInfo.DefaultIsolationLevel = _isolationLevel; processInfo.FetchAtOpen = ShouldFetchAtOpen(); _process = _session.ServerSession.StartProcess(processInfo); _cursor = new DAECursor(_process); _cursor.OnErrors += new CursorErrorsOccurredHandler(CursorOnErrors); }
// StopProcess public void StopProcess(IServerProcess process) { try { ((ServerProcess)process).Dispose(); // Is protected by a latch in the ServerChildObjects collection } catch (Exception E) { throw WrapException(E); } }
private void StopProcess() { if (_process != null) { UnprepareParentPlan(); UnprepareChildPlan(); UnprepareRootPlan(); _process.Session.StopProcess(_process); _process = null; } }
protected internal void ReleaseCacheLock(IServerProcess process, LockMode mode) { if (mode == LockMode.Exclusive) { _cacheLock.ReleaseWriterLock(); } else { _cacheLock.ReleaseReaderLock(); } }
public bool IsMaster; // true if this parameter is part of a master/detail relationship public override void Bind(IServerProcess process) { if (!Source.DataSet.IsEmpty() && Source.DataSet.Fields[ColumnName].HasValue()) { Value = Source.DataSet.Fields[ColumnName].AsNative; } else { Value = null; } }
public static DataParam Create(IServerProcess process, string name, decimal tempValue) { return (new DataParam ( name, process.DataTypes.SystemDecimal, DAE.Language.Modifier.In, tempValue )); }
public static DataParam Create(IServerProcess process, string name, object tempValue, DAE.Schema.IScalarType dataType) { return (new DataParam ( name, dataType, DAE.Language.Modifier.In, tempValue )); }
public AutomaticRetryProcess([NotNull] IServerProcess innerProcess) { if (innerProcess == null) throw new ArgumentNullException("innerProcess"); _innerProcess = innerProcess; _logger = LogProvider.GetLogger(_innerProcess.GetProcessType()); MaxRetryAttempts = DefaultMaxRetryAttempts; MaxAttemptDelay = DefaultMaxAttemptDelay; DelayCallback = GetBackOffMultiplier; }
public void Open(IServer server, IServerSession session, IServerProcess process) { if (_server == null) { _foreignServer = true; OnBeforeOpen(); _server = server; _session = session; _serverProcess = process; OnAfterOpen(); } }
private static void InsertDocument(IServerProcess process, Guid documentID, Guid rootElementID) { DataParams paramsValue = new DataParams(); paramsValue.Add(DataParam.Create(process, "ADocumentID", documentID)); paramsValue.Add(DataParam.Create(process, "AElementID", rootElementID)); process.Execute ( "insert table { row { ADocumentID ID, AElementID Root_Element_ID }, key { } } into .System.Internet.XMLDocument", paramsValue ); }
private void SaveToImageCache(string document, IServerProcess process, IScalar LResult) { lock (ImageCache) { byte[] value = null; if ((LResult != null) && (!LResult.IsNil)) { value = LResult.AsByteArray; } ImageCache.Add(document, value); } }
#pragma warning disable 618 private static IServerProcess WrapProcess(IServerProcess process) #pragma warning restore 618 { return new InfiniteLoopProcess(new AutomaticRetryProcess(process)); }
private static IServerProcess WrapProcess(IServerProcess process) { return new InfiniteLoopProcess(new AutomaticRetryProcess(process)); }
private InfiniteLoopProcess CreateProcess(IServerProcess process) { return new InfiniteLoopProcess(process); }