コード例 #1
0
ファイル: App.cs プロジェクト: devncore/devflow
        protected override void OnStartup(StartupEventArgs e)
        {
            Resources.MergedDictionaries.Add(new ResourceDictionary {
                Source = new Uri("/DevFlow.Resources;component/Themes/Generic.Drawings.xaml", UriKind.RelativeOrAbsolute)
            });

            bool dialogResult = true;

            ConfigModel config = FlowConfig.LoadConfig();

            Theme.Switch(config.Theme);
            Culture.Switch(config.Language);

            while (dialogResult)
            {
                ShutdownMode = ShutdownMode.OnExplicitShutdown;
                Main.Views.MainWindow main = new()
                {
                    DataContext = new MainViewModel(Theme, Culture)
                };
                _            = main.ShowDialog();
                dialogResult = (bool)main.DialogResult;
            }
            Environment.Exit(0);
        }
    }
コード例 #2
0
        public FlowDeploymentSession(FlowConfig config) : base(config.Name, null)
        {
            Attachments      = new ConcurrentDictionary <string, object>();
            ProgressMessages = new List <string>();

            UpdateFlowConfig(config);
        }
コード例 #3
0
        public async Task <IHttpActionResult> PutFlowConfig(int id, FlowConfig flowConfig)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != flowConfig.Id)
            {
                return(BadRequest());
            }

            db.Entry(flowConfig).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FlowConfigExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #4
0
        /// <summary>
        /// Execute the passed-in job operation callback on the given flow
        /// </summary>
        /// <param name="flow"></param>
        /// <param name="oper"></param>
        /// <returns></returns>
        private async Task <Result> ExecuteJobOperationForFlow(FlowConfig flow, Func <string, Task <Result> > oper)
        {
            Ensure.NotNull(flow, "flow");
            var flowName = flow.Name;

            var jobNames = flow.JobNames;

            if (jobNames == null || jobNames.Length == 0)
            {
                return(new FailedResult($"No jobs are associated with flow '{flowName}'"));
            }

            try
            {
                var results    = (await Task.WhenAll(jobNames.Select(oper))).ToList();
                var failedOnes = results.Where(r => !r.IsSuccess).Select(r => r.Message).ToList();
                if (failedOnes.Count > 0)
                {
                    return(new FailedResult($"Some jobs failed for flow '{flowName}': {string.Join(",", failedOnes)}"));
                }

                return(new SuccessResult($"done with {results.Count} jobs"));
            }
            catch (Exception e)
            {
                return(new FailedResult($"encounter exception:'{e.Message}' when processing job '{flowName}'"));
            }
        }
コード例 #5
0
        public void UpdateFlowConfig(FlowConfig config)
        {
            Ensure.NotNull(config, "config");
            Config = config;

            SetStringToken(FlowConfig.TokenName_Name, config.Name);
            Tokens.AddDictionary(config.Properties?.ToTokens());

            _jobs = null;
        }
コード例 #6
0
        public async Task <IHttpActionResult> GetFlowConfig(int id)
        {
            FlowConfig flowConfig = await db.FlowConfigs.FindAsync(id);

            if (flowConfig == null)
            {
                return(NotFound());
            }

            return(Ok(flowConfig));
        }
コード例 #7
0
        public async Task <FlowConfig> GetDefaultConfig(TokenDictionary tokens = null)
        {
            var config = await CommonsData.GetByName(CommonDataName_DefaultFlowConfig);

            if (tokens != null)
            {
                config = tokens.Resolve(config);
            }

            return(FlowConfig.From(config));
        }
コード例 #8
0
        public async Task <IHttpActionResult> PostFlowConfig(FlowConfig flowConfig)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.FlowConfigs.Add(flowConfig);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = flowConfig.Id }, flowConfig));
        }
コード例 #9
0
        public async Task <FlowConfig> GetFlowConfigByInputType(string inputType, TokenDictionary tokens = null)
        {
            var flowConfigName = this.GetFlowConfigName(inputType);
            var config         = await CommonsData.GetByName(flowConfigName);

            if (tokens != null)
            {
                config = tokens.Resolve(config);
            }

            return(FlowConfig.From(config));
        }
コード例 #10
0
        public async Task <IHttpActionResult> DeleteFlowConfig(int id)
        {
            FlowConfig flowConfig = await db.FlowConfigs.FindAsync(id);

            if (flowConfig == null)
            {
                return(NotFound());
            }

            db.FlowConfigs.Remove(flowConfig);
            await db.SaveChangesAsync();

            return(Ok(flowConfig));
        }
コード例 #11
0
 public async Task <Result> Upsert(FlowConfig config)
 {
     if (config == null)
     {
         return(new FailedResult("input config for the flow is null"));
     }
     else if (string.IsNullOrWhiteSpace(config.Name))
     {
         return(new FailedResult("name of the flow cannot be empty"));
     }
     else
     {
         return(await this.Storage.SaveByName(config.Name, config.ToString(), DataCollectionName));
     }
 }
コード例 #12
0
        /// <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);
        }
コード例 #13
0
        /// <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);
        }
コード例 #14
0
        public async Task TestConfigSaved()
        {
            string flowName = "localconfiggentest";

            var input = await File.ReadAllTextAsync(@"Resource\guiInput.json");

            var inputJson = JsonConfig.From(input);
            var result    = await this.FlowOperation.SaveFlowConfig(FlowGuiConfig.From(inputJson));

            Assert.IsTrue(result.IsSuccess, result.Message);

            var actualJson = await this.FlowOperation.GetFlowByName(flowName);

            var expectedJson = FlowConfig.From(await File.ReadAllTextAsync(@"Resource\flowSaved.json"));

            foreach (var match in EntityConfig.Match(expectedJson, actualJson))
            {
                Assert.AreEqual(expected: match.Item2, actual: match.Item3, message: $"path:{match.Item1}");
            }
        }
コード例 #15
0
        public async Task TestConfigSaved()
        {
            await CommonData.Add(FlowDataManager.CommonDataName_DefaultFlowConfig, @"Resource\flowDefault.json");

            var input = await File.ReadAllTextAsync(@"Resource\guiInput.json");

            var inputJson = JsonConfig.From(input);
            var result    = await this.FlowOperation.SaveFlowConfig(FlowGuiConfig.From(inputJson));

            Assert.IsTrue(result.IsSuccess, result.Message);

            var actualJson = await this.FlowOperation.GetFlowByName("configgentest");

            var expectedJson = FlowConfig.From(await File.ReadAllTextAsync(@"Resource\flowSaved.json"));

            foreach (var match in EntityConfig.Match(expectedJson, actualJson))
            {
                Assert.AreEqual(expected: match.Item2, actual: match.Item3, message: $"path:{match.Item1}");
            }

            Cleanup();
        }
コード例 #16
0
        public async Task <FlowConfig> Build(FlowGuiConfig inputGuiConfig)
        {
            var defaultConfig = await FlowData.GetFlowConfigByInputType(inputGuiConfig.Input.InputType);

            var config = defaultConfig ?? FlowConfig.From(JsonConfig.CreateEmpty());

            // Set the flowName. This will be the case for new flow creation
            if (string.IsNullOrWhiteSpace(inputGuiConfig.Name))
            {
                string flowName = GenerateValidFlowName(inputGuiConfig.DisplayName);
                config.Name         = flowName;
                inputGuiConfig.Name = flowName;
            }
            var guiConfig = await HandleSensitiveData(inputGuiConfig);

            config.Name = guiConfig?.Name ?? config.Name;

            config.DisplayName = guiConfig?.DisplayName ?? config.DisplayName;
            config.Gui         = guiConfig.ToJson()._jt;

            return(FlowConfig.From(config.ToString()));
        }
コード例 #17
0
        public static List <FlowConfig> ConvertToFlowConfig(DataTable dt)
        {
            List <FlowConfig> list = new List <FlowConfig>();

            if (dt != null)
            {
                foreach (DataRow row in dt.Rows)
                {
                    var item = new FlowConfig()
                    {
                        ID            = Convert.ToInt32(row["ID"] == DBNull.Value ? 0 : row["ID"]),
                        StartVersion  = row["StartVersion"]?.ToString(),
                        EndVersion    = row["EndVersion"]?.ToString(),
                        Title         = row["Title"]?.ToString(),
                        StartDateTime = Convert.ToDateTime(row["StartDateTime"] == DBNull.Value ? DateTime.MinValue : row["StartDateTime"]),
                        EndDateTime   = Convert.ToDateTime(row["EndDateTime"] == DBNull.Value ? DateTime.MaxValue : row["EndDateTime"]),
                        LinkUrl       = HttpUtility.UrlDecode(row["LinkUrl"] == DBNull.Value ? "" : row["LinkUrl"].ToString()),
                    };
                    list.Add(item);
                }
            }
            return(list);
        }
コード例 #18
0
ファイル: MainViewModel.cs プロジェクト: devncore/devflow
 private void SkinSelected(SkinModel theme)
 {
     this.theme.Switch(theme.Skin);
     FlowConfig.SaveTheme(theme.Skin);
 }
コード例 #19
0
        public async Task <FlowConfig> GetByName(string flowName)
        {
            var json = await this.Storage.GetByName(flowName, DataCollectionName);

            return(FlowConfig.From(json));
        }
コード例 #20
0
ファイル: MainViewModel.cs プロジェクト: devncore/devflow
 private void LanguageChanged(LanguageModel culture)
 {
     this.culture.Switch(culture.Language);
     FlowConfig.SaveLanguage(culture.Language);
 }
コード例 #21
0
 /// <summary>
 /// validate if the given flow config has all the required fields present
 /// </summary>
 /// <param name="config">the given config</param>
 /// <returns>Success result if validation passes, else a FailedResult</returns>
 private Result ValidateFlowConfig(FlowConfig config)
 {
     //TODO: implement the validations.
     return(new SuccessResult());
 }