Beispiel #1
0
        static void Main()
        {
            Console.WriteLine("Set firewall...");
            Assembly assembly = Assembly.GetExecutingAssembly();

            Starter.SetTiaPortalFirewall(assembly);
            TiaPortal tiaPortal = null;

            try
            {
                Console.WriteLine("Get instance...");
                tiaPortal = Starter.GetInstance(TiaPortalMode.WithUserInterface);

                Console.WriteLine("Create project...");
                string  projectFullPath = Path.Combine(DataPath, "debug", "MyProject", "MyProject.ap15_1");
                Project project         = ProjectHelper.CreateProjectIfNotExists(tiaPortal, projectFullPath);

                Console.WriteLine("Insert devices...");
                List <Device> devices = InsertDevices(project);

                Console.WriteLine("Get network interfaces...");
                List <Node> nodes = GetNetworkInterfaces(devices);

                Console.WriteLine("Create Subnet...");
                NetworkHelper.ConnectNodesToNetwork(project, "System:Subnet.Ethernet", "MySubnet", nodes);

                Console.WriteLine("Get software...");
                List <Software> softwareList = GetSoftwareList(devices);

                Console.WriteLine("Insert blocks from SCL source...");
                List <PlcSoftware> plcSoftwareList = softwareList.OfType <PlcSoftware>().ToList();
                InsertBlocksFromSclSource(plcSoftwareList);

                Console.WriteLine("Compile...");
                CompileHelper.Compile(softwareList);

                Console.WriteLine("Save project...");
                project.Save();

                Console.WriteLine("Show block in editor...");
                var block = plcSoftwareList.FirstOrDefault()?.BlockGroup.Blocks
                            .OfType <OB>()
                            .FirstOrDefault(obj => obj.Number.Equals(1));
                block?.ShowInEditor();
            }
            finally
            {
                tiaPortal?.Dispose();
            }
        }
Beispiel #2
0
        private async void BtnRun_Click(object sender, RoutedEventArgs e)
        {
            if (Code.IsNullOrEmpty())
            {
                return;
            }

            string lang = "";

            switch (CodeLanguage)
            {
            case "python":
                lang = "py";
                break;

            case "cplusplus":
                lang = "cpp";
                break;

            case "c":
                lang = "c";
                break;

            case "java":
                lang = "java";
                break;

            default:
                break;
            }

            if (lang == "")
            {
                await DispatcherHelper.ExecuteOnUIThreadAsync(() => {
                    RunResult = "暂不支持此语言";
                });
            }
            else
            {
                await DispatcherHelper.ExecuteOnUIThreadAsync(() => {
                    RunResult = "正在编译运行……";
                });

                string result = await CompileHelper.Compile(lang, Code, new Random().Next().ToString());

                await DispatcherHelper.ExecuteOnUIThreadAsync(() => {
                    RunResult = result;
                });
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns>True if successfully compiled, false otherwise.</returns>
        public static bool CompileStzFile(string fileName)
        {
            Project.Instance.Clear();
            Project.Instance.ProjectFileName   = fileName;
            Project.Instance.CompileFolderName = "";
            Project.Instance.Open(fileName);
            Settings.Default.CodeFile = System.IO.Path.GetTempFileName();

            if (CompileHelper.Compile(false))
            {
                return(true);
            }
            return(false);
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            var entityStr = @"
                            using System;
                            using ConsoleApp;

                            public class Student : IEntity
                            {
                                public int Id { get; set; }

                                public string Name { get; set; }

                                public short Age { get; set; }
                            }
                            ";
            var assembly  = CompileHelper.Compile(entityStr, CompileHelper.GetCompileAssemblies(typeof(IEntity)));

            Program.DyAssembly = assembly;
            modelBuilder.DynamicBindingEntityTypes(assembly, typeof(IEntity));
        }
Beispiel #5
0
        public void AutoPropertiesFromFSharpAreHandled()
        {
            const string source = @"
namespace FileHelpers

open System
open FileHelpers

[<CLIMutable>]
[<FixedLengthRecord>]
type SampleFSharpType = 
    { [<FieldFixedLength(8)>]
      [<FieldConverter(ConverterKind.Date, ""ddMMyyyy"")>]
      Field1: DateTime

      [<FieldFixedLength(3)>]
      [<FieldAlign(AlignMode.Left, ' ')>]
      [<FieldTrim(TrimMode.Both)>]
      Field2: string

      [<FieldFixedLength(3)>]
      [<FieldAlign(AlignMode.Right, '0')>]
      [<FieldTrim(TrimMode.Both)>]
      [<FieldOptional>]
      Field3: int }
";

            var assembly = CompileHelper.Compile(source);
            var type     = assembly.GetType("FileHelpers.SampleFSharpType");

            var fileHelpersAssembly = typeof(EngineBase).Assembly;
            var dateConverterType   = fileHelpersAssembly.GetType("FileHelpers.Converters.DateTimeConverter");

            var engine = new FileHelperEngine(type);

            Check.That(engine.Options.FieldCount).IsEqualTo(3);

            Check.That(engine.Options.Fields[0].Converter.GetType()).IsEqualTo(dateConverterType);
            Check.That(engine.Options.Fields[2].IsOptional).IsEqualTo(true);
        }
Beispiel #6
0
        //static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        //{
        //    Controller.ReportError((Exception)e.ExceptionObject);
        //    Environment.Exit(1);
        //}

        //static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        //{
        //    Controller.ReportError(e.Exception);
        //}

        internal static bool CompileFromCommandLine(string fileName, bool debugVersion)
        {
            Project.Instance.Open(fileName);
            Settings.Default.CodeFile = System.IO.Path.GetTempFileName();
            return(CompileHelper.Compile(debugVersion));
        }
Beispiel #7
0
        public async Task <int> Execute(IReadOnlyList <string> args)
        {
            int argumentsResult =
                this.SetArguments(args);

            if (argumentsResult != 0)
            {
                return(argumentsResult);
            }

            try
            {
                if (this._DomainInfos.Count == 0)
                {
                    this._DomainInfos.AddRange(this.FetchDomains());
                }

                foreach (DomainInfo dI in this._DomainInfos)
                {
                    CompileHelper compileHelper =
                        new CompileHelper();
                    await compileHelper.Compile(
                        this._XeoraProjectPath,
                        dI.DomainPath,
                        dI.Password,
                        !this._Publish?this._OutputLocation : string.Empty,
                        this._Recursive,
                        this._ExternalContent
                        );

                    if (this._Publish || !this._ExternalContent)
                    {
                        continue;
                    }

                    if (await this.CompileDomainContentForExternal(dI.DomainPath))
                    {
                        return(1);
                    }
                }

                if (!this._Publish)
                {
                    return(0);
                }

                List <string> publishArgs =
                    new List <string>();
                publishArgs.AddRange(new[] { "-o", this._OutputLocation, "-c" });

                if (this._ExternalContent)
                {
                    publishArgs.Add("-x");
                }

                if (this._AutoApprove)
                {
                    publishArgs.Add("-y");
                }

                publishArgs.Add(this._XeoraProjectPath);

                Publish publish =
                    new Publish();
                await publish.Execute(publishArgs);

                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("Compile operation has been failed!");
                Console.WriteLine($"   Reason: {e.Message}");
                return(1);
            }
        }