From code can I determine if glimpse is active for the current request? - glimpse

I want to add some custom plugins to glimpse. However the profiling I want to do is expensive so I only want to do it if glimpse id turned on for the current request. Can I access a property in code to tell me if glimpse is currently on.
Something like:
if(GlimpseConfig.IsGlimpseActive)
{
}

First of all if you're creating a plugin for Glimpse like a custom tab then your tab will only be asked for data if Glimpse is active for the given request.
So to be clear, if you want to make a check like you mentioned above inside your tab, then that is not necessary since Glimpse will not call you in the first place. But if you are talking about enabling/disabling some profiling code that will be accessed by your custom tab and which might be expensive, then I guess a check might indeed by helpful. Unfortunately there is currently no way to do this without some kind of abuse of Glimpse internals.
Your question seems to have the same requirement as this question so I'm not going to paste the same answer here, but I'll paste the code sample for completeness of this answer.
But in short you could do the following if you keep in mind that there are no guarantees on whether this will continue to work in upcoming releases, but check the other question for more details.
public static class CurrentGlimpseStatus
{
private const string GlimpseCurrentRuntimePolicyKey = "__GlimpseRequestRuntimePermissions";
public static bool IsEnabled
{
get
{
RuntimePolicy currentRuntimePolicy = RuntimePolicy.Off;
if (System.Web.HttpContext.Current.Items.Contains(GlimpseCurrentRuntimePolicyKey))
{
currentRuntimePolicy = (RuntimePolicy)System.Web.HttpContext.Current.Items[GlimpseCurrentRuntimePolicyKey];
}
return !currentRuntimePolicy.HasFlag(RuntimePolicy.Off);
}
}
}

Related

Is it possible to not sample particular requests in Application Insights?

I have a question about Azure Application Insights Sampling.
I do require sampling at 10%, which I know I can achieve easily on Application Insights using applicationinsights.json. But I also have a use case where I do not want to sample (filter out) certain requests depending on a parameter. For e.g. let's say I hit a manual test request, then I do not want it to get filtered by sampling. Another use case, let's say for a specific user, I do not want the request to get filtered.
But the config for this is not static, which means, I cannot fix this during startup in the applicationinsights.json. I need to decide it at the request level. I will need to check some request parameters, and based on them, I will decide whether to sample or not sample this request.
Is this possible to achieve? Could you please share code/docs if it is?
I believe it is accomplished by providing a custom TelemetryInitializer.
See the question "There are certain rare events I always want to see. How can I get them past the sampling module?" in the sampling document: https://learn.microsoft.com/en-us/azure/azure-monitor/app/sampling
public class MyTelemetryInitializer : ITelemetryInitializer
{
public void Initialize(ITelemetry telemetry)
{
if (somecondition)
{
((ISupportSampling)telemetry).SamplingPercentage = 100;
}
}
}

XPage DynamicViewPanel link bug, or developer blindness?

Preamble: the last time I had an issue with something from the extension libraries, I immediately posted a bug report on openNTF.org. It then turned out that I had missed a property setting that made everything work perfectly. To prevent this issue from happening again, I decided to post the question here first, can anyone reproduce the error that I am having, or am I missing a property on the xe:DynamicViewPanel control?
tested ExtLib versions tested:
901v00_06.20140424-0600
901v00_02.20131212-1115
Domino/Notes version used Domino 9.0.1
Steps to reproduce
Create a dashboard XPage application. - data is stored in a different database.
Using a dynamicViewPanel control, access a database that lies ON THE SAME SERVER and show information from that database in the view.
Click on a document link in the dynamic view panel and look at the URL in the browser. When the dynamicViewPanel is pointing to a view in a different database hosted on the same server as the dashboard, the url looks like this : http://path/Portal.nsf/%24%24OpenDominoDocument.xsp?databaseName=CN=Maestro/O=hol-dev/C=DE!!path/Portal.nsf&documentId=A6727D8AF7D2FE19C1257C9E0034A14C&action=editDocument
The appropriate Xpage defined by the form name of the document being clicked on will open and the data saved in that document will even be loaded.
Click on a button that performs any action with the defined document datasource. It can be as simple as printing a string to the server when notesXspDoc.isNewNote(). You will get an error message saying that (in the case above) NotesXSPDocument.isNewNote() null. This means that the variable IS NOT null, but for some reason you are getting a null error response.
This error will only happen when the dashboard and the data database are on the same domino server. As soon as one of them are moved, it will work perfectly AND the URL will be correctly written; the server name of the databaseName parameter will be written in the abbreviated way.
In an attempt to understand/fix this issue, I took a closer look at the code in the Extension Library class com.ibm.xsp.extlib.component.dynamicview.UIDynamicViewPanel. There, I found the call to super(XspViewPanel).getDocumentUrl(). My guess is that the error lies in that function, but that is not a class that is defined by the ExtLibs. At the very least I would be interested to know what is written there.
educated guesswork
I am pretty certain of the following: The page when first open loads because key information is saved in the requestScope. This information is not not passed on to the java DominoDocument object which is created by the NotesXspDocument javascript 'class'. When (in the background) the DomDoc.restoreDocument() function is called, it tries to locate the database CN (as returned by the param.get("databaseName") function) and fails. Thus, no further function can be called on the object since an exception would always be thrown. (This is all an educated guess on my part)
My Questions clearly stated
Is this a known bug and I am just not finding it in my google searches?
Am I just not seeing a property of the ViewPanel that would fix this error?
Is there a better work around other than setting the "ignoreUrlParams" property of the document data source and calculating the server/documentID?
Thank you very much for all assistance given!
EDIT
Changing the "ignoreRequestParams" property to true and calculating the databaseName and the documentID does not make a difference at all. I am really confused as to why it does not work, I would think that calculating the source information and not paying any attention to the request parameters would solve it, but i am having the same issues. Any further assistance would be greatly appreciated!
After a great deal of testing, deleting functions and re-adding them, I think I have the answer I sought. I cannot really say why this is, and I find it a crappy design if my thoughts are correct.
I found that when I commented out a certain javascript line which opened the database in a background java class to find out the user's current roles, it worked again. Upon further investigation, when I took out the java lines that recycled the source database, the dashboard worked again. This means, however, that the background c++ object is still existing in the background somewhere. In this project, it seems to only be an issue when the source DB and dashboard DB are hosted on the same server.
I am going to answer my question with "No, this is not a bug in the dynamicViewPanel", but rather a questionable design from IBM itself. Either we should be recycling our Notes objects, or we should not be recycling our Notes objects, or we should be given a very detailed description of when and when not to recycle. Maybe I am just not used doing my own GC. Here is the code that was giving me a hard time (some variable names have changed to protect the anonymity of the customer):
public String getDatabaseRoles(){
Session session = null;
Database db = null;
Vector<String> roles = null;
try {
session = SessionHelper.getCurrentSession();
db = DatabaseController.getApplicationInstance().getDbFile().getDatabase();
roles = db.queryAccessRoles(session.getEffectiveUserName());
} catch (NullDatabaseException e) {
// already logged
} catch (NotesException e) {
ErrorWriter.getSessionInstance().writeError(new Date(), ErrorLevel.ERROR, "EprDatabaseController.getDatabaseRoles()",
e);
} catch (NullSessionException e) {
// already logged
} finally {
//if(db != null) try {db.recycle();} catch(NotesException e) {} //commented out due to issues when portal is on same server as data.
//if(session != null) try {session.recycle();} catch(NotesException e) {}
}
StringBuilder roleStr = new StringBuilder();
if(roles != null){
for(String role : roles){
if(!StringHelper.isNullOrEmpty(role)){
roleStr.append(role);
roleStr.append(":");
}
}
}
ErrorWriter.getSessionInstance().writeError(new Date(), ErrorLevel.TRACE, "DatabaseController.getEPRDatabaseRoles()",
"Database Roles: " + roleStr.toString());
return roleStr.toString();
}
Again, just so workarounds are already answered for future readers,
have the source database on a different server.
set the ignoreUrlParams property of the document datasource and calculate the the documentID and databaseName correctly inserting the server name as abbreviated.
This not being the true answer of my question, I am just putting this here for future user ease.

Orchard CMS: Invoking two actions leads to duplicate notifications

Our Orchard application displays two of all notifications that are added to the notification service. So far we have traced the problem and know what is causing it, but are looking for a solution other than the obvious, for reasons I shall now elaborate.
So we are using a number of themes to render our Orchard based application. Within our layout, we have a Razor call to draw a header bar that displays a set of information about the user that is logged in.
#Html.Action("OutOfGameHeader", "Options", new { area = "Area.area.Location.Common" })
This action calls the OnResultExecuting() method in Orchard.UI.Notify.NotifyFilter which (among other things) populates the Messages Zone with the current set of notifications. When we make the call the render the Messages Zone, this same method runs again and the notifications are added to the Zone's shape again resulting in duplicate notification being displayed when the Zone is actually drawn.
Can anyone think of a solution that meets the following criteria:
Drawing the header without calling #Html.Action() to avoid OnResultExecuting() being triggered the first time.
Without creating a new Widget in a new Zone as this would involve us changing the manifest for dozens of existing themes to include it.
We also found this just below the point in the code where the notifications are added to the Zone, so if anyone knows anything more about it, that would be helpful too.
//todo: (heskew) probably need to keep duplicate messages from being pushed into the zone like the previous behavior
//baseViewModel.Messages = baseViewModel.Messages == null ? messageEntries .Messages.Union(messageEntries).ToList();
//baseViewModel.Zones.AddRenderPartial("content:before", "Messages", baseViewModel.Messages);
Any thoughts greatly appreciated.
Avoid Html.Action. This runs through the whole lifecycle as if this was a new request. That you think you need it is often a sign that you need to refactor and extract that logic that you want to re-use out of your controller. In Orchard, it's also better to use dynamic shapes.

Sharepoint 2007 Webpart variables problem on reload

I'm having trouble with the webparts variables... I came from standard ASP language, so, to me, store variables in session and other parts is the common way to do everything =)
Now i had to create a webpart, the wp has to write a graph from parameter and i cannot understand HOW variables works: i cannot understand WHEN saved and WHEN erased and other thing like this!
Let me explain: i have a web part with the configuration toolbar on the right in which i put the values.. Everytime a button is pressed or a value in the dropdown list changes, it raises an event which causes the "CreateChild" function..
Many times the data is "stored", other time they are not!
That's the way i used to store value (in the ApplyChanges override function):
WPChartGenerator wpParent = (WPChartGenerator)this.ParentToolPane.SelectedWebPart;
wpParent.WebUrl = txtWebUrl.Text.Trim();
And in the CreateChild event i get the value like:
WPChartGenerator wpParent = (WPChartGenerator)this.ParentToolPane.SelectedWebPart;
this.ddlWeb = new DropDownList();
this.ddlWeb.ID = "ddlweb" + wpParent.ID;
ddlWeb.SelectedValue = wpParent.WebService;
Now.. Sometimes this works, for example, when i push a button I invoke in the code of the button and then the code to store every value.. In some case (like buttons) this works, in other (like dropdown list index changed event) this fails and i found every object in the wpParent equal to it's initial value.
Another thing i noticed, is that in certain cases when an event is triggered, the first thing to be executed (even first than the event's associated code) il CreateChild (even first than OnLoad!!!)
Can anybody tell me what I'm doing in the wrong way? Do anybody has a good tutoria for this matter?
Thanks & sorry 4 my School level English =)
Forget to say that every variable has been implemented as a Property, like that:
[WebBrowsable(false)]
[Personalizable(PersonalizationScope.Shared)]
[WebPartStorage(Storage.Shared)]
public string WebUrl
{
get
{
return this.webUrl;
}
set
{
this.webUrl = value;
}
}
I can't see all the code there so I don't really know what you're doing wrong (i.e. do you actually have an ApplyChanges method) but from the way you've worded your question it sounds like you really need to start at the beginning, follow one of these walkthrough tutorials and make sure you understand the basics and then start adding in the code for your project.
MSDN - Creating Web Parts for SharePoint (VS2010)
MSDN - Walkthrough: Creating a Basic SharePoint Web Part (WSS 3.0)
Developing SharePoint 2007 Web Parts

SharePoint web part storage with multiple instances of web part on same page

I have a custom web part I've built, that I'm attempting to place three instances of on a single page. What I've noticed is that when I have a single instance on the page, the custom properties save and work appropriately. When I then add two more instances of the same custom web part to the page, the following web parts do not save their custom property values. I figure I must be doing something wrong when it comes to the WebPartStorage attribute. Any thoughts?
[Browsable(true), Category("Miscellaneous"),
WebPartStorage(Storage.Personal),
FriendlyName("List"), Description("List")]
public String List { get; set; }
Have you tried Storage.Shared rather than Storage.Personal?
This would help to isolate the personalisation store as the cause of the problem.
Additionally try removing the FriendlyName and Description attributes.
Interestingly enough, I ended up removing the default value and description attributes and my scenario began working. Not a very helpful explanation, I know, but maybe it will help someone else in the future.

Resources