Пример #1
0
    private static void PushToNeedToUnLoadPakage(int instanceID)
    {
        ResourcePackage req = AllocResourcePackage(instanceID);

        //如果加载列表里有他
        if (m_ResourcePackageRequestTable.Contains(instanceID))
        {
            int refcout = req.Release();
            if (refcout <= 0)
            {
                m_ResourcePackageRequestTable.Remove(instanceID);
                RemoveFromAssetsFileUpLoadQueue(instanceID);
                req.ResetPriority();
                if (req.isUpLoadToLoadingThread)
                {
                    //加入到将要卸载的列表
                    m_NeedToUnLoadResourcePackageTable.Add(instanceID);
                }
                else
                {
                    RemoveAssetsFileProcessingList(req.instanceID);
                }
            }
        }
    }
Пример #2
0
 /// <summary>
 /// 释放资源包
 /// </summary>
 /// <param name="assetBundleName"></param>
 private static void ReleaseAssetBundle(string assetBundleName)
 {
     //非编辑器下,还有AssetBundle
     if (isOnRunTimeMode)
     {
         ResourcePackage pkg = AllocResourcePackage(assetBundleName);
         //如果这个ab没有被加载出来.
         if (!m_LoadedResourcePackage.Contains(pkg.instanceID))
         {
             PushToNeedToUnLoadPakage(pkg.instanceID);
         }
         else
         {
             //baundle的引用减少
             int assetBundleRefCount = pkg.Release();
             //如果这个bundle已经没有引用了,卸载bundle
             if (assetBundleRefCount <= 0)
             {
                 RemoveAllResourcePackageCallBackList(assetBundleName);
                 //移除加载
                 UnLoadAssetBundle(pkg.instanceID);
             }
         }
     }
 }
Пример #3
0
    private static void ProcessResourcePackageCallBack()
    {
        Temp_LoadCompleteList_int.Clear();
        Temp_LoadCompleteList_int.AddRange(m_ResourcePackageWatingForCallBack);
        m_ResourcePackageWatingForCallBack.Clear();

        foreach (int id in Temp_LoadCompleteList_int)
        {
            ResourcePackage packageTemp = AllocResourcePackage(id);
            Temp_resourcePackageCallBackList.Clear();
            Temp_callBackDataList.Clear();

            Temp_resourcePackageCallBackList.AddRange(packageTemp.resourcePackageCallBackList);
            Temp_callBackDataList.AddRange(packageTemp.callBackDataList);
            packageTemp.ClearAsyncCallBackData();

            for (int i = 0; i < Temp_resourcePackageCallBackList.Count; i++)
            {
                System.Action <ResourcePackageCallBackObj> cb = Temp_resourcePackageCallBackList[i];
                ResNode result = AllocResNode(Temp_callBackDataList[i].resInstanceID);

                cb(Temp_callBackDataList[i]);
            }
        }
    }
    private static void ReleaseAssetBundleIfNeed(ResNode res)
    {
        if (!isOnRunTimeMode)
        {
            return;
        }
        if (res.assetType == AssetType.Asset_FBX)
        {
            return;
        }
        if (res.assetType != AssetType.Asset_Prefab && !IsUnionDependenicesAssetBundle(res.AssetBundleName))
        {
            return;
        }

        if (res.isBeReleaseAssetBundleIfNeed)
        {
            return;
        }
        res.isBeReleaseAssetBundleIfNeed = true;
        ResourcePackage pkg = AllocResourcePackage(res.AssetBundleName);

        if (m_LoadedResourcePackage.Contains(pkg.instanceID))
        {
            int refcout = pkg.Release();
            if (refcout <= 0)
            {
                UnLoadAssetBundle(pkg.instanceID, false);
            }
        }
    }
Пример #5
0
    private static ResourcePackageCallBackObj BuildResourcePackageCallBackObj(ResourcePackage pack, ResNode res, ResConfigData data, System.Action <ResConfigData, ResNode, System.Object> usercallBack, System.Object userdataObj)
    {
        ResourcePackageCallBackObj reslut = AllocResourcePackageCallBackObj(res.instanceID, pack.instanceID);

        reslut.userCallBck = usercallBack;
        reslut.userDataObj = userdataObj;
        reslut.configData  = data;
        return(reslut);
    }
Пример #6
0
 private static void RemoveNeedToUnLoadPackage(int instanceID)
 {
     if (m_NeedToUnLoadResourcePackageTable.Contains(instanceID))
     {
         ResourcePackage req = AllocResourcePackage(instanceID);
         m_NeedToUnLoadResourcePackageTable.Remove(instanceID);
         m_ResourcePackageRequestTable.Add(instanceID);
     }
 }
Пример #7
0
 private static void FillUnioFileInfo(UnionResConfigData cf, ResourcePackage pkg)
 {
     if (cf == null || pkg == null)
     {
         return;
     }
     pkg.unionIndx  = cf.unionIndx;;
     pkg.startIndex = cf.startIndex;
     pkg.dataLength = cf.dataLength;
 }
Пример #8
0
    private static ResourcePackage GetResourcePackge(ResConfigData config)
    {
        ResourcePackage pkg = AllocResourcePackage(config.AssetBundleName);

        if (m_LoadedResourcePackage.Contains(pkg.instanceID))
        {
            pkg.AddRef();
        }
        else
        {
            string abName = config.AssetBundleName;
            string patch  = AssetBundleManager.FullAssetPackagePathRoot + config.AssetBundleName;

            UnionResConfigData unionRes = config as UnionResConfigData;
            if (unionRes != null)
            {
                patch  = unionRes.UnionFilePath;
                abName = unionRes.ShortUnionFilePath;
            }

            if (!m_RespackageTable.ContainsKey(abName))
            {
                AssetBudleLog("AssetBundle文件不存在!,路径:" + patch);
                return(pkg);
            }
            RemoveNeedToUnLoadPackage(pkg.instanceID);
            //异步加载的列表里有他,那么要强制同步加载了
            if (m_ResourcePackageRequestTable.Contains(pkg.instanceID))
            {
                m_ResourcePackageRequestTable.Remove(pkg.instanceID);
                if (pkg.isUpLoadToLoadingThread)
                {
                    pkg.AssetBundleInstance = pkg.fileRequest.assetBundle;
                }
                else
                {
                    pkg.isUpLoadToLoadingThread = true;
                    pkg.AssetBundleInstance     = LoadAssetBundle(patch, config);
                }
                RemoveFromAssetsFileUpLoadQueue(pkg.instanceID);
                RemoveAssetsFileProcessingList(pkg.instanceID);
                PushToResourcePackageCallBackList(pkg.instanceID);
            }
            else
            {
                AssetBundle pAssetBundle = LoadAssetBundle(patch, config);
                pkg.AssetBundleInstance = pAssetBundle;
            }
            pkg.filePatch = patch;
            pkg.AddRef();
            m_LoadedResourcePackage.Add(pkg.instanceID);
        }

        return(pkg);
    }
Пример #9
0
    private static int AssetsFileAsyncRequestSortFunc(int left, int right)
    {
        ResourcePackage req_left  = AllocResourcePackage(left);
        ResourcePackage req_right = AllocResourcePackage(right);

        if (null == req_left || null == req_right)
        {
            Debug.LogError("AssetsFileAsyncRequestSort failed,req_left:" + req_left + ",req_right:" + req_right);
            return(0);
        }
        return(req_left.priority.CompareTo(req_right.priority));
    }
Пример #10
0
 private static void ReleaseResourcePackageWhenLoadFiald(ResourcePackage pkg)
 {
     if (null == pkg)
     {
         return;
     }
     //不用管了,加载失败之后啥都没的
     //pkg.RefCount--;
     //if (pkg.RefCount <= 0)
     //{
     //    UnLoadAssetBundle(pkg.AssetBundleName);
     //}
 }
Пример #11
0
        private void ResourceManager_PackageStarted(ResourceManager packageManager, ResourcePackage package)
        {
            var      spriteFrame = package.ResourceType.GetSpriteFrame();
            CCSprite sprite      = new CCSprite(spriteFrame)
            {
                BlendFunc = CCBlendFunc.NonPremultiplied
            };

            Packages.Add(package, sprite);
            package.RequiresRedraw += r => RedrawRequested = true;
            RedrawRequested         = true;
            AddChild(sprite);
        }
Пример #12
0
    private static void UnLoadAssetBundle(int bundleID, bool toUnLoadAllAssets = true)
    {
        ResourcePackage pkg = AllocResourcePackage(bundleID);

        if (m_LoadedResourcePackage.Contains(bundleID))
        {
            if (pkg.AssetBundleInstance)
            {
                pkg.AssetBundleInstance.Unload(toUnLoadAllAssets);
            }
            m_LoadedResourcePackage.Remove(bundleID);
            pkg.Clear();
        }
    }
Пример #13
0
    private static void RemoveAllResourcePackageCallBackList(string AssetBundleName)
    {
        if (AssetBundleName.Equals(string.Empty))
        {
            return;
        }
        ResourcePackage package = AllocResourcePackage(AssetBundleName);

        package.ClearAsyncCallBackData();
        if (m_ResourcePackageWatingForCallBack.Contains(package.instanceID))
        {
            m_ResourcePackageWatingForCallBack.Remove(package.instanceID);
        }
    }
Пример #14
0
        private void _dc_Ended(IDataOpItem item)
        {
            if (item is DownloadDataItem)
            {
                DownloadDataItem ddi = item as DownloadDataItem;
                if (ddi.Success)
                {
                    if (_excludedItems.Contains(Kits.GetFilename(ddi.Target)))
                    {
                        return;
                    }
                    _downedCount++;
                    //unpackage
                    string target = ddi.Target.Replace(@"\" + _temp, "");

                    string dir = (new FileInfo(target)).DirectoryName;
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    try
                    {
                        int l = ResourcePackage.Unpackage(ddi.Target, target);
                        Notified?.Invoke(CVRDownloadResult.Finished, new FinishedItem {
                            Name = target, Length = l
                        });
                    }
                    catch
                    {
                        Notified?.Invoke(CVRDownloadResult.UnpackageHappened, target);
                    }

                    if (_requestedCount == _downedCount)
                    {
                        string targetemp = Path.Combine(Target, _temp);
                        if (Directory.Exists(targetemp))
                        {
                            Kits.DeleteDirectory(targetemp);
                        }

                        Notified?.Invoke(CVRDownloadResult.Completed, _downedCount);
                    }
                }
                else
                {
                    Notified?.Invoke(CVRDownloadResult.DownloadHappened, ddi.Source);
                }
            }
        }
Пример #15
0
    /// <summary>
    /// 更新异步加载资源文件的加载进度
    /// </summary>
    /// <param name="LoadCompleteList"></param>
    private static void UpdateLoadingAssetFileProgress(List <int> LoadCompleteList)
    {
        if (m_ResourcePackageRequestTable.Count > 0)
        {
            LoadCompleteList.Clear();

            foreach (int ins in m_ResourcePackageRequestTable)
            {
                ResourcePackage package = AllocResourcePackage(ins);


                if (!package.isUpLoadToLoadingThread)
                {
                    continue;
                }

                /*为了保证资源的加载顺序,只要有一个包没有加载完成,
                 * 就直接跳出本次检测,防止有的包加载完了,但是他依赖的包还没有加载完成
                 */
                if (package.isDone)
                {
                    LoadCompleteList.Add(ins);
                    AssetBundle pAssetBundle = package.fileRequest.assetBundle;

                    package.AssetBundleInstance = pAssetBundle;
                    m_LoadedResourcePackage.Add(package.instanceID);


                    //加载完一个异步,从正在处理中移除
                    if (!RemoveAssetsFileProcessingList(ins))
                    {
                        Debug.LogError("AssetBundle重大错误222!");
                    }
                }
                //else
                //{
                //    break;
                //}
            }

            //移除已经加载完成的
            foreach (int s in LoadCompleteList)
            {
                m_ResourcePackageRequestTable.Remove(s);
                ResourcePackage package = AllocResourcePackage(s);
                PushToResourcePackageCallBackList(s);
            }
        }
    }
Пример #16
0
    private static ResourcePackage AllocResourcePackage(int instanceID)
    {
        ResourcePackage reslut = null;

        if (AssetBundleNameInstanceIDList.Contains(instanceID))
        {
            if (!allCreatedResourcePackage.TryGetValue(instanceID, out reslut))
            {
                reslut = new ResourcePackage();
                reslut.Clear();
                reslut.instanceID = instanceID;
                allCreatedResourcePackage.Add(instanceID, reslut);
            }
        }

        return(reslut);
    }
Пример #17
0
        public string Add(ResourcePackageViewModel model)
        {
            if (ModelState.IsValid)
            {
                ResourcePackage rpackge = new ResourcePackage()
                {
                    Name  = model.Name,
                    Sort  = model.Sort,
                    State = model.State > 0
                };
                bool isSucessed = new ResourcePackageController().Add(rpackge);

                return(isSucessed ? "ok" : "error");
            }

            return("error");
        }
Пример #18
0
        private void _dc_Ended(IDataOpItem item)
        {
            if (item is DownloadDataItem)
            {
                DownloadDataItem ddi = item as DownloadDataItem;
                if (ddi.Success)
                {
                    string crc = FileMD5.Create(ddi.Target);
                    if (crc == ddi.Crc)
                    {
                        string localPathfile = _dc.GetLocalPathfile(ddi.Source);

                        try
                        {
                            if (LocalFile)
                            {
                                ResourcePackage.Unpackage(ddi.Target, localPathfile);
                                Notified?.Invoke(CVResRequestResult.RequestFileSucceed, localPathfile);
                            }
                            else
                            {
                                byte[] buff = ResourcePackage.Unpackage(File.ReadAllBytes(ddi.Target));
                                Notified?.Invoke(CVResRequestResult.RequestDataSucceed, buff);
                            }
                        }
                        catch (NullReferenceException)
                        {
                            Notified?.Invoke(CVResRequestResult.UnpackageFailed, localPathfile);
                        }
                        catch (IOException)
                        {
                            Notified?.Invoke(CVResRequestResult.WriteFailed, localPathfile);
                        }
                    }
                    else
                    {
                        Notified?.Invoke(CVResRequestResult.CrcFailded, ddi.Message);
                    }
                }
                else
                {
                    Notified?.Invoke(CVResRequestResult.DownloadFailed, ddi.Message);
                }
            }
        }
        private void InstallPackage(ResourcePackage package)
        {
            CurrentPackage = package;
            _completedPackageList.Add(package);

            if (ResourceInstallStepUpdate != null)
            {
                ResourceInstallStepUpdate(this, new MobileResourceInstallEventArgs {
                    StepNumber = CurrentStep++
                });
            }

            var client = new WebClient();

            client.DownloadProgressChanged += ResourceDownloadProgressChanged;
            client.DownloadFileCompleted   += ResourceDownloadFileCompleted;
            client.DownloadFileAsync(new Uri(string.Format("https://github.com/{0}/{1}/archive/{2}", package.Account, package.Repository, package.Archive)), Path.Combine(MobilePath, package.File));
        }
Пример #20
0
    private static void ProcessAssetsFileAsyncRequest(float dealtTime)
    {
        Temp_LoadCompleteList_int.Clear();
        //已经在处理请求或者没有请求返回
        if (isProcessingAssetsFileAsyncRequest ||
            m_WaitForUpLoadAssetsFileAsyncRequestSet.Count <= 0)
        {
            return;
        }

        currUpLoad_AssetsFile_AsyncRequestClipTime += dealtTime;
        int cout = m_WaitForUpLoadAssetsFileAsyncRequestSet.Count;

        //数量足够,或者达到了一个异步时间片段
        if (cout < MinUpLoadAssetsFileAsyncRequestCount && currUpLoad_AssetsFile_AsyncRequestClipTime < MaxUpLoad_AssetsFile_AsyncRequestClipTime)
        {
            return;
        }
        currUpLoad_AssetsFile_AsyncRequestClipTime = 0.0f;
        int UpLoadCount = 0;

        TempList_int.Clear();
        TempList_int.AddRange(m_WaitForUpLoadAssetsFileAsyncRequestSet);
        TempList_int.Sort(AssetsFileAsyncRequestSortFunc);

        ResourcePackage req = AllocResourcePackage(TempList_int[0]);

        foreach (int id in TempList_int)
        {
            //一次最多上传MinUpLoadAsyncRequestCount请求
            if (UpLoadCount >= MinUpLoadAssetsFileAsyncRequestCount)
            {
                break;
            }

            req = AllocResourcePackage(id);

            RemoveFromAssetsFileUpLoadQueue(id);
            UpLoadCount++;
            req.fileRequest             = LoadAssetBundleAsync(req.filePatch, req.startIndex);
            req.isUpLoadToLoadingThread = true;
            m_ProcessingAssetsFileAsyncRequestList.Add(id);
        }
    }
Пример #21
0
    /// <summary>
    /// 移除延迟回调列表,这个是指调用异步加载,而已经加载完成的延迟回调,确保回调函数是慢于调用函数的
    /// </summary>
    private static void RemoveFromResourcePackageCallBackList(string AssetBundleName, ResNode result)
    {
        if (AssetBundleName.Equals(string.Empty))
        {
            return;
        }

        ResourcePackage package = AllocResourcePackage(AssetBundleName);

        for (int i = 0; i < package.resourcePackageCallBackList.Count; i++)
        {
            if (package.callBackDataList[i].resInstanceID.Equals(result.instanceID))
            {
                package.resourcePackageCallBackList.RemoveAt(i);
                package.callBackDataList.RemoveAt(i);
                break;
            }
        }
    }
Пример #22
0
        public override IEnumerable <IVersionable> Build(IEnumerable <IVersionable> ws)
        {
            Collection <IVersionable> allItems = getAllItems();

            var sus = allItems.OfType <StudyUnit>().ToList();

            for (var i = 0; i < sus.Count(); i++)
            {
                foreach (var dc in sus[i].DataCollections)
                {
                    var rp = new ResourcePackage();
                    rp.DublinCoreMetadata.Title = dc.ItemName;
                    allItems.Add(rp);
                    sus[i].AddChild(rp);
                    rp.AddChild(dc);
                }
            }
            return(allItems);
        }
Пример #23
0
 public ResourceLoader(string fileName)
 {
     _enuResourceFileName = fileName;
     InitRuFileName();
     _enuResourcePackage = new ResourcePackage(CultureInfo.GetCultureInfo("en-US"));
     using (var stream = new FileStream(fileName, FileMode.Open)) {
         using (var reader = new XmlResourceReader(stream)) {
             reader.ReadToDescendant("Resources");
             _enuResourcePackage.ReadXml(reader);
         }
     }
     _ruResourcePackage = new ResourcePackage(CultureInfo.GetCultureInfo("ru-RU"));
     using (var stream = new FileStream(_ruResourceFileName, FileMode.Open)) {
         using (var reader = new XmlResourceReader(stream)) {
             reader.ReadToDescendant("Resources");
             _ruResourcePackage.ReadXml(reader);
         }
     }
 }
Пример #24
0
        CodeList GetCodeList(string[] factors, string agencyId, ResourcePackage resourcePackage)
        {
            var codeList = new CodeList {
                AgencyId = agencyId
            };

            for (int i = 0; i < factors.Length; i++)
            {
                int    value = i + 1;
                string label = factors[i];

                var category = new Category {
                    AgencyId = agencyId
                };
                category.Label.Current = label;

                var code = new Code()
                {
                    AgencyId = agencyId
                };
                code.Category = category;
                code.Value    = value.ToString();
                codeList.Codes.Add(code);

                // Check for existing Code+Cat schemes with which to harmonize.
                CodeList existingCodeScheme      = null;
                bool     codeSchemeAlreadyExists = harmonizingCache.TryGetExistingCodeScheme(
                    codeList, out existingCodeScheme);
                if (codeSchemeAlreadyExists)
                {
                    codeList = existingCodeScheme;
                }
                else
                {
                    // The CodeList isn't in this.ResourcePackage or the cache yet, so add it.
                    resourcePackage.CodeSchemes.Add(codeList);
                    harmonizingCache.AddCodeScheme(codeList);
                }
            }

            return(codeList);
        }
Пример #25
0
    private static void ProcessNeedToUnLoadPackage(List <int> LoadCompleteList)
    {
        if (m_NeedToUnLoadResourcePackageTable.Count > 0)
        {
            LoadCompleteList.Clear();

            foreach (int ins in m_NeedToUnLoadResourcePackageTable)
            {
                ResourcePackage package = AllocResourcePackage(ins);

                if (!package.isUpLoadToLoadingThread)
                {
                    continue;
                }

                /*为了保证资源的加载顺序,只要有一个包没有加载完成,
                 * 就直接跳出本次检测,防止有的包加载完了,但是他依赖的包还没有加载完成
                 */
                if (package.isDone)
                {
                    LoadCompleteList.Add(ins);
                    AssetBundle pAssetBundle = package.fileRequest.assetBundle;
                    pAssetBundle.Unload(true);
                }
                else
                {
                    break;
                }
            }

            //移除已经加载完成的
            foreach (int s in LoadCompleteList)
            {
                RemoveAssetsFileProcessingList(s);
                m_NeedToUnLoadResourcePackageTable.Remove(s);
            }
        }
    }
Пример #26
0
        /// <summary>
        /// 上传
        /// </summary>
        /// <param name="localPathfile">本地全路径文件名</param>
        /// <param name="version"></param>
        /// <param name="group"></param>
        /// <param name="remark"></param>
        public void Upload(string localPathfile, string version = "", int group = 0, string remark = "")
        {
            try
            {
                string tempPathfile = Kits.GetTempPathfile(Kits.GetFilename(localPathfile));
                ResourcePackage.Package(localPathfile, tempPathfile);

                UploadDataItem ud = new UploadDataItem()
                {
                    Source  = tempPathfile,
                    Target  = _dc.GetRemotePathfile(localPathfile),
                    Version = version,
                    Group   = group,
                    Remark  = remark,
                    Tag     = localPathfile
                };
                _dc.Add(ud);
            }
            catch (IOException ioe)
            {
                Notified?.Invoke(CVReSubmitResult.SourceNotFound, ioe.Message);
            }
        }
Пример #27
0
    private static void UnLoadAllAssetBundle()
    {
        ClearPrefabRes();
        ClearAnimatorControllerRes();
        ClearFBXRes();
        ClearAnimationClipRes();
        ClearMaterialRes();
        ClearUIRes();
        ClearTexutreRes();
        ClearAudioRes();

        foreach (int id in m_LoadedResourcePackage)
        {
            ResourcePackage pkg = AllocResourcePackage(id);
            if (pkg.AssetBundleInstance)
            {
                pkg.AssetBundleInstance.Unload(true);
                pkg.AssetBundleInstance = null;
            }
        }

        ResNode.ClearWhenGameEnd();
        m_ResourcePackageRequestTable.Clear();
        m_NeedToUnLoadResourcePackageTable.Clear();
        m_ResWaitingForCallBack.Clear();

        m_LoadedResourcePackage.Clear();
        m_NeedToUnLoadList.Clear();
        m_LoadingAssetList.Clear();
        m_ReadyForUpLoadAssetsAsyncRequestTable.Clear();
        m_ResourcePackageWatingForCallBack.Clear();
        m_ProcessingAssetsFileAsyncRequestList.Clear();
        m_WaitForUpLoadAssetsFileAsyncRequestSet.Clear();
        currUpLoad_AssetsFile_AsyncRequestClipTime = 0.0f;
        ClearAssetFile();
    }
Пример #28
0
        // read one package
        private async Task <Pair <ResourcePackage, PackageHeader> > readPackage(PackageHeader packageHeader)
        {
            Pair <ResourcePackage, PackageHeader> pair = new Pair <ResourcePackage, PackageHeader>();
            //read packageHeader
            ResourcePackage resourcePackage = new ResourcePackage(packageHeader);

            pair.setLeft(resourcePackage); //= new Pair<ResourcePackage, PackageHeader>(resourcePackage, null);
            //pair. = resourcePackage; //.setLeft(resourcePackage);

            long beginPos = buffer.position();

            // read type string pool
            if (packageHeader.getTypeStrings() > 0)
            {
                buffer.position((int)(beginPos + packageHeader.getTypeStrings()
                                      - packageHeader.getHeaderSize()));
                resourcePackage.setTypeStringPool(await ParseUtils.readStringPool(buffer,
                                                                                  (StringPoolHeader)await readChunkHeader()));
            }

            //read key string pool
            if (packageHeader.getKeyStrings() > 0)
            {
                buffer.position((int)(beginPos + packageHeader.getKeyStrings()
                                      - packageHeader.getHeaderSize()));
                resourcePackage.setKeyStringPool(await ParseUtils.readStringPool(buffer,
                                                                                 (StringPoolHeader)await readChunkHeader()));
            }


            //outer:
            while (buffer.hasRemaining())
            {
                ChunkHeader chunkHeader = await readChunkHeader();

                long chunkBegin = buffer.position();
                switch (chunkHeader.getChunkType())
                {
                case ChunkType.TABLE_TYPE_SPEC:
                    TypeSpecHeader typeSpecHeader = (TypeSpecHeader)chunkHeader;
                    long[]         entryFlags     = new long[(int)typeSpecHeader.getEntryCount()];
                    for (int i = 0; i < typeSpecHeader.getEntryCount(); i++)
                    {
                        entryFlags[i] = Buffers.readUInt(buffer);
                    }

                    TypeSpec typeSpec = new TypeSpec(typeSpecHeader);


                    typeSpec.setEntryFlags(entryFlags);
                    //id start from 1
                    typeSpec.setName(resourcePackage.getTypeStringPool()
                                     .get(typeSpecHeader.getId() - 1));

                    resourcePackage.addTypeSpec(typeSpec);
                    buffer.position((int)(chunkBegin + typeSpecHeader.getBodySize()));
                    break;

                case ChunkType.TABLE_TYPE:
                    TypeHeader typeHeader = (TypeHeader)chunkHeader;
                    // read offsets table
                    long[] offsets = new long[(int)typeHeader.getEntryCount()];
                    for (int i = 0; i < typeHeader.getEntryCount(); i++)
                    {
                        offsets[i] = Buffers.readUInt(buffer);
                    }

                    RType type = new RType(typeHeader);
                    type.setName(resourcePackage.getTypeStringPool().get(typeHeader.getId() - 1));
                    long entryPos = chunkBegin + typeHeader.getEntriesStart() - typeHeader.getHeaderSize();
                    buffer.position((int)entryPos);
                    ByteBuffer b = await buffer.slice();

                    await b.order(byteOrder);

                    type.setBuffer(b);
                    type.setKeyStringPool(resourcePackage.getKeyStringPool());
                    type.setOffsets(offsets);
                    type.setStringPool(stringPool);
                    resourcePackage.addType(type);
                    locales.Add(type.getLocale());
                    buffer.position((int)(chunkBegin + typeHeader.getBodySize()));
                    break;

                case ChunkType.TABLE_PACKAGE:
                    // another package. we should read next package here
                    //pair = new Pair<ResourcePackage, PackageHeader>(pair.Key, (PackageHeader)chunkHeader);
                    pair.setRight((PackageHeader)chunkHeader);
                    //break outer;
                    return(pair);

                case ChunkType.TABLE_LIBRARY:
                    // read entries
                    LibraryHeader libraryHeader = (LibraryHeader)chunkHeader;
                    for (long i = 0; i < libraryHeader.getCount(); i++)
                    {
                        int    packageId = buffer.getInt();
                        string name      = await Buffers.readZeroTerminatedString(buffer, 128);

                        LibraryEntry entry = new LibraryEntry(packageId, name);
                        //TODO: now just skip it..
                    }
                    buffer.position((int)(chunkBegin + chunkHeader.getBodySize()));
                    break;

                default:
                    throw new Exception("unexpected chunk type: 0x" + chunkHeader.getChunkType());
                }
            }

            return(pair);
        }
Пример #29
0
        public ResourcePackage Import(string path, string agencyId)
        {
            this.harmonizingCache = new HarmonizingCache(MultilingualString.CurrentCulture);

            var resourcePackage = new ResourcePackage();

            resourcePackage.AgencyId = agencyId;

            logger.Debug("Importing RData");

            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("fileName");
            }
            if (!File.Exists(path))
            {
                throw new ArgumentException("The specified file must exist");
            }

            string fileNameWithExtension = Path.GetFileName(path);
            string fileNameOnly          = Path.GetFileNameWithoutExtension(path);

            logger.Debug("RData import file: " + fileNameOnly);


            resourcePackage.DublinCoreMetadata.Title.Current = fileNameOnly;

            // Create the PhysicalInstance.
            var physicalInstance = new PhysicalInstance()
            {
                AgencyId = agencyId
            };

            resourcePackage.PhysicalInstances.Add(physicalInstance);
            physicalInstance.DublinCoreMetadata.Title.Current = fileNameOnly;

            // File location
            if (path != null)
            {
                DataFileIdentification fileID = new DataFileIdentification();
                Uri uri;
                if (Uri.TryCreate(path, UriKind.RelativeOrAbsolute, out uri))
                {
                    fileID.Uri = uri;
                }
                fileID.Path = path;

                physicalInstance.FileIdentifications.Add(fileID);
            }

            // Create the DataRelationship.
            var dataRelationship = new DataRelationship();

            physicalInstance.DataRelationships.Add(dataRelationship);
            dataRelationship.AgencyId      = agencyId;
            dataRelationship.Label.Current = fileNameOnly;

            // Load the file into R.
            string pathForR = path.Replace("\\", "/");

            engine.Evaluate(string.Format("load('{0}')", pathForR));


            // Find all the data frames.
            var dataFrames = GetDataFrames();

            // For each data frame in the RData file, create a LogicalRecord.
            foreach (var pair in dataFrames)
            {
                string name      = pair.Key;
                var    dataFrame = pair.Value;

                // TODO This should be tracked per record, not PhysicalInstance.
                physicalInstance.FileStructure.CaseQuantity = dataFrame.RowCount;

                var logicalRecord = new LogicalRecord()
                {
                    AgencyId = agencyId
                };
                dataRelationship.LogicalRecords.Add(logicalRecord);
                logicalRecord.Label.Current = name;

                List <string> variableLabels     = null;
                var           variableLabelsExpr = dataFrame.GetAttribute("var.labels");
                if (variableLabelsExpr != null)
                {
                    var labelVector = variableLabelsExpr.AsVector();
                    variableLabels = new List <string>(labelVector.Select(x => (string)x));
                }

                for (int i = 0; i < dataFrame.ColumnCount; i++)
                {
                    string columnName = dataFrame.ColumnNames[i];
                    var    column     = dataFrame[i];

                    var variable = new Variable()
                    {
                        AgencyId = agencyId
                    };
                    logicalRecord.VariablesInRecord.Add(variable);

                    // Name
                    variable.ItemName.Current = columnName;

                    // Label
                    if (variableLabels != null)
                    {
                        variable.Label.Current = variableLabels[i];
                    }

                    // Type
                    if (column.Type == RDotNet.Internals.SymbolicExpressionType.NumericVector)
                    {
                        variable.RepresentationType = RepresentationType.Numeric;
                        variable.Additivity         = AdditivityType.Stock;
                    }
                    else if (column.Type == RDotNet.Internals.SymbolicExpressionType.IntegerVector)
                    {
                        if (column.IsFactor())
                        {
                            variable.RepresentationType = RepresentationType.Code;

                            string[] factors = column.AsFactor().GetLevels();
                            variable.CodeRepresentation.Codes = GetCodeList(factors, agencyId, resourcePackage);
                        }
                        else
                        {
                            variable.RepresentationType = RepresentationType.Numeric;
                            variable.NumericRepresentation.NumericType = NumericType.Integer;
                            variable.Additivity = AdditivityType.Stock;
                        }
                    }
                    else if (column.Type == RDotNet.Internals.SymbolicExpressionType.CharacterVector)
                    {
                        variable.RepresentationType = RepresentationType.Text;
                    }
                }
            }

            return(resourcePackage);
        }
Пример #30
0
    private static void BuildPrefabWhenInAsyncLoading(ref ResNode res, UnionResConfigData config)
    {
        //先检查
        if (null == res)
        {
            return;
        }

        if (!isOnRunTimeMode)
        {
            return;
        }

        if (!res.isAsync)
        {
            return;
        }

        if (res.isLoadFinish)
        {
            return;
        }

        res.StartLoadedTime();
        //先从回调列表里移除
        if (m_AsyncLoadingDependicensPrefabResNode.ContainsKey(res.instanceID))
        {
            m_AsyncLoadingDependicensPrefabResNode.Remove(res.instanceID);
        }
        //卸载依赖
        UnLoadDependenicesAsync(res.instanceID);

        //开始加载依赖
        if (LoadDependenices(config))
        {
            ResourcePackage pkg = null;

            pkg = GetResourcePackge(config);

            if (null != pkg)
            {
                LoadAssetFromAssetBundle <GameObject>(ref res, config, pkg.AssetBundleInstance);
            }
            else
            {
                AssetBudleLog("加载AssetBundle失败:" + config.AssetBundleName);
            }

            if (!res.IsValid())
            {
                UnLoadDependenices(res.instanceID);
            }
        }
        else
        {
            UnLoadDependenices(res.instanceID);
        }

        res.status = ResNodeStatus.LoadFinish;
        m_PrefabResTable.Add(res.instanceID, res);

        //取出回调列表
        List <AsyncLoadingObject> list = null;

        if (m_PrefabRequestTable.TryGetValue(res.instanceID, out list))
        {
            ReleaseDependenicesAssetBundleIfNeed(res);
            ReleaseAssetBundleIfNeed(res);
            m_PrefabRequestTable.Remove(res.instanceID);

            foreach (AsyncLoadingObject obj in list)
            {
                PushToResDelayCallBackList(res, config, obj.callBack, obj.UserDataObj);
            }
        }


        return;
    }
        public void CompareWithRepository()
        {
            var client = Utility.GetClient();

            var facet = new SearchFacet()
            {
                SearchLatestVersion = true
            };

            facet.ItemTypes.Add(DdiItemType.StudyUnit);
            var response = client.Search(facet);

            foreach (var result in response.Results)
            {
                var su = client.GetItem(
                    result.CompositeId,
                    ChildReferenceProcessing.PopulateLatest) as StudyUnit;
                foreach (var dc in su.DataCollections)
                {
                    try
                    {
                        var scope = scopes[dc.ItemName.Best];
                        scope.su = su;
                        scope.rp = su.ResourcePackages.Where(x => x.ItemName.Best == dc.ItemName.Best).FirstOrDefault();
                    } catch (KeyNotFoundException)
                    {
                    }
                }
            }

            foreach (var scope in scopes)
            {
                if (scope.Value.rp != default(ResourcePackage))
                {
                    continue;
                }

                var wsRps = workingSet.OfType <ResourcePackage>().Where(x => string.Compare(
                                                                            x.DublinCoreMetadata.Title.Best, scope.Value.name
                                                                            ) == 0
                                                                        );
                if (wsRps.Any())
                {
                    scope.Value.rp = wsRps.First();
                    var bubbleOut = false;
                    foreach (var g in workingSet.OfType <Algenta.Colectica.Model.Ddi.Group>())
                    {
                        foreach (var su in g.StudyUnits)
                        {
                            if (su.DataCollections.Count(x => x.ItemName.Best == scope.Key) > 0)
                            {
                                scope.Value.su = su;
                                var gatherer = new ItemGathererVisitor();
                                g.Accept(gatherer);
                                toBeAdded.AddRange(gatherer.FoundItems);
                                bubbleOut = true;
                            }
                            if (bubbleOut)
                            {
                                break;
                            }
                        }
                        if (bubbleOut)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    var rp = new ResourcePackage();
                    rp.DublinCoreMetadata.Title["en-GB"] = scope.Key;
                    scope.Value.su.AddChild(rp);
                    toBeAdded.Add(scope.Value.su);
                    rp.AddChild(scope.Value.su.DataCollections.First(x => x.ItemName.Best == scope.Key));
                    scope.Value.rp = rp;
                }
            }

            var ccgs = workingSet.OfType <ControlConstructGroup>();

            if (ccgs.Count() > 1)
            {
                facet.ItemTypes.Clear();
                facet.SearchTargets.Clear();
                facet.ItemTypes.Add(DdiItemType.QuestionConstruct);
                facet.SearchTargets.Add(DdiStringType.UserId);
                foreach (var ccg in ccgs)
                {
                    var qcs = ccg.GetChildren().OfType <QuestionActivity>().ToList();
                    foreach (var qc in ccg.GetChildren().OfType <QuestionActivity>())
                    {
                        facet.SearchTerms.Clear();
                        facet.SearchTerms.Add(qc.UserIds.First().Identifier);

                        response = client.Search(facet);
                        if (response.Results.Count > 1)
                        {
                            Console.WriteLine("{0} question constrcuts found during CCG syncing for the question '{1}'", response.Results.Count, qc.UserIds.First().Identifier);
                        }
                        else if (response.Results.Count < 1)
                        {
                            Console.WriteLine("No question constructs were found for the CCG syncing matching '{0}'", qc.UserIds.First().Identifier);
                        }
                        else
                        {
                            var remote_qc = client.GetItem(response.Results.First().CompositeId) as IVersionable;
                            if (remote_qc != default(IVersionable))
                            {
                                ccg.ReplaceChild(qc.CompositeId, remote_qc);
                            }
                        }
                    }
                }
            }

            var vgs = workingSet.OfType <VariableGroup>();

            if (vgs.Count() > 0)
            {
                facet.ItemTypes.Clear();
                facet.ItemTypes.Add(DdiItemType.Variable);
                foreach (var vg in vgs)
                {
                    foreach (var variable in vg.GetChildren().OfType <Variable>())
                    {
                        facet.SearchTerms.Clear();
                        facet.SearchTargets.Clear();
                        bool closer_id_found = false;
                        foreach (var user_id in variable.UserIds)
                        {
                            if (user_id.Type == "closer:id")
                            {
                                closer_id_found = true;
                                facet.SearchTerms.Add(user_id.Identifier);
                                facet.SearchTargets.Add(DdiStringType.UserId);
                                break;
                            }
                        }
                        if (!closer_id_found)
                        {
                            facet.SearchTerms.Add(variable.ItemName.Best);
                            facet.SearchTargets.Add(DdiStringType.Name);
                        }
                        response = client.Search(facet);
                        if (response.Results.Count > 1)
                        {
                            Console.WriteLine("{0} variables found during variable group syncing for the variable '{1}:{2}'", response.Results.Count, name, variable.ItemName.Best);
                        }
                        else if (response.Results.Count < 1)
                        {
                            Console.WriteLine("No variables were found for the variable grouping syncing matching '{0}:{1}'", name, variable.ItemName.Best);
                        }
                        else
                        {
                            var remote_variable = client.GetItem(response.Results.First().CompositeId) as IVersionable;
                            if (remote_variable != default(IVersionable))
                            {
                                vg.ReplaceChild(variable.CompositeId, remote_variable);
                            }
                        }
                    }
                }
            }

            var progress = new ParallelProgressMonitor(scopes.Count);

            Parallel.ForEach <KeyValuePair <string, Scope> >(scopes, scope =>
            {
                string text = String.Format("{0}: Comparing {1}", name, scope.Value.name);
                progress.StartThread(
                    Thread.CurrentThread.ManagedThreadId,
                    text
                    );
                scope.Value.Compare();
                progress.FinishThread(
                    Thread.CurrentThread.ManagedThreadId,
                    text.PadRight(40, '-') +
                    "> done." +
                    String.Format("{0} compared.", scope.Value.counter[Counters.Compared]).PadLeft(16) +
                    String.Format("{0} updated.", scope.Value.counter[Counters.Updated]).PadLeft(16) +
                    String.Format("{0} added.", scope.Value.counter[Counters.Added]).PadLeft(16) +
                    String.Format("{0} removed.", scope.Value.counter[Counters.Removed]).PadLeft(16)
                    );
            });
        }
Пример #32
0
        void InitializeDdiElements()
        {
            resourcePackage = new ResourcePackage();
            resourcePackage.DublinCoreMetadata.Title["en"] = "ISCO Classification";
            resourcePackage.Abstract.Strings["en"] = "Not specified";
            resourcePackage.Purpose.Strings["en"] = "Not specified";

            categoryScheme = new CategoryScheme();
            categoryScheme.Label["en"] = "ISCO Categories";

            codeScheme = new CodeScheme();
            codeScheme.Label["en"] = "ISCO Codes";

            resourcePackage.CategorySchemes.Add(categoryScheme);
            resourcePackage.CodeSchemes.Add(codeScheme);

            instance = new DdiInstance();
            instance.ResourcePackages.Add(resourcePackage);
        }
Пример #33
0
        /// <summary>
        /// This method builds up a DdiInstance and writes it to a 
        /// valid DDI 3.1. XML file.
        /// </summary>
        public void BuildSomeDdiAndWriteToXml()
        {
            // It is helpful to set some default properties before
            // working with the SDK's model. These two properties
            // determine the default language and agency identifier
            // for every item.
            MultilingualString.CurrentCulture = "en-US";
            VersionableBase.DefaultAgencyId = "example.org";

            // Start out by creating a new DDIInstance.
            // The DdiInstance can hold StudyUnits, Groups, and ResourcePackages.
            DdiInstance instance = new DdiInstance();
            Instance = instance;
            instance.DublinCoreMetadata.Title.Current = "My First Instance";

            // Since we set the CurrentCulture to "en-US", that last line is
            // equivalent to this next one.
            instance.DublinCoreMetadata.Title["en-US"] = "My First Instance";

            // We can set multiple languages, if we want to.
            instance.DublinCoreMetadata.Title["fr"] = "TODO";

            // Add a ResourcePackage to the DdiInstance. There are three things to do.
            // 1. First, create it.
            // 2. Then, set whatever properties you like. Here, we just set the Title.
            // 3. Add the item to it's parent. In this case, that's the DdiInstance.
            ResourcePackage resourcePackage = new ResourcePackage();
            resourcePackage.DublinCoreMetadata.Title.Current = "RP1";
            instance.AddChild(resourcePackage);

            // Now let's add a ConceptScheme to the ResourcePackage. We'll do this
            // using the same three steps we used to create the ResourcePackage.
            ConceptScheme conceptScheme = new ConceptScheme();
            conceptScheme.ItemName.Current = "My Concepts";
            conceptScheme.Description.Current = "Just some concepts for testing.";
            resourcePackage.AddChild(conceptScheme);

            // Let's add some Concepts to the ConceptScheme.
            string[] conceptLabels = { "Pet", "Dog", "Cat", "Bird", "Fish", "Monkey" };
            foreach (string label in conceptLabels)
            {
                // Again, for each Concept we create, we want to perform the
                // same three steps as above:
                // 1. instantiate, 2. assign properties, 3. add to parent.
                Concept concept = new Concept();
                concept.Label.Current = label;
                conceptScheme.AddChild(concept);
            }

            // Let's create a collection of questions.
            QuestionScheme questionScheme = new QuestionScheme();
            questionScheme.ItemName.Current = "Sample Questions";
            resourcePackage.QuestionSchemes.Add(questionScheme);

            // First, we can ask for a name. This will just collect textual data.
            Question q1 = new Question();
            q1.QuestionText.Current = "What is your name?";
            q1.ResponseDomains.Add(new TextDomain());
            questionScheme.Questions.Add(q1);

            // Next, we can ask what method of transportation somebody used to get to Minneapolis.
            Question transportationQuestion = new Question();
            transportationQuestion.QuestionText.Current = "How did you get to Minneapolis?";

            // For this question, the respondent will choose from a list of answers.
            // Let's make that list.
            CategoryScheme catScheme = new CategoryScheme();
            resourcePackage.CategorySchemes.Add(catScheme);

            var codeScheme = new CodeList();
            resourcePackage.CodeSchemes.Add(codeScheme);

            // Add the first category and code: Airplane
            Category airplaneCategory = new Category();
            airplaneCategory.Label.Current = "Airplane";
            Code airplaneCode = new Code
            {
                Value = "0",
                Category = airplaneCategory
            };
            catScheme.Categories.Add(airplaneCategory);
            codeScheme.Codes.Add(airplaneCode);

            // Car
            Category carCategory = new Category();
            carCategory.ItemName.Current = "Car";
            Code carCode = new Code
            {
                Value = "1",
                Category = carCategory
            };
            catScheme.Categories.Add(carCategory);
            codeScheme.Codes.Add(carCode);

            // Train
            Category trainCategory = new Category();
            trainCategory.ItemName.Current = "Train";
            Code trainCode = new Code
            {
                Value = "2",
                Category = trainCategory
            };
            catScheme.Categories.Add(trainCategory);
            codeScheme.Codes.Add(trainCode);

            // Now that we have a Category and CodeScheme, we can create
            // a CodeDomain and assign this as the type of data the transportation
            // question will collect.
            CodeDomain codeDomain = new CodeDomain();
            codeDomain.Codes = codeScheme;
            transportationQuestion.ResponseDomains.Add(codeDomain);
            questionScheme.Questions.Add(transportationQuestion);

            // We have created a DdiInstance, a ResourcePackage, some concepts,
            // and some questions.
            //
            // Now what?
            //
            // Let's save all this to a DDI 3.1 XML file.
            //
            // First, we can call EnsureCompliance to make sure
            // our objects have all fields that are required
            // by the DDI 3.1 schemas. If we missed anything,
            // this method will fill in some defaults for us.
            DDIWorkflowSerializer.EnsureCompliance(instance);

            // Now, create the serializer object that will save our items to XML.
            // Setting UseConciseBoundedDescription to false makes sure we
            // write every item, and not just references to items.
            DDIWorkflowSerializer serializer = new DDIWorkflowSerializer();
            serializer.UseConciseBoundedDescription = false;

            // Getting a valid XML representation of our model is just one method call.
            XmlDocument xmlDoc = serializer.Serialize(instance);

            // Finally, save the XML document to a file.
            xmlDoc.Save("sample.xml");
        }