private void WriteDomainCollectionToDTOCollection(IEntity entity) { cw.WriteLine("protected {0} {1}", NamingHelperStack.ToDTOCollectionTypeName(entity, interfacesEnvironment), ToMethodSignature_DomainCollectionToDTO(entity)); cw.BeginScope(); cw.WriteLine("{0} {1} = new {0}();", NamingHelperStack.ToDTOCollectionTypeName(entity, interfacesEnvironment), VarName_DTOCollection); cw.WriteLine("foreach({0} {1} in {2})", domainEnvironment.ToTypeName(entity, true), VarName_DomainObject, VarName_DomainCollection); cw.BeginScope(); cw.WriteLine("{0} {1} = new {0}();", NamingHelperStack.ToDTOTypeName(entity, interfacesEnvironment), VarName_DTO); cw.WriteLine("{0}.{1}({2}, {3});", NamingHelperStack.ToServiceName(entity, null), MethodName_DomainObjectToDTO, VarName_DomainObject, VarName_DTO); cw.WriteLine("{0}.Add({1});", VarName_DTOCollection, VarName_DTO); cw.EndScope(); cw.WriteLine("return {0};", VarName_DTOCollection); cw.EndScope(); }
private void WriteCollectionPesponse(IEntity entity) { cw.WriteLine("[DataContract]"); cw.BeginClass(AccessLevel.Public, true, NamingHelperStack.ToServiceResponseCollectionName(entity, null), Const.EmptyName); intfh.WriteProperty(NamingHelperStack.ToDTOCollectionTypeName(entity, null), NamingHelperStack.ToDTOCollectionPropertyName(entity)); intfh.WriteProperty("ResponseStatus", "ResponseStatus"); cw.WriteLine(); cw.BeginRegion("Constructors"); cw.WriteLine("public {0}()", NamingHelperStack.ToServiceResponseCollectionName(entity, null)); cw.BeginScope(); cw.WriteLine("this.ResponseStatus = new ResponseStatus();"); cw.WriteLine("this.{0} = new {1}();", NamingHelperStack.ToDTOCollectionPropertyName(entity), NamingHelperStack.ToDTOCollectionTypeName(entity, null)); cw.EndScope(); cw.EndRegion(); cw.EndClass(); }
private void WriteEntityDTOAdapterCollection(IEntity entity) { string baseClass = String.Format("{0}<{1}", entity.Persistence.Persisted ? ClassName_PersistentDTOAdapterCollection : ClassName_DTOAdapterCollection, NamingHelperStack.ToDTOAdapterTypeName(entity, environment)); if (entity.Persistence.Persisted) { baseClass += ", " + NamingHelper.ToDTOTypeName(entity, dtoEnvironment) + ">"; } else { baseClass += ">"; } cw.BeginClass(AccessLevel.Public, true, NamingHelperStack.ToDTOAdapterCollectionTypeName(entity, null), baseClass); cw.BeginRegion("Constructors"); cw.BeginFunction("public {0} ()", NamingHelperStack.ToDTOAdapterCollectionTypeName(entity, null)); cw.EndFunction(); cw.BeginFunction("public {0} ({1} {2})", NamingHelperStack.ToDTOAdapterCollectionTypeName(entity, null), NamingHelperStack.ToDTOCollectionTypeName(entity, dtoEnvironment), VarName_DTOCollection); cw.WriteLine("foreach ({0} {1} in {2})", NamingHelper.ToDTOTypeName(entity, dtoEnvironment), VarName_DTO, VarName_DTOCollection); cw.BeginScope(); cw.WriteLine("this.InternalAdd(new {0}({1}));", NamingHelperStack.ToDTOAdapterTypeName(entity, environment), VarName_DTO); cw.EndScope(); cw.EndFunction(); cw.EndRegion(); cw.WriteLine(); // Get page // cw.BeginFunction("public static {0} {1}(int pageNum = 0, int pageSize = 20)", // NamingHelperStack.ToDTOAdapterCollectionTypeName(entity, null), // MethodName_GetPage); // cw.WriteLine("return null;"); // cw.EndFunction(); // cw.WriteLine(); // Get by query cw.BeginFunction("public static {0} {1}(string query, {2}.{3} queryParams, int pageNum = 0, int pageSize = {4})", NamingHelperStack.ToDTOAdapterCollectionTypeName(entity, null), MethodName_GetByQuery, interfacesEnvironment.BaseNamespace, NamingHelper.ClassName_ServicesQueryParams, RestServiceHelper.MaxPageSize); cw.WriteLine("{0} request = new {0}();", NamingHelperStack.ToServiceRequestName(entity, interfacesEnvironment)); cw.WriteLine("request.{0} = query;", NamingHelperStack.ParamName_Query); cw.WriteLine("request.{0} = queryParams;", NamingHelperStack.ParamName_QueryParams); cw.WriteLine("request.{0} = pageNum;", NamingHelperStack.ParamName_PageNumber); cw.WriteLine("request.{0} = pageSize;", NamingHelperStack.ParamName_PageSize); cw.WriteLine("{0} {1} =", NamingHelperStack.ToServiceResponseCollectionName(entity, interfacesEnvironment), VarName_Response); cw.Indent++; cw.WriteLine("WebClientFactory.GetJsonClient()"); cw.WriteLine(".Post<{0}>(\"/{1}\", request);", NamingHelperStack.ToServiceResponseCollectionName(entity, interfacesEnvironment), NamingHelperStack.ToServiceName(entity, null)); cw.Indent--; cw.WriteLine("WebClientFactory.CheckResponseStatus({0}.ResponseStatus);", VarName_Response); cw.WriteLine("return new {0}({1}.{2});", NamingHelperStack.ToDTOAdapterCollectionTypeName(entity, null), VarName_Response, NamingHelperStack.ToDTOCollectionPropertyName(entity)); cw.EndFunction(); cw.WriteLine(); // Get by relations foreach (IRelation r in entity.Parents) { cw.BeginFunction("public static {0} {1}", NamingHelperStack.ToDTOAdapterCollectionTypeName(entity, null), ServicesLayerConfig.Methods.GetByRelationParent(r, interfacesEnvironment).Signature); cw.WriteLine("{0} request = new {0}();", NamingHelperStack.ToServiceRequestName(entity, interfacesEnvironment)); cw.WriteLine("{0} {1} = WebClientFactory.GetJsonClient()", NamingHelperStack.ToServiceResponseCollectionName(entity, interfacesEnvironment), VarName_Response); cw.Indent++; cw.WriteLine(".Get<{0}>(String.Format(\"/{1}/{2}\", {3}));", NamingHelperStack.ToServiceResponseCollectionName(entity, interfacesEnvironment), NamingHelperStack.ToServiceName(entity, null), cw.ToSeparatedString(r.ChildAttributes.ToList(), "/", delegate(object item, int count) { return(String.Format("{0}/{{{1}}}", (item as IAttribute).Name, count)); }), environment.ToArguments(r.ChildAttributes) ); cw.Indent--; cw.WriteLine("WebClientFactory.CheckResponseStatus({0}.ResponseStatus);", VarName_Response); cw.WriteLine("return new {0}({1}.{2});", NamingHelperStack.ToDTOAdapterCollectionTypeName(entity, null), VarName_Response, NamingHelperStack.ToDTOCollectionPropertyName(entity)); cw.EndFunction(); cw.WriteLine(); } cw.EndClass(); }