Ejemplo n.º 1
0
        public virtual AnalyseResult Analyse <T>(string content)
            where T : DatabaseObject
        {
            AnalyseResult result = null;

            if (typeof(T) == typeof(Procedure))
            {
                result = this.AnalyseProcedure(content);
            }
            else if (typeof(T) == typeof(Function))
            {
                result = this.AnalyseFunction(content);
            }
            else if (typeof(T) == typeof(View))
            {
                result = this.AnalyseView(content);
            }
            else if (typeof(T) == typeof(TableTrigger))
            {
                result = this.AnalyseTrigger(content);
            }
            else
            {
                throw new NotSupportedException($"Not support analyse for type:{typeof(T).Name}");
            }

            return(result);
        }
Ejemplo n.º 2
0
    void UseSkillStatistic(System.Drawing.Graphics g, ZedGraph.MasterPane masterPane)
    {
        GraphPane graphPane = masterPane[0];

        graphPane.Fill = new Fill(WebConfig.GraphPaneBgColor);

        graphPane.Legend.Fill.IsVisible          = false;
        graphPane.Legend.Border.IsVisible        = false;
        graphPane.Legend.FontSpec.Fill.IsVisible = false;

        graphPane.XAxis.Title.Text          = StringDef.Date;
        graphPane.XAxis.MajorGrid.Color     = WebConfig.GraphXAxisGridColor;
        graphPane.XAxis.Type                = AxisType.DateAsOrdinal;
        graphPane.XAxis.MinorTic.Size       = 0;
        graphPane.XAxis.Scale.MajorStep     = 1;
        graphPane.XAxis.Scale.FontSpec.Size = 12;
        switch (_viewType)
        {
        case ViewType.ByMonth:
            graphPane.XAxis.Scale.MajorUnit = DateUnit.Month;
            break;

        case ViewType.ByDay:
            graphPane.XAxis.Scale.MajorUnit = DateUnit.Day;
            break;
        }

        graphPane.YAxis.MajorGrid.IsVisible = true;
        graphPane.YAxis.MajorGrid.DashOff   = 0;
        graphPane.YAxis.MajorGrid.Color     = Color.Gray;
        graphPane.YAxis.MinorGrid.IsVisible = true;
        graphPane.YAxis.MinorGrid.Color     = Color.LightGray;
        graphPane.YAxis.MinorGrid.DashOff   = 0;

        graphPane.Title.Text       = String.Format("{0} - {1}", StringDef.UseSkill, _statisticDesc);
        graphPane.YAxis.Title.Text = StringDef.UseSkill;

        AnalyseResult result = null;

        if (_useCache)
        {
            result = Session["AdvancedStatistic_UseSkillStatistic"] as AnalyseResult;
        }
        if (result == null)
        {
            result = _analyseResultList[0];
            Session["AdvancedStatistic_UseSkillStatistic"] = result;
            Session["AdvancedStatistic_CanUseCache"]       = true;
        }
        if (_chartType == ChartType.Bar)
        {
            BarItem barItem = graphPane.AddBar("使用技能", result.Times, result.Counts, Color.Blue);
            barItem.Bar.Fill = new Fill(Color.Blue);
        }
        else if (_chartType == ChartType.Line)
        {
            LineItem lineItem = graphPane.AddCurve("使用技能", result.Times, result.Counts, Color.Blue);
        }
    }
Ejemplo n.º 3
0
 public AnalysisContext(CardPromptAnalysis analysis, List <PrompCards> prompCardsList, IReadOnlyList <Card> handCards,
                        IReadOnlyList <Card> target,
                        CardType targetType)
 {
     this.Analysis       = analysis;
     this.PrompCardsList = prompCardsList;
     this.HandCards      = handCards;
     this.Target         = target;
     this.TargetType     = targetType;
     this.AnalyseResults = AnalyseResult.Analyse(handCards);
 }
Ejemplo n.º 4
0
        private void Analysis(List <Card> cards)
        {
            List <AnalyseResult> results = AnalyseResult.Analyse(cards);

            // 王
            var jokers = cards.Where(f => CardsHelper.IsJoker(f)).ToList();

            // 最大的8炸
            if (jokers.Count == 4)
            {
            }

            // 炸弹
            var booms = results.Where(f => !CardsHelper.IsJoker(f.Weight) && f.Count > 3).ToList();
        }
Ejemplo n.º 5
0
        public override AnalyseResult AnalyseView(string content)
        {
            SqlSyntaxError error = null;

            DdlStatementContext ddlStatement = this.GetDdlStatementContext(content, out error);

            AnalyseResult result = new AnalyseResult()
            {
                Error = error
            };

            if (!result.HasError && ddlStatement != null)
            {
                ViewScript script = new ViewScript();

                CreateViewContext view = ddlStatement.createView();

                if (view != null)
                {
                    #region Name
                    this.SetScriptName(script, view.fullId());
                    #endregion

                    #region Statement

                    foreach (var child in view.children)
                    {
                        if (child is SimpleSelectContext select)
                        {
                            script.Statements.Add(this.ParseSelectStatement(select));
                        }
                    }

                    #endregion
                }

                this.ExtractFunctions(script, ddlStatement);

                result.Script = script;
            }

            return(result);
        }
Ejemplo n.º 6
0
        static AnalyseResult Analyse(Expression expression)
        {
            var result = new AnalyseResult
            {
                WasParameter = expression is ParameterExpression
            };

            if (result.WasParameter)
            {
                return(result);
            }

            if (expression is MemberExpression member)
            {
                result.Member = member.Expression is UnaryExpression innerUnary && innerUnary.NodeType == ExpressionType.Convert
                    ? Expression.Property(innerUnary.Operand, member.Member.Name)
                    : member;
            }

            if (expression is UnaryExpression unary && unary.Operand is MemberExpression member2)
            {
                result.Member = member2;
            }

            // TODO: Fix the issues with following idea to support x.AnotherEntity.Prop == x.MainEntityProp
            bool isFromParam(Expression exp)
            {
                if (exp == null)
                {
                    return(false);
                }
                if (exp is ParameterExpression)
                {
                    return(true);
                }
                return(isFromParam((exp as MemberExpression)?.Expression));
            }

            result.FromParameter = isFromParam(result.Member);

            return(result);
        }
Ejemplo n.º 7
0
    void MoneyStatistic(System.Drawing.Graphics g, ZedGraph.MasterPane masterPane)
    {
        bool      showSymbol = true;
        GraphPane graphPane  = masterPane[0];

        graphPane.Fill = new Fill(WebConfig.GraphPaneBgColor);

        graphPane.Legend.Fill.IsVisible          = false;
        graphPane.Legend.Border.IsVisible        = false;
        graphPane.Legend.FontSpec.Fill.IsVisible = false;

        graphPane.XAxis.Title.Text          = StringDef.Date;
        graphPane.XAxis.MajorGrid.Color     = WebConfig.GraphXAxisGridColor;
        graphPane.XAxis.Type                = AxisType.DateAsOrdinal;
        graphPane.XAxis.MinorTic.Size       = 0;
        graphPane.XAxis.Scale.MajorStep     = 1;
        graphPane.XAxis.Scale.FontSpec.Size = 12;
        switch (_viewType)
        {
        case ViewType.ByMonth:
            graphPane.XAxis.Scale.MajorUnit = DateUnit.Month;
            break;

        case ViewType.ByDay:
            graphPane.XAxis.Scale.MajorUnit = DateUnit.Day;
            break;
        }

        graphPane.YAxis.MajorGrid.IsVisible = true;
        graphPane.YAxis.MajorGrid.DashOff   = 0;
        graphPane.YAxis.MajorGrid.Color     = Color.Gray;
        graphPane.YAxis.MinorGrid.IsVisible = true;
        graphPane.YAxis.MinorGrid.Color     = Color.LightGray;
        graphPane.YAxis.MinorGrid.DashOff   = 0;

        graphPane.Title.Text       = String.Format("{0} - {1}", StringDef.MoneyStatistic, _statisticDesc);
        graphPane.YAxis.Title.Text = StringDef.Money;

        AnalyseResult addMoneyResult    = null;
        AnalyseResult removeMoneyResult = null;

        if (_analyseResultList != null && _analyseResultList.Count != 0)
        {
            int index = 0;
            if (CheckBoxShowAddMoney.Checked || CheckBoxShowChangeMoney.Checked)
            {
                addMoneyResult = _analyseResultList[index];
                ++index;
            }
            if (CheckBoxShowRemoveMoney.Checked || CheckBoxShowChangeMoney.Checked)
            {
                removeMoneyResult = _analyseResultList[index];
            }
        }

        if (CheckBoxShowChangeMoney.Checked)
        {
            double[] changeMoneyValues = new double[addMoneyResult.Values.Length];
            double[] changeMoneyTimes  = new double[addMoneyResult.Times.Length];
            if (addMoneyResult.Values.Length == removeMoneyResult.Values.Length)
            {
                for (int i = 0; i < changeMoneyValues.Length; i++)
                {
                    changeMoneyValues[i] = addMoneyResult.Values[i] + removeMoneyResult.Values[i];
                    changeMoneyTimes[i]  = addMoneyResult.Times[i];
                }
            }

            if (_chartType == ChartType.Bar)
            {
                graphPane.BarSettings.Type = BarType.SortedOverlay;

                if (CheckBoxShowAddMoney.Checked)
                {
                    BarItem barItemAddMoney = graphPane.AddBar(StringDef.AddMoney, addMoneyResult.Times, addMoneyResult.Values, Color.Black);
                    barItemAddMoney.Bar.Fill = new Fill(Color.Green);
                }
                if (CheckBoxShowRemoveMoney.Checked)
                {
                    BarItem barItemRemoveMoney = graphPane.AddBar(StringDef.RemoveMoney, removeMoneyResult.Times, removeMoneyResult.Values, Color.Black);
                    barItemRemoveMoney.Bar.Fill = new Fill(Color.Red);
                }

                BarItem barItemChangeMoney = graphPane.AddBar(StringDef.ChangeMoney, changeMoneyTimes, changeMoneyValues, Color.Black);
                barItemChangeMoney.Bar.Fill = new Fill(Color.Blue);
            }
            else if (_chartType == ChartType.Line)
            {
                if (CheckBoxShowAddMoney.Checked)
                {
                    graphPane.AddCurve(StringDef.AddMoney, addMoneyResult.Times, addMoneyResult.Values, Color.Green, (showSymbol ? WebConfig.GraphSymbols[0] : SymbolType.None));
                }
                if (CheckBoxShowRemoveMoney.Checked)
                {
                    graphPane.AddCurve(StringDef.RemoveMoney, removeMoneyResult.Times, removeMoneyResult.Values, Color.Red, (showSymbol ? WebConfig.GraphSymbols[1] : SymbolType.None));
                }

                graphPane.AddCurve(StringDef.ChangeMoney, changeMoneyTimes, changeMoneyValues, Color.Blue, (showSymbol ? WebConfig.GraphSymbols[2] : SymbolType.None));
            }
        }
        else
        {
            if (_chartType == ChartType.Bar)
            {
                graphPane.BarSettings.Type = BarType.SortedOverlay;

                if (CheckBoxShowAddMoney.Checked)
                {
                    BarItem barItemAddMoney = graphPane.AddBar(StringDef.AddMoney, addMoneyResult.Times, addMoneyResult.Values, Color.Black);
                    barItemAddMoney.Bar.Fill = new Fill(Color.Green);
                }
                if (CheckBoxShowRemoveMoney.Checked)
                {
                    BarItem barItemRemoveMoney = graphPane.AddBar(StringDef.RemoveMoney, removeMoneyResult.Times, removeMoneyResult.Values, Color.Black);
                    barItemRemoveMoney.Bar.Fill = new Fill(Color.Red);
                }
            }
            else if (_chartType == ChartType.Line)
            {
                if (CheckBoxShowAddMoney.Checked)
                {
                    graphPane.AddCurve(StringDef.AddMoney, addMoneyResult.Times, addMoneyResult.Values, Color.Green, (showSymbol ? WebConfig.GraphSymbols[0] : SymbolType.None));
                }
                if (CheckBoxShowRemoveMoney.Checked)
                {
                    graphPane.AddCurve(StringDef.RemoveMoney, removeMoneyResult.Times, removeMoneyResult.Values, Color.Red, (showSymbol ? WebConfig.GraphSymbols[1] : SymbolType.None));
                }
            }
        }
    }
Ejemplo n.º 8
0
    AnalyseResult AnalyseData(GameServer server, int logEventId, string additionalFilter)
    {
        double[] statisticValues = null;
        double[] statisticTimes  = null;
        double[] statisticCounts = null;

        bool bQuitFlag = false;

        StringBuilder whereStatement = new StringBuilder();

        whereStatement.AppendFormat(" WHERE {0}={1} ", FS2TableString.LogFieldLogEvent, logEventId);

        if (_roleGuid != null)
        {
            whereStatement.AppendFormat(" AND {0}='{1}'", FS2TableString.LogFieldLogKey1, _roleGuid);
        }

        whereStatement.AppendFormat(" AND {0} >= '{1}' AND {0} <= '{2}'",
                                    FS2TableString.LogFieldLogTime,
                                    _startDate,
                                    _endDate);

        if (additionalFilter != null && additionalFilter.Length > 0)
        {
            whereStatement.AppendFormat(" AND {0} ", additionalFilter);
        }

        string baseCmdString = string.Empty;

        switch (_viewType)
        {
        case ViewType.ByMonth:
            baseCmdString = string.Format("SELECT DATE_FORMAT(LogTime,'%Y-%m'),SUM(LogKey6),COUNT(*) FROM {0} {1} GROUP BY LogEvent",
                                          "{0}",
                                          whereStatement.ToString());

            int monthCount = 12 * (_endDate.Year - _startDate.Year) + (_endDate.Month - _startDate.Month) + 1;
            statisticValues = new double[monthCount];
            statisticTimes  = new double[monthCount];
            statisticCounts = new double[monthCount];

            for (int index = 0; index != statisticValues.Length; ++index)
            {
                DateTime tempDate = _startDate.AddMonths(index);
                statisticTimes[index] = new XDate(tempDate.Year, tempDate.Month, 1);
            }

            break;

        case ViewType.ByDay:
            baseCmdString = string.Format("SELECT DATE(LogTime), SUM(LogKey6), COUNT(*) FROM {0} {1} GROUP BY DATE(LogTime)",
                                          "{0}",
                                          whereStatement.ToString());

            TimeSpan span     = _endDate.Subtract(_startDate);
            int      dayCount = span.Days + 1;
            statisticValues = new double[dayCount];
            statisticTimes  = new double[dayCount];
            statisticCounts = new double[dayCount];
            for (int index = 0; index != statisticTimes.Length; ++index)
            {
                DateTime tempDate = _startDate.Date.AddDays(index);
                statisticTimes[index] = new XDate(tempDate);
            }
            break;

        case ViewType.ByHour:
            bQuitFlag = true;
            break;

        default:
            bQuitFlag = true;
            break;
        }

        if (bQuitFlag)
        {
            return(null);
        }

        string addTableCmdString;

        WebUtil.AddTableNameToCmd(CurrentUser.Id, server, baseCmdString, _startDate, _endDate, out addTableCmdString);
        if (addTableCmdString.Length == 0)
        {
            return(null);
        }

        SqlResult sqlResult = WebUtil.QueryGameServerDb(CurrentUser.Id, server, new SqlCommand(addTableCmdString));

        if (sqlResult != null && sqlResult.Success)
        {
            sqlResult.SetFieldType(new SqlDataType[] {
                SqlDataType.DateTime,
                SqlDataType.Int64,
                SqlDataType.Int32
            });

            object[] record = sqlResult.ReadRecord();

            switch (_viewType)
            {
            case ViewType.ByMonth:
                while (record != null)
                {
                    DateTime date  = (DateTime)record[0];
                    long     sum   = (long)record[1];
                    int      count = (int)record[2];

                    int monthIndex = 12 * (date.Year - _startDate.Year) + (date.Month - _startDate.Month);
                    statisticTimes[monthIndex]  = new XDate(date);
                    statisticValues[monthIndex] = sum;
                    statisticCounts[monthIndex] = count;

                    record = sqlResult.ReadRecord();
                }
                break;

            case ViewType.ByDay:
                while (record != null)
                {
                    DateTime date  = (DateTime)record[0];
                    long     sum   = (long)record[1];
                    int      count = (int)record[2];

                    TimeSpan indexSpan = date.Subtract(_startDate.Date);
                    statisticTimes[indexSpan.Days]  = new XDate(date);
                    statisticValues[indexSpan.Days] = sum;
                    statisticCounts[indexSpan.Days] = count;

                    record = sqlResult.ReadRecord();
                }
                break;
            }
        }
        else
        {
            return(null);
        }

        AnalyseResult result = new AnalyseResult();

        result.Values = statisticValues;
        result.Times  = statisticTimes;
        result.Counts = statisticCounts;

        return(result);
    }
Ejemplo n.º 9
0
    protected void LinkButtonStatistic_Click(object sender, EventArgs e)
    {
        ClearAllCacheData();

        try
        {
            GameServer server = ServerDropDownList.SelectedGameServer;
            if (server == null)
            {
                LabelOpMsg.Text = string.Format(StringDef.MsgCannotBeNone, StringDef.GameServer);
                return;
            }
            if (!server.IsConnected)
            {
                LabelOpMsg.Text = StringDef.NoConnectionAlert;
                return;
            }
            _startDate = StartDate.SelectedDate;
            if (_startDate == DateTime.MinValue)
            {
                LabelOpMsg.Text = StringDef.ParameterInputError + StringDef.Colon + StringDef.StartDate;
                return;
            }
            _endDate = EndDate.SelectedDate;
            if (_endDate == DateTime.MinValue)
            {
                LabelOpMsg.Text = StringDef.ParameterInputError + StringDef.Colon + StringDef.StartDate;
                return;
            }
            if (_startDate > _endDate)
            {
                LabelOpMsg.Text = StringDef.EndTimeError;
                return;
            }

            string roleName = TextBoxRoleName.Text.Trim();
            if (roleName.Length != 0)
            {
                _roleGuid = WebUtil.FindRoleGuidByName(CurrentUser.Id, server, roleName);
                if (_roleGuid == null || _roleGuid.Length == 0)
                {
                    LabelOpMsg.Text = string.Format(StringDef.RoleWithNameNotExist, roleName);
                    return;
                }
                _statisticDesc = String.Format(StringDef.RoleWithName, roleName);
            }
            else
            {
                _statisticDesc = StringDef.AllRoles;
            }

            switch (this._viewContent)
            {
            case ViewContent.Exp:
                AnalyseResult expResult = AnalyseData(server, 13, string.Empty);
                if (expResult != null)
                {
                    _analyseResultList.Add(expResult);
                }
                break;

            case ViewContent.Item:
                string itemTemplateIdFilter = null;
                if (TextBoxItemTemplateId.Text.Trim().Length > 0)
                {
                    itemTemplateIdFilter = string.Format("LogKey2='{0}'", TextBoxItemTemplateId.Text.Trim());
                }

                for (int i = 0; i < ItemCountTypes.Length; i++)
                {
                    ListItem item = CheckBoxListShowItemCount.Items[i];
                    if (item.Selected)
                    {
                        AnalyseResult itemResult = AnalyseData(server, ItemCountEventIds[i], itemTemplateIdFilter);
                        if (itemResult != null)
                        {
                            _analyseResultList.Add(itemResult);
                        }
                    }
                }
                break;

            case ViewContent.Money:
                AnalyseResult addMoneyResult    = null;
                AnalyseResult removeMoneyResult = null;
                if (CheckBoxShowAddMoney.Checked || CheckBoxShowChangeMoney.Checked)
                {
                    addMoneyResult = AnalyseData(server, EventIdAddMoney, null);
                }
                if (CheckBoxShowRemoveMoney.Checked || CheckBoxShowChangeMoney.Checked)
                {
                    removeMoneyResult = AnalyseData(server, EventIdRemoveMoney, null);
                }
                if (addMoneyResult != null)
                {
                    _analyseResultList.Add(addMoneyResult);
                }
                if (removeMoneyResult != null)
                {
                    _analyseResultList.Add(removeMoneyResult);
                }
                break;

            case ViewContent.PlayerDeath:
                AnalyseResult playerKillDeathResult = AnalyseData(server, EventIdPlayerDeath, "LENGTH(LogKey2)>=32");
                AnalyseResult npcKillDeathResult    = AnalyseData(server, EventIdPlayerDeath, "LENGTH(LogKey2)<32");
                if (playerKillDeathResult != null)
                {
                    _analyseResultList.Add(playerKillDeathResult);
                    Session["AdvancedStatistic_PlayerDeathStatistic_PlayerKill"] = playerKillDeathResult;
                    Session["AdvancedStatistic_CanUseCache"] = true;
                }
                if (npcKillDeathResult != null)
                {
                    _analyseResultList.Add(npcKillDeathResult);
                    Session["AdvancedStatistic_PlayerDeathStatistic_NpcKill"] = npcKillDeathResult;
                    Session["AdvancedStatistic_CanUseCache"] = true;
                }
                break;

            case ViewContent.Quest:
                string questFilter = null;

                if (TextBoxQuestId.Text.Trim().Length > 0)
                {
                    try
                    {
                        int questId = int.Parse(TextBoxQuestId.Text.Trim());
                        if (questId < 0)
                        {
                            throw new Exception();
                        }

                        questFilter = string.Format("LogKey2='{0}'", questId);
                    }
                    catch (Exception)
                    {
                        LabelOpMsg.Text = StringDef.ParameterInputError;
                        return;
                    }
                }
                for (int i = 0; i < QuestCountTypes.Length; i++)
                {
                    ListItem item = CheckBoxListShowQuestCount.Items[i];
                    if (item.Selected)
                    {
                        AnalyseResult questResult = AnalyseData(server, QuestCountEventIds[i], questFilter);
                        if (questResult != null)
                        {
                            _analyseResultList.Add(questResult);
                            Session[string.Format("AdvancedStatistic_QuestStatistic_{0}", i)] = questResult;
                            Session["AdvancedStatistic_CanUseCache"] = true;
                        }
                    }
                }
                break;

            case ViewContent.UseSkill:
                string skillFilter = null;
                try
                {
                    FS2SkillData selectedSkill = SkillDropDownList1.SelectedSkill;
                    if (selectedSkill != null)
                    {
                        skillFilter = string.Format("LogKey2='{0}'", selectedSkill.TemplateId);
                    }
                }
                catch (Exception)
                {
                    LabelOpMsg.Text = StringDef.ParameterInputError;
                    return;
                }
                AnalyseResult useSkillResult = AnalyseData(server, EventIdUseSkill, skillFilter);
                if (useSkillResult != null)
                {
                    _analyseResultList.Add(useSkillResult);
                }
                break;
            }
            if (_analyseResultList != null && _analyseResultList.Count != 0)
            {
                ZedGraphWebExpStatistic.Visible = true;
            }
            else
            {
                LabelOpMsg.Text = StringDef.OperationFail;
            }
        }
        catch (Exception ex)
        {
            LabelOpMsg.Text = ex.Message;
        }
    }
Ejemplo n.º 10
0
        public override void Translate()
        {
            if (this.sourceDbInterpreter.DatabaseType == this.targetDbInterpreter.DatabaseType)
            {
                return;
            }

            if (this.hasError)
            {
                return;
            }

            this.LoadMappings();

            SqlAnalyserBase sourceAnalyser = this.GetSqlAnalyser(this.sourceDbInterpreter.DatabaseType);
            SqlAnalyserBase targetAnalyser = this.GetSqlAnalyser(this.targetDbInterpreter.DatabaseType);

            Action <T, CommonScript> processTokens = (dbObj, script) =>
            {
                if (typeof(T) == typeof(Function))
                {
                    AnalyseResult result = sourceAnalyser.AnalyseFunction(dbObj.Definition.ToUpper());

                    if (!result.HasError)
                    {
                        RoutineScript routine = result.Script as RoutineScript;

                        if (this.targetDbInterpreter.DatabaseType == DatabaseType.MySql && routine.ReturnTable != null)
                        {
                            routine.Type = RoutineType.PROCEDURE;
                        }
                    }
                }

                ScriptTokenProcessor tokenProcessor = new ScriptTokenProcessor(script, dbObj, this.sourceDbInterpreter, this.targetDbInterpreter);
                tokenProcessor.UserDefinedTypes = this.UserDefinedTypes;
                tokenProcessor.TargetDbOwner    = this.TargetDbOwner;

                tokenProcessor.Process();

                dbObj.Definition = targetAnalyser.GenerateScripts(script);
            };

            foreach (T dbObj in this.scripts)
            {
                if (this.hasError)
                {
                    break;
                }

                try
                {
                    Type type = typeof(T);

                    this.FeedbackInfo($"Begin to translate {type.Name} \"{dbObj.Name}\".");

                    bool tokenProcessed = false;

                    this.Validate(dbObj);

                    string originalDefinition = dbObj.Definition;

                    AnalyseResult result = sourceAnalyser.Analyse <T>(originalDefinition.ToUpper());

                    CommonScript script = result.Script;

                    bool replaced = false;

                    if (result.HasError)
                    {
                        #region Special handle for view
                        if (typeof(T) == typeof(View))
                        {
                            //Currently, ANTLR can't parse some complex tsql accurately, so it uses general strategy.
                            if (this.sourceDbInterpreter.DatabaseType == DatabaseType.SqlServer)
                            {
                                ViewTranslator viewTranslator = new ViewTranslator(this.sourceDbInterpreter, this.targetDbInterpreter, new List <View>()
                                {
                                    dbObj as View
                                }, this.TargetDbOwner)
                                {
                                    SkipError = this.SkipError
                                };
                                viewTranslator.Translate();

                                replaced = true;
                            }

                            //Currently, ANTLR can't parse some view correctly, use procedure to parse it temporarily.
                            if (this.sourceDbInterpreter.DatabaseType == DatabaseType.Oracle)
                            {
                                string oldDefinition = dbObj.Definition;

                                int asIndex = oldDefinition.IndexOf(" AS ", StringComparison.OrdinalIgnoreCase);

                                StringBuilder sbNewDefinition = new StringBuilder();

                                sbNewDefinition.AppendLine($"CREATE OR REPLACE PROCEDURE {dbObj.Name} AS");
                                sbNewDefinition.AppendLine("BEGIN");
                                sbNewDefinition.AppendLine($"{oldDefinition.Substring(asIndex + 5).TrimEnd(';') + ";"}");
                                sbNewDefinition.AppendLine($"END {dbObj.Name};");

                                dbObj.Definition = sbNewDefinition.ToString();

                                AnalyseResult procResult = sourceAnalyser.Analyse <Procedure>(dbObj.Definition.ToUpper());

                                if (!procResult.HasError)
                                {
                                    processTokens(dbObj, procResult.Script);

                                    tokenProcessed = true;

                                    dbObj.Definition = Regex.Replace(dbObj.Definition, " PROCEDURE ", " VIEW ", RegexOptions.IgnoreCase);
                                    dbObj.Definition = Regex.Replace(dbObj.Definition, @"(BEGIN[\r][\n])|(END[\r][\n])", "", RegexOptions.IgnoreCase);

                                    replaced = true;
                                }
                            }
                        }
                        #endregion
                    }

                    if (!result.HasError && !tokenProcessed)
                    {
                        processTokens(dbObj, script);
                    }

                    bool formatHasError = false;

                    string definition = this.ReplaceVariables(dbObj.Definition);

                    dbObj.Definition = definition; // this.FormatSql(definition, out formatHasError);

                    if (formatHasError)
                    {
                        dbObj.Definition = definition;
                    }

                    if (this.OnTranslated != null)
                    {
                        this.OnTranslated(this.targetDbInterpreter.DatabaseType, dbObj, new TranslateResult()
                        {
                            Error = result.Error, Data = dbObj.Definition
                        });
                    }

                    this.FeedbackInfo($"End translate {type.Name} \"{dbObj.Name}\", translate result: { (result.HasError ? "Error" : "OK") }.");

                    if (!replaced && result.HasError)
                    {
                        this.FeedbackError(this.ParseSqlSyntaxError(result.Error, originalDefinition).ToString(), this.SkipError);

                        if (!this.SkipError)
                        {
                            this.hasError = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    var sce = new ScriptConvertException <T>(ex)
                    {
                        SourceServer   = this.sourceDbInterpreter.ConnectionInfo.Server,
                        SourceDatabase = this.sourceDbInterpreter.ConnectionInfo.Database,
                        SourceObject   = dbObj.Name,
                        TargetServer   = this.targetDbInterpreter.ConnectionInfo.Server,
                        TargetDatabase = this.targetDbInterpreter.ConnectionInfo.Database,
                        TargetObject   = dbObj.Name
                    };

                    if (!this.SkipError)
                    {
                        this.hasError = true;
                        throw sce;
                    }
                    else
                    {
                        this.FeedbackError(ExceptionHelper.GetExceptionDetails(ex), this.SkipError);
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public override AnalyseResult AnalyseProcedure(string content)
        {
            SqlSyntaxError error = null;

            DdlStatementContext ddlStatement = this.GetDdlStatementContext(content, out error);

            AnalyseResult result = new AnalyseResult()
            {
                Error = error
            };

            if (!result.HasError && ddlStatement != null)
            {
                RoutineScript script = new RoutineScript()
                {
                    Type = RoutineType.PROCEDURE
                };

                CreateProcedureContext proc = ddlStatement.createProcedure();

                if (proc != null)
                {
                    #region Name
                    this.SetScriptName(script, proc.fullId());
                    #endregion

                    #region Parameters
                    ProcedureParameterContext[] parameters = proc.procedureParameter();

                    if (parameters != null)
                    {
                        foreach (ProcedureParameterContext parameter in parameters)
                        {
                            Parameter parameterInfo = new Parameter();

                            UidContext uid = parameter.uid();

                            parameterInfo.Name = new TokenInfo(uid)
                            {
                                Type = TokenType.ParameterName
                            };

                            parameterInfo.DataType = new TokenInfo(parameter.dataType().GetText())
                            {
                                Type = TokenType.DataType
                            };

                            this.SetParameterType(parameterInfo, parameter.children);

                            script.Parameters.Add(parameterInfo);
                        }
                    }
                    #endregion

                    #region Body

                    this.SetScriptBody(script, proc.routineBody());

                    #endregion
                }

                this.ExtractFunctions(script, ddlStatement);

                result.Script = script;
            }

            return(result);
        }
Ejemplo n.º 12
0
        public void Test()
        {
            List <Card> cards = new List <Card>();

            cards.Add(new Card {
                Color = CardColor.Club, Weight = CardWeight._3
            });
            cards.Add(new Card {
                Color = CardColor.Club, Weight = CardWeight._3
            });
            cards.Add(new Card {
                Color = CardColor.Club, Weight = CardWeight._3
            });
            cards.Add(new Card {
                Color = CardColor.Club, Weight = CardWeight._8
            });
            cards.Add(new Card {
                Color = CardColor.Club, Weight = CardWeight._7
            });

            cards.Add(new Card {
                Color = CardColor.Club, Weight = CardWeight._5
            });
            cards.Add(new Card {
                Color = CardColor.Diamond, Weight = CardWeight._5
            });
            cards.Add(new Card {
                Color = CardColor.Heart, Weight = CardWeight._5
            });
            cards.Add(new Card {
                Color = CardColor.Spade, Weight = CardWeight._9
            });
            cards.Add(new Card {
                Color = CardColor.Spade, Weight = CardWeight._10
            });

            cards.Add(new Card {
                Color = CardColor.Club, Weight = CardWeight._4
            });
            cards.Add(new Card {
                Color = CardColor.Diamond, Weight = CardWeight._4
            });
            cards.Add(new Card {
                Color = CardColor.Heart, Weight = CardWeight._4
            });
            cards.Add(new Card {
                Color = CardColor.Spade, Weight = CardWeight._9
            });
            cards.Add(new Card {
                Color = CardColor.Spade, Weight = CardWeight._10
            });

            CardsHelper.Sort(cards);

            var list = AnalyseResult.Analyse(cards);

            foreach (AnalyseResult analyseResult in list)
            {
                Debug.Log(analyseResult);
            }

            Debug.Log("================================");
            list.Sort();
            foreach (AnalyseResult analyseResult in list)
            {
                Debug.Log(analyseResult);
            }

            Assert.AreEqual(list[0].Weight, CardWeight._3);
            Assert.AreEqual(list[1].Weight, CardWeight._4);
            Assert.AreEqual(list[2].Weight, CardWeight._5);

            Assert.AreEqual(list[list.Count - 1].Weight, CardWeight._8);
        }
Ejemplo n.º 13
0
        public void Invoke(AnalysisContext context)
        {
            // 1.搜寻炸弹
            //      a.先确定王的个数
            //      b.大于等于4张的炸弹
            //      c.王与炸弹的所有组合
            //      d.按照炸弹权重排序
            List <AnalyseResult> jokerAnalyseResults = context.AnalyseResults.Where(f => CardsHelper.IsJoker(f.Weight)).ToList();
            int jokerCount = jokerAnalyseResults.Sum(f => f.Count);

            // 不包括王,如果王有4张,就再最后的时候,把4张王单独添加。
            List <AnalyseResult> boomResults = context.AnalyseResults.Where(f => f.Count >= 4 && !CardsHelper.IsJoker(f.Weight)).ToList();

            for (int i = 0; i < boomResults.Count; i++)
            {
                var result = boomResults[i];

                // 验证此牌是否能接目标牌型
                if (context.CheckPop(result.Cards, CardType.Boom))
                {
                    context.Add(new PrompCards {
                        CardType = CardType.Boom, Cards = result.Cards.ToList()
                    });
                }

                // 组合王
                var boomCards = result.Cards.ToList();

                for (int j = 0; j < jokerAnalyseResults.Count; j++)
                {
                    AnalyseResult analyseResult = jokerAnalyseResults[j];
                    for (int k = 0; k < analyseResult.Count; k++)
                    {
                        var item = analyseResult.Cards[k];
                        boomCards.Add(item);

                        // 每添加一个王,就向提示列表中,添加一种。
                        if (context.CheckPop(boomCards, CardType.Boom))
                        {
                            context.Add(new PrompCards {
                                CardType = CardType.Boom, Cards = boomCards.ToList()
                            });
                        }
                    }
                }
            }

            // 4张王,算最大的炸弹. 单独添加进提示列表
            if (jokerCount == 4)
            {
                var jokerBoomCards = new List <Card>();
                for (int i = 0; i < jokerAnalyseResults.Count; i++)
                {
                    jokerBoomCards.AddRange(jokerAnalyseResults[i].Cards);
                }

                context.Add(new PrompCards {
                    CardType = CardType.JokerBoom, Cards = jokerBoomCards
                });
            }
        }
Ejemplo n.º 14
0
	AnalyseResult AnalyseData(GameServer server, int logEventId,string additionalFilter)
	{
        double[] statisticValues = null;
		double[] statisticTimes = null;
		double[] statisticCounts = null;

        bool bQuitFlag = false;

        StringBuilder whereStatement = new StringBuilder();
        whereStatement.AppendFormat(" WHERE {0}={1} ", FS2TableString.LogFieldLogEvent, logEventId);
        
        if (_roleGuid != null)
		{
            whereStatement.AppendFormat(" AND {0}='{1}'", FS2TableString.LogFieldLogKey1, _roleGuid);
		}

        whereStatement.AppendFormat(" AND {0} >= '{1}' AND {0} <= '{2}'",
            FS2TableString.LogFieldLogTime, 
            _startDate,
            _endDate);

        if (additionalFilter != null && additionalFilter.Length > 0)
            whereStatement.AppendFormat(" AND {0} ", additionalFilter);

        string baseCmdString = string.Empty;
        switch (_viewType)
        {
            case ViewType.ByMonth:
                baseCmdString = string.Format("SELECT DATE_FORMAT(LogTime,'%Y-%m'),SUM(LogKey6),COUNT(*) FROM {0} {1} GROUP BY LogEvent",
                            "{0}",
                            whereStatement.ToString());

                int monthCount = 12 * (_endDate.Year - _startDate.Year) + (_endDate.Month - _startDate.Month) + 1;
                statisticValues = new double[monthCount];
                statisticTimes = new double[monthCount];
                statisticCounts = new double[monthCount];

                for (int index = 0; index != statisticValues.Length; ++index)
                {
                    DateTime tempDate = _startDate.AddMonths(index);
                    statisticTimes[index] = new XDate(tempDate.Year, tempDate.Month, 1);
                }

                break;
            case ViewType.ByDay:
                baseCmdString = string.Format("SELECT DATE(LogTime), SUM(LogKey6), COUNT(*) FROM {0} {1} GROUP BY DATE(LogTime)",
                            "{0}",
                            whereStatement.ToString());

                TimeSpan span = _endDate.Subtract(_startDate);                
                int dayCount = span.Days + 1;
                statisticValues = new double[dayCount];
                statisticTimes = new double[dayCount];
                statisticCounts = new double[dayCount];
                for (int index = 0; index != statisticTimes.Length; ++index)
                {
                    DateTime tempDate = _startDate.Date.AddDays(index);
                    statisticTimes[index] = new XDate(tempDate);
                }
                break;
            case ViewType.ByHour:
                bQuitFlag = true;                
                break;
            default:
                bQuitFlag = true;                
                break;
        }

        if (bQuitFlag) return null;

        string addTableCmdString;
        WebUtil.AddTableNameToCmd(CurrentUser.Id, server, baseCmdString, _startDate, _endDate, out addTableCmdString);
        if (addTableCmdString.Length == 0)
        {
            return null;
        }        

        SqlResult sqlResult = WebUtil.QueryGameServerDb(CurrentUser.Id, server, new SqlCommand(addTableCmdString));
        if (sqlResult != null && sqlResult.Success)
        {
            sqlResult.SetFieldType(new SqlDataType[] { 
                        SqlDataType.DateTime,
                        SqlDataType.Int64,
                        SqlDataType.Int32
                    });

            object[] record = sqlResult.ReadRecord();

            switch (_viewType)
            {
                case ViewType.ByMonth:
                    while (record != null)
                    {
                        DateTime date = (DateTime)record[0];
                        long sum = (long)record[1];
                        int count = (int)record[2];

                        int monthIndex = 12 * (date.Year - _startDate.Year) + (date.Month - _startDate.Month);
                        statisticTimes[monthIndex] = new XDate(date);
                        statisticValues[monthIndex] = sum;
                        statisticCounts[monthIndex] = count;

                        record = sqlResult.ReadRecord();
                    }
                    break;
                case ViewType.ByDay:                    
                    while (record != null)
                    {
                        DateTime date = (DateTime)record[0];
                        long sum = (long)record[1];
                        int count = (int)record[2];

                        TimeSpan indexSpan = date.Subtract(_startDate.Date);
                        statisticTimes[indexSpan.Days] = new XDate(date);
                        statisticValues[indexSpan.Days] = sum;
                        statisticCounts[indexSpan.Days] = count;

                        record = sqlResult.ReadRecord();
                    }
                    break;
            }
        }
        else
        {
            return null;
        }

		AnalyseResult result = new AnalyseResult();
		result.Values = statisticValues;
		result.Times = statisticTimes;
		result.Counts = statisticCounts;

		return result;
	}
Ejemplo n.º 15
0
    void ItemStatistic(System.Drawing.Graphics g, ZedGraph.MasterPane masterPane)
    {
        GraphPane graphPane = masterPane[0];

        graphPane.Fill = new Fill(WebConfig.GraphPaneBgColor);

        graphPane.Legend.Fill.IsVisible          = false;
        graphPane.Legend.Border.IsVisible        = false;
        graphPane.Legend.FontSpec.Fill.IsVisible = false;

        graphPane.XAxis.Title.Text          = StringDef.Date;
        graphPane.XAxis.MajorGrid.Color     = WebConfig.GraphXAxisGridColor;
        graphPane.XAxis.Type                = AxisType.DateAsOrdinal;
        graphPane.XAxis.MinorTic.Size       = 0;
        graphPane.XAxis.Scale.MajorStep     = 1;
        graphPane.XAxis.Scale.FontSpec.Size = 12;
        switch (_viewType)
        {
        case ViewType.ByMonth:
            graphPane.XAxis.Scale.MajorUnit = DateUnit.Month;
            break;

        case ViewType.ByDay:
            graphPane.XAxis.Scale.MajorUnit = DateUnit.Day;
            break;
        }

        graphPane.YAxis.MajorGrid.IsVisible = true;
        graphPane.YAxis.MajorGrid.DashOff   = 0;
        graphPane.YAxis.MajorGrid.Color     = Color.Gray;
        graphPane.YAxis.MinorGrid.IsVisible = true;
        graphPane.YAxis.MinorGrid.Color     = Color.LightGray;
        graphPane.YAxis.MinorGrid.DashOff   = 0;

        graphPane.Title.Text       = String.Format("{0} - {1}", "物品数量统计", _statisticDesc);
        graphPane.YAxis.Title.Text = "数量";

        string itemTemplateIdFilter = null;

        if (TextBoxItemTemplateId.Text.Length > 0)
        {
            itemTemplateIdFilter = string.Format("LogKey2='{0}'", TextBoxItemTemplateId.Text);
        }

        int index = 0;

        for (int i = 0; i < ItemCountTypes.Length; i++)
        {
            ListItem item = CheckBoxListShowItemCount.Items[i];
            if (item.Selected)
            {
                AnalyseResult result = null;
                if (_useCache)
                {
                    result = Session[string.Format("AdvancedStatistic_ItemStatistic_{0}", i)] as AnalyseResult;
                }
                if (result == null)
                {
                    result = _analyseResultList[index];
                    ++index;
                    Session[string.Format("AdvancedStatistic_ItemStatistic_{0}", i)] = result;
                    Session["AdvancedStatistic_CanUseCache"] = true;
                }
                if (_chartType == ChartType.Bar)
                {
                    BarItem barItem = graphPane.AddBar(ItemCountTypes[i], result.Times, result.Values, ItemCountColors[i]);
                    barItem.Bar.Fill = new Fill(ItemCountColors[i]);
                }
                else if (_chartType == ChartType.Line)
                {
                    LineItem lineItem = graphPane.AddCurve(ItemCountTypes[i], result.Times, result.Values, ItemCountColors[i]);
                }
            }
        }

        if (_chartType == ChartType.Bar)
        {
            graphPane.BarSettings.Type = BarType.SortedOverlay;
        }
        else if (_chartType == ChartType.Line)
        {
        }
    }
Ejemplo n.º 16
0
    void PlayerDeathStatistic(System.Drawing.Graphics g, ZedGraph.MasterPane masterPane)
    {
        bool      showSymbol = true;
        GraphPane graphPane  = masterPane[0];

        graphPane.Fill = new Fill(WebConfig.GraphPaneBgColor);

        graphPane.Legend.Fill.IsVisible          = false;
        graphPane.Legend.Border.IsVisible        = false;
        graphPane.Legend.FontSpec.Fill.IsVisible = false;

        graphPane.XAxis.Title.Text          = StringDef.Date;
        graphPane.XAxis.MajorGrid.Color     = WebConfig.GraphXAxisGridColor;
        graphPane.XAxis.Type                = AxisType.DateAsOrdinal;
        graphPane.XAxis.MinorTic.Size       = 0;
        graphPane.XAxis.Scale.MajorStep     = 1;
        graphPane.XAxis.Scale.FontSpec.Size = 12;
        switch (_viewType)
        {
        case ViewType.ByMonth:
            graphPane.XAxis.Scale.MajorUnit = DateUnit.Month;
            break;

        case ViewType.ByDay:
            graphPane.XAxis.Scale.MajorUnit = DateUnit.Day;
            break;
        }

        graphPane.YAxis.MajorGrid.IsVisible = true;
        graphPane.YAxis.MajorGrid.DashOff   = 0;
        graphPane.YAxis.MajorGrid.Color     = Color.Gray;
        graphPane.YAxis.MinorGrid.IsVisible = true;
        graphPane.YAxis.MinorGrid.Color     = Color.LightGray;
        graphPane.YAxis.MinorGrid.DashOff   = 0;

        graphPane.Title.Text       = String.Format("{0} - {1}", StringDef.PlayerDeath, _statisticDesc);
        graphPane.YAxis.Title.Text = StringDef.DeathCount;

        AnalyseResult playerKillDeathResult = null;
        AnalyseResult npcKillDeathResult    = null;

        if (_analyseResultList != null && _analyseResultList.Count != 0)
        {
            int index = 0;
            if (CheckBoxShowPlayerKill.Checked)
            {
                if (_useCache)
                {
                    playerKillDeathResult = Session["AdvancedStatistic_PlayerDeathStatistic_PlayerKill"] as AnalyseResult;
                }
                if (playerKillDeathResult == null)
                {
                    playerKillDeathResult = _analyseResultList[index];
                    ++index;
                    Session["AdvancedStatistic_PlayerDeathStatistic_PlayerKill"] = playerKillDeathResult;
                    Session["AdvancedStatistic_CanUseCache"] = true;
                }
            }
            if (CheckBoxShowNpcKill.Checked)
            {
                if (_useCache)
                {
                    npcKillDeathResult = Session["AdvancedStatistic_PlayerDeathStatistic_NpcKill"] as AnalyseResult;
                }
                if (npcKillDeathResult == null)
                {
                    npcKillDeathResult = _analyseResultList[index];
                    Session["AdvancedStatistic_PlayerDeathStatistic_NpcKill"] = npcKillDeathResult;
                    Session["AdvancedStatistic_CanUseCache"] = true;
                }
            }
        }

        if (_chartType == ChartType.Bar)
        {
            graphPane.BarSettings.Type = BarType.Stack;

            if (playerKillDeathResult != null)
            {
                BarItem barPlayerKillDeathCount = graphPane.AddBar(StringDef.PlayerDeathByPlayer, playerKillDeathResult.Times, playerKillDeathResult.Counts, Color.Black);
                barPlayerKillDeathCount.Bar.Fill = new Fill(Color.Red);
            }

            if (npcKillDeathResult != null)
            {
                BarItem barNpcKillDeathCount = graphPane.AddBar(StringDef.PlayerDeathByNpc, npcKillDeathResult.Times, npcKillDeathResult.Counts, Color.Black);
                barNpcKillDeathCount.Bar.Fill = new Fill(Color.Blue);
            }
        }
        else if (_chartType == ChartType.Line)
        {
            if (playerKillDeathResult != null)
            {
                graphPane.AddCurve(StringDef.PlayerDeathByPlayer, playerKillDeathResult.Times, playerKillDeathResult.Counts, Color.Red, (showSymbol ? WebConfig.GraphSymbols[0] : SymbolType.None));
            }

            if (npcKillDeathResult != null)
            {
                graphPane.AddCurve(StringDef.PlayerDeathByNpc, npcKillDeathResult.Times, npcKillDeathResult.Counts, Color.Blue, (showSymbol ? WebConfig.GraphSymbols[0] : SymbolType.None));
            }
        }
    }
Ejemplo n.º 17
0
        public override AnalyseResult AnalyseTrigger(string content)
        {
            SqlSyntaxError error = null;

            DdlStatementContext ddlStatement = this.GetDdlStatementContext(content, out error);

            AnalyseResult result = new AnalyseResult()
            {
                Error = error
            };

            if (!result.HasError && ddlStatement != null)
            {
                TriggerScript script = new TriggerScript();

                CreateTriggerContext trigger = ddlStatement.createTrigger();

                if (trigger != null)
                {
                    #region Name

                    FullIdContext[] ids = trigger.fullId();

                    this.SetScriptName(script, ids.First());

                    if (ids.Length > 1)
                    {
                        script.OtherTriggerName = new TokenInfo(ids[1]);
                    }

                    #endregion

                    script.TableName = new TokenInfo(trigger.tableName())
                    {
                        Type = TokenType.TableName
                    };

                    foreach (var child in trigger.children)
                    {
                        if (child is TerminalNodeImpl terminalNode)
                        {
                            switch (terminalNode.Symbol.Type)
                            {
                            case MySqlParser.BEFORE:
                                script.Time = TriggerTime.BEFORE;
                                break;

                            case MySqlParser.AFTER:
                                script.Time = TriggerTime.AFTER;
                                break;

                            case MySqlParser.INSERT:
                                script.Events.Add(TriggerEvent.INSERT);
                                break;

                            case MySqlParser.UPDATE:
                                script.Events.Add(TriggerEvent.UPDATE);
                                break;

                            case MySqlParser.DELETE:
                                script.Events.Add(TriggerEvent.DELETE);
                                break;

                            case MySqlParser.PRECEDES:
                                script.Behavior = nameof(MySqlParser.PRECEDES);
                                break;

                            case MySqlParser.FOLLOWS:
                                script.Behavior = nameof(MySqlParser.FOLLOWS);
                                break;
                            }
                        }
                    }

                    #region Body

                    this.SetScriptBody(script, trigger.routineBody());

                    #endregion
                }

                this.ExtractFunctions(script, ddlStatement);

                result.Script = script;
            }

            return(result);
        }