// Get domain handle: // NameOrID: should be filled // ParentNameOrID: if not specified, the default Territory will be assumed // public static async Task <iS3DomainHandle> GetDomainHandle(string nameOrID, string parentNameOrID) { if (nameOrID == null) { return(null); } iS3TerritoryHandle territoryHandle = null; iS3DomainHandle result = null; using (var ctx = new iS3MainDbContext()) { territoryHandle = await getTerritoryHandle(parentNameOrID, ctx); if (territoryHandle == null) { return(null); } result = territoryHandle.GetDomainHandle(nameOrID); } return(result); }
public async Task <IHttpActionResult> AddDomain(iS3DomainHandle handle) { if (handle == null) { return(BadRequest("Argument Null")); } iS3DomainHandle newHandle = await MiniServer.AddDomain(handle); return(Ok(newHandle)); }
public async Task <IHttpActionResult> GetDomainHandle(string nameOrID, string parentNameOrID) { if (nameOrID == null) { return(BadRequest("Argument Null")); } iS3DomainHandle result = null; result = await MiniServer.GetDomainHandle(nameOrID, parentNameOrID); return(Ok(result)); }
// Add domain using the corresponding information in handle // Returns the newly added domain handle (not the input one). // public static async Task <iS3DomainHandle> AddDomain( iS3DomainHandle domainHandle) { iS3DomainHandle newHandle = await MiniServer.AddDomainHandle(domainHandle.Name, domainHandle.Type, domainHandle.ParentID, domainHandle.DbName); iS3Territory territory = MiniServer.GetTerritory(newHandle.ParentID); Type t = MiniServer.GetType(newHandle.Type); iS3Domain domain = (iS3Domain) Activator.CreateInstance(t, newHandle); territory.Domains.Add(domain); return(newHandle); }
// Add a new domain handle: // name, type, parentNameOrID should be filled // if dbName is not given, i.e., null, default database name will be used. // public static async Task <iS3DomainHandle> AddDomainHandle(string name, string type, string parentNameOrID, string dbName = null) { iS3TerritoryHandle territoryHandle = null; using (var ctx = new iS3MainDbContext()) { territoryHandle = await getTerritoryHandle(parentNameOrID, ctx); if (territoryHandle == null) { throw new Exception("Territory null and no default"); } bool exist = territoryHandle.DomainHandles.Any(c => c.Name == name); if (exist) { throw new Exception("Already exists"); } iS3DomainHandle domainHandle = new iS3DomainHandle(); domainHandle.ID = int.Parse(Guid.NewGuid().ToString()); domainHandle.Name = name; domainHandle.Type = type; domainHandle.ParentID = territoryHandle.ID.ToString(); if (domainHandle.DbName == null) { if (territoryHandle.DbName != null) { domainHandle.DbName = territoryHandle.DbName; } else { domainHandle.DbName = MiniServer.DefaultDatabase; } } territoryHandle.DomainHandles.Add(domainHandle); await ctx.SaveChangesAsync(); return(domainHandle); } }
public iS3DomainHandle GetDomainHandle(string NameOrID) { iS3DomainHandle result = null; bool exist = DomainHandles.Any(c => c.ID == int.Parse(NameOrID)); if (exist) { result = DomainHandles.First(c => c.ID == int.Parse(NameOrID)); } else { exist = DomainHandles.Any(c => c.Name == NameOrID); if (exist) { result = DomainHandles.First(c => c.Name == NameOrID); } } return(result); }
public iS3Domain(iS3DomainHandle handle) : base(handle) { DomainHandle = handle; }