public string CreateMarkdown(Model modelToSummarise) { // get help uri string helpURL = ""; try { HelpUriAttribute helpAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(HelpUriAttribute), false) as HelpUriAttribute; string modelHelpURL = ""; if (helpAtt != null) { modelHelpURL = helpAtt.ToString(); } // does offline help exist var directory = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); string offlinePath = Path.Combine(directory, "CLEM/Help"); if (File.Exists(Path.Combine(offlinePath, "Default.htm"))) { helpURL = offlinePath.Replace(@"\", "/") + "/" + modelHelpURL.TrimStart('/'); } // is this application online for online help if (NetworkInterface.GetIsNetworkAvailable()) { // set to web address // not currently available during development until web help is launched helpURL = "https://www.apsim.info/clem/" + modelHelpURL.TrimStart('/'); } if (helpURL == "") { helpURL = "https://www.apsim.info"; } } catch (Exception ex) { throw new Exception(ex.Message); } string markdownString = ""; if (File.Exists(targetFilePath)) { markdownString = $"[View descriptive summary of current settings in browser](<{targetFilePath.Replace("\\", "/")}> \"descriptive summary\") {Environment.NewLine} {Environment.NewLine}"; } markdownString += $"View reference details for this component [{modelToSummarise.GetType().Name}](<{helpURL}> \"{modelToSummarise.GetType().Name} help\") {Environment.NewLine}"; return(markdownString); }
public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.ApsimXFile = model as Simulations; this.ExplorerPresenter = explorerPresenter; this.View = view as IModelDetailsWrapperView; if (model != null) { ViewNameAttribute viewName = ReflectionUtilities.GetAttribute(model.GetType(), typeof(ViewNameAttribute), false) as ViewNameAttribute; PresenterNameAttribute presenterName = ReflectionUtilities.GetAttribute(model.GetType(), typeof(PresenterNameAttribute), false) as PresenterNameAttribute; View.ModelTypeText = model.GetType().ToString().Substring("Models.".Length); DescriptionAttribute descAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(DescriptionAttribute), false) as DescriptionAttribute; if (descAtt != null) { View.ModelDescriptionText = descAtt.ToString(); } else { View.ModelDescriptionText = ""; } // Set CLEM specific colours for title if (View.ModelTypeText.Contains(".Resources.")) { View.ModelTypeTextColour = "996633"; } else if (View.ModelTypeText.Contains("Activities.")) { View.ModelTypeTextColour = "009999"; } HelpUriAttribute helpAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(HelpUriAttribute), false) as HelpUriAttribute; View.ModelHelpURL = ""; if (helpAtt != null) { View.ModelHelpURL = helpAtt.ToString(); } if (viewName != null && presenterName != null) { ShowInLowerPanel(model, viewName.ToString(), presenterName.ToString()); } } }
public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.ApsimXFile = model as Simulations; this.explorerPresenter = explorerPresenter; this.view = view as IModelDetailsWrapperView; if (model != null) { ViewNameAttribute viewName = ReflectionUtilities.GetAttribute(model.GetType(), typeof(ViewNameAttribute), false) as ViewNameAttribute; PresenterNameAttribute presenterName = ReflectionUtilities.GetAttribute(model.GetType(), typeof(PresenterNameAttribute), false) as PresenterNameAttribute; this.view.ModelTypeText = model.GetType().ToString().Substring("Models.".Length); DescriptionAttribute descAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(DescriptionAttribute), false) as DescriptionAttribute; if (descAtt != null) { this.view.ModelDescriptionText = descAtt.ToString(); } else { this.view.ModelDescriptionText = ""; } // Set CLEM specific colours for title if (this.view.ModelTypeText.Contains(".Resources.")) { this.view.ModelTypeTextColour = "996633"; } else if (this.view.ModelTypeText.Contains(".Activities.LabourRequirement")) { this.view.ModelTypeTextColour = "cc33cc"; } else if (this.view.ModelTypeText.Contains(".Activities.")) { this.view.ModelTypeTextColour = "009999"; } else if (this.view.ModelTypeText.Contains(".Groupings.")) { this.view.ModelTypeTextColour = "cc33cc"; } else if (this.view.ModelTypeText.Contains(".File")) { this.view.ModelTypeTextColour = "008000"; } else if (this.view.ModelTypeText.Contains(".Market")) { this.view.ModelTypeTextColour = "1785FF"; } HelpUriAttribute helpAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(HelpUriAttribute), false) as HelpUriAttribute; this.view.ModelHelpURL = ""; if (helpAtt != null) { this.view.ModelHelpURL = helpAtt.ToString(); } var vs = ReflectionUtilities.GetAttributes(model.GetType(), typeof(VersionAttribute), false); if (vs.Count() > 0) { VersionAttribute verAtt = vs.ToList <Attribute>().Cast <VersionAttribute>().OrderBy(a => a.ToString()).Last() as VersionAttribute; if (verAtt != null) { string v = "Version "; v += verAtt.ToString(); this.view.ModelVersionText = v; } else { this.view.ModelVersionText = ""; } } if (viewName != null && presenterName != null) { // if model CLEMModel if (model.GetType().IsSubclassOf(typeof(CLEMModel)) | model is ZoneCLEM | model is Market | model is RandomNumberGenerator) { // all CLEMModels will handle this presenter ShowInLowerPanel(model, "UserInterface.Views.CLEMView", "UserInterface.Presenters.CLEMPresenter"); } else if (typeof(ICLEMPresenter).IsAssignableFrom(Assembly.GetExecutingAssembly().GetType(presenterName.ToString()))) { // apply this if the presenter has ICLEMPresenter interface and is ready to create presenters ShowInLowerPanel(model, "UserInterface.Views.CLEMView", "UserInterface.Presenters.CLEMPresenter"); } else { ShowInLowerPanel(model, viewName.ToString(), presenterName.ToString()); } } } }
public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.ApsimXFile = model as Simulations; this.ExplorerPresenter = explorerPresenter; this.View = view as IModelDetailsWrapperView; if (model != null) { ViewNameAttribute viewName = ReflectionUtilities.GetAttribute(model.GetType(), typeof(ViewNameAttribute), false) as ViewNameAttribute; PresenterNameAttribute presenterName = ReflectionUtilities.GetAttribute(model.GetType(), typeof(PresenterNameAttribute), false) as PresenterNameAttribute; View.ModelTypeText = model.GetType().ToString().Substring("Models.".Length); DescriptionAttribute descAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(DescriptionAttribute), false) as DescriptionAttribute; if (descAtt != null) { View.ModelDescriptionText = descAtt.ToString(); } else { View.ModelDescriptionText = ""; } // Set CLEM specific colours for title if (View.ModelTypeText.Contains(".Resources.")) { View.ModelTypeTextColour = "996633"; } else if (View.ModelTypeText.Contains(".Activities.LabourRequirement")) { View.ModelTypeTextColour = "cc33cc"; } else if (View.ModelTypeText.Contains(".Activities.")) { View.ModelTypeTextColour = "009999"; } else if (View.ModelTypeText.Contains(".Groupings.")) { View.ModelTypeTextColour = "cc33cc"; } else if (View.ModelTypeText.Contains(".File")) { View.ModelTypeTextColour = "008000"; } HelpUriAttribute helpAtt = ReflectionUtilities.GetAttribute(model.GetType(), typeof(HelpUriAttribute), false) as HelpUriAttribute; View.ModelHelpURL = ""; if (helpAtt != null) { View.ModelHelpURL = helpAtt.ToString(); } var vs = ReflectionUtilities.GetAttributes(model.GetType(), typeof(VersionAttribute), false); if (vs.Count() > 0) { VersionAttribute verAtt = vs.ToList <Attribute>().Last() as VersionAttribute; if (verAtt != null) { string v = "Version "; v += verAtt.ToString(); View.ModelVersionText = v; } else { View.ModelVersionText = ""; } } if (viewName != null && presenterName != null) { // if model CLEMModel if (model.GetType().IsSubclassOf(typeof(CLEMModel)) || model is ZoneCLEM) { ShowInLowerPanel(model, "UserInterface.Views.CLEMView", "UserInterface.Presenters.CLEMPresenter"); } else { ShowInLowerPanel(model, viewName.ToString(), presenterName.ToString()); } } } }