Активность для представления логики PIX скрипта в тексте

addewyd@

Active member
Иногда бывает удобно просматривать сложные алгоритмы в более удобочитаемом виде (и ещё по мелочи).
Может быть, кому-нибудь пригодится.
 
Последнее редактирование:

artarik

Active member
upd. надо поиграться, вещь полезная, но пока не придумал куда ее втулить :)
А можете поделиться мануалом по созданию пользовательской активности?
 

addewyd@

Active member
А можете поделиться мануалом по созданию пользовательской активности?
Вот оно (активность, то есть):

C#:
using System;
using BR.Core;
using BR.Core.Attributes;

namespace Activities.TL
{
    [ScreenName("PIX Script Walker")]
    [Representation("[ScriptFile] -> Logic File or String")]
    [Path("TL — utils")]
    [Description("walker converts PIX script to text")]
    [OptionList("To File","To String")]
 
    public class Walker : Activity
    {
        [ScreenName("ScriptFile")]
        [Description("ScriptFile")]
        [IsRequired]
        [IsFilePathChooser]
        [Options(0, 1)]
        public string ScriptFile { get; set; }

        [ScreenName("Logic")]
        [Description("Logic")]
        [IsFilePathChooser]
        [Options(0)]
        public string ScLogic { get; set; }

        [ScreenName("Logic")]
        [Description("Logic")]
        [Options(1)]
        [IsOut]
        public string ScStrLogic { get; set; }

        private void writeiline(System.IO.TextWriter sv, int level, String s)
        {
            for(int i = 0; i < level; i ++)
            {
                sv.Write("    ");
            }
            sv.WriteLine(s);
        }

        public override void Execute(int? optionID)
        {
            var x = System.IO.File.ReadAllText(ScriptFile);
            var t = BR.Logic.Serializer.GetObjectFromXML<BR.Logic.Script>(x);
            var k = t.Logic.Childs.Count.ToString();

            var w = new BR.Logic.ScriptWalker(t);
            var l = w.AllSteps;
            var s = w.Script;
            int level = 0;

            System.IO.TextWriter sv;
            if (optionID == 0)
            {
                sv = System.IO.File.CreateText(ScLogic);
            }
            else
            {
                sv = new System.IO.StringWriter();
            }
            try
            {
                sv.WriteLine(ScriptFile + ":\n");
                var sparams = s.Params;
                try
                {
                    foreach (var step in l)
                    {
                        level = step.StepLevel - 1;

                        bool es = true;
                        if (step is BR.Logic.ExecutableStep)
                        {
                            es = (step as BR.Logic.ExecutableStep).EnableStatus;
                        }

                        if (!es)
                        {
                            writeiline(sv, level, $"Step {step.Title} DISABLED");
                            continue;
                        }
                        writeiline(sv, level, step.Title?.ToString());
                        writeiline(sv, level, $"Repreresentation: {step.Representation}");

                        string text = null;
                        if (step is BR.Logic.ExecutableStep)
                        {
                            var exstep = step as BR.Logic.ExecutableStep;
                            //var a = exstep.
                            text = exstep.Text;
                        }
                        if (step is BR.Logic.CommentStep)
                        {
                            text = (step as BR.Logic.CommentStep).Text;
                        }

                        writeiline(sv, level, "Text: " + text);
                        writeiline(sv, level, "Properties:");
                        int c = step.PropertyValues.Count;
                        string propstring = "";
                        for(int i = 0; i < c; i ++)
                        {
                            if(step.PropertyValues[i].PropertyName == "Parameters")
                            {
                                var a = step.PropertyValues[i].Value as ExpressionArguments;
                                writeiline(sv, level + 1, $"Parameters {a.Count}:");
                                foreach (var arg in a)
                                {
                                    string args = $"{arg.ArgumentName} Type: {arg.Type} Value: {arg.Expression}";
                                    writeiline(sv, level + 2, args);
                                }
                            }
                            else
                            {
                                propstring = $@"Name: {step.PropertyValues[i].PropertyName} Value: {step.PropertyValues[i].Value} Expression: {step.PropertyValues[i].Expression}";
                                writeiline(sv, level + 1, propstring);
                            }
                        }
                        //sv.WriteLine("");
                    }
                    sv.WriteLine("");
                    writeiline(sv, 0, $"Script: {s.Name} Parameters {sparams.Count}:");
                    foreach (var param in sparams)
                    {
                        writeiline(sv, 1, $"{param.Name} Type: {param.Type}  Value: {param.Value}");
                    }
                }
                catch (Exception ex)
                {
                    sv.WriteLine("Exception:" + ex.Message + "\n" + ex.StackTrace);
                }
                sv.Close();
                ScStrLogic = sv.ToString();
            }
            finally
            {
                sv.Close();
            }
        }
    }
}
 

artarik

Active member
хм, забавно, сколько раз смотрел БЗ, а этого не видел :)
 

addewyd@

Active member
Этого кода нет? Само собой. А раздел о создании есть.
 

addewyd@

Active member
да я тоже недавно наткнулся. Случайно. Судя по дате первого сообщения неделю назад.
 
Верх