What use is initUserDefaultOptionalParameterPackage in EWL? - c#

I'm using EWL and I have an EwfPage and when I type partial in the Info class I see:
partial void initDefaultOptionalParameterPackage( OptionalParameterPackage package )
and
partial void initUserDefaultOptionalParameterPackage( OptionalParameterPackage package )
I don't really see what they're used for. They also sound similar and I'm wondernig what the difference between them is.

They are both used if you want an optional parameter to default to something other than the default value of its C# data type. There are two significant differences:
initUserDefaultOptionalParameterPackage is called only when you are creating an Info object for the page; it is not called when the page is requested. If a request is made without a parameter value in the URL, the framework will fall back to the value specified in initDefaultOptionalParameterPackage or the data type default.
You can access AppTools.User from initUserDefaultOptionalParameterPackage if you meet the conditions specified in the doc comment for AppTools.User.
An example of when you might use initUserDefaultOptionalParameterPackage is a page that should default to showing information for the currently logged-in user but has a select list or something that lets you look at information for a different user.

Related

Specflow global tag?

Please this simple scenario:
#Chrome
Scenario: Simple Calculation
Given user
When User login to the system
And ....
So i have many scenarios, each scenario use default Browser or specific one (in this example the Browser is Chrome)
So i have several URLs than i am checking so i looking for way to define global Tag what will represent URL and inside .cs file this Tag will converted into my URL (and as i mentioned before i have several).
And i want to use it this way:
#GlobalURL
#Chrome
Scenario: Simple Calculation
Given user
When User login to the 'GlobalURL'
And ....
Any suggestion ?
If you want to use #GlobalURL tag for scenarios, then you can add method with annotation: [BeforeScenario] and in this method get that hook, and depending on it's value get correct url. In my project I made a separate class - TestConfiguration, which properties (base url, key, what kind of test) and filled from tags before every scenario, and then used in test.
Also you can in scenario send parameter and based on it choose url in the code.

Property from C# installer UI not accessible in Installer class

I'm having a problem with an installer from which I need to take a couple of fields of user input. Say that I have a Textboxes UI dialog in VS, in which I have set the first field's Property name to "URI". All the articles, StackOverflow posts etc that I can find are telling me I should access that value like so:
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
string uri = this.Context.Parameters["URI"];
}
but this is not working; all I am getting is an empty string. Why is that? What do I need to do differently?
This was a misconception partly due to examples I read passing the CustomAction Data property using the same name and capitalisation for the UI property name as for the CustomAction name. Specifically, I had interpreted it as meaning if one specified the value of 'Edit1Property' in a Textboxes UI dialog as "URI", the value entered would be passed to Context.Parameters["URI"]. This is missing a step. As per Alex's answer, specifically this article linked in the answer he suggested, one must also add each property that needs to be passed to the CustomActionData field for the Custom Action which uses it.
Thank you Alex.

How can I add a content type to an index programmatically?

I'm trying to programmatically create indexes corresponding to several types, so I can search through items of specific types in my controllers. (I tried using the type keyword in Lucene, but that seems to not work at all no matter what I do, so I changed my approach.)
However, I can't figure out how to tell Orchard to include a specific type in an index in a migration. I tried using:
var typeIndexing = ContentDefinitionManager.GetTypeDefinition(contentType)
.Settings.GetModel<TypeIndexing>();
typeIndexing.List = typeIndexing.List.Concat(indexName.Yield()).ToArray();
but that just returns null as the result of GetTypeDefinition().
I'm looking at using:
ContentDefinitionManager.AlterTypeDefinition(contentType, builder => {
builder.WithSetting("TypeIndexing.Indexes", indexName);
});
but that seems like it replaces the previous configured index, if it works at all (EDIT: nope), and I don't want to clobber the existing setting. (A different person on the team is handling our setup recipe.)
Is there any place where I could touch that setting and have it be stored and actually used by Orchard outside the recipe file?
To illustrate what I'm trying to accomplish using the analogous admin UI changes, under Content Definition > [Content Type Name] > Edit:
Before:
After:
What you're looking for is the Indexed() extension method. It accepts the indexes you want to use on the content type.
ContentDefinitionManager.AlterTypeDefinition(nameof(contentType),type =>
type
.Indexed("FirstIndex", "SecondIndex"));

REST API different resources for GET and POST/PUT?

I'm currently in the process of designing as RESTful of an API as I can using Microsoft's Web API 2 in C#. What I'm struggling on is how best to represent resources or the proper way to do it where the GET call and POST/PUT are very different.
For example say I have something calls states that have an id, name, status, etc., these can be assigned to a document. So I have a route like this /documents/{id}/states/ . If I call a GET here I need to get the full list of all assigned states including their id, name, etc.
However, in order to change which states are assigned to the document I simply need to pass the id. I cannot do this individually, it must be an array that gets sent up since users may be interacting with hundreds or thousands at a time.
So in this case I have a few issues. I don't even know if POST or PUT is correct here, and second whichever one it is can I just take in an array of integers?
In your case, I would suggest PUT is the method you would be wanting to use, as you know the location of the resource that you are updating. For more info, see here: http://restcookbook.com/HTTP%20Methods/put-vs-post/
In ASP.NET Web API 2 you can use the [FromBody] parameter attribute, so that your method signature would be:
public void UpdateStates(int id, [FromBody]List<int> states) {}
More info on parameter attributes can be found here: http://www.asp.net/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api

Using a variable page type in Frame.Navigate

Using WinRT, I am trying to implement navigation based on the users input. I tried to use a variable page type in the Navigate method. Unfortunately it doesn't look like it accepts variables as a page type. Does anybody know a way around this?
object myPage = page2;
this.Frame.Navigate(typeof(myPage));
I could just create switch statements and put the whole instruction in each statement but that seems ungainly and hard to maintain, especially since I may end up having a great deal of page types.
Any help would be appreciated.
Thank you.
Edit: A little clarification. I am writing a quiz program that stores the quizzes in a List, however the are multiple types of quizzes that require specific page formats so I need different page types. I am storing the the Page type as a string in the List, and the list is randomized so I don't know the next page type from the current test. The quiz engine will pre read the next quiz in the queue and extract the page type and create a variable to insert into the this.Frame.Navigate command. This is where I am having the problem. Any ideas on how to get around this issue?
Thanks
There is no any "variable" type. var just allows you to write less code. Compiler substitutes return type of the expression as the variable type, there's no "magic".
You can write it like this:
object myPage;
if (???)
myPage = new Page1();
else
myPage = new Page2();
this.Frame.Navigate(myPage.GetType());
If you want to implement navigation based on the user's input, you definely need to use if or switch statement. You need to pass type of the page to Navigate() method. I don't really get what have you been trying to do with code above. I would do it by using simple if statement.

Categories

Resources