public InstanceActionResult SendDataMessage(StitchFullId fullStitchId, StitchDataMessage message)
        {
            var adaptor = _adaptors.Get(fullStitchId.StitchInstanceId);

            if (adaptor == null)
            {
                return(InstanceActionResult.NotFound(fullStitchId.StitchInstanceId));
            }

            adaptor.SendMessage(message.Id, message.DataChannelName, message.Data, message.FromNodeId, message.FromStitchInstanceId);
            return(InstanceActionResult.Result(fullStitchId.StitchInstanceId, true));
        }
        public InstanceActionResult Stop(StitchInstance stitchInstance)
        {
            try
            {
                var adaptor = _adaptors.Get(stitchInstance.Id);
                if (adaptor == null)
                {
                    return(InstanceActionResult.NotFound(stitchInstance.Id));
                }

                adaptor.Stop();
                stitchInstance.State = InstanceStateType.Stopped;

                return(InstanceActionResult.Result(stitchInstance.Id, true, stitchInstance));
            }
            catch (Exception e)
            {
                return(InstanceActionResult.Failure(stitchInstance.Id, true, stitchInstance, e));
            }
        }
        public InstanceActionResult Start(PackageFile packageFile, StitchInstance stitchInstance)
        {
            if (string.IsNullOrEmpty(stitchInstance?.Id))
            {
                return(InstanceActionResult.BadRequest());
            }

            string         instanceId = stitchInstance.Id;
            IStitchAdaptor adaptor    = null;

            try
            {
                stitchInstance.State = InstanceStateType.Stopped;
                adaptor = GetOrCreateStitchAdaptor(packageFile, stitchInstance);
                if (adaptor == null)
                {
                    stitchInstance.State = InstanceStateType.Missing;
                    return(InstanceActionResult.NotFound(instanceId));
                }

                // TODO: On Stitch start, we should send it information about the application topology
                // TODO: We should also send application topology change notifications to every Stitch
                // involved in the affected application.

                bool started = adaptor.Start();
                if (started)
                {
                    stitchInstance.State = InstanceStateType.Started;
                }

                return(InstanceActionResult.Result(instanceId, started, stitchInstance));
            }
            catch (Exception e)
            {
                stitchInstance.State = InstanceStateType.Error;
                return(InstanceActionResult.Failure(stitchInstance.Id, adaptor != null, e));
            }
        }