Пример #1
0
        private void UpdateCurrent(UserChartEntity current)
        {
            Header = new TextBlock
            {
                Inlines = 
                { 
                    new Run(
                    current == null ? typeof(UserChartEntity).NicePluralName() : current.DisplayName), 
                    UserCharts == null || UserCharts.Count==0 ? (Inline)new Run():  new Bold(new Run(" (" + UserCharts.Count + ")")) 
                }
            };

            foreach (var item in this.Items.OfType<MenuItem>().Where(mi => mi.IsCheckable))
            {
                item.IsChecked = ((Lite<UserChartEntity>)item.Tag).RefersTo(current);
            }
        }
Пример #2
0
        public static ChartRequestModel ToRequest(this UserChartEntity uq)
        {
            var result = new ChartRequestModel(uq.QueryName)
            {
                ChartScript = uq.ChartScript,
                Filters     = uq.Filters.ToFilterList(),
            };

            result.Columns.ZipForeach(uq.Columns, (r, u) =>
            {
                r.Token        = u.Token;
                r.DisplayName  = u.DisplayName;
                r.OrderByIndex = u.OrderByIndex;
                r.OrderByType  = u.OrderByType;
            });

            result.Parameters.ForEach(r =>
            {
                r.Value = uq.Parameters.FirstOrDefault(u => u.Name == r.Name)?.Value ?? r.ScriptParameter.DefaultValue(r.ScriptParameter.GetToken(uq));
            });
            return(result);
        }
Пример #3
0
        public static UserChartEntity ToUserChart(this ChartRequest request)
        {
            var result = new UserChartEntity
            {
                Owner = UserQueryUtils.DefaultOwner(),

                QueryName = request.QueryName,

                GroupResults = request.GroupResults,
                ChartScript  = request.ChartScript,

                Filters = request.Filters.Select(f => new QueryFilterEmbedded
                {
                    Token       = new QueryTokenEmbedded(f.Token),
                    Operation   = f.Operation,
                    ValueString = FilterValueConverter.ToString(f.Value, f.Token.Type),
                }).ToMList(),

                Orders = request.Orders.Select(o => new QueryOrderEmbedded
                {
                    Token     = new QueryTokenEmbedded(o.Token),
                    OrderType = o.OrderType
                }).ToMList()
            };

            result.Columns.ZipForeach(request.Columns, (u, r) =>
            {
                u.Token       = r.Token;
                u.DisplayName = r.DisplayName;
            });

            result.Parameters.ForEach(u =>
            {
                u.Value = request.Parameters.FirstOrDefault(r => r.Name == u.Name).Value;
            });

            return(result);
        }
Пример #4
0
        public static ChartRequest ToRequest(this UserChartEntity uq)
        {
            var result = new ChartRequest(uq.QueryName)
            {
                GroupResults = uq.GroupResults,
                ChartScript  = uq.ChartScript,
                Filters      = uq.Filters.Select(qf => new Filter(qf.Token.Token, qf.Operation,
                                                                  FilterValueConverter.Parse(qf.ValueString, qf.Token.Token.Type, qf.Operation.IsList()))).ToList(),
                Orders = uq.Orders.Select(o => new Order(o.Token.Token, o.OrderType)).ToList(),
            };

            result.Columns.ZipForeach(uq.Columns, (r, u) =>
            {
                r.Token       = u.Token;
                r.DisplayName = u.DisplayName;
            });

            result.Parameters.ForEach(r =>
            {
                r.Value = uq.Parameters.FirstOrDefault(u => u.Name == r.Name)?.Value ?? r.ScriptParameter.DefaultValue(r.ScriptParameter.GetToken(uq));
            });
            return(result);
        }
Пример #5
0
 public static void SetUserChart(DependencyObject obj, UserChartEntity value)
 {
     obj.SetValue(UserChartProperty, value);
 }
Пример #6
0
        internal static void OpenChartRequest(ChartRequest chartRequest, UserChartEntity uc, Entity currentEntity)
        {
            Navigator.OpenIndependentWindow(() => 
            {
                var crw = new ChartRequestWindow()
                {
                    DataContext = chartRequest,
                    Title = ChartMessage.ChartOf0.NiceToString().FormatWith(QueryUtils.GetNiceName(chartRequest.QueryName)),
                    Icon = Finder.Manager.GetFindIcon(chartRequest.QueryName, false) ?? ExtensionsImageLoader.GetImageSortName("chartIcon.png")
                };

                if (uc != null)
                    SetUserChart(crw, uc);

                if (currentEntity != null)
                    UserAssetsClient.SetCurrentEntity(crw, currentEntity);

                return crw; 
            });
        }
Пример #7
0
        internal static void View(UserChartEntity uc, Entity currentEntity)
        {
            if (uc.EntityType != null)
            {
                if (currentEntity == null)
                {
                    var entity = Finder.Find(new FindOptions(Server.GetType(uc.EntityType.ToString())));

                    if (entity == null)
                        return;

                    currentEntity = entity.Retrieve();
                }
            }

            var query = QueryClient.GetQueryName(uc.Query.Key);
            
            OpenChartRequest(new ChartRequest(query), uc, currentEntity);
        }
Пример #8
0
        static void ChartLogic_Retrieved(UserChartEntity userQuery)
        {
            object queryName = QueryLogic.ToQueryName(userQuery.Query.Key);

            QueryDescription description = DynamicQueryManager.Current.QueryDescription(queryName);

            foreach (var item in userQuery.Columns)
            {
                item.parentChart = userQuery;
            }

            userQuery.ParseData(description);
        }
Пример #9
0
        static SqlPreCommand ProcessUserChart(Replacements replacements, Table table, UserChartEntity uc)
        {
            try
            {
                Console.Clear();

                SafeConsole.WriteLineColor(ConsoleColor.White, "UserChart: " + uc.DisplayName);
                Console.WriteLine(" ChartScript: " + uc.ChartScript.ToString());
                Console.WriteLine(" Query: " + uc.Query.Key);

                if (uc.Filters.Any(a => a.Token.ParseException != null) ||
                   uc.Columns.Any(a => a.Token != null && a.Token.ParseException != null) ||
                   uc.Orders.Any(a => a.Token.ParseException != null))
                {
                    QueryDescription qd = DynamicQueryManager.Current.QueryDescription(uc.Query.ToQueryName());

                    SubTokensOptions canAggregate = uc.GroupResults ? SubTokensOptions.CanAggregate : 0;

                    if (uc.Filters.Any())
                    {
                        Console.WriteLine(" Filters:");
                        foreach (var item in uc.Filters.ToList())
                        {
                            QueryTokenEntity token = item.Token;
                            switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanAnyAll | SubTokensOptions.CanElement | canAggregate, "{0} {1}".FormatWith(item.Operation, item.ValueString), allowRemoveToken: true, allowReCreate: false))
                            {
                                case FixTokenResult.Nothing: break;
                                case FixTokenResult.DeleteEntity: return table.DeleteSqlSync(uc);
                                case FixTokenResult.RemoveToken: uc.Filters.Remove(item); break;
                                case FixTokenResult.SkipEntity: return null;
                                case FixTokenResult.Fix: item.Token = token; break;
                                default: break;
                            }
                        }
                    }

                    if (uc.Columns.Any())
                    {
                        Console.WriteLine(" Columns:");
                        foreach (var item in uc.Columns.ToList())
                        {
                            QueryTokenEntity token = item.Token;
                            if (item.Token == null)
                                break;

                            switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanElement | canAggregate, item.ScriptColumn.DisplayName, allowRemoveToken: item.ScriptColumn.IsOptional, allowReCreate: false))
                            {
                                case FixTokenResult.Nothing: break;
                                case FixTokenResult.DeleteEntity: return table.DeleteSqlSync(uc);
                                case FixTokenResult.RemoveToken: item.Token = null; break;
                                case FixTokenResult.SkipEntity: return null;
                                case FixTokenResult.Fix: item.Token = token; break;
                                default: break;
                            }
                        }
                    }

                    if (uc.Orders.Any())
                    {
                        Console.WriteLine(" Orders:");
                        foreach (var item in uc.Orders.ToList())
                        {
                            QueryTokenEntity token = item.Token;
                            switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanElement | canAggregate, item.OrderType.ToString(), allowRemoveToken: true, allowReCreate: false))
                            {
                                case FixTokenResult.Nothing: break;
                                case FixTokenResult.DeleteEntity: return table.DeleteSqlSync(uc);
                                case FixTokenResult.RemoveToken: uc.Orders.Remove(item); break;
                                case FixTokenResult.SkipEntity: return null;
                                case FixTokenResult.Fix: item.Token = token; break;
                                default: break;
                            }
                        }
                    }
                }

                foreach (var item in uc.Filters.ToList())
                {
                    string val = item.ValueString;
                    switch (QueryTokenSynchronizer.FixValue(replacements, item.Token.Token.Type, ref val, allowRemoveToken: true, isList: item.Operation == FilterOperation.IsIn))
                    {
                        case FixTokenResult.Nothing: break;
                        case FixTokenResult.DeleteEntity: return table.DeleteSqlSync(uc);
                        case FixTokenResult.RemoveToken: uc.Filters.Remove(item); break;
                        case FixTokenResult.SkipEntity: return null;
                        case FixTokenResult.Fix: item.ValueString = val; break;
                    }
                }

                foreach (var item in uc.Columns)
                {
                    uc.FixParameters(item);
                }


                try
                {
                    return table.UpdateSqlSync(uc, includeCollections: true);
                }
                catch(Exception e)
                {
                    Console.WriteLine("Integrity Error:");
                    SafeConsole.WriteLineColor(ConsoleColor.DarkRed, e.Message);
                    while (true)
                    {
                        SafeConsole.WriteLineColor(ConsoleColor.Yellow, "- s: Skip entity");
                        SafeConsole.WriteLineColor(ConsoleColor.Red, "- d: Delete entity");

                        string answer = Console.ReadLine();

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

                        answer = answer.ToLower();

                        if (answer == "s")
                            return null;

                        if (answer == "d")
                            return table.DeleteSqlSync(uc);
                    }
                }

               
            }
            catch (Exception e)
            {
                return new SqlPreCommandSimple("-- Exception in {0}: {1}".FormatWith(uc.BaseToString(), e.Message));
            }
            finally
            {
                Console.Clear();
            }
        }
Пример #10
0
        private void SetCurrent(UserChartEntity uc)
        {
            CurrentUserChart = uc;

            this.ChartWindow.Request = CurrentUserChart.ToRequest();

            this.ChartWindow.GenerateChart();
        }
Пример #11
0
        public static UserChartEntity ToUserChart(this ChartRequest request)
        {
            var result = new UserChartEntity
            {
                Owner = UserQueryUtils.DefaultRelated(),

                QueryName = request.QueryName,

                GroupResults = request.GroupResults,
                ChartScript = request.ChartScript,

                Filters = request.Filters.Select(f => new QueryFilterEntity
                {
                    Token = new QueryTokenEntity(f.Token),
                    Operation = f.Operation,
                    ValueString = FilterValueConverter.ToString(f.Value, f.Token.Type),
                }).ToMList(),

                Orders = request.Orders.Select(o => new QueryOrderEntity
                {
                    Token = new QueryTokenEntity(o.Token),
                    OrderType = o.OrderType
                }).ToMList()
            };

            result.Columns.ZipForeach(request.Columns, (u, r) =>
            {
                u.Token = r.Token;
                u.DisplayName = r.DisplayName;
            });

            result.Parameters.ForEach(u =>
            {
                u.Value = request.Parameters.FirstOrDefault(r => r.Name == u.Name).Value;
            });

            return result;
        }