/// <summary>
        /// Starts the new instance of the microservice by passing input arguments.
        /// This method will start the new instance of orchestration
        /// </summary>
        /// <param name="orchestrationQualifiedName">The full qualified name of orchestration to be started.</param>
        /// <param name="inputArgs">Input arguments.</param>
        /// <returns></returns>
        //public Task<MicroserviceInstance> StartServiceAsync(string orchestrationQualifiedName, object inputArgs, Dictionary<string, object> context = null)
        //{
        //    //return StartServiceAsync(Type.GetType(orchestrationQualifiedName), inputArgs, context);
        //}

        /// <summary>
        /// Creates the instance of service from service name.
        /// </summary>
        /// <param name="orchestrationQualifiedNameOrName"></param>
        /// <param name="inputArgs"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        //protected Task<MicroserviceInstance> CreateServiceInstanceAsync(string orchestrationQualifiedName, object inputArgs, Dictionary<string, object> context)
        //{
        //    return createServiceInstanceAsync(Type.GetType(orchestrationQualifiedName), inputArgs, context);
        //}
        #endregion

        /// <summary>
        /// Starts the new instance of the microservice by passing input arguments.
        /// This method will start the new instance of orchestration
        /// </summary>
        /// <param name="orchestrationQualifiedName">The full qualified name of orchestration to be started.</param>
        /// <param name="inputArgs">Input arguments.</param>
        /// <returns></returns>
        public async Task <MicroserviceInstance> StartServiceAsync(string orchestrationQualifiedNameOrName, object inputArgs, Dictionary <string, object> context = null, string version = "")
        {
            try
            {
                var tokens = orchestrationQualifiedNameOrName.Split(',');
                if (tokens.Length > 1)
                {
                    orchestrationQualifiedNameOrName = tokens[0];
                }

                ensureActIdInContext(context, inputArgs);

                var ms = new MicroserviceInstance()
                {
                    OrchestrationInstance = await m_HubClient.CreateOrchestrationInstanceAsync(orchestrationQualifiedNameOrName, version, inputArgs),
                };
                return(ms);
            }
            catch (Exception ex)
            {
                if (ex.GetType().Name == "StorageException" && ex.Message.Contains(": (404) Not Found"))
                {
                    throw new Exception("The microservce host should be started at least once, before starting orchestration. This error may also indicate, that incorrect hub name is used.", ex);
                }
                throw;
            }
        }
        /// <summary>
        /// Here we create a context and ensure that ActivityId is provided.
        /// </summary>
        /// <param name="orchestration"></param>
        /// <param name="inputArgs"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        private async Task <MicroserviceInstance> createServiceInstanceAsync(Type orchestration, object inputArgs, Dictionary <string, object> context, string version = null)
        {
            ensureActIdInContext(context, inputArgs);

            var ms = new MicroserviceInstance()
            {
                OrchestrationInstance = await m_HubClient.CreateOrchestrationInstanceAsync(orchestration, inputArgs),
            };

            return(ms);
        }
Пример #3
0
 /// <summary>
 /// Raises an event in the specified orchestration instance, which eventually causes
 /// the OnEvent() method in the orchestration to fire.</summary>
 /// <param name="instance"></param>
 /// <param name="eventName"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public async Task RaiseEventAsync(MicroserviceInstance instance, string eventName, string data)
 {
     await m_HubClient.RaiseEventAsync(instance.OrchestrationInstance, eventName, data);
 }
Пример #4
0
 /// <summary>
 /// Forcefully terminate the specified orchestration instance
 /// </summary>
 /// <param name="svcInst"></param>
 /// <param name="reason"></param>
 /// <returns></returns>
 public async Task TerminateAsync(MicroserviceInstance svcInst, string reason = "Terminated by host.")
 {
     await m_HubClient.TerminateInstanceAsync(svcInst.OrchestrationInstance, reason);
 }
        /// <summary>
        /// Waits on single instance to complete execution with any of supported states.
        /// Instance is running if it is in one of Pending, ContinuedAsNew or Running states.
        /// </summary>
        /// <param name="instance">The instance of the service to wait on.</param>
        /// <param name="wait"></param>
        /// <returns>Returns the state of orchestration after it has enetered on of terminal states:
        /// Canceled, Termnated, Failed or Completed.</returns>
        public async Task <OrchestrationState> WaitOnInstanceAsync(MicroserviceInstance instance, int wait = int.MaxValue)
        {
            var state = await this.m_HubClient.WaitForOrchestrationAsync(instance.OrchestrationInstance, TimeSpan.FromMilliseconds(wait));

            return(state);
        }