public ObjectViewModel Build(CachedObject cachedObject)
        {
            IDictionary<string, DataSourceViewModel> dataSourceInstances = new Dictionary<string, DataSourceViewModel>();

              if (!string.IsNullOrEmpty(cachedObject.CachedDataSources))
              {
            foreach (CachedDataSource cachedDataSource in JsonConvert.DeserializeObject<IEnumerable<CachedDataSource>>(cachedObject.CachedDataSources))
            {
              System.Type type = System.Type.GetType(cachedDataSource.CSharpClassName);
              IDataSource dataSourceInstance = System.Activator.CreateInstance(type) as IDataSource;

              dataSourceInstance.Initialize(this.handler, cachedObject, this.GetParameters(cachedDataSource.Parameters));
              dataSourceInstances.Add(cachedDataSource.Code, new DataSourceViewModelBuilder(this.handler).Build(dataSourceInstance.GetCachedObjects()));
            }
              }

              IEnumerable<CachedProperty> cachedProperties = JsonConvert.DeserializeObject<IEnumerable<CachedProperty>>(cachedObject.CachedProperties);

              return new ObjectViewModel()
              {
            Id = cachedObject.ObjectId,
            Class = new ClassViewModelBuilder(this.handler).Build(cachedObject.ClassId, cachedObject.ClassViewName),
            Url = cachedObject.Url,
            Properties = cachedProperties.ToDictionary(
              cp => cp.MemberCode,
              cp => new PropertyViewModelBuilder(this.handler).Build(cp)
            ),
            DataSources = dataSourceInstances
              };
        }
示例#2
0
 public void Initialize(IHandler handler, CachedObject cachedObject, params KeyValuePair<string, string>[] args)
 {
     this.handler = handler;
       this.cachedObject = cachedObject;
       this.args = args.ToDictionary(a => a.Key, a => a.Value);
 }