public static bool SyncronizeColumns(this ChartScriptEntity chartScript, IChartBase chart)
        {
            bool result = false;

            if (chartScript == null)
            {
                result = true;
                chart.Columns.Clear();
            }

            for (int i = 0; i < chartScript.Columns.Count; i++)
            {
                if (chart.Columns.Count <= i)
                {
                    chart.Columns.Add(new ChartColumnEntity());
                    result = true;
                }

                chart.Columns[i].parentChart = chart;
                chart.Columns[i].ScriptColumn = chartScript.Columns[i];
             
                if (!result)
                    result = chart.Columns[i].IntegrityCheck() != null;
            }

            if (chart.Columns.Count > chartScript.Columns.Count)
            {
                chart.Columns.RemoveRange(chartScript.Columns.Count, chart.Columns.Count - chartScript.Columns.Count);
                result = true;
            }

            if (chart.Parameters.Modified != ModifiedState.Sealed)
            {
                if (chart.Parameters.Select(a => a.Name).OrderBy().SequenceEqual(chartScript.Parameters.Select(a => a.Name).OrderBy()))
                {
                    foreach (var cp in chart.Parameters)
                    {
                        var sp = chartScript.Parameters.FirstEx(a => a.Name == cp.Name);

                        cp.parentChart = chart;
                        cp.ScriptParameter = sp;
                        //if (cp.PropertyCheck(() => cp.Value).HasText())
                        //    cp.Value = sp.DefaultValue(cp.GetToken());
                    }
                }
                else
                {
                    var byName = chart.Parameters.ToDictionary(a => a.Name);
                    chart.Parameters.Clear();
                    foreach (var sp in chartScript.Parameters)
                    {
                        var cp = byName.TryGetC(sp.Name);

                        if (cp != null)
                        {
                            cp.parentChart = chart;
                            cp.ScriptParameter = sp;

                            //if (cp.PropertyCheck(() => cp.Value).HasText())
                            //    cp.Value = sp.DefaultValue(cp.GetToken());
                        }
                        else
                        {
                            cp = new ChartParameterEntity
                            {
                                Name = sp.Name,
                                parentChart = chart,
                                ScriptParameter = sp,
                            };

                            cp.Value = sp.DefaultValue(sp.GetToken(chart));
                        }

                        chart.Parameters.Add(cp);
                    }
                }
            }

            if (chartScript.GroupBy == GroupByChart.Always && chart.GroupResults == false)
            {
                chart.GroupResults = true;
                result = true;
            }
            else if (chartScript.GroupBy == GroupByChart.Never && chart.GroupResults == true)
            {
                chart.GroupResults = false;
                result = true;
            }

            return result;
        }
Esempio n. 2
0
        private static FixTokenResult FixParameter(ChartParameterEntity item, ref string val)
        {
            var error = item.PropertyCheck(nameof(item.Value));
            if (error == null)
                return FixTokenResult.Nothing;

            SafeConsole.WriteLineColor(ConsoleColor.White, "Parameter Name: {0}".FormatWith(item.ScriptParameter.Name));
            SafeConsole.WriteLineColor(ConsoleColor.White, "Parameter Definition: {0}".FormatWith(item.ScriptParameter.ValueDefinition));
            SafeConsole.WriteLineColor(ConsoleColor.White, "CurrentValue: {0}".FormatWith(item.Value));
            SafeConsole.WriteLineColor(ConsoleColor.White, "Error: {0}.".FormatWith(error));
            SafeConsole.WriteLineColor(ConsoleColor.Yellow, "- s: Skip entity");
            SafeConsole.WriteLineColor(ConsoleColor.DarkRed, "- r: Remove parame");
            SafeConsole.WriteLineColor(ConsoleColor.Red, "- d: Delete entity");
            SafeConsole.WriteLineColor(ConsoleColor.Green, "- freeText: New value");

            string answer = Console.ReadLine();

            if (answer == null)
                throw new InvalidOperationException("Impossible to synchronize interactively without Console");

            string a = answer.ToLower();

            if (a == "s")
                return FixTokenResult.SkipEntity;

            if (a == "r")
                return FixTokenResult.RemoveToken;

            if (a == "d")
                return FixTokenResult.DeleteEntity;

            val = answer;
            return FixTokenResult.Fix;
        }