Here is the thing, I have a problem creating a new object using the remote mechanism "marshal by value".
Here is my class:
[Serializable]
internal class Empleado_MBV
{
public Empleado_MBV()
{
Id = 123456789;
Nombres = "NotEntry";
Apellidos = "NotEntry";
FechaNacimiento = DateTime.MinValue;
Direccion = "NotEntry";
Metapreferencias = "NotEntry";
}
private List<Multas> _multas;
internal List<Multas> Multas
{
get { return _multas; }
set { _multas = value; }
}
private int _id;
public int Id
{
get { return _id; }
set { _id = value; }
}
private string _nombres;
public string Nombres
{
get { return _nombres; }
set { _nombres = value; }
}
private string _apellidos;
public string Apellidos
{
get { return _apellidos; }
set { _apellidos = value; }
}
private DateTime _FecNac;
public DateTime FechaNacimiento
{
get { return _FecNac; }
set { _FecNac = value; }
}
private string _direccion;
public string Direccion
{
get { return _direccion; }
set { _direccion = value; }
}
private string _metapreferencias;
public string Metapreferencias
{
get { return _metapreferencias; }
set { _metapreferencias = value; }
}
public string _AppDomainHost
{
get { return AppDomain.CurrentDomain.FriendlyName.ToString(); }
}
}
But when I try to create an object in another "appdomain", the property "_AppDomainHost" of "Empleado" does not show the "appdomain" I had created, but show the "appdomain" by default. Some ideas?
AppDomain ad1 = AppDomain.CreateDomain("NewAppDomain");
//Crear new object in my new AD.
Empleado_MBV mbv_emp = (Empleado_MBV)ad1.CreateInstanceFromAndUnwrap("DEMO_MBV_MBR.exe", "DEMO_MBV_MBR.Empleado_MBV");
Console.WriteLine(AppDomain.CurrentDomain.FriendlyName.ToString());
Console.WriteLine("MBV : {0}",mbv_emp._AppDomainHost.ToString());
Console.ReadLine();
Result:
DEMO_MBV_MBR.vshost.exe
MBV : DEMO_MBV_MBR.vshost.exe
The result that I want:
DEMO_MBV_MBR.vshost.exe
MBV : NewAppDomain
You need to store AppDomain in Empleado_MBV's constructor.
What you are doing right now is displaying current AppDomain using its Current static property. It will return the AppDomain where current code is being executed.
Example:
private string _appDomainHost;
public string _AppDomainHost
{
get { return _appDomainHost; }
}
and in constructor:
_appDomainHost = AppDomain.CurrentDomain.FriendlyName.ToString();
Related
I'm using reflection to order by list of objects.
I would like to order this list on a property of a nested object.
This is the code in which I get the list, and I do the sorting of the list
List<DocumentModel> documentList;
if (contractid == -1)
documentList = helpsi.framework.core.CustomerProvider.DocumentModel.getAllDocumentModelListByCustomer(custid, custtypeid);
else
documentList = helpsi.framework.core.CustomerProvider.DocumentModel.getAllDocumentModelListGridByContract(contractid);
if (sord.Equals("asc")) documentList = documentList.OrderBy(x => x.GetType().GetProperty(sidx.ToUpper()).GetValue(x, null)).ToList();
else documentList = documentList.OrderByDescending(x => x.GetType().GetProperty(sidx.ToUpper()).GetValue(x, null)).ToList();
The DocumentModel object has a DocumentModelType property that contains a DocumentStateDesc string property.
Can I sort the list by the DocumentTypeDesc property using reflection? What can I use in the sidx parameter?
Thanks
This is the DocumentModel class
public class DocumentModel : ObjBase
{
#region Attributi
private long _id;
private string _documentModel;
private long? _documentModelTypeId;
private long? _documentModelIssuingEntityId;
private string _documentModelFilename;
private string _documentModelPath;
private DateTime? _documentModelStart;
private DateTime? _documentModelEnd;
private string _documentModelVersion;
private long _contractId;
private string _contractNumber;
private long _contractTypeId;
private long _contractStateId;
private string _contractState;
private long _documentModelStateId;
private string _documentModelValoId;
private DateTime? _documentModelUploadDate;
private byte[] _documentModelContent;
private long _documentModelFilter;
private bool _flagDeleted;
private long _userId;
private int _orderDocumentModel = 0;
private string _placeOfIssue;
private string _issuingEntity;
private DateTime? _releaseDate;
private int? _idOpInsert;
private int? _idOpId;
private long? _customerId;
private long? _customerTypeId;
private string _customerNumber;
private DateTime? _documentModelInvalidated;
private bool _flagValidating;
private string _fileRemotePath;
private long? _folderId;
private string _folderName;
protected new HELPSI_Database HELPSI_Database = Common.HELPSI_Database.HELPSI_Anag;
[XmlElement(ElementName = "CODE_DOCUMENT_MODEL_ID")]
public long CODE_DOCUMENT_MODEL_ID
{
get { return _id; }
set { _id = value; }
}
[XmlElement(ElementName = "DESC_DOCUMENT_MODEL")]
public string DESC_DOCUMENT_MODEL
{
get { return _documentModel; }
set { _documentModel = value; }
}
[XmlElement(ElementName = "CODE_DOCUMENT_MODEL_TYPE_ID")]
public long? CODE_DOCUMENT_MODEL_TYPE_ID
{
get { return _documentModelTypeId; }
set { _documentModelTypeId = value; }
}
[XmlElement(ElementName = "CODE_DOCUMENT_MODEL_ISSUING_ENTITY_ID")]
public long? CODE_DOCUMENT_MODEL_ISSUING_ENTITY_ID
{
get { return _documentModelIssuingEntityId; }
set { _documentModelIssuingEntityId = value; }
}
[XmlElement(ElementName = "DESC_DOCUMENT_MODEL_FILENAME", IsNullable = true)]
public string DESC_DOCUMENT_MODEL_FILENAME
{
get { return _documentModelFilename; }
set { _documentModelFilename = value; }
}
[XmlElement(ElementName = "DESC_DOCUMENT_MODEL_PATH", IsNullable=true)]
public string DESC_DOCUMENT_MODEL_PATH
{
get { return _documentModelPath; }
set { _documentModelPath = value; }
}
[XmlElement(ElementName = "DATE_DOCUMENT_MODEL_START")]
public DateTime? DATE_DOCUMENT_MODEL_START
{
get { return _documentModelStart; }
set { _documentModelStart = value; }
}
[XmlElement(ElementName = "DATE_DOCUMENT_MODEL_END")]
public DateTime? DATE_DOCUMENT_MODEL_END
{
get { return _documentModelEnd; }
set { _documentModelEnd = value; }
}
[XmlElement(ElementName = "DESC_DOCUMENT_MODEL_VERSION", IsNullable = true)]
public string DESC_DOCUMENT_MODEL_VERSION
{
get { return _documentModelVersion; }
set { _documentModelVersion = value; }
}
[XmlElement(ElementName = "CODE_CONTRACT_ID")]
public long CODE_CONTRACT_ID
{
get { return _contractId; }
set { _contractId = value; }
}
[XmlElement(ElementName = "FLAG_DELETED")]
public bool FLAG_DELETED
{
get { return _flagDeleted; }
set { _flagDeleted = value; }
}
[XmlElement(ElementName = "CODE_USER_ID")]
public long CODE_USER_ID
{
get { return _userId; }
set { _userId = value; }
}
[XmlElement(ElementName = "ORDER_DOCUMENT_MODEL")]
public int ORDER_DOCUMENT_MODEL
{
get { return _orderDocumentModel; }
set { _orderDocumentModel = value;}
}
private DocumentModelType _documentModelType;
[XmlElement(ElementName = "DocumentModelType", IsNullable = true)]
public DocumentModelType documentModelType
{
get { return _documentModelType; }
set { _documentModelType = value; }
}
private DocumentModelState _documentModelState;
[XmlElement(ElementName = "DocumentModelState", IsNullable = true)]
public DocumentModelState documentModelState
{
get { return _documentModelState; }
set { _documentModelState = value; }
}
private DocumentModelIssuingEntity _documentModelIssuingEntity;
[XmlElement(ElementName = "DocumentModelIssuingEntity", IsNullable = true)]
public DocumentModelIssuingEntity documentModelIssuingEntity
{
get { return _documentModelIssuingEntity; }
set { _documentModelIssuingEntity = value; }
}
//private DocumentModelFolder _documentModelFolder;
//[XmlElement(ElementName = "DocumentModelFolder", IsNullable = true)]
//public DocumentModelFolder documentModelFolder
//{
// get { return _documentModelFolder; }
// set { _documentModelFolder = value; }
//}
[XmlElement(ElementName = "CODE_DOCUMENT_MODEL_STATE_ID")]
public long CODE_DOCUMENT_MODEL_STATE_ID
{
get { return _documentModelStateId; }
set { _documentModelStateId = value; }
}
[XmlElement(ElementName = "VALO_DOCUMENT_MODEL_ID")]
public string VALO_DOCUMENT_MODEL_ID
{
get { return _documentModelValoId; }
set { _documentModelValoId = value; }
}
[XmlElement(ElementName = "DATE_DOCUMENT_MODEL_UPLOAD")]
public DateTime? DATE_DOCUMENT_MODEL_UPLOAD
{
get { return _documentModelUploadDate; }
set { _documentModelUploadDate = value; }
}
[XmlElement(ElementName = "DESC_DOCUMENT_MODEL_CONTENT")]
public byte[] DESC_DOCUMENT_MODEL_CONTENT
{
get { return _documentModelContent; }
set { _documentModelContent = value; }
}
[XmlElement(ElementName = "CODE_DOCUMENT_MODEL_FILTER_ID")]
public long CODE_DOCUMENT_MODEL_FILTER_ID
{
get { return _documentModelFilter; }
set { _documentModelFilter = value; }
}
private long _code_siteId;
[XmlElement(ElementName = "CODE_SITEID")]
public long CODE_SITEID
{
get { return _code_siteId; }
set { _code_siteId = value; }
}
[XmlElement(ElementName = "DESC_DOCUMENT_RELEASE_PLACE")]
public string DESC_DOCUMENT_RELEASE_PLACE
{
get { return _placeOfIssue; }
set { _placeOfIssue = value; }
}
[XmlElement(ElementName = "DESC_DOCUMENT_RELEASED_BY")]
public string DESC_DOCUMENT_RELEASED_BY
{
get { return _issuingEntity; }
set { _issuingEntity = value; }
}
[XmlElement(ElementName = "DATE_DOCUMENT_RELEASED")]
public DateTime? DATE_DOCUMENT_RELEASED
{
get { return _releaseDate; }
set { _releaseDate = value; }
}
[XmlElement(ElementName = "CODE_OP_INSERT_ID")]
public int? CODE_OP_INSERT_ID
{
get { return _idOpInsert; }
set { _idOpInsert = value; }
}
[XmlElement(ElementName = "CODE_OP_ID_ID")]
public int? CODE_OP_ID_ID
{
get { return _idOpId; }
set { _idOpId = value; }
}
[XmlElement(ElementName = "CODE_CUSTOMERID")]
public long? CODE_CUSTOMERID
{
get { return _customerId; }
set { _customerId = value; }
}
[XmlElement(ElementName = "CODE_CUSTOMERTYPEID")]
public long? CODE_CUSTOMERTYPEID
{
get { return _customerTypeId; }
set { _customerTypeId = value; }
}
[XmlElement(ElementName = "DATE_DOCUMENT_MODEL_INVALIDATED")]
public DateTime? DATE_DOCUMENT_MODEL_INVALIDATED
{
get { return _documentModelInvalidated; }
set { _documentModelInvalidated = value; }
}
[XmlElement(ElementName = "FLAG_VALIDATING")]
public bool FLAG_VALIDATING
{
get { return _flagValidating; }
set { _flagValidating = value; }
}
[XmlElement(ElementName = "CODE_CONTRACT_STATES_ID")]
public long CODE_CONTRACT_STATES_ID
{
get { return _contractStateId; }
set { _contractStateId = value; }
}
[XmlElement(ElementName = "DESC_CONTRACT_STATES")]
public string DESC_CONTRACT_STATES
{
get { return _contractState; }
set { _contractState = value; }
}
[XmlElement(ElementName = "CODE_CONTRACT_TYPE_ID")]
public long CODE_CONTRACT_TYPE_ID
{
get { return _contractTypeId; }
set { _contractTypeId = value; }
}
[XmlElement(ElementName = "DESC_CONTRACT_NUMBER")]
public string DESC_CONTRACT_NUMBER
{
get { return _contractNumber; }
set { _contractNumber = value; }
}
[XmlElement(ElementName = "DESC_CONTACT_NUMBER")]
public string DESC_CONTACT_NUMBER
{
get { return _customerNumber; }
set { _customerNumber = value; }
}
[XmlElement(ElementName = "CODE_DOCUMENT_MODEL_FOLDER_ID")]
public long? CODE_DOCUMENT_MODEL_FOLDER_ID
{
get { return _folderId; }
set { _folderId = value; }
}
[XmlElement(ElementName = "DocumentModelFolderName")]
public string DocumentModelFolderName
{
get { return _folderName; }
set { _folderName = value; }
}
[XmlElement(ElementName = "DESC_FILEREMOTEPATH")]
public string DESC_FILEREMOTEPATH
{
get { return _fileRemotePath; }
set { _fileRemotePath = value; }
}
#endregion
}
And this is the DocumentModelType Class
public class DocumentModelType : ObjBase
{
#region Attributi
private long _id;
private string _documentModelType;
private bool _flagDeleted;
private long _userId;
protected new HELPSI_Database HELPSI_Database = Common.HELPSI_Database.HELPSI_Anag;
[XmlElement(ElementName = "CODE_DOCUMENT_MODEL_TYPE_ID")]
public long CODE_DOCUMENT_MODEL_TYPE_ID
{
get { return _id; }
set { _id = value; }
}
[XmlElement(ElementName = "DESC_DOCUMENT_MODEL_TYPE")]
public string DESC_DOCUMENT_MODEL_TYPE
{
get { return _documentModelType; }
set { _documentModelType = value; }
}
[XmlElement(ElementName = "FLAG_DELETED")]
public bool FLAG_DELETED
{
get { return _flagDeleted; }
set { _flagDeleted = value; }
}
[XmlElement(ElementName = "CODE_USER_ID")]
public long CODE_USER_ID
{
get { return _userId; }
set { _userId = value; }
}
#endregion
}
You should be using x => x.DocumentModelType.GetType().GetProperty(sidx.ToUpper()).GetValue(x.DocumentModelType, null) inside OrderBy clause. Here sidx should be DocumentStateDesc as you mentioned that you want order on this column.
Complete code will be like below.
List<DocumentModel> documentList;
if (contractid == -1)
documentList = helpsi.framework.core.CustomerProvider.DocumentModel.getAllDocumentModelListByCustomer(custid, custtypeid);
else
documentList = helpsi.framework.core.CustomerProvider.DocumentModel.getAllDocumentModelListGridByContract(contractid);
if (sord.Equals("asc"))
documentList = documentList.OrderBy(x => x.DocumentModelType.GetType().GetProperty(sidx.ToUpper()).GetValue(x.DocumentModelType, null)).ToList();
else
documentList = documentList.OrderByDescending(x => x.DocumentModelType.GetType().GetProperty(sidx.ToUpper()).GetValue(x.DocumentModelType, null)).ToList();
One quick and dirty fix is to introduce property in parent class that just returns the property value of another property. Just don't assign XmlElement attribute to it. If the classes are auto-generated you can't change them, but they are probably declared as partial, and then you can add this new property in additional class definition.
public string DocumentModelType_DocumentStateDesc { get => DocumentModelType.DocumentStateDesc; }
But if you want to have a general solution for several properties with several sub-properties then some sort of pathing is required. You could String.Split sidx on some delimiter like '\' or '.', use recursion, and then OrderBy the last item in the path.
In the code below I hope that I specify correctly whats wrong. I need to be able to call item.departments.dept_Type and that should be possible because of the association that I have made. I don't need to create inner joins on a query to get the data if I understand correctly.
This is my PersonClass
namespace DATALAYER.DataHandler
{
[Table(Name = "People")]
public class Person
{
private int _DepartmentID;
public EntityRef<Department> _Department;
public Person() { this._Department = new EntityRef<Department>(); }
private int _ID;
[Column(IsPrimaryKey =true, Storage ="_ID")]
public int ID
{
get { return this._ID; }
set { this._ID = value; }
}
private string _p_FirstName;
[Column(Storage = "_p_FirstName")]
public string p_FirstName
{
get { return this._p_FirstName; }
set { this._p_FirstName = value; }
}
private string _LastName;
[Column(Storage = "_LastName")]
public string p_LastName
{
get { return this._LastName; }
set { this._LastName = value; }
}
private string _EmailAddress;
[Column(Storage = "_EmailAddress")]
public string p_EmailAddress
{
get { return this._EmailAddress; }
set { this._EmailAddress = value; }
}
private string _Password;
[Column(Storage = "_Password")]
public string p_Password
{
get { return this._Password; }
set { this._Password = value; }
}
private string _SSID;
[Column(Storage = "_SSID")]
public string p_SSID
{
get { return this._SSID; }
set { this._SSID = value; }
}
private string _DOB;
[Column(Storage = "_DOB")]
public string p_DOB
{
get { return this._DOB; }
set { this._DOB = value; }
}
private string _CellNumber;
[Column(Storage = "_CellNumber")]
public string p_CellNumber
{
get { return this._CellNumber; }
set { this._CellNumber = value; }
}
[Column(Storage = "_DepartmentID", DbType = "Int")]
public int p_Department_dept_ID
{
get { return this._DepartmentID; }
set { this._DepartmentID = value; }
}
[Association(Storage = "_DepartmentID", ThisKey = "p_Department_dept_ID")]
public Department Department
{
get { return this._Department.Entity; }
set { this._Department.Entity = value; }
}
}
}
This is my Department code
namespace DATALAYER.DataHandler
{
[Table(Name = "Departments")]
public class Department
{
//private EntitySet<Person> _Person;
//public Department()
//{
// this._Person = new EntitySet<Person>();
//}
private int _DepartmentID;
[Column(IsPrimaryKey = true, Storage = "_DepartmentID")]
public int dept_ID
{
get { return this._DepartmentID; }
set { this._DepartmentID = value; }
}
private string _deptType;
[Column(Storage = "_deptType")]
public string dept_Type
{
get { return this._deptType; }
set { this._deptType = value; }
}
//[Association(Storage = "_Person", OtherKey = "ID")]
//public EntitySet<Person> Persons
//{
// get { return this._Person; }
// set { this._Person.Assign(value); }
//}
}
}
Now the problem I'm thinking is that there is a problem with datatypes between the primary key of the person and a foreign key the departments. But Since they are both int I don't see how that can be a problem.
If someone can just explain my problem to cleary if Im wrong or something or help me with a solution pls.
Added this class
namespace DATALAYER.DataHandler
{
public class SHSdb2 : DataContext
{
public Table<Person> People;
public Table<Department> Department;
//public Table<Address> Address;
public SHSdb2(string connection) : base(connection) { }
}
}
Person table
Department table
Without this code it works but then I can only call stuff inside the table
[Column(Storage = "_DepartmentID", DbType = "Int")]
public int p_Department_dept_ID
{
get { return this._DepartmentID; }
set { this._DepartmentID = value; }
}
[Association(Storage = "_DepartmentID", ThisKey = "p_Department_dept_ID")]
public Department Department
{
get { return this._Department.Entity; }
set { this._Department.Entity = value; }
}
Seems like I fixed it with this not sure if its a fix or I just lucky if someone can still maybe explain this to me it would be much appreciated.
var personQuery =
from per in db.People
where per.p_FirstName == "Christian"
select per.Department;
I'm thinking by specifying that it needs to get the data from department it would allow it in the foreach.
I'm using ServerManager (Microsoft.Web.Administration.dll) to create an Application to manage my web servers, All of my server are running IIS 7 and above. Majority of the site is complete, i can manage servers, sites, FTP, SSL etc.
Here is my issue,
I am able to create virtual directories and applications, but having an issue with listing them separately when viewing the site information as you can do in IIS. I am able to list the all together as Virtual Directories by just getting item.VirtualDirectories[0].PhysicalPath but would like to show Applications in one column and basic virtual directories in the second column. I'm sure i need to be looking for if root application path is siteid, or if it has an AppPool somehow but having a hard time figuring how. Any help would be appreciated.
My Code:
SiteVirtualDirectory.cs
private string anonymousUsername;
private string anonymousUserPassword;
private string contentPath;
private bool enableWritePermissions;
private bool enableParentPaths;
private bool enableDirectoryBrowsing;
private bool enableAnonymousAccess;
private bool enableWindowsAuthentication;
private bool enableBasicAuthentication;
private bool enableDynamicCompression;
private bool enableStaticCompression;
private string defaultDocs;
private string httpRedirect;
private HttpError[] httpErrors;
private HttpErrorsMode errorMode;
private HttpErrorsExistingResponse existingResponse;
private MimeMap[] mimeMaps;
private HttpHeader[] httpHeaders;
private bool aspInstalled;
private string aspNetInstalled;
private string phpInstalled;
private bool perlInstalled;
private bool pythonInstalled;
private bool coldfusionInstalled;
private bool cgiBinInstalled;
private string applicationPool;
private bool dedicatedApplicationPool;
private string parentSiteName;
private bool redirectExactUrl;
private bool redirectDirectoryBelow;
private bool redirectPermanent;
private bool sharePointInstalled;
private bool iis7;
private string consoleUrl;
private string php5VersionsInstalled;
public string AnonymousUsername
{
get { return anonymousUsername; }
set { anonymousUsername = value; }
}
public string AnonymousUserPassword
{
get { return anonymousUserPassword; }
set { anonymousUserPassword = value; }
}
public string ContentPath
{
get { return contentPath; }
set { contentPath = value; }
}
public string HttpRedirect
{
get { return httpRedirect; }
set { httpRedirect = value; }
}
public string DefaultDocs
{
get { return defaultDocs; }
set { defaultDocs = value; }
}
public MimeMap[] MimeMaps
{
get { return mimeMaps; }
set { mimeMaps = value; }
}
public HttpError[] HttpErrors
{
get { return httpErrors; }
set { httpErrors = value; }
}
public HttpErrorsMode ErrorMode
{
get { return errorMode; }
set { errorMode = value; }
}
public HttpErrorsExistingResponse ExistingResponse
{
get { return existingResponse; }
set { existingResponse = value; }
}
public string ApplicationPool
{
get { return this.applicationPool; }
set { this.applicationPool = value; }
}
public bool EnableParentPaths
{
get { return this.enableParentPaths; }
set { this.enableParentPaths = value; }
}
public HttpHeader[] HttpHeaders
{
get { return this.httpHeaders; }
set { this.httpHeaders = value; }
}
public bool EnableWritePermissions
{
get { return this.enableWritePermissions; }
set { this.enableWritePermissions = value; }
}
public bool EnableDirectoryBrowsing
{
get { return this.enableDirectoryBrowsing; }
set { this.enableDirectoryBrowsing = value; }
}
public bool EnableAnonymousAccess
{
get { return this.enableAnonymousAccess; }
set { this.enableAnonymousAccess = value; }
}
public bool EnableWindowsAuthentication
{
get { return this.enableWindowsAuthentication; }
set { this.enableWindowsAuthentication = value; }
}
public bool EnableBasicAuthentication
{
get { return this.enableBasicAuthentication; }
set { this.enableBasicAuthentication = value; }
}
public bool EnableDynamicCompression
{
get { return this.enableDynamicCompression; }
set { this.enableDynamicCompression = value; }
}
public bool EnableStaticCompression
{
get { return this.enableStaticCompression; }
set { this.enableStaticCompression = value; }
}
public bool AspInstalled
{
get { return this.aspInstalled; }
set { this.aspInstalled = value; }
}
public string AspNetInstalled
{
get { return this.aspNetInstalled; }
set { this.aspNetInstalled = value; }
}
public string PhpInstalled
{
get { return this.phpInstalled; }
set { this.phpInstalled = value; }
}
public bool PerlInstalled
{
get { return this.perlInstalled; }
set { this.perlInstalled = value; }
}
public bool PythonInstalled
{
get { return this.pythonInstalled; }
set { this.pythonInstalled = value; }
}
public bool ColdFusionInstalled
{
get { return this.coldfusionInstalled; }
set { this.coldfusionInstalled = value; }
}
public bool DedicatedApplicationPool
{
get { return this.dedicatedApplicationPool; }
set { this.dedicatedApplicationPool = value; }
}
public string ParentSiteName
{
get { return this.parentSiteName; }
set { this.parentSiteName = value; }
}
public bool RedirectExactUrl
{
get { return this.redirectExactUrl; }
set { this.redirectExactUrl = value; }
}
public bool RedirectDirectoryBelow
{
get { return this.redirectDirectoryBelow; }
set { this.redirectDirectoryBelow = value; }
}
public bool RedirectPermanent
{
get { return this.redirectPermanent; }
set { this.redirectPermanent = value; }
}
public bool CgiBinInstalled
{
get { return this.cgiBinInstalled; }
set { this.cgiBinInstalled = value; }
}
public bool SharePointInstalled
{
get { return this.sharePointInstalled; }
set { this.sharePointInstalled = value; }
}
public bool IIs7
{
get { return this.iis7; }
set { this.iis7 = value; }
}
public string ConsoleUrl
{
get { return consoleUrl; }
set { consoleUrl = value; }
}
public string Php5VersionsInstalled
{
get { return php5VersionsInstalled; }
set { php5VersionsInstalled = value; }
}
[XmlIgnore]
public string VirtualPath
{
get
{
// virtual path is rooted
if (String.IsNullOrEmpty(ParentSiteName))
return "/"; //
else if (!Name.StartsWith("/"))
return "/" + Name;
//
return Name;
}
}
[XmlIgnore]
public string FullQualifiedPath
{
get
{
if (String.IsNullOrEmpty(ParentSiteName))
return Name;
else if (Name.StartsWith("/"))
return ParentSiteName + Name;
else
return ParentSiteName + "/" + Name;
}
}
Get Virtual Directories:
public class GetVirtualDirectories(ServerManager iismanager, string siteId)
{
if (!SiteExists(iismanager, siteId))
return new SiteVirtualDirectory[] { };
var vdirs = new List<SiteVirtualDirectory>();
var iisObject = iismanager.Sites[siteId];
//
foreach (var item in iisObject.Applications)
{
// do not list root Virtual Directory
if (item.Path == "/")
continue;
//
vdirs.Add(new SiteVirtualDirectory
{
Name = ConfigurationUtility.GetNonQualifiedVirtualPath(item.Path),
ContentPath = item.VirtualDirectories[0].PhysicalPath
});
}
//
return vdirs.ToArray();
}
I have a customer object class:
public class customerObject
{
private string _address1;
private string _address2;
private string _address3;
private string _category;
private string _country;
private string _county;
private string _custcode;
private string _fullname;
private string _int_rep_hou;
private string _int_rep_key;
private double _lat;
private double _lng;
private string _postcode;
private string _rep_code;
private string _telephone;
public customerObject()
{
}
public string Address1
{
get { return _address1; }
set { _address1 = value; }
}
public string Address2
{
get
{
return _address2;
}
set { _address2 = value; }
}
public string Address3 { get { return _address3; } set { _address3 = value; } }
public string Category
{
get { return _category; }
set { _category = value; }
}
public string Country { get { return _country; } set { _country = value; } }
public string County { get { return _county; } set { _county = value; } }
public string Custcode
{
get { return _custcode; }
set { _custcode = value; }
}
public string Fullname
{
get { return _fullname; }
set { _fullname = value; }
}
public string Int_rep_hou
{
get { return _int_rep_hou; }
set { _int_rep_hou = value; }
}
public string Int_rep_key
{
get { return _int_rep_key; }
set { _int_rep_key = value; }
}
public double Lat { get { return _lat; } set { _lat = value; } }
public double Lng { get { return _lng; } set { _lng = value; } }
public string Postcode { get { return _postcode; } set { _postcode = value; } }
public string Rep_code
{
get { return _rep_code; }
set { Rep_code = value; }
}
public string Telephone { get { return _telephone; } set { _telephone = value; }
}
}
I have a CustomCollections class
public class CustomerCollection
{
public List<customerObject> Customers { get; set; }
}
My method that loops through dt rows and converts to a customer object
public List<Valueobjects.CustomerCollection> dolist(DataTable temptablename)
{
//Create Collection Object
Valueobjects.CustomerCollection Collection = new Valueobjects.CustomerCollection();
foreach (DataRow row in temptablename.Rows)
{
//Create Customer Object
Valueobjects.customerObject Customer = new Valueobjects.customerObject();
//set values of customer object
Customer.Rep_code = "";
Customer.Int_rep_key = "";
Customer.Int_rep_hou = "";
Customer.Fullname = row["Fullname"].ToString().Trim();
Customer.Custcode = row["Custcode"].ToString().Trim();
Customer.Category = row["Category"].ToString().Trim();
Customer.Address1 = row["Address1"].ToString().Trim();
Customer.Address2 = row["Address2"].ToString().Trim();
Customer.Address3 = row["Address3"].ToString().Trim();
Customer.Postcode = row["Postcode"].ToString().Trim();
Customer.Country = row["Country"].ToString().Trim();
Customer.Telephone = row["Telephone"].ToString().Trim();
Customer.Lat = Convert.ToDouble(row["Lat"]);
Customer.Lng = Convert.ToDouble(row["Lng"]);
Customer.County = row["County"].ToString().Trim();
//add to the collection (list)
Collection.Customers.Add(Customer);
}
temptablename = null;
return Collection;
}
However when I create a new Customer object and a new CustomerCollection object I am getting an error when adding the customer to the collection list.
Error:
Error 32 Cannot implicitly convert type
'Classes.Valueobjects.CustomerCollection' to
'System.Collections.Generic.List'
Your method is returning a List<CustomerCollection>:
public List<Valueobjects.CustomerCollection> dolist(DataTable temptablename)
{
//...
}
But the code is trying to return a CustomerCollection:
return Collection;
Just as the error says, these two types are different.
If a CustomerCollection is already a collection of customers, then semantically what is a List<Valueobjects.CustomerCollection>? A collection of collections? It seems like you're over-pluralizing your objects :)
There are two approaches here. Either return a CustomerCollection from the method:
public CustomerCollection dolist(DataTable temptablename)
{
//...
}
Or use a List<Customer> if you want to use generic lists as your collection containers:
public List<Customer> dolist(DataTable temptablename)
{
//...
var Collection = new List<Customer>();
//...
Collection.Add(Customer);
//...
return Collection;
}
Side note: You may want to stick to C# conventions for variable naming. As you can see from the code highlighting here on Stack Overflow, your variable names can easily be mistaken for classes/types, which can cause confusion when supporting the code.
Return a CustomerCollection instead of a List<Valueobjects.CustomerCollection>:
public Valueobjects.CustomerCollection Dolist(DataTable temptablename)
{
// ...
Your object has a list, it is not a list.
MSDN: Inheritance
"[{\"active\":true,\"campaignId\":11401,\"createdtime\":1355919181000,\"description\":\"Ankit Demo Edited By Nirav\",\"enddate\":1363132800000,\"groupId\":10179,\"isdeleted\":false,\"lastmodifiedby\":10405,\"modifiedtime\":1362556187000,\"name\":\"Ankit Demo\",\"noofweek\":12,\"organizationId\":11153,\"startdate\":1355875200000,\"status\":2,\"userId\":11161},
{\"active\":true,\"campaignId\":21901,\"createdtime\":1358493958000,\"description\":\"sdadadasd\",\"enddate\":1359072000000,\"groupId\":10179,\"isdeleted\":false,\"lastmodifiedby\":10405,\"modifiedtime\":1358751277000,\"name\":\"NEW CAMP TEST\",\"noofweek\":1,\"organizationId\":10707,\"startdate\":1358467200000,\"status\":4,\"userId\":10405},
{\"active\":true,\"campaignId\":33601,\"createdtime\":1361441582000,\"description\":\"dasdsadasd\",\"enddate\":1363219200000,\"groupId\":10179,\"isdeleted\":false,\"lastmodifiedby\":10405,\"modifiedtime\":1361795632000,\"name\":\"BHAVIK UTC\",\"noofweek\":3,\"organizationId\":10707,\"startdate\":1361404800000,\"status\":2,\"userId\":10405}]"
I have Above Jsong String in my string variable ..and i want to convert this json string into an object of my custom class..i have created the custom class ..
following is the code in which i getingg the response in json from HttpWebResponse and converting in list object of my custom class
HttpWebResponse response = default(HttpWebResponse);
try
{
response = (HttpWebResponse)request.GetResponse();
// response.Close()
string sResult = null;
using (StreamReader responseReader = new StreamReader(response.GetResponseStream()))
{
sResult = responseReader.ReadToEnd();
}
response.Close();
Console.WriteLine(sResult);
List<Class1> myDeserializedObjList = (List<Class1>)Newtonsoft.Json.JsonConvert.DeserializeObject(Request[sResult], typeof(List<Class1>));
int counts= myDeserializedObjList.Count;
}
but its giving me error
Value cannot be null.
Parameter name: s
Can anyone Please guide me how to solve this problem?
this is my custom class to which i want to assign the objects from json string
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for Class1
/// </summary>
public class Class1
{
private Boolean active;
public Boolean Active
{
get { return active; }
set { active = value; }
}
private long campaignId;
public long CampaignId
{
get { return campaignId; }
set { campaignId = value; }
}
private long createdtime;
public long Createdtime
{
get { return createdtime; }
set { createdtime = value; }
}
private string description;
public string Description
{
get { return description; }
set { description = value; }
}
private long enddate;
public long Enddate
{
get { return enddate; }
set { enddate = value; }
}
private long groupId;
public long GroupId
{
get { return groupId; }
set { groupId = value; }
}
private Boolean isdeleted;
public Boolean Isdeleted
{
get { return isdeleted; }
set { isdeleted = value; }
}
private long modifiedtime;
public long Modifiedtime
{
get { return modifiedtime; }
set { modifiedtime = value; }
}
private long lastmodifiedby;
public long Lastmodifiedby
{
get { return lastmodifiedby; }
set { lastmodifiedby = value; }
}
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private int noofweek;
public int Noofweek
{
get { return noofweek; }
set { noofweek = value; }
}
private long organizationId;
public long OrganizationId
{
get { return organizationId; }
set { organizationId = value; }
}
private long startdate;
public long Startdate
{
get { return startdate; }
set { startdate = value; }
}
private Boolean status;
public Boolean Status
{
get { return status; }
set { status = value; }
}
private long userId;
public long UserId
{
get { return userId; }
set { userId = value; }
}
public Class1()
{
}
}
If your Request[sResult] is the json string you mentionned.
Try
Newtonsoft.Json.JsonConvert.DeserializeObject<List<Class1>>(Request[sResult]);
Edit, i mean :
List<Class1> myDeserializedObjList =Newtonsoft.Json.JsonConvert.DeserializeObject<List<Class1>>(Request[sResult]);