Example #1
0
        /// <summary>
        /// Save a flow with the gui input
        /// </summary>
        /// <param name="flowConfig"></param>
        /// <returns></returns>
        public async Task <Result> SaveFlowConfig(FlowGuiConfig flowConfig)
        {
            var config = await ConfigBuilder.Build(flowConfig);

            var existingFlow = await FlowData.GetByName(config.Name);

            Result result = null;

            if (existingFlow != null)
            {
                existingFlow.Gui = config.Gui;
                existingFlow.CommonProcessor.Template            = config.CommonProcessor.Template;
                existingFlow.CommonProcessor.SparkJobTemplateRef = config.CommonProcessor.SparkJobTemplateRef;
                existingFlow.DisplayName = config.DisplayName;
                config = existingFlow;
                result = await FlowData.UpdateGuiForFlow(config.Name, config.Gui);

                if (result.IsSuccess)
                {
                    result = await FlowData.UpdateCommonProcessorForFlow(config.Name, config.CommonProcessor);
                }
            }
            else
            {
                result = await this.FlowData.Upsert(config);
            }

            if (result.IsSuccess)
            {
                // pass the generated config back with the result
                var properties = new Dictionary <string, object>()
                {
                    { FlowConfigPropertyName, config }
                };

                if (result.Properties != null)
                {
                    result.Properties.AppendDictionary(properties);
                }
                else
                {
                    result.Properties = properties;
                }
            }
            return(result);
        }
        /// <summary>
        /// Update the last processed time for a batch job in the config
        /// </summary>
        /// <returns></returns>
        private async Task <Result> UpdateLastProcessedTime(FlowConfig config, int index, long value)
        {
            var existingFlow = await FlowData.GetByName(config.Name).ConfigureAwait(false);

            Result result = null;

            if (existingFlow != null)
            {
                var gui = config.GetGuiConfig();

                var batch = gui.BatchList[index];
                batch.Properties.LastProcessedTime = value.ToString(CultureInfo.InvariantCulture);

                config.Gui = JObject.FromObject(gui);
                result     = await FlowData.UpdateGuiForFlow(config.Name, config.Gui).ConfigureAwait(false);
            }

            return(result);
        }
        /// <summary>
        /// Disable a batch job in the config
        /// </summary>
        /// <returns></returns>
        private async Task <Result> DisableBatchConfig(FlowConfig config, int index)
        {
            var existingFlow = await FlowData.GetByName(config.Name).ConfigureAwait(false);

            Result result = null;

            if (existingFlow != null)
            {
                var gui = config.GetGuiConfig();

                var batch = gui.BatchList[index];
                batch.Disabled = true;

                config.Gui = JObject.FromObject(gui);
                result     = await FlowData.UpdateGuiForFlow(config.Name, config.Gui).ConfigureAwait(false);
            }

            return(result);
        }