コード例 #1
0
ファイル: FileBasedRegistry.cs プロジェクト: i-Asset/basyx
        public IResult <IElementContainer <ISubmodelDescriptor> > RetrieveSubmodels(string aasId)
        {
            if (string.IsNullOrEmpty(aasId))
            {
                return(new Result <ElementContainer <ISubmodelDescriptor> >(new ArgumentNullException(nameof(aasId))));
            }

            string aasIdHash        = GetHashString(aasId);
            string aasDirectoryPath = Path.Combine(FolderPath, aasIdHash);

            if (Directory.Exists(aasDirectoryPath))
            {
                ElementContainer <ISubmodelDescriptor> submodelDescriptors = new ElementContainer <ISubmodelDescriptor>();
                string submodelDirectoryPath = Path.Combine(aasDirectoryPath, SubmodelFolder);
                if (Directory.Exists(submodelDirectoryPath))
                {
                    string[] files = Directory.GetFiles(submodelDirectoryPath);
                    foreach (var file in files)
                    {
                        string submodelId = file.Split(Path.DirectorySeparatorChar)?.Last()?.Replace(".json", "");
                        var    descriptor = RetrieveSubmodel(aasId, submodelId);
                        if (descriptor.Success && descriptor.Entity != null)
                        {
                            submodelDescriptors.Create(descriptor.Entity);
                        }
                    }
                }
                return(new Result <ElementContainer <ISubmodelDescriptor> >(true, submodelDescriptors));
            }
            else
            {
                return(new Result <ElementContainer <ISubmodelDescriptor> >(false, new NotFoundMessage($"Asset Administration Shell with {aasId}")));
            }
        }
コード例 #2
0
ファイル: FileBasedRegistry.cs プロジェクト: i-Asset/basyx
        public IResult <IElementContainer <IAssetAdministrationShellDescriptor> > RetrieveAssetAdministrationShells()
        {
            string[] aasDirectories;
            try
            {
                aasDirectories = Directory.GetDirectories(FolderPath);
            }
            catch (Exception e)
            {
                return(new Result <ElementContainer <IAssetAdministrationShellDescriptor> >(e));
            }

            ElementContainer <IAssetAdministrationShellDescriptor> aasDescriptors = new ElementContainer <IAssetAdministrationShellDescriptor>();

            if (aasDirectories?.Length > 0)
            {
                foreach (var directory in aasDirectories)
                {
                    try
                    {
                        string aasIdHash   = directory.Split(Path.DirectorySeparatorChar).Last();
                        string aasFilePath = Path.Combine(directory, aasIdHash) + ".json";
                        IResult <IAssetAdministrationShellDescriptor> readAASDescriptor = ReadAssetAdministrationShell(aasFilePath);
                        if (readAASDescriptor.Success && readAASDescriptor.Entity != null)
                        {
                            aasDescriptors.Create(readAASDescriptor.Entity);
                        }
                    }
                    catch (Exception e)
                    {
                        return(new Result <ElementContainer <IAssetAdministrationShellDescriptor> >(e));
                    }
                }
            }
            return(new Result <ElementContainer <IAssetAdministrationShellDescriptor> >(true, aasDescriptors));
        }