Пример #1
0
        private void CheckLicense()
        {
            ComponentLicense lic = LicenseManager.Validate(typeof(LicensableControl), this) as ComponentLicense;

            if (lic != null)
            {
                _isDemo = lic.IsDemo;
            }
        }
        private void CheckLicense()
        {
            ComponentLicense lic = LicenseManager.Validate(typeof(PrescriptionTmpControl), this) as ComponentLicense;

            if (lic != null)
            {
                _isDemo = lic.IsDemo;
                if (_isDemo)
                {
                    MessageBox.Show("正确设置[PrescriptionTmpControl]控件的许可证,才能使用!");
                }
            }
        }
Пример #3
0
        public static Bom Deserialize(string csv)
        {
            using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(csv)))
                using (var reader = new StreamReader(stream))
                    using (var csvReader = new CsvReader(reader, CultureInfo.InvariantCulture))
                    {
                        csvReader.Configuration.MissingFieldFound     = null;
                        csvReader.Configuration.PrepareHeaderForMatch = (string header, int index) => header.ToLower();

                        var bom = new Bom();
                        bom.Components = new List <Component>();

                        csvReader.Read();
                        csvReader.ReadHeader();
                        while (csvReader.Read())
                        {
                            var component = new Component
                            {
                                Type     = csvReader.GetField <Component.ComponentType?>("Type") ?? Component.ComponentType.Library,
                                MimeType = csvReader.GetField("MimeType").NullIfWhiteSpace(),
                                // BomRef not supported
                                Supplier = new OrganizationalEntity
                                {
                                    // additional supplier information not supported
                                    Name = csvReader.GetField("Supplier").NullIfWhiteSpace()
                                },
                                Author      = csvReader.GetField("Author").NullIfWhiteSpace(),
                                Publisher   = csvReader.GetField("Publisher").NullIfWhiteSpace(),
                                Group       = csvReader.GetField("Group").NullIfWhiteSpace(),
                                Name        = csvReader.GetField("Name").NullIfWhiteSpace(),
                                Version     = csvReader.GetField("Version").NullIfWhiteSpace(),
                                Description = csvReader.GetField("Description").NullIfWhiteSpace(),
                                Scope       = csvReader.GetField("Scope").NullIfWhiteSpace(),
                                Copyright   = csvReader.GetField("Copyright").NullIfWhiteSpace(),
                                Cpe         = csvReader.GetField("Cpe").NullIfWhiteSpace(),
                                Purl        = csvReader.GetField("Purl").NullIfWhiteSpace(),
                                Swid        = new Swid
                                {
                                    TagId      = csvReader.GetField("SwidTagId").NullIfWhiteSpace(),
                                    Name       = csvReader.GetField("SwidName").NullIfWhiteSpace(),
                                    Version    = csvReader.GetField("SwidVersion").NullIfWhiteSpace(),
                                    TagVersion = csvReader.GetField <int?>("SwidTagVersion"),
                                    Patch      = csvReader.GetField <bool?>("SwidPatch"),
                                    Text       = new AttachedText
                                    {
                                        ContentType = csvReader.GetField("SwidTextContentType").NullIfWhiteSpace(),
                                        Encoding    = csvReader.GetField("SwidTextEncoding").NullIfWhiteSpace(),
                                        Content     = csvReader.GetField("SwidTextContent".NullIfWhiteSpace())
                                    },
                                    Url = csvReader.GetField("SwidUrl").NullIfWhiteSpace()
                                },
                                Modified = csvReader.GetField <bool?>("Modified"),
                                // pedigree not supported
                                // external references not supported
                                // sub-components not supported
                            };
                            if (component.Supplier.Name == null)
                            {
                                component.Supplier = null;
                            }
                            if (component.Swid.Text.Content == null)
                            {
                                component.Swid.Text = null;
                            }
                            if (component.Swid.TagId == null)
                            {
                                component.Swid = null;
                            }

                            var hashAlgorithms = Enum.GetValues(typeof(Hash.HashAlgorithm)).Cast <Hash.HashAlgorithm>();
                            var hashes         = new List <Hash>();
                            foreach (var hashAlgorithm in hashAlgorithms)
                            {
                                var hash = new Hash();
                                hash.Alg     = hashAlgorithm;
                                hash.Content = csvReader.GetField(hashAlgorithm.ToString().Replace('_', '-'));
                                if (!string.IsNullOrEmpty(hash.Content))
                                {
                                    hashes.Add(hash);
                                }
                            }
                            if (hashes.Count > 0)
                            {
                                component.Hashes = hashes;
                            }

                            var componentLicenses  = new List <ComponentLicense>();
                            var licenseExpressions = csvReader.GetField("LicenseExpressions")?.Split(',');
                            if (licenseExpressions != null)
                            {
                                foreach (var licenseExpressionString in licenseExpressions)
                                {
                                    if (licenseExpressionString.Contains(" ")) // license expression
                                    {
                                        var componentLicense = new ComponentLicense
                                        {
                                            Expression = licenseExpressionString
                                        };
                                        componentLicenses.Add(componentLicense);
                                    }
                                    else if (!string.IsNullOrEmpty(licenseExpressionString)) // license ID
                                    {
                                        var componentLicense = new ComponentLicense
                                        {
                                            License = new License
                                            {
                                                Id = licenseExpressionString
                                            }
                                        };
                                        componentLicenses.Add(componentLicense);
                                    }
                                }
                            }
                            var licenseNames = csvReader.GetField("LicenseNames")?.Split(',');
                            if (licenseNames != null)
                            {
                                foreach (var licenseName in licenseNames)
                                {
                                    if (!string.IsNullOrEmpty(licenseName))
                                    {
                                        componentLicenses.Add(new ComponentLicense
                                        {
                                            License = new License
                                            {
                                                Name = licenseName
                                            }
                                        });
                                    }
                                }
                            }
                            if (componentLicenses.Count > 0)
                            {
                                component.Licenses = componentLicenses;
                            }

                            bom.Components.Add(component);
                        }
                        return(bom);
                    }
        }