Пример #1
0
        /// <summary>
        /// 异步加载组件
        /// </summary>
        /// <param name="model"></param>
        /// <param name="p_model"></param>
        /// <returns></returns>
        public static Task <Dictionary <string, SkpComponent> > GetComponentsAsync(SUModelRef model, SkpModel p_model)
        {
            TaskCompletionSource <Dictionary <string, SkpComponent> > tcs = new TaskCompletionSource <Dictionary <string, SkpComponent> >();

            Task.Run(() =>
            {
                long componentsCount = 0;
                SKPCExport.SUModelGetNumComponentDefinitions(model, ref componentsCount);

                if (componentsCount > 0)
                {
                    SUComponentDefinitionRef[] componentRefs = new SUComponentDefinitionRef[componentsCount];
                    SKPCExport.SUModelGetComponentDefinitions(model, componentsCount, componentRefs, ref componentsCount);

                    TaskExcutor.Run <SkpComponent, SUComponentDefinitionRef>(componentRefs, c =>
                    {
                        SkpComponent component = new SkpComponent(p_model);
                        component.Load(c);
                        return(component);
                    }).ContinueWith(t =>
                    {
                        if (t.IsFaulted)
                        {
                            tcs.TrySetException(t.Exception);
                        }
                        else
                        {
                            Dictionary <string, SkpComponent> components = t.Result.ToDictionary(p => p.Identity, p => p);
                            tcs.TrySetResult(components);
                        }
                    });
                }
                else
                {
                    tcs.TrySetResult(new Dictionary <string, SkpComponent>());
                }
            });

            return(tcs.Task);
        }
Пример #2
0
        public static Dictionary <string, SkpComponent> GetComponents(SUModelRef model, SkpModel p_model)
        {
            Dictionary <string, SkpComponent> components = new Dictionary <string, SkpComponent>(200);

            long componentsCount = 0;

            SKPCExport.SUModelGetNumComponentDefinitions(model, ref componentsCount);

            if (componentsCount > 0)
            {
                SUComponentDefinitionRef[] componentRefs = new SUComponentDefinitionRef[componentsCount];
                SKPCExport.SUModelGetComponentDefinitions(model, componentsCount, componentRefs, ref componentsCount);

                for (long i = 0; i < componentsCount; i++)
                {
                    SkpComponent component = new SkpComponent(p_model);
                    component.Load(componentRefs[i]);
                    components.Add(component.Identity, component);
                }
            }

            return(components);
        }