Example #1
0
        /// <summary>
        /// @see ITasklet#Execute.
        /// </summary>
        /// <param name="contribution"></param>
        /// <param name="chunkContext"></param>
        /// <returns></returns>
        public RepeatStatus Execute(StepContribution contribution, ChunkContext chunkContext)
        {
            Chunk <TI> inputs = (Chunk <TI>)chunkContext.GetAttribute(InputsKey);

            if (inputs == null)
            {
                inputs = _chunkProvider.Provide(contribution);
                if (_buffering)
                {
                    chunkContext.SetAttribute(InputsKey, inputs);
                }
            }

            _chunkProcessor.Process(contribution, inputs);
            _chunkProvider.PostProcess(contribution, inputs);

            // Allow a message coming back from the processor to say that we
            // are not done yet
            if (inputs.Busy)
            {
                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug("Inputs still busy");
                }
                return(RepeatStatus.Continuable);
            }

            chunkContext.RemoveAttribute(InputsKey);
            chunkContext.SetComplete();
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("Inputs not busy, ended: {0}", inputs.End);
            }
            return(RepeatStatus.ContinueIf(!inputs.End));
        }
Example #2
0
 /// <summary>
 /// Custom constructor
 /// </summary>
 /// <param name="chunkContext"></param>
 /// <param name="semaphore"></param>
 /// <param name="owner"></param>
 public ChunkTransactionCallback(ChunkContext chunkContext, Semaphore semaphore, TaskletStep owner)
 {
     _chunkContext  = chunkContext;
     _stepExecution = chunkContext.StepContext.StepExecution;
     _semaphore     = semaphore;
     _ownerStep     = owner;
 }
        /// <summary>
        /// Generates the report
        /// @see ITasklet#Execute
        /// </summary>
        /// <param name="contribution"></param>
        /// <param name="chunkContext"></param>
        /// <returns></returns>
        public RepeatStatus Execute(StepContribution contribution, ChunkContext chunkContext)
        {
            LocalReport report = new LocalReport
            {
                ReportPath = ReportFile.GetFileInfo().FullName
            };

            if (Parameters != null && Parameters.Any())
            {
                if (Logger.IsTraceEnabled)
                {
                    Logger.Trace("{0} parameter(s) were given for the report ", Parameters.Count);
                }
                report.SetParameters(Parameters.Select(p => new ReportParameter(p.Key, p.Value)));
            }
            else
            {
                if (Logger.IsTraceEnabled)
                {
                    Logger.Trace("No parameter was given for the report ");
                }
            }

            //DataSet
            DataSet ds = DbOperator.Select(Query, QueryParameterSource);

            //ReportDataSource
            ReportDataSource rds = new ReportDataSource
            {
                Name  = DatasetName,
                Value = ds.Tables[0]
            };

            report.DataSources.Add(rds);

            if (Logger.IsTraceEnabled)
            {
                Logger.Trace("Report init : DONE => Preparing to render");
            }

            byte[] output = report.Render(ReportFormat);

            if (Logger.IsTraceEnabled)
            {
                Logger.Trace("Report init : rendering DONE => Preparing to serialize");
            }
            //Create target directory if required
            OutFile.GetFileInfo().Directory.Create();

            //dump to target file
            using (FileStream fs = new FileStream(OutFile.GetFileInfo().FullName, FileMode.Create))
            {
                fs.Write(output, 0, output.Length);
            }
            if (Logger.IsTraceEnabled)
            {
                Logger.Info("Report init : serialization DONE - end of ReportTasklet execute.");
            }
            return(RepeatStatus.Finished);
        }
                public override int GetHashCode()
                {
                    int hash = 1;

                    if (ReceiverId.Length != 0)
                    {
                        hash ^= ReceiverId.GetHashCode();
                    }
                    if (TechnicalMessageType.Length != 0)
                    {
                        hash ^= TechnicalMessageType.GetHashCode();
                    }
                    if (TeamSetContextId.Length != 0)
                    {
                        hash ^= TeamSetContextId.GetHashCode();
                    }
                    if (chunkContext_ != null)
                    {
                        hash ^= ChunkContext.GetHashCode();
                    }
                    if (PayloadSize != 0L)
                    {
                        hash ^= PayloadSize.GetHashCode();
                    }
                    if (sentTimestamp_ != null)
                    {
                        hash ^= SentTimestamp.GetHashCode();
                    }
                    if (SequenceNumber != 0L)
                    {
                        hash ^= SequenceNumber.GetHashCode();
                    }
                    if (SenderId.Length != 0)
                    {
                        hash ^= SenderId.GetHashCode();
                    }
                    if (createdAt_ != null)
                    {
                        hash ^= CreatedAt.GetHashCode();
                    }
                    if (MessageId.Length != 0)
                    {
                        hash ^= MessageId.GetHashCode();
                    }
                    if (metadata_ != null)
                    {
                        hash ^= Metadata.GetHashCode();
                    }
                    if (_unknownFields != null)
                    {
                        hash ^= _unknownFields.GetHashCode();
                    }
                    return(hash);
                }
Example #5
0
 private void CheckStoppingState(ChunkContext chunkContext)
 {
     if (_stoppable)
     {
         JobExecution jobExecution = JobExplorer.GetJobExecution(chunkContext.StepContext.StepExecution.GetJobExecutionId().Value);
         if (jobExecution.IsStopping())
         {
             _stopped = true;
         }
     }
 }
Example #6
0
            public RepeatStatus Execute(StepContribution contribution, ChunkContext chunkContext)
            {
                // Write counter to a file - Should be running for 10 seconds roughly
                int counter = 1000;

                string[] lines = new string[counter];
                for (int i = 0; i < counter; i++)
                {
                    lines[i] = DateTime.Now.Ticks.ToString();
                    Thread.Sleep(10);
                }
                File.WriteAllLines(@"C:\temp\MyDummyTasklet_out_" + DateTime.Now.Ticks + ".txt", lines);
                return(RepeatStatus.Finished);
            }
Example #7
0
        /// <summary>
        /// Configures a <see cref="Sorter{T}"/> and executes it.
        /// </summary>
        /// <param name="contribution">ignored</param>
        /// <param name="chunkContext">ignored</param>
        /// <returns><see cref="RepeatStatus.Finished"/></returns>
        public RepeatStatus Execute(StepContribution contribution, ChunkContext chunkContext)
        {
            Logger.Info("Starting sort tasklet.");
            var sorter = BuildSorter();

            var stopwatch = new Stopwatch();

            stopwatch.Start();
            sorter.Sort();
            stopwatch.Stop();
            Logger.Info("Total sort time: {0:F2}s", stopwatch.ElapsedMilliseconds / 1000d);

            contribution.ExitStatus = ExitStatus.Completed;
            return(RepeatStatus.Finished);
        }
Example #8
0
    public Contexts()
    {
        chunk     = new ChunkContext();
        game      = new GameContext();
        gameState = new GameStateContext();
        input     = new InputContext();

        var postConstructors = System.Linq.Enumerable.Where(
            GetType().GetMethods(),
            method => System.Attribute.IsDefined(method, typeof(Entitas.CodeGeneration.Attributes.PostConstructorAttribute))
            );

        foreach (var postConstructor in postConstructors)
        {
            postConstructor.Invoke(this, null);
        }
    }
 public RepeatStatus Execute(StepContribution contribution, ChunkContext chunkContext)
 {
     // open connection
     using (DbConnection connection = _providerFactory.CreateConnection())
     {
         connection.ConnectionString = _connectionString;
         connection.Open();
         string    preparedCommand = PrepareCommands(Resource);
         DbCommand command         = connection.CreateCommand();
         command.CommandText = preparedCommand;
         int sqlDone = command.ExecuteNonQuery();
         if (Logger.IsTraceEnabled)
         {
             Logger.Trace("SQL script execution end with {0} return code", sqlDone);
         }
     }
     return(RepeatStatus.Finished);
 }
        /// <summary>
        /// @see ITasklet#Execute()
        /// </summary>
        /// <param name="contribution"></param>
        /// <param name="chunkContext"></param>
        /// <returns></returns>
        public RepeatStatus Execute(StepContribution contribution, ChunkContext chunkContext)
        {
            switch (Mode)
            {
            case FileUtilsMode.Copy:
                Copy();
                break;

            case FileUtilsMode.Delete:
                foreach (IResource target in Targets)
                {
                    if (target.Exists())
                    {
                        Delete(target);
                    }
                    else
                    {
                        Error(target);
                    }
                }
                break;

            case FileUtilsMode.Merge:
                Merge(true);
                break;

            case FileUtilsMode.MergeCopy:
                Merge(false);
                break;

            case FileUtilsMode.Reset:
                Reset();
                break;

            case FileUtilsMode.Compare:
                Compare();
                break;

            default:
                throw new InvalidOperationException("This mode is not supported :[" + Mode + "]");
            }
            return(RepeatStatus.Finished);
        }
    public void RecalculateMesh()
    {
        Material[] mats = null;
        meshFilters = this.gameObject.FindInChildren<MeshFilter>();
        renderers = this.gameObject.FindInChildren<MeshRenderer>();

        if ( renderers.Count > 0 )
        {
            var myRender = this.GetComponent<MeshRenderer>();
            mats = myRender.materials = renderers[renderers.Count-1].materials;
        }

        CombineInstance[] combine = null;

        for ( int i = 0; i < dirtyIndices.Count; i++ )
        {
            if ( batches.ContainsKey(dirtyIndices[i]) ) {
                batches[dirtyIndices[i]].MeshFilters.Clear();
            }
        }

        for (var i = 0; i < meshFilters.Count; i++){
            if ( meshFilters[i] == this.GetComponent<MeshFilter>() )
            {
                continue;
            }

            var pos = meshFilters[i].transform.position;
            BlockIndex index = new BlockIndex( (int)(pos.x / ChunkSize), (int)(pos.y / ChunkSize), (int)(pos.z / ChunkSize));

            if ( dirtyIndices.Count > 0 && dirtyIndices.Contains(index) == false )
            {
                continue;
            }

            ChunkContext context = null;

            if ( batches.ContainsKey( index ) == false )
            {
                context = new ChunkContext();
                context.Chunk = new GameObject();
                context.Chunk.AddComponent<MeshFilter>();
                context.Chunk.AddComponent<MeshRenderer>().materials = mats;
                context.Chunk.transform.parent = OptimizedChunk.transform;
                context.Chunk.name = this.name + "_CHUNK_" + (index.x + "_" +index.y + "_"  +index.z );
                batches[index] = context;
                indices.Add(index);

            } else {
                context = batches[index];
            }

            context.MeshFilters.Add(meshFilters[i]);
        }

        var indexList = (dirtyIndices.Count == 0) ? indices : dirtyIndices;

        for ( int i = 0; i < indexList.Count; i++ )
        {
            BlockIndex index = indexList[i];

            if ( batches.ContainsKey(index) == false )
            {
                //Might have been a diff kinda block.
                continue;
            }

            ChunkContext context = batches[index];

            combine = new CombineInstance[ context.MeshFilters.Count ];
            for ( int j = 0; j < context.MeshFilters.Count; j++)
            {
                combine[j].mesh = context.MeshFilters[j].sharedMesh;
                combine[j].transform = context.MeshFilters[j].transform.localToWorldMatrix;
                context.MeshFilters[j].gameObject.active = false;
            }

            if ( combine.Length > 0 )
            {
                context.Chunk.transform.GetComponent<MeshFilter>().mesh = new Mesh();
                context.Chunk.transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine);
                context.Chunk.transform.gameObject.active = true;
            }
        }

        dirtyIndices.Clear();
        meshFilters.Clear();
        renderers.Clear();
        dirty = false;
    }
 public void MergeFrom(Header other)
 {
     if (other == null)
     {
         return;
     }
     if (other.ReceiverId.Length != 0)
     {
         ReceiverId = other.ReceiverId;
     }
     if (other.TechnicalMessageType.Length != 0)
     {
         TechnicalMessageType = other.TechnicalMessageType;
     }
     if (other.TeamSetContextId.Length != 0)
     {
         TeamSetContextId = other.TeamSetContextId;
     }
     if (other.chunkContext_ != null)
     {
         if (chunkContext_ == null)
         {
             ChunkContext = new global::Agrirouter.Commons.ChunkComponent();
         }
         ChunkContext.MergeFrom(other.ChunkContext);
     }
     if (other.PayloadSize != 0L)
     {
         PayloadSize = other.PayloadSize;
     }
     if (other.sentTimestamp_ != null)
     {
         if (sentTimestamp_ == null)
         {
             SentTimestamp = new global::Google.Protobuf.WellKnownTypes.Timestamp();
         }
         SentTimestamp.MergeFrom(other.SentTimestamp);
     }
     if (other.SequenceNumber != 0L)
     {
         SequenceNumber = other.SequenceNumber;
     }
     if (other.SenderId.Length != 0)
     {
         SenderId = other.SenderId;
     }
     if (other.createdAt_ != null)
     {
         if (createdAt_ == null)
         {
             CreatedAt = new global::Google.Protobuf.WellKnownTypes.Timestamp();
         }
         CreatedAt.MergeFrom(other.CreatedAt);
     }
     if (other.MessageId.Length != 0)
     {
         MessageId = other.MessageId;
     }
     if (other.metadata_ != null)
     {
         if (metadata_ == null)
         {
             Metadata = new global::Agrirouter.Commons.Metadata();
         }
         Metadata.MergeFrom(other.Metadata);
     }
     _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
 }
Example #13
0
 public RepeatStatus Execute(StepContribution contribution, ChunkContext chunkContext)
 {
     _logger.Info("OK transition was used");
     return(RepeatStatus.Finished);
 }
Example #14
0
        public override ASTNode VisitChunk([NotNull] ChunkContext ctx)
        {
            BlockStatNode block = this.Visit(ctx.block()).As <BlockStatNode>();

            return(new SourceNode(this.AddDeclarations(block.Children)));
        }
Example #15
0
 /// <summary>
 /// Do nothing execution, since all the logic is in after step
 /// </summary>
 /// <param name="contribution"></param>
 /// <param name="chunkContext"></param>
 /// <returns></returns>
 public RepeatStatus Execute(StepContribution contribution, ChunkContext chunkContext)
 {
     return(RepeatStatus.Finished);
 }
Example #16
0
 /// <summary>
 /// Scan remote directory for files matching the given file name pattern and download
 /// them, if any, to the given local directory.
 /// @see ITasklet#Execute
 /// </summary>
 /// <param name="contribution"></param>
 /// <param name="chunkContext"></param>
 /// <returns></returns>
 public RepeatStatus Execute(StepContribution contribution, ChunkContext chunkContext)
 {
     //Delegated
     DoExecute();
     return(RepeatStatus.Finished);
 }
Example #17
0
        /// <summary>
        /// Wraps command execution into system process call.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public RepeatStatus Execute(StepContribution contribution, ChunkContext chunkContext)
        {
            if (Logger.IsTraceEnabled)
            {
                Logger.Trace("*** Executing PowerShell Script File: {0}", ScriptResource.GetFullPath());
            }

            //=> PowerShell will throw an error if we do not Suppress ambient transaction...
            //   see https://msdn.microsoft.com/en-us/library/system.transactions.transaction.current(v=vs.110).aspx#NotExistJustToMakeTheAElementVisible
            using (var transactionScope = new TransactionScope(TransactionScopeOption.Suppress))
            {
                //=> Runspace configuration information includes the assemblies, commands, format and type files,
                //   providers, and scripts that are available within the runspace.
                RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();

                //Creates a single runspace that uses the default host and runspace configuration
                using (Runspace runSpace = RunspaceFactory.CreateRunspace(runspaceConfiguration))
                {
                    //=> When this runspace is opened, the default host and runspace configuration
                    //   that are defined by Windows PowerShell will be used.
                    runSpace.Open();

                    //=> Set Variables so they are available to user script...
                    if (Variables != null && Variables.Any())
                    {
                        foreach (KeyValuePair <string, object> variable in Variables)
                        {
                            runSpace.SessionStateProxy.SetVariable(variable.Key, variable.Value);
                        }
                    }

                    //=> this is exit status variables to be tested on exit from power shell script...
                    //   it is defined in PwerShell global scope...and must be set by scipt writer on exit...
                    runSpace.SessionStateProxy.SetVariable("ScriptExitStatus", _scriptExitStatus);

                    //=> Allows the execution of commands from a CLR
                    //RunspaceInvoke scriptInvoker = new RunspaceInvoke(runSpace);
                    //scriptInvoker.Invoke("Set-ExecutionPolicy Unrestricted");

                    using (PowerShell psInstance = PowerShell.Create())
                    {
                        try
                        {
                            // prepare a new collection to store output stream objects
                            PSDataCollection <PSObject> outputCollection = new PSDataCollection <PSObject>();
                            outputCollection.DataAdded           += AllStreams_DataAdded;
                            psInstance.Streams.Error.DataAdded   += AllStreams_DataAdded;
                            psInstance.Streams.Verbose.DataAdded += AllStreams_DataAdded;
                            psInstance.Streams.Warning.DataAdded += AllStreams_DataAdded;
                            psInstance.Streams.Debug.DataAdded   += AllStreams_DataAdded;

                            psInstance.Runspace = runSpace;

                            //=> This tasklet should be in the same dll as ExitStatus, i.e. Summer.Batch.Core.dll
                            //   we need to get the path to loaded Summer.Batch.Core.dll so we can load it in PowerShell
                            var assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;

                            //=> need to load Summer.Batch.Core into runspace so we can reference ExitStatus
                            psInstance.AddScript("[System.Reflection.Assembly]::LoadFrom(\"" + assemblyLocation + "\")").AddStatement();

                            //=> add user command and its parameters...
                            psInstance.AddCommand(ScriptResource.GetFullPath());
                            if (Parameters != null && Parameters.Any())
                            {
                                foreach (KeyValuePair <string, object> variable in Parameters)
                                {
                                    psInstance.AddParameter(variable.Key, variable.Value);
                                }
                            }

                            //=> Invoke Asynchronously...
                            IAsyncResult asyncResult = psInstance.BeginInvoke <PSObject, PSObject>(null, outputCollection);

                            // do something else until execution has completed.
                            long t0 = DateTime.Now.Ticks;
                            while (!asyncResult.IsCompleted)
                            {
                                //=> take a nap and let script do its job...
                                Thread.Sleep(new TimeSpan(_checkInterval));

                                //=> to check if job was told to stop...
                                CheckStoppingState(chunkContext);

                                //=> lets make sure we did not exceed alloted time...
                                long timeFromT0 = (long)(new TimeSpan(DateTime.Now.Ticks - t0)).TotalMilliseconds;
                                if (timeFromT0 > _timeout)
                                {
                                    //=> Stop PowerShell...
                                    psInstance.Stop();

                                    //=> behave based on TimeoutBehaviorOption
                                    if (_timeoutBehavior.Equals(TimeoutBehaviorOption.SetExitStatusToFailed))
                                    {
                                        contribution.ExitStatus = ExitStatus.Failed;
                                        break;
                                    }
                                    else if (_timeoutBehavior.Equals(TimeoutBehaviorOption.ThrowException))
                                    {
                                        //=> lets dump what we got before throwing an error...
                                        LogStreams();
                                        throw new FatalStepExecutionException("Execution of PowerShell script exceeded allotted time.", null);
                                    }
                                }
                                else if (_execution.TerminateOnly)
                                {
                                    //=> Stop PowerShell...
                                    psInstance.Stop();

                                    //=> lets dump what we got before throwing an error...
                                    LogStreams();

                                    throw new JobInterruptedException(
                                              string.Format("Job interrupted while executing PowerShell script '{0}'", ScriptResource.GetFilename()));
                                }
                                else if (_stopped)
                                {
                                    psInstance.Stop();
                                    contribution.ExitStatus = ExitStatus.Stopped;
                                    break;
                                }
                            } // end while scope

                            //=> Wait to the end of execution...
                            //psInstance.EndInvoke(_asyncResult);

                            //NOTE: asyncResult.IsCompleted will be set to true if PowerShell.Stop was called or
                            //      PowerShell completed its work

                            //=> if status not yet set (script completed)...handle completion...
                            if (contribution.ExitStatus.IsRunning())
                            {
                                //=> script needs to set exit code...if exit code not set we assume 0
                                var lastExitCode = (int)runSpace.SessionStateProxy.PSVariable.GetValue("LastExitCode", 0);

                                _scriptExitStatus = runSpace.SessionStateProxy.GetVariable("ScriptExitStatus") as ExitStatus;

                                //=> set exit status...
                                if (_scriptExitStatus != null && !_scriptExitStatus.IsRunning())
                                {
                                    if (Logger.IsTraceEnabled)
                                    {
                                        Logger.Trace("***> ScriptExitStatus returned by script => {0}", _scriptExitStatus);
                                    }

                                    contribution.ExitStatus = _scriptExitStatus;
                                }
                                else //=> let user decide on ExitStatus
                                {
                                    if (Logger.IsTraceEnabled)
                                    {
                                        if (_scriptExitStatus == null)
                                        {
                                            Logger.Trace("***> ScriptExitStatus is null. Using PowerShellExitCodeMapper to determine ExitStatus.");
                                        }
                                        else if (_scriptExitStatus.IsRunning())
                                        {
                                            Logger.Trace("***> ScriptExitStatus is EXECUTING or UNKNOWN. Using PowerShellExitCodeMapper to determine ExitStatus.");
                                        }
                                    }

                                    if (PowerShellExitCodeMapper != null)
                                    {
                                        //=> determine exit status using User Provided PowerShellExitCodeMapper
                                        contribution.ExitStatus = PowerShellExitCodeMapper.GetExitStatus(lastExitCode);
                                    }
                                    else //at this point we are not able to determine exit status, user needs to fix this...
                                    {
                                        //=> lets dump what we got before throwing an error...
                                        LogStreams();
                                        throw new FatalStepExecutionException(
                                                  "PowerShellTasklet is not able to determine ExitStatus. ScriptExitStatus is null or (is EXECUTING or UNKNOWN) and " +
                                                  "PowerShellExitCodeMapper is NOT defined. Please set $global:ScriptExitStatus or define PowerShellExitCodeMapper.", null);
                                    }
                                }
                            }

                            if (Logger.IsInfoEnabled)
                            {
                                Logger.Info("PowerShell execution exit status [{0}]", contribution.ExitStatus);
                            }

                            //=> output captured stream data to Log...
                            LogStreams();
                        }
                        catch (RuntimeException ex)
                        {
                            Logger.Error(ex.Message);
                            throw;
                        }
                    } // end PowerShell Scope

                    //=> close Runspace...
                    runSpace.Close();

                    //=> we are done...
                    return(RepeatStatus.Finished);
                } // end of Runspace Scope
            }     // end of TransactionScope
        }
Example #18
0
 public RepeatStatus Execute(StepContribution contribution, ChunkContext chunkContext)
 {
     _logger.Info("KO transition was used");
     throw new Exception("Job failed: Wrong transition used");
 }