Exemplo n.º 1
0
        public static void CopyUnmanagedAssemblies(string assemblyFileName, Stream?assemblyContent)
        {
            var workingDirectory = AgLinkRequirementsHelper.WorkingDirectory;
            var assemblyFile     = new FileInfo(Path.Combine(workingDirectory.FullName, assemblyFileName));

            if (assemblyContent is null)
            {
#if DEBUG
                Debug.WriteLine($"The unmanaged AGLink assembly '{assemblyFile.Name}' does not exist as embedded resource. Therefore using any instance of '{nameof(AgLinkPlc)}' will probably fail.");
#else
                throw new ApplicationException($"The unmanaged AGLink assembly '{assemblyFile.Name}' does not exist as embedded resource. Please ensure its existence and then try again.");
#endif
            }
            else
            {
                using (assemblyContent)
                {
                    using var fileStream = assemblyFile.Open(FileMode.Create);
                    assemblyContent.CopyTo(fileStream);
                    fileStream.Flush();
                }

                // Setup auto deletion of this file.
                AgLinkRequirementsHelper.AutomaticallyDeleteUnmanagedAssembly();

                // Save a reference to the file, so that it can be deleted when the process ends.
                _unmanagedAgLinkAssemblyFile = assemblyFile;
            }
        }
Exemplo n.º 2
0
        static DemoAgLinkPlc()
        {
            // Extract the unmanaged assembly.
            var(unmanagedAgLinkAssemblyFile, resourceStream) = DemoAgLinkPlcEmbeddedRequirementsHelper.LoadUnmanagedAssembly();
            AgLinkRequirementsHelper.CopyUnmanagedAssemblies(unmanagedAgLinkAssemblyFile, resourceStream);

            // Try to get the license key and activate AGLink.
            var licenseKey = DemoAgLinkPlcEmbeddedRequirementsHelper.LoadLicenseKey();

            AgLinkRequirementsHelper.ActivateAgLink(licenseKey);

            // Override error mapping from base class.
            var errorFileContent = DemoAgLinkPlcEmbeddedRequirementsHelper.LoadErrorMapping();

            AgLinkRequirementsHelper.OverrideErrorMapping(new AgLinkErrorMapping(errorFileContent));
        }