示例#1
0
    private BundleWrapper LoadBundle(string bundleName)
    {
        string target_local_path = FileUtils.getAbPath(bundleName);

        if (!System.IO.File.Exists(target_local_path))
        {
            if (m_isLocalization)
            {
                SetLocalization(false);
                target_local_path = FileUtils.getAbPath(bundleName);
                SetLocalization(true);
            }
            else
            {
                return(null);
            }
        }
        byte[]      target_content = System.IO.File.ReadAllBytes(target_local_path);
        AssetBundle target_bundle  = AssetBundle.LoadFromMemory(target_content);

        Assert.IsNotNull <AssetBundle>(target_bundle, "assetbundle为空 " + bundleName);
        BundleWrapper target_bundle_bw = new BundleWrapper(bundleName, target_bundle);

        m_bundleCache.Add(bundleName, target_bundle_bw);
        return(target_bundle_bw);
    }
示例#2
0
    /// <summary>
    /// 鍐呴儴鍔犺浇assetbundle鐨兲
    /// </summary>
    BundleWrapper LoadBundle(string abName)
    {
        string target_local_path = GetLocalFileUrl(abName);

        if (!System.IO.File.Exists(target_local_path))
        {
            // 鏈?湴鍖栬祫婧愭湭鎵惧埌渚濊禆鍖咃紝鍘诲叕鍏卞寘鐩?綍鎵教
            if (m_isLocalization)
            {
                SetLocalization(false);
                target_local_path = GetLocalFileUrl(abName);
                SetLocalization(true);
            }
            else
            {
                return(null);
            }
        }
        byte[]      target_content = System.IO.File.ReadAllBytes(target_local_path);
        AssetBundle target_bundle  = AssetBundle.LoadFromMemory(target_content);

        //AssetBundle target_bundle = AssetBundle.CreateFromFile(target_local_path);
        Assert.IsNotNull <AssetBundle>(target_bundle, "assetbundle璧勬簮涓嶅瓨鍦?" + abName);
        BundleWrapper target_bundle_bw = new BundleWrapper(abName, target_bundle);

        m_bundleCache.Add(abName, target_bundle_bw);
        return(target_bundle_bw);
    }
        private async Tasks.Task <BundleWrapper> CreateBundle(IEnumerable <string> batch, FhirVersion fhirVersion)
        {
            var serializer = new SerializationWrapper(fhirVersion);
            var bundle     = new BundleWrapper(fhirVersion);

            foreach (var file in batch)
            {
                ResourceWrapper resource = null;
                try
                {
                    var content = await File.ReadAllTextAsync(file);

                    resource = serializer.Parse(content, _arguments.MimeType);
                }
                catch (Exception e)
                {
                    _logger.LogError($"Could not read and parse {file}. Skipping: {e.Message}");
                }
                var entry   = bundle.AddResourceEntry(resource, null);
                var request = new RequestComponentWrapper(fhirVersion);
                request.Method = HTTPVerbWrapper.PUT;
                request.Url    = $"/{resource.ResourceType}/{resource.Id}";
                entry.Request  = request;
                _logger.LogInformation($"  Added {request.Url} to bundle");
            }

            return(bundle);
        }
        public void Start()
        {
            // The json file is a bundle compiled from the compartment definitions currently defined by HL7.
            // The definitions are available at https://www.hl7.org/fhir/compartmentdefinition.html.
            using Stream stream         = _modelInfoProvider.OpenVersionedFileStream("compartment.json");
            using TextReader reader     = new StreamReader(stream);
            using JsonReader jsonReader = new JsonTextReader(reader);
            var bundle = new BundleWrapper(FhirJsonNode.Read(jsonReader).ToTypedElement(_modelInfoProvider.StructureDefinitionSummaryProvider));

            Build(bundle);
        }
        internal void Build(BundleWrapper bundle)
        {
            var compartmentLookup = ValidateAndGetCompartmentDict(bundle);

            _compartmentSearchParamsLookup  = BuildResourceTypeLookup(compartmentLookup.Values);
            _compartmentResourceTypesLookup = new Dictionary <CompartmentType, HashSet <string> >();
            foreach ((CompartmentType key, (CompartmentType Code, Uri Url, IList <(string Resource, IList <string> Params)> Resources)value) in compartmentLookup)
            {
                _compartmentResourceTypesLookup[key] = value.Resources.Where(x => x.Params.Any()).Select(x => x.Resource).ToHashSet();
            }
        }
示例#6
0
            public override T DoLoad <T>(string strBundleName, string strPath_With_ExtensionName, bool bNotLoad_IsError)
            {
                if (_mapLoadedBundle.ContainsKey(strBundleName) == false)
                {
                    if (bNotLoad_IsError)
                    {
                        Debug.LogError($"{_pOwner.name} Bundle Is Not Loaded! {strBundleName}", _pOwner);
                        return(null);
                    }
                    else
                    {
                        string strBundlePath = GetBundlePath(strBundleName);
                        var    pBundleNew    = AssetBundle.LoadFromFile(strBundlePath);
                        if (pBundleNew == null)
                        {
                            Debug.LogError($"{_pOwner.name} Failed to load AssetBundle! {strBundleName}", _pOwner);
                            return(null);
                        }

                        BundleWrapper pBundleWrapper = new BundleWrapper(strBundleName, null);
                        pBundleWrapper.DoSetBundle(pBundleNew);
                        _mapLoadedBundle.Add(strBundleName, pBundleWrapper);
                    }
                }

                if (strPath_With_ExtensionName.Contains("/"))
                {
                    int iCutIndex = strPath_With_ExtensionName.LastIndexOf("/");
                    strPath_With_ExtensionName = strPath_With_ExtensionName.Substring(iCutIndex + 1, strPath_With_ExtensionName.Length - iCutIndex - 1);
                }


                var pBundle = _mapLoadedBundle[strBundleName].pBundle;
                T   pObject = pBundle.LoadAsset <T>(strPath_With_ExtensionName);

                if (pObject == null)
                {
                    if (bNotLoad_IsError)
                    {
                        Debug.LogError($"{_pOwner.name} Streaming Asset LoadFail  Bundle : {strBundleName} File Name : {strPath_With_ExtensionName}", _pOwner);
                    }

                    return(null);
                }

                return(pObject);
            }
        private async Task SerializeAndStore(BundleWrapper result, DirectoryInfo baseDir)
        {
            if (result == null)
            {
                return;
            }

            var serializer = new SerializationWrapper(result.FhirVersion);
            var resources  = result.GetResources();

            _logger.LogInformation($"  Fetched {resources.Count()} resources from server");
            foreach (var resource in resources)
            {
                string serialized = serializer.Serialize(resource, _arguments.MimeType);
                await Store(resource.Id, serialized, baseDir);
            }
        }
示例#8
0
            public override IEnumerator PreLoadBundle_Coroutine(string strBundleName, delOnLoadBundle OnLoadBundle)
            {
                bool bLoaded = false;

                if (_mapLoadedBundle.ContainsKey(strBundleName))
                {
                    var pAsyncExist = _mapLoadedBundle[strBundleName].pAsyncOperation;
                    if (pAsyncExist.isDone)
                    {
                        OnLoadBundle(strBundleName, true);
                        yield break;
                    }
                    else
                    {
                        // yield return pAsyncExist; 다른 코루틴에서 같은 yield 탄다고 에러 뱉음
                        while (pAsyncExist.isDone == false)
                        {
                            yield return(null);
                        }

                        bLoaded = true;
                    }
                }

                if (bLoaded == false)
                {
                    var           pAsync         = AssetBundle.LoadFromFileAsync(GetBundlePath(strBundleName));
                    BundleWrapper pBundleWrapper = new BundleWrapper(strBundleName, pAsync);
                    _mapLoadedBundle.Add(strBundleName, pBundleWrapper);

                    yield return(pAsync);

                    pBundleWrapper.DoSetBundle(pAsync.assetBundle);
                }

                bool bResult = _mapLoadedBundle[strBundleName].pBundle != null;

                if (bResult == false)
                {
                    Debug.LogError($"{_pOwner.name} PreLoadBundle Fail - {strBundleName}", _pOwner);
                }
                OnLoadBundle(strBundleName, bResult);
            }
 private BundleWrapper UpdateBundleServerUrl(BundleWrapper bundle, string endpoint)
 {
     return(bundle.UpdateLinks(new Uri(endpoint)));
 }
        private static Dictionary <CompartmentType, (CompartmentType, Uri, IList <(string, IList <string>)>)> ValidateAndGetCompartmentDict(BundleWrapper bundle)
        {
            EnsureArg.IsNotNull(bundle, nameof(bundle));

            var issues = new List <OperationOutcomeIssue>();
            var validatedCompartments = new Dictionary <CompartmentType, (CompartmentType, Uri, IList <(string, IList <string>)>)>();

            IReadOnlyList <BundleEntryWrapper> entries = bundle.Entries;

            for (int entryIndex = 0; entryIndex < entries.Count; entryIndex++)
            {
                // Make sure resources are not null and they are Compartment.
                BundleEntryWrapper entry = entries[entryIndex];

                var compartment = entry.Resource;

                if (compartment == null || !string.Equals(KnownResourceTypes.CompartmentDefinition, compartment.InstanceType, StringComparison.Ordinal))
                {
                    AddIssue(Core.Resources.CompartmentDefinitionInvalidResource, entryIndex);
                    continue;
                }

                string code = compartment.Scalar("code")?.ToString();
                string url  = compartment.Scalar("url")?.ToString();

                if (code == null)
                {
                    AddIssue(Core.Resources.CompartmentDefinitionInvalidCompartmentType, entryIndex);
                    continue;
                }

                CompartmentType typeCode = EnumUtility.ParseLiteral <CompartmentType>(code).GetValueOrDefault();

                if (validatedCompartments.ContainsKey(typeCode))
                {
                    AddIssue(Core.Resources.CompartmentDefinitionIsDupe, entryIndex);
                    continue;
                }

                if (string.IsNullOrWhiteSpace(url) || !Uri.IsWellFormedUriString(url, UriKind.Absolute))
                {
                    AddIssue(Core.Resources.CompartmentDefinitionInvalidUrl, entryIndex);
                    continue;
                }

                var resources = compartment.Select("resource")
                                .Select(x => (x.Scalar("code")?.ToString(), (IList <string>)x.Select("param").AsStringValues().ToList()))
                                .ToList();

                var resourceNames = resources.Select(x => x.Item1).ToArray();

                if (resourceNames.Length != resourceNames.Distinct().Count())
                {
                    AddIssue(Core.Resources.CompartmentDefinitionDupeResource, entryIndex);
                    continue;
                }

                validatedCompartments.Add(
                    typeCode,
                    (typeCode, new Uri(url), new List <(string, IList <string>)>(resources)));
            }

            if (issues.Count != 0)
            {
                throw new InvalidDefinitionException(
                          Core.Resources.CompartmentDefinitionContainsInvalidEntry,
                          issues.ToArray());
            }

            return(validatedCompartments);

            void AddIssue(string format, params object[] args)
            {
                issues.Add(new OperationOutcomeIssue(
                               OperationOutcomeConstants.IssueSeverity.Fatal,
                               OperationOutcomeConstants.IssueType.Invalid,
                               string.Format(CultureInfo.InvariantCulture, format, args)));
            }
        }
        internal void Build(BundleWrapper bundle)
        {
            var compartmentLookup = ValidateAndGetCompartmentDict(bundle);

            _compartmentSearchParamsLookup = BuildResourceTypeLookup(compartmentLookup.Values);
        }
示例#12
0
    private AssetWrapper LoadRes(AssetBundleInfo info, System.Type assetType)
    {
        string assetPath  = info.assetName;
        string bundleName = info.bundleName;

        if (info.dependencies != null)
        {
            foreach (string dep in info.dependencies)
            {
                if (m_bundleCache.ContainsKey(dep))
                {
                    m_bundleCache[dep].AddRefAsset(bundleName);
                    continue;
                }
                else
                {
                    if (string.IsNullOrEmpty(dep))
                    {
                        Debugger.LogError("AB name " + bundleName + " 依赖名空!");
                        continue;
                    }

                    BundleWrapper loaded_bundle_bw = LoadBundle(dep);
                    loaded_bundle_bw.AddRefAsset(bundleName);
                    UnityEngine.Object temp = loaded_bundle_bw.GetBundle().mainAsset;
                    if (temp != null)
                    {
                        Debugger.Log("dep_bundle mainAsset: " + temp.name);
                    }
                }
            }
        }

        if (m_bundleCache.ContainsKey(bundleName))
        {
            UnityEngine.Object obj = m_bundleCache[bundleName].GetBundle().LoadAsset(assetPath, assetType);
            AssetWrapper       ret = new AssetWrapper(obj, assetPath, assetType, bundleName, IsSceneBundle(bundleName));
            m_assetWrapperCache.Add(assetPath, ret);
            m_bundleCache[bundleName].AddRefAsset(assetPath);
            return(ret);
        }

        // load target bundle
        BundleWrapper target_bundle_bw = LoadBundle(bundleName);

        target_bundle_bw.AddRefAsset(assetPath);
        // load asset
        AssetWrapper ret_aw;

        if (IsSceneBundle(bundleName))
        {
            ret_aw = new AssetWrapper(null, assetPath, assetType, bundleName, true);
        }
        else
        {
            string realPath = assetPath;
            //if (m_isLocalization)
            //{
            //    realPath = Regex.Replace(realPath, "^Assets/", "Assets/L10n/" + Const.L10n + "/");
            //}
            UnityEngine.Object obj = target_bundle_bw.GetBundle().LoadAsset(realPath, assetType);
            if (obj == null)
            {
                Debugger.LogError("targetBundle Wrong!");
                return(null);
            }
            ret_aw = new AssetWrapper(obj, assetPath, assetType, bundleName, false);
        }
        m_assetWrapperCache.Add(assetPath, ret_aw);

        return(ret_aw);
    }
示例#13
0
        private List <(string ResourceType, SearchParameterInfo SearchParameter)> ValidateAndGetFlattenedList()
        {
            var issues = new List <OperationOutcomeIssue>();

            BundleWrapper bundle = null;

            using (Stream stream = _modelInfoProvider.OpenVersionedFileStream(_embeddedResourceName, _embeddedResourceNamespace, _assembly))
            {
                using TextReader reader     = new StreamReader(stream);
                using JsonReader jsonReader = new JsonTextReader(reader);
                try
                {
                    bundle = new BundleWrapper(FhirJsonNode.Read(jsonReader).ToTypedElement(_modelInfoProvider.StructureDefinitionSummaryProvider));
                }
                catch (FormatException ex)
                {
                    AddIssue(ex.Message);
                }
            }

            EnsureNoIssues();

            IReadOnlyList <BundleEntryWrapper> entries = bundle.Entries;

            // Do the first pass to make sure all resources are SearchParameter.
            for (int entryIndex = 0; entryIndex < entries.Count; entryIndex++)
            {
                // Make sure resources are not null and they are SearchParameter.
                BundleEntryWrapper entry = entries[entryIndex];

                ITypedElement searchParameterElement = entry.Resource;

                if (searchParameterElement == null || !string.Equals(searchParameterElement.InstanceType, KnownResourceTypes.SearchParameter, StringComparison.OrdinalIgnoreCase))
                {
                    AddIssue(Core.Resources.SearchParameterDefinitionInvalidResource, entryIndex);
                    continue;
                }

                var searchParameter = new SearchParameterWrapper(searchParameterElement);

                try
                {
                    SearchParameterInfo searchParameterInfo = CreateSearchParameterInfo(searchParameter);
                    _uriDictionary.Add(new Uri(searchParameter.Url), searchParameterInfo);
                }
                catch (FormatException)
                {
                    AddIssue(Core.Resources.SearchParameterDefinitionInvalidDefinitionUri, entryIndex);
                    continue;
                }
                catch (ArgumentException)
                {
                    AddIssue(Core.Resources.SearchParameterDefinitionDuplicatedEntry, searchParameter.Url);
                    continue;
                }
            }

            EnsureNoIssues();

            var validatedSearchParameters = new List <(string ResourceType, SearchParameterInfo SearchParameter)>
            {
                // _type is currently missing from the search params definition bundle, so we inject it in here.
                (KnownResourceTypes.Resource, new SearchParameterInfo(SearchParameterNames.ResourceType, SearchParamType.Token, SearchParameterNames.ResourceTypeUri, null, "Resource.type().name", null)),
            };

            // Do the second pass to make sure the definition is valid.
            for (int entryIndex = 0; entryIndex < entries.Count; entryIndex++)
            {
                BundleEntryWrapper entry = entries[entryIndex];

                ITypedElement searchParameterElement = entry.Resource;
                var           searchParameter        = new SearchParameterWrapper(searchParameterElement);

                // If this is a composite search parameter, then make sure components are defined.
                if (string.Equals(searchParameter.Type, SearchParamType.Composite.GetLiteral(), StringComparison.OrdinalIgnoreCase))
                {
                    var composites = searchParameter.Component;
                    if (composites.Count == 0)
                    {
                        AddIssue(Core.Resources.SearchParameterDefinitionInvalidComponent, searchParameter.Url);
                        continue;
                    }

                    for (int componentIndex = 0; componentIndex < composites.Count; componentIndex++)
                    {
                        ITypedElement component     = composites[componentIndex];
                        var           definitionUrl = GetComponentDefinition(component);

                        if (definitionUrl == null ||
                            !_uriDictionary.TryGetValue(new Uri(definitionUrl), out SearchParameterInfo componentSearchParameter))
                        {
                            AddIssue(
                                Core.Resources.SearchParameterDefinitionInvalidComponentReference,
                                searchParameter.Url,
                                componentIndex);
                            continue;
                        }

                        if (componentSearchParameter.Type == SearchParamType.Composite)
                        {
                            AddIssue(
                                Core.Resources.SearchParameterDefinitionComponentReferenceCannotBeComposite,
                                searchParameter.Url,
                                componentIndex);
                            continue;
                        }

                        if (string.IsNullOrWhiteSpace(component.Scalar("expression")?.ToString()))
                        {
                            AddIssue(
                                Core.Resources.SearchParameterDefinitionInvalidComponentExpression,
                                searchParameter.Url,
                                componentIndex);
                            continue;
                        }
                    }
                }

                // Make sure the base is defined.
                var bases = searchParameter.Base;
                if (bases.Count == 0)
                {
                    AddIssue(Core.Resources.SearchParameterDefinitionBaseNotDefined, searchParameter.Url);
                    continue;
                }

                for (int baseElementIndex = 0; baseElementIndex < bases.Count; baseElementIndex++)
                {
                    var code = bases[baseElementIndex];

                    string baseResourceType = code;

                    // Make sure the expression is not empty unless they are known to have empty expression.
                    // These are special search parameters that searches across all properties and needs to be handled specially.
                    if (ShouldExcludeEntry(baseResourceType, searchParameter.Name) ||
                        (_modelInfoProvider.Version == FhirSpecification.R5 && _knownBrokenR5.Contains(new Uri(searchParameter.Url))))
                    {
                        continue;
                    }
                    else
                    {
                        if (string.IsNullOrWhiteSpace(searchParameter.Expression))
                        {
                            AddIssue(Core.Resources.SearchParameterDefinitionInvalidExpression, searchParameter.Url);
                            continue;
                        }
                    }

                    validatedSearchParameters.Add((baseResourceType, CreateSearchParameterInfo(searchParameter)));
                }
            }

            EnsureNoIssues();

            return(validatedSearchParameters);

            void AddIssue(string format, params object[] args)
            {
                issues.Add(new OperationOutcomeIssue(
                               OperationOutcomeConstants.IssueSeverity.Fatal,
                               OperationOutcomeConstants.IssueType.Invalid,
                               string.Format(CultureInfo.InvariantCulture, format, args)));
            }

            void EnsureNoIssues()
            {
                if (issues.Count != 0)
                {
                    throw new InvalidDefinitionException(
                              Core.Resources.SearchParameterDefinitionContainsInvalidEntry,
                              issues.ToArray());
                }
            }
        }
示例#14
0
 public void AddBundle(Guid id, [FromBody]  BundleWrapper bundle)
 {
     _addBundleToOrderCommand.Run(id, bundle.BundleId);
 }
示例#15
0
    private AssetWrapper LoadRes(string assetPath, System.Type assetType)
    {
        //寮€濮嬪姞杞藉?搴旂殑璧勬簮鍖勭.assetbundle)
        string abName = _asset2Bundle[assetPath];

        string[] dps;
        if (m_isLocalization)
        {
            dps = m_manifestL10n.GetAllDependencies(abName);
        }
        else
        {
            dps = m_manifest.GetAllDependencies(abName);
        }

        for (int i = 0; i < dps.Length; i++)
        {
            string dep_name = dps[i];
            if (m_bundleCache.ContainsKey(dep_name))
            {
                m_bundleCache[dep_name].AddRefAsset(assetPath);
                continue;
            }
            else
            {
                if (string.IsNullOrEmpty(dep_name))
                {
                    Log.PrintMsg("鏌ヤ竴涓娺" + abName + " 鐨刴anifest鏂囦欢锛屾湁渚濊禆鏄?┖鐨勩€佱");
                    continue;
                }
                //string local_path = GetLocalFileUrl(dep_name);
                //byte[] dep_content = System.IO.File.ReadAllBytes(local_path);
                //AssetBundle dep_bundle = AssetBundle.CreateFromMemoryImmediate(dep_content);
                ////AssetBundle dep_bundle = AssetBundle.CreateFromFile(local_path); //鍦ㄦ煇浜涘钩鍙颁笂璇诲彇鍘嬬缉鏂囦欢浼氬穿婧冨緟鏂皏ersion瑙e喅
                //Assert.IsNotNull<AssetBundle>(dep_bundle, "渚濊禆鎵撳寘璧勬簮鏈夐棶棰楖" + dep_name);
                //Object temp = dep_bundle.mainAsset;
                //if(temp!= null)
                //    Debugger.Log("dep_bundle mainAsset:" + temp.name);
                //BundleWrapper loaded_bundle_bw = new BundleWrapper(dep_name, dep_bundle);
                //loaded_bundle_bw.AddRefAsset(assetPath);
                //m_bundleCache.Add(dep_name, loaded_bundle_bw); // keep in bundle cache
                BundleWrapper loaded_bundle_bw = LoadBundle(dep_name);
                loaded_bundle_bw.AddRefAsset(assetPath);
                Object temp = loaded_bundle_bw.GetBundle().mainAsset;
                if (temp != null)
                {
                    Debugger.Log("dep_bundle mainAsset:" + temp.name);
                }
            }
        }//渚濊禆璧勬簮鍔犺浇瀹屾瘯; Lorry


        if (m_bundleCache.ContainsKey(abName))
        {//宸茬粡瀛樺湪姝?undle鐨勭紦瀛橈紝浣嗘槸娌℃湁asset缂撳瓨锛岃瘉鏄庤祫婧愬寘宸茬粡鍔犺浇锛屽彧鏄?病鏈塴oad 姝_asset,鍦ㄧ壒娈婃儏鍐典笅鍑虹幇bug
            Object       obj = m_bundleCache[abName].GetBundle().LoadAsset(assetPath, assetType);
            AssetWrapper ret = new AssetWrapper(obj, assetPath, assetType, abName, IsSceneBundle(abName));
            m_assetWrapperCache.Add(assetPath, ret);
            //TODO:鑰冭檻缁檅undle娣诲姞寮曠敤,浣嗕及璁狓0%涓嶇敤閿€姣?闇€浠旂粏鑰冭檻 Lorry
            m_bundleCache[abName].AddRefAsset(assetPath);
            return(ret);
        }

        // load target bundle
        BundleWrapper target_bundle_bw = LoadBundle(abName);

        target_bundle_bw.AddRefAsset(assetPath);
        // load asset
        AssetWrapper ret_aw;

        if (IsSceneBundle(abName))
        {//濡傛灉鏄?満鏅?紝assetBundle杞藉叆鍚庯紝閫氳繃loadlevel杩涘叆;
            ret_aw = new AssetWrapper(null, assetPath, assetType, abName, true);
        }
        else
        {
            // 璇诲彇鏈?湴鍖栬祫婧愭椂锛屽皢瀹為檯璺?緞涓?殑/L10n/xxx/琛ヤ笂; ly0464
            string realPath = assetPath;
            if (m_isLocalization)
            {
                realPath = Regex.Replace(realPath, "^Assets/", "Assets/L10n/" + Const.L10n + "/");
            }
            Object obj = target_bundle_bw.GetBundle().LoadAsset(realPath, assetType);
            if (obj == null)
            {
                Debugger.LogError("targetBundle Wrong!");
                return(null);
            }
            ret_aw = new AssetWrapper(obj, assetPath, assetType, abName, false);
            // add bundle refs
            //AddBundleRefAsset(abName, assetPath);
        }
        m_assetWrapperCache.Add(assetPath, ret_aw);

        return(ret_aw);
    }