public void SingleCohort_ZeroBiomass() { SiteCohorts cohorts = new SiteCohorts(); const ushort initialBiomass = 100; cohorts.AddNewCohort(poputrem, initialBiomass); mockCalculator.CountCalled = 0; mockCalculator.Change = -2; expectedSender = cohorts[poputrem]; expectedDistType = null; // death during growth phase expectedSite = activeSite; deadCohorts.Clear(); for (int time = 1; time <= 60; time++) { if (time % successionTimestep == 0) { Util.Grow(cohorts, successionTimestep, activeSite, true); } } expectedCohorts.Clear(); Util.CheckCohorts(expectedCohorts, cohorts); Assert.AreEqual(1, deadCohorts.Count); ICohort deadCohort = deadCohorts[0]; Assert.AreEqual(poputrem, deadCohort.Species); Assert.AreEqual(initialBiomass / -mockCalculator.Change, deadCohort.Age); Assert.AreEqual(0, deadCohort.Biomass); }
/// <summary> /// 创建记录时触发的事件 /// </summary> /// <param name="data"></param> /// <param name="stage"></param> /// <param name="entityMetadata"></param> private void InternalOnCreate(AggregateRoot data, OperationStage stage, AggregateRootMetaData aggRootMetaDatas) { //plugin var entityId = aggRootMetaDatas.MainMetadata.EntityMetadata.EntityId; Guid? businessObjectId = aggRootMetaDatas.SystemFormId; PlugInType pluginType = PlugInType.Form; _pluginExecutor.Execute(entityId, businessObjectId, pluginType, OperationTypeEnum.Update, stage, data, aggRootMetaDatas); if (stage == OperationStage.PreOperation) { //event publishing _eventPublisher.Publish(new AggRootCreatingEvent(data) { AggRootMetaData = aggRootMetaDatas }); } else if (stage == OperationStage.PostOperation) { //event publishing _eventPublisher.Publish(new AggRootCreatedEvent(data) { AggRootMetaData = aggRootMetaDatas }); } OnCreate(data, stage, aggRootMetaDatas); }
//--------------------------------------------------------------------- /// <summary> /// Initializes a new instance. /// </summary> /// <param name="name">The plug-in's name</param> /// <param name="type">The plug-in's type</param> /// <param name="implementationName">The AssemblyQualifiedName of the /// class that implements the plug-in.</param> public PlugInInfo(string name, PlugInType type, string implementationName) : base(name, typeof(PlugIn), implementationName) { this.type = type; }
//--------------------------------------------------------------------- private void CheckPercentageTable(string tableName, IPercentageTable table, string nextTableName) { inputLine.MatchName(tableName); bool haveLine = inputLine.GetNext(); while (haveLine && inputLine.VariableName != nextTableName) { StringReader currentLine = new StringReader(inputLine.ToString()); string disturbance = ReadInputValue <string>(currentLine); PlugInType disturbanceType; if (disturbance == "(default)") { disturbanceType = new PlugInType(disturbance); } else { disturbanceType = new PlugInType("disturbance:" + disturbance); } PoolPercentages percentages = table[disturbanceType]; Assert.AreEqual((double)percentages.Woody, (double)ReadInputValue <Percentage>(currentLine)); Assert.AreEqual((double)percentages.NonWoody, (double)ReadInputValue <Percentage>(currentLine)); haveLine = inputLine.GetNext(); } }
public void Execute(Guid entityId, Guid?businessObjectId, PlugInType typeCode, OperationTypeEnum op, OperationStage stage, TData tData, KMetadata kMetadata) { var plugins = _entityPluginFinder.QueryByEntityId(entityId, Enum.GetName(typeof(OperationTypeEnum), op), businessObjectId, typeCode); if (plugins.NotEmpty()) { foreach (var pg in plugins) { if (pg.StateCode == RecordState.Disabled) { continue; } var pinstance = GetInstance(pg); if (pinstance != null) { pinstance.Execute(new PluginExecutionContextT <TData, KMetadata>() { MessageName = op , Stage = stage , User = _currentUser , Target = tData , metadata = kMetadata }); } } } }
public void Init() { poputrem = Data.Species["poputrem"]; bool[,] grid = new bool[, ] { { true, false }, { false, true } }; DataGrid <bool> dataGrid = new DataGrid <bool>(grid); ILandscape landscape = new Landscape.Landscape(dataGrid); activeSite = landscape[1, 1]; activeSite2 = landscape[2, 2]; expectedSender = null; expectedDistType = null; expectedSite = null; mockCalculator = new MockCalculator(); Landis.Biomass.Cohorts.Initialize(successionTimestep, mockCalculator); Landis.Biomass.Cohort.DeathEvent += CohortDeath; expectedCohorts = new Dictionary <ISpecies, ushort[]>(); deadCohorts = new List <ICohort>(); cohortsKilledByAgeOnlyDist = new List <ICohort>(); }
public virtual void SignOut() { string id = string.Empty; try { id = GetIdFromParameters(); } catch { return; } PlugInType plugInType = PlugInType; DataRow instanceRow = Maps.Instance.DuradosMap.Database.GetSelectedInstanceRow(id, plugInType); int appId = (int)instanceRow["AppId"]; if (GetRegisteredUserId().HasValue&& !IsSignedIn(GetRegisteredUsername())) { if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["plugInSignOut"] ?? "true")) { Map.Logger.Log(this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString(), "username: "******", id: " + this.Request.QueryString["id"], null, 77, "url: " + System.Web.HttpContext.Current.Request.Url.ToString() + ", appId: " + appId); PlugInHelper.SignOut(); } } }
//--------------------------------------------------------------------- private void RemoveCohort(int index, ICohort cohort, ActiveSite site, PlugInType disturbanceType) { cohortData.RemoveAt(index); Cohort.Died(this, cohort, site, disturbanceType); }
//--------------------------------------------------------------------- /// <summary> /// Raises a Cohort.DeathEvent. /// </summary> public static void Died(object sender, ICohort cohort, ActiveSite site, PlugInType disturbanceType) { if (DeathEvent != null) { DeathEvent(sender, new DeathEventArgs(cohort, site, disturbanceType)); } }
//--------------------------------------------------------------------- /// <summary> /// Raises a Cohort.AgeOnlyDeathEvent. /// </summary> public static void KilledByAgeOnlyDisturbance(object sender, ICohort cohort, ActiveSite site, PlugInType disturbanceType) { if (AgeOnlyDeathEvent != null) { AgeOnlyDeathEvent(sender, new DeathEventArgs(cohort, site, disturbanceType)); } }
public void SingleCohort_LongevityReached() { SiteCohorts cohorts = new SiteCohorts(); const ushort initialBiomass = 300; cohorts.AddNewCohort(poputrem, initialBiomass); mockCalculator.CountCalled = 0; mockCalculator.Change = 1; expectedSender = cohorts[poputrem]; expectedDistType = null; // death during growth phase expectedSite = activeSite; deadCohorts.Clear(); // Repeatedly grow for succession timesteps until longevity // reached. int time = 0; do { time += successionTimestep; Util.Grow(cohorts, successionTimestep, activeSite, true); } while (time <= poputrem.Longevity); expectedCohorts.Clear(); Util.CheckCohorts(expectedCohorts, cohorts); // Calculator called L times where L is longevity. Inituitively, // one would think since initial cohort's age is 1, it'd only take // L-1 times to get to the max age (= L). So the calculator // should be called L-1 times. But the combining of young cohorts // at the first succession timestep (t_succ = 20) results in the // calculator being called twice with cohort age = t_succ-1 (19). // At the end of year 19, the cohort's age is 20 and the // calculator has been called 19 times. But at the start of year // 20, the combine-young-cohorts operation is done because it's a // succession timestep. The combine operation takes all the young // cohorts (age <= t_succ = 20) and replaces them with one cohort // with age = t_succ-1 (= 19). This ensures that after the growth // phase, the cohort's age will be t_succ (20). So the growth // phase of year 20 calls the calculator for the 20th time with // cohort age 19. Assert.AreEqual(poputrem.Longevity, mockCalculator.CountCalled); Assert.AreEqual(1, deadCohorts.Count); ICohort deadCohort = deadCohorts[0]; Assert.AreEqual(poputrem, deadCohort.Species); Assert.AreEqual(poputrem.Longevity, deadCohort.Age); Assert.AreEqual(initialBiomass + (poputrem.Longevity * mockCalculator.Change), deadCohort.Biomass); }
public void AgeOnlyDisturbance() { Landis.Biomass.SiteCohorts.AgeOnlyDisturbanceEvent += AgeOnlyDisturbanceEvent; Landis.Biomass.Cohort.AgeOnlyDeathEvent += AgeOnlyCohortDeath; cohortsKilledByAgeOnlyDist.Clear(); expectedDistType = RemoveAgeBetween5And30.DisturbanceType; expectedSite = activeSite2; CohortsRemoved(new RemoveAgeBetween5And30_AgeOnly(activeSite2)); CheckDeadCohorts(cohortsKilledByAgeOnlyDist); Landis.Biomass.Cohort.AgeOnlyDeathEvent -= AgeOnlyCohortDeath; Landis.Biomass.SiteCohorts.AgeOnlyDisturbanceEvent -= AgeOnlyDisturbanceEvent; }
//--------------------------------------------------------------------- private void RemoveCohort(int index, ICohort cohort, ActiveSite site, PlugInType disturbanceType) { if (isDebugEnabled) { log.DebugFormat(" cohort removed: {0}, {1} yrs, {2} Mg/ha ({3})", cohort.Species.Name, cohort.Age, cohort.Biomass, disturbanceType != null ? disturbanceType.Name : cohort.Age >= species.Longevity ? "senescence" : cohort.Biomass == 0 ? "attrition" : "UNKNOWN"); } cohortData.RemoveAt(index); Cohort.Died(this, cohort, site, disturbanceType); }
/// <summary> /// Function to retrieve a friendly description of a <see cref="PlugInType"/> value. /// </summary> /// <param name="pluginType">The plug in type to evaluate.</param> /// <returns>The friendly description.</returns> public static string GetDescription(this PlugInType pluginType) { switch (pluginType) { case PlugInType.Writer: return(Resources.GOREDIT_PLUGIN_TYPE_WRITER); case PlugInType.Content: return(Resources.GOREDIT_PLUGIN_TYPE_CONTENT); case PlugInType.Tool: return(Resources.GOREDIT_PLUGIN_TYPE_TOOL); case PlugInType.Reader: return(Resources.GOREDIT_PLUGIN_TYPE_READER); case PlugInType.ContentImporter: return(Resources.GOREDIT_PLUGIN_TYPE_IMPORTER); default: return(Resources.GOREDIT_PLUGIN_TYPE_UNKNOWN); } }
//--------------------------------------------------------------------- /// <summary> /// Initializes a new instance. /// </summary> public DisturbanceEventArgs(ActiveSite site, PlugInType disturbanceType) { this.site = site; this.disturbanceType = disturbanceType; }
//--------------------------------------------------------------------- /// <summary> /// Initializes a new instance. /// </summary> protected PlugIn(string name, PlugInType type) { this.name = name; this.type = type; }
/// <summary> /// Gets a list of installed plug-in names. The list can be restricted by some filters. /// </summary> /// <param name="typeFilter"> /// The enumeration flags that determine which types of plug-ins are included. /// </param> /// <param name="loaded">true if loaded plug-ins are returned.</param> /// <param name="unloaded">true if unloaded plug-ins are returned.</param> /// <returns>An array of installed plug-in names. This can be empty, but not null.</returns> public static string[] GetInstalledPlugInNames(PlugInType typeFilter, bool loaded, bool unloaded) { int count = InstalledPlugInCount; System.Collections.Generic.List<string> names = new System.Collections.Generic.List<string>(32); for (int i = 0; i < count; i++) { IntPtr name = UnsafeNativeMethods.CRhinoPlugInManager_GetName(i); if (name != IntPtr.Zero) { if (UnsafeNativeMethods.CRhinoPlugInManager_PassesFilter(i, (int)typeFilter, loaded, unloaded, false)) { string sName = Marshal.PtrToStringUni(name); if (!string.IsNullOrEmpty(sName)) names.Add(sName); } } } return names.ToArray(); }
public void BiomassDisturbance() { expectedDistType = RemoveAgeBetween5And30.DisturbanceType; expectedSite = activeSite; CohortsRemoved(new RemoveAgeBetween5And30_Biomass(activeSite)); }
public List <EntityPlugin> QueryByEntityId(Guid entityid, string eventName, Guid?businessObjectId = null, PlugInType typeCode = PlugInType.Entity) { List <EntityPlugin> entities = _cacheService.GetVersionItems(entityid + "/" + eventName, () => { return(_entityPluginRepository.Query(x => x.EntityId == entityid)?.ToList()); }); if (entities.NotEmpty()) { if (businessObjectId.HasValue) { entities.RemoveAll(x => !(x.EventName.IsCaseInsensitiveEqual(eventName) && x.BusinessObjectId == businessObjectId.Value && x.TypeCode == (int)typeCode)); } else { entities.RemoveAll(x => !(x.EventName.IsCaseInsensitiveEqual(eventName) && x.BusinessObjectId == Guid.Empty && x.TypeCode == (int)typeCode)); } } return(entities.OrderBy(x => x.ProcessOrder).ToList()); }
public PlugInAttribute(string name, PlugInType plugInType) { Name = name; PlugInType = plugInType; }
public ActionResult Widget() { string id = GetIdFromParameters(); PlugInType plugInType = PlugInType; //string userId = GetUserID(); //if (string.IsNullOrEmpty(userId)) //{ // userId = Maps.Instance.DuradosMap.Database.CreatePlugInUser(id, plugInType, GetPlugInUserGuid()); //} //if (string.IsNullOrEmpty(userId)) // return RedirectToAction(EmptyWidgetActionName); DataRow instanceRow = Maps.Instance.DuradosMap.Database.GetSelectedInstanceRow(id, plugInType); if (instanceRow == null) { int?sampleAppId = null; if (string.IsNullOrEmpty(Request.QueryString[SampleAppIdInQueryString])) { sampleAppId = Maps.Instance.DuradosMap.Database.GetFirstSampleId(plugInType); } else { sampleAppId = (int?)Convert.ToInt32(Request.QueryString[SampleAppIdInQueryString]); } instanceRow = Maps.Instance.DuradosMap.Database.CreateSampleInstanceRow(id, plugInType, sampleAppId, GetPlugInUserId()); if (instanceRow == null) { new AppsGenerator().Generate(sampleAppId.Value, Maps.PlugInSampleGenerationCount); instanceRow = Maps.Instance.DuradosMap.Database.CreateSampleInstanceRow(id, plugInType, sampleAppId, GetPlugInUserId()); } if (instanceRow == null) { Exception exception = new DuradosException("Could not create sample instance"); Map.Logger.Log(this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString(), "username: "******", id: " + this.Request.QueryString["id"], exception, 78, "url: " + System.Web.HttpContext.Current.Request.Url.ToString()); return(RedirectToAction(EmptyWidgetActionName)); } } //int appId = Maps.Instance.DuradosMap.Database.GetAppId(id, plugInType, instanceRow, userId); //(int)instanceRow["AppId"]; int appId = (int)instanceRow["AppId"]; string viewName = (string)instanceRow["ViewName"]; string appName = Maps.Instance.GetAppRow(appId).Name; if (string.IsNullOrEmpty(appName)) { Exception exception = new DuradosException("No app name for id:" + appId); Map.Logger.Log(this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString(), "username: "******", id: " + this.Request.QueryString["id"], exception, 78, "url: " + System.Web.HttpContext.Current.Request.Url.ToString() + ", appName: " + appName + ", viewName: " + viewName); return(RedirectToAction(EmptyWidgetActionName)); } //bool isSampleApp = !instanceRow.IsNull("SampleAppId"); //string paremeters = string.Empty; //if (isSampleApp) //{ // string creatorGuid = GetCreatorGuid(appId); // paremeters = "&id=" + creatorGuid; //} Map map = Maps.Instance.GetMap(appName); if (!IsAuthorized(map)) { Exception exception = new DuradosException("Not authorized for app " + appName); Map.Logger.Log(this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString(), "username: "******", id: " + this.Request.QueryString["id"], exception, 78, "url: " + System.Web.HttpContext.Current.Request.Url.ToString() + ", appName: " + appName + ", viewName: " + viewName); return(RedirectToAction(EmptyWidgetActionName)); } Durados.View view = map.Database.Views.ContainsKey(viewName) ? map.Database.Views[viewName] : null; if (view == null || !IsAuthorized(view)) { Exception exception = new DuradosException("Could not find view " + viewName + " check that configuration files exist"); Map.Logger.Log(this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString(), "username: "******", id: " + this.Request.QueryString["id"], exception, 78, "url: " + System.Web.HttpContext.Current.Request.Url.ToString() + ", appName: " + appName + ", viewName: " + viewName); return(RedirectToAction(EmptyWidgetActionName)); } string url = GetViewUrl(map, viewName) + GetPublicParameter(); //string url = GetViewUrl(map, viewName) + GetUserIdParameterForLogin(instanceRow, appId) + GetPublicParameter(); //if (!IsSignedIn(Maps.Instance.DuradosMap.Database.GetCreatorUsername(appId))) //{ // SignOut(); // SignIn(Maps.Instance.DuradosMap.Database.GetCreatorUsername(appId)); // return Redirect(url); //} UpdatePlan(instanceRow); ViewData["url"] = url; ViewData["signOutUrl"] = Url.Action("SignOut") + "?" + GetParameters(); //map.Url + "/Account/LogOff"; Map.Logger.Log(this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString(), "username: "******", id: " + this.Request.QueryString["id"], null, 77, "url: " + System.Web.HttpContext.Current.Request.Url.ToString() + ", redirect: " + url + ", appName: " + appName + ", viewName: " + viewName); return(View()); //return Redirect(url); }