How to handle conditional formatting/CSS in PnP Search Web Part?

I just love the PnP Search web part as it allows us to bring forward the enterprise search solutions. Great work!!

My question is how to best handle conditional formatting. In the code below I have a requirement that site collections should have a green header color and anything else should be red. The code works but I have a hard time mixing content and css. Is there any guideline how this should be handled? Thanks

 {{#each items as |item|}}                 <div class="ms-Grid-col ms-sm12 ms-md6 ms-lg4">                     {{#> resultTypes}}                         {{!-- The block below will be used as default item template if no result types matched --}}                         <div class="singleCard">                                 {{#eq RefinableString01 'STS'}}                                     <li class="ms-ListItem ms-ListItem--document" style="background-color: green"  tabindex="0">                                 {{else}}                                         <li class="ms-ListItem ms-ListItem--document" style="background-color: red"  tabindex="0">                                 {{/eq}}                                 <div class="cardInfo">                                     <span class="HeaderImage" ><img  src="/sites/TestingReactSearchWebPart/ModernDisplaytemplates/classic_logo_large.png" alt=""></span>                                     <span class="titleArea" style="word-wrap: break-word"> <h3><a  href="{{getUrl item}}">{{Title}}</a><br /></h3> </span>                                        <span class="ms-ListItem-secondaryText">Template: {{RefinableString01}}</span>                                     <span class="ms-ListItem-tertiaryText">{{getDate Created "LL"}}</span>                                      <div class="ms-ListItem-selectionTarget"></div>                                 </div>                             </li>                         </div>                     {{/resultTypes}}                 </div>             {{/each}} 

Are Result objects the cleaner way to handle failure, than exceptions? [duplicate]

This question already has an answer here:

  • Are error variables an anti-pattern or good design? 11 answers

I was watching the following video by Vladimir Khorikov, which recommends to “Refactoring Away from Exceptions” pluralsight.com – Applying Functional Principles in C# – Refactoring Away from Exceptions and instead using a Result object. You can also find a blog about it here: enterprisecraftsmanship.com – Functional C#: Handling failures, input errors

To summarize it, the recommendation is to prefer returning a result object then throwing an exception. Exceptions should be used to signalize a bug only. The arguments for this approach are the following:

  • Methods which throws exceptions are not “honest”. You can’t recognize if a method is expected to fail or not, by looking at its signature.
  • Exception handling adds a lot of boiler plate code.
  • When exceptions are used to control the flow, it has a “goto” semantic, where you can jump to specific line of code.

On the other hand return values can be ignored (at least in C#), which exceptions can not.

Is it a good idea to refactor a existing enterprise application in this direction? Or is a less radical approach the better one? (I belive that it make sense for sure to avoid Vexing exceptions by using return types for method like ValidateUserInput(string input))

Note that Are error variables an anti-pattern or good design? is a similar question. The difference is, that I am not talking about “Error by magic values” (returning a error code or even worse null) which is clearly an anti pattern. I am talking about the pattern presented by Vladimir Khorikov, which doesn’t have the same drawbacks like just returning a primitive error code. (For example: Result objects have a error message, like exceptions does)

How do I handle a player who wants to burn everything down?

In my most recent adventure, the party was attacking a wooden goblin fort when the dragonborn PC had the bright idea to use his fiery breath to burn it down. I thought that it was a clever idea and was glad that he thought of it, but I am wary of letting this become the solution to every problem (especially as an adventure in the near future may involve exploring an evil forest). The reason that I am worried about this is because I think that burning down a building from the outside will often be a lot less interesting than exploring it and fighting its denizens.

How can I prevent a player from burning down everything to solve problems?

Note that I am not particularly concerned with whether or not dragonborn breath is capable of setting something on fire. I don’t feel like just telling the player “the rules say that you can’t do that” would be a fun solution. I want to keep things fun but also prevent the game from getting completely out of control.

How to handle major changes (cross-cutting concerns) in REST API?

Let’s say we have a REST API application A consumed by other 30 applications. Application “A” uses a cross-cutting security implementation using a Security NuGet package 1.0. All minor/major changes are properly versioned and backwards compatible (e.g. not breaking existing consumers with new changes).

The problem is, what happens if you need to upgrade your Security NuGet package to 2.0 and do major changes to your security across application A. Technically, the API contract between source and consumers don’t change but you may need a thorough regression testing to make sure app A with Security 2.0 is not breaking any existing functionality in any of the 30 consumers

Should you:

  1. Create a new source code base for Security 2.0 version of the app and Deploy and maintain old and new versions of the app? Then move the 30 consumers gradually to the new API? or
  2. Migrate app A to Security 2.0 and do thorough regression testing from all 30 consumers

What is the recommended approach to handle these type of changes that span across applications and cannot be handled through endpoint versioning? E.g. wide cross-cutting security implementation? In theory your source API (app A) should be agnostic of consumers as long as it’s not breaking them).

As this article points out, this is not a versioning problem but a change management problem: https://www.ben-morris.com/rest-apis-dont-need-a-versioning-strategy-they-need-a-change-strategy/

How should I handle docstrings of subclass methods?

I have an abstract class structured somewhat like this:

class AbstractQuery(object, zip_code):     def execute(self):         """         Retrieve information about a zip code         The information returned will depend on the subclass         """         url, params = self._build_query(zip_code)         response = requests.get(url, params=params)         if self._is_valid(response):             # etc.      def _build_query(self, zip_code):         """         Returns a tuple (url, params) where         url is the url of the API to query and         params are the query params for the API call         """         raise NotImplementedError      def _is_valid(self, response):         """         Returns True if response contains information necessary         to continue processing         """         raise NotImplementedError 

_build_query for example is always going to do the same thing, there’s just going to be minor implementation differences. Do I just keep the docstring in the base class? Or copy/paste it down and violate DRY? What would a user or maintainer of these classes want to see?

How do I handle a group that does not understand the ‘assumption rule’?

1st rule of D&D (as of 3rd edition/pathfinder): The GM is the final arbiter on all rules.

I understand this, completely, and do not disagree. That said, I’m having trouble with a group that doesn’t seem to understand what I call the ‘assumption rule,’ which is as follows.

Assumption Rule: Unless and until the GM makes a ruling to the contrary, the rules of the game are assumed to be as they are stated in the book.

I have yet to find anywhere that it actually says this, but it just seems like common sense to me. If I cannot assume, at least for the majority of the time, that the rules of the game are as they are stated in the books we’re using to play the game, how can I expect to be able to make and use a character that I made with those rules in mind?

Also, I’m not referring to one instance. This is not me complaining about a GM denying me the ability to abuse one minor loophole in the system to break the game. The group I am referring to will, as soon as anyone says anything like ‘the book says,’ almost yell ‘the GM trumps book.’ Whether or not the GM has actually said anything about making a ruling, or even disagreeing with the book in the first place.

The biggest issue I’m having with this is that, for the current campaign, the GM we have is relatively new, and isn’t an expert on the rules, as they are depicted in the book. He is so used to playing with this same group, that he assumed a common house rule to actually be the rule as it was stated in the book. (The rule in question was the re-rolling of 1’s when rolling stats. He was surprised when I asked him if we were doing that for his game.) This is becoming a frequent problem for me, as I play in multiple groups, and house rules vary between them. So, I’m forced to fall-back on the ‘assumption rule’ more often then not, only to have it blow up in my face every time I try to use a completely-legal tactic to gain an advantage in combat, or make a check that the rules say I can make, then have the group turn on me when I point that out because the GM did not specifically state that we weren’t using that rule.

UPDATE: To clarify something I’m not entirely sure everyone reading this is getting, I’m not being a ‘rules-lawyer.’ I’m not quoting the rule book religiously, or trying to use it to argue with the GM, or anything like that. I’ll do something like try to change a random NPC’s opinion of my character with a diplomacy check, only to be told that I have to role-play it out. It won’t be someone important to the plot, or even someone that I could potentially get some huge advantage from. This exact situation was me trying to rp my character talking the bartender into giving him a minor discount. And it was the group that told me I had to RP it, not the GM.

Or, as another example, during one combat session, I said that I was going to use the withdraw action, only to have the whole table look at me like I was stupid, except the GM who just looked confused. When they (the group, not the the GM) told me that I would take an AoP for it, they yelled their ‘GM trumps rules’ mantra at me just because I looked up what a ‘withdraw action’ is.

This is not a rant. I’m not trying to vent about something. I’m trying to convey what happened, as it happened, and ask for advice on how best to deal with this. Answers from experience would be appreciated, but I will listen to any advice anyone has to offer.

I like the group, and I enjoy being part of the campaigns they play, it’s just this one issue that seems to keep coming up. I would hate for something like this to get me kicked out.

As the dungeon master, how do I handle a player that insists on a specific class when I already know that choice will cause issues?

I agreed to DM Dragon Heist for a group of my friends. One of them wants to play a wizard. Based on past experience, I know that she will ignore the prepared spells and just cast anything she wants. Our previous DM attempted to keep her to the rules, but she wore him down and eventually he caved on multiple occasions. Because of this, I recommended she play a sorcerer. While I don’t think this will stop them from trying to cheat, I’m hoping it will at least help with the type of issues she caused in the previous campaign. She’s also the least experienced player in our group, doesn’t usually play attention, and rarely even remembers to bring her character sheet. She is ignoring my recommendation, though, and insists on playing a wizard. I’m not really sure why, other than she knows that I don’t want her to play one.

How can I best handle this situation? I would love to exclude her from the game, but I already know that the remainder of my friends would be unhappy. I can allow her to play a wizard, but based on prior experience I know that she bends the rules and I really don’t want to DM a campaign where one or more players are cheating. I know that eventually she’ll lose interest and stop showing up to the game, but I would prefer to deal with the issue now. Also I’d rather address it now, than have to argue with her every single session. I’m worried about setting the precedent that her player can do absolutely anything that she wants.

I offered to let someone else DM, but no one appears willing to. The previous DM seems to need a break, and will only be a player in this campaign.

Based on the comments, I get the impression that the general advice is that I should just stop worrying and let my players have fun even when that means ignoring the rules.

TLDR: One of my players chose a certain class, but I am concrened that allowing them to play the class will create problems and drag the game down.

How to handle a player who asks me never ending questions about roleplay things

Recently I started up a new game. I recruited players, got them to make characters, and was ready to have some fun with them.

One of the players keeps asking questions. They ask about every detail of their character, they ask about other roleplay systems, they ask about other characters they’re generating, they ask about games and movies they’re playing, they ask questions about the rules. It’s a long, never ending barrage.

I regret inviting them into the game now, because it’s such a drain being asked endless questions. I’ve told them to ask questions in the public discord or online, they agree, but they immediately go back to asking me more questions, in private messages on discord when they get some new idea. There’s a certain amount of, politeness in helping them with their character and understanding the world, but their sheer volume of questions is getting tiring.

It’s made worse by the fact that English isn’t their first language, and often their questions are vague and confusing and not easy to answer.

We’re involved in another game, and I need to remain reasonably polite, so saying “Go away and shut up.” isn’t a good option. What’s a reasonably polite way to stem the tide of questions?

The game we are playing is Dungeons and Dragons fifth edition, so there are many knobs to tweak and play with on characters.

MainWindowHandle returns wrong IntPtr handle

I have a window with a button which has a tooltip. Clicking the button shows a dialog window. The problem occurs when focus is switched from the app to other app (e.g. notepad) then clicking the button with visible tooltip Process.GetCurrentProcess().MainWindowHandle returns different handle than when the button is clicked before the tooltip is shown or when focus is on the app.

I am using that handle to set dialog’s owner with WindowInteropHelper. When that wrong handle is assigned and dialog is shown it appears for half a second and disappears. The main window is blocked and the app must be killed.

I have checked call stack and the process stops in ShowDialog method waiting for the dialog to be closed. I have also checked what makes that dialog to close and it is some Windows API connected with tooltip that forcefully closes the dialog.

As far as I know WPF creates handles for each window but each control in that window is related to that handle (unlike in Win32 where each one has its own hwnd). However, popups like dropdowns, context menus have their own handles. Maybe the same thing applies to the tooltip. If so, based on what I already know it seems that when the app is out of focus MainWindowHandle property returns tooltip’s handle and dialog’s owner is that tooltip. After button click the tooltip closes and the app is stuck. I have read about it here. Nevertheless, it is weird that when the app has focus everything works correctly. Moreover, the logs from below are also strange. When hovering over the button MainWindowHandle returns correct handle but when it is clicked it switches to something else.

Debug logs from tooltip’s Opening and Closing events when the app is out of focus and button is clicked:

Tooltip Opening - MainWindowHandle: 198116 Tooltip Opening - MainWindowTitle: MainWindow ------ Tooltip Closing - MainWindowHandle: 2295110 Tooltip Closing - MainWindowTitle:  ------ 

Click handler for the button with tooltip:

private void ClickMeButtonClick(object sender, RoutedEventArgs e)         {             var myDialog = new MyDialogWindow();             var process = Process.GetCurrentProcess();             MainWindowHandle = process.MainWindowHandle;             MainWindowTitle = process.MainWindowTitle;             var windowInterop = new WindowInteropHelper(myDialog) {Owner = MainWindowHandle};             myDialog.ShowDialog();         } 

I am not sure if it is a bug. Maybe I am doing something wrong? Or the problem lies somewhere else? How do I get main window’s handle is such case? Note that I have to use WindowInteropHelper and Process.GetCurrentProcess().MainWindowHandle because WPF is hosted in MFC window. However, I was able to reproduce this issue in a simple WPF app.