Using assigned variable to an InArgument<> - c#

I want to use an InArgument parameter in my Activity. I use an expressionTextBox to showing and using the InArgument value in XAML code. My problem is this I declare a variable and assign it to this expressiontextbox in Activity Library designer. When in the Execute() method of the activity, I change the value of InArgument parameter - I want the variable value to change too. How can I do it?
My code is like this...
...
public InArgument<string> AcceptedForms{ get; set; }
...
protected override void Execute(CodeActivityContext context)
{
...
string AForms= "#AcceptedForms_"+ this.Id;
AcceptedForms.Set(context, AForms);
...
}
I can use the value of AcceptedForms in this method after changing it's value. But it doesn't pass to the variable that I assign to it in Activity Library Designer. I want to use it's value in another Activity.

You won't be able to do that because when they are passed into the WF runtime I don't think they are passed by reference. So, what you'll have to do is setup an OutArgument that you set while in the Execute method and set that OutArgument -- in the workflow -- to the variable.
UPDATE
If you can take 15 minutes and watch this video I think you'll better understand what's going on. And BTW, below is the entire list of videos in this series, it's an amazing foundation on these types of things.
Part 1
Part 2
Part 3
Part 4
Part 5

Related

Can't Cast Type (Public Activity Instance) to Activity in Xamarin Android C#

I want to access a public class from my activity. I have a public class called HomePageActivity (It's using AppCompatActivity) which is that public class activity contains another class called Model.User CurrentUser (It's for calling current user since login by calling the userEmail on my database model property). HomePageActivity contains shared preference and I store all of the user data with variables such as current user, userID and email and I can call it from another class. In the next activity (UploadActivity), I want to access HomePageActivity and its attributes.
So, what I do :
Declare the HomePageActivity in my next activity which is in UploadActivity ==> public HomePageActivity m_currentActivity;
Call the m_currentActivity inside onCreate since I use Android.Support.V4.App.FragmentActivity ==> m_currentActivity = (HomePageActivity) this.Activity;
Try to call the m_currentActivity on my needed area ==> m_currentActivity.idUser;
But, I failed. I stuck. I can't cast HomePageActivity. Fortunately, I can use m_currentActivity = (HomePageActivity) this.Activity; on my Android.Support.V4.App.Fragment (on another fragment) but, why in UploadActivity which uses Android.Support.V4.App.FragmentActivity I can't cast my HomePageActivity
What happens if I don't use m_currentActivity = (HomePageActivity) this.Activity; ?
Well, based on my previous trial and error on my fragment and also on my UploadActivity, if I don't declare and cast the HomepageActivity, I can't get the value of the entities such as I can't get the value of m_currentActivity.idUser. If I debug, it will return null or crash like
object reference not set to an instance of an object
I've searched a lot of articles, but I still can't get my answer. I hope to hear the answer and recommendation from all of you. Thank in advance!
this.Activity is only available inside of the Fragments. If your UploadActivity inherits from Android.Support.V4.App.FragmentActivity you will not get this.Activity. If you are running any fragments inside the UploadActivity than inside those fragments you will get this.Activity of type UploadActivity.
If you some data to take with you to next activity use Intents. If you really want complete context of the last activity use a static property in the first activity and pass this in it. In you case create a static property in HomePageActivity and of type HomePageActivity and in OnCreate method pass this(current instance) in it. This property will be available through out the project. Make sure to use it if you absolutely have to.
Well, guys thank you for your response. Basically, I use intent and I access from my main class. Before it, I already put global variables in my main activity so, I can call them and access them from the main activity

Hangfire - Configure AutomaticRetry for specific RecurringJob at runtime

I'm using Hangfire v1.7.9 and I'm trying to configure a series of recurring background jobs within my MVC 5 application to automate the retrieval of external reference data into the application. I've tested this with one task and this works great, but I'd like administrators within the system to be able to configure the Attempts and DelayInSeconds attribute parameters associated with the method that is called in these background jobs.
The AutomaticRetryAttribute states that you have to use...
...a constant expression, typeof expression or an array creation expression of an attribute parameter type
... which from what I've read is typical of all Attributes. However, this means that I can't achieve my goal by setting a property value elsewhere and then referencing that in the class that contains the method I want to run.
Additionally, it doesn't look like there is any way to configure the automatic retry properties in the BackgroundJob.Enqueue or RecurringJob.AddOrUpdate methods. Lastly, I looked at whether you could utilise a specific retry count for each named Queue but alas the only properties about Hangfire queues you can set is their names in the BackgroundJobServerOptions class when the Hangfire server is initialised.
Have I exhausted every avenue here? The only other thing I can think of is to create my own implementation of the AutomaticRetryAttribute and set the values at compile time by using an int enum, though that in itself would create an issue in the sense that I would need to provide a defined list of each of the values that a user would need to select. Since I wanted the number of retries to be configurable from 5 minutes all the way up to 1440 minutes (24 hours), I really don't want a huge, lumbering enum : int with every available value. Has anyone ever encountered this issue or is this something I should submit as a request on the Hangfire GitHub?
I would take the approach of making a custom attribute that decorates AutomaticRetryAttribute:
public class MyCustomRetryAttribute : JobFilterAttribute, IElectStateFilter, IApplyStateFilter
{
public void OnStateElection(ElectStateContext context)
{
GetAutomaticRetryAttribute().OnStateElection(context);
}
public void OnStateApplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
{
GetAutomaticRetryAttribute().OnStateApplied(context, transaction);
}
public void OnStateUnapplied(ApplyStateContext context, IWriteOnlyTransaction transaction)
{
GetAutomaticRetryAttribute().OnStateUnapplied(context, transaction);
}
private AutomaticRetryAttribute GetAutomaticRetryAttribute()
{
// Somehow instantiate AutomaticRetryAttribute with dynamically fetched/set `Attempts` value
return new AutomaticRetryAttribute { Attempts = /**/ };
}
}
Edit: To clarify, this method allows you to reuse AutomaticRetryAttribute's logic, without duplicating it. However, if you need to change more aspects on per-job basis, you may need to duplicate the logic inside your own attribute.
Also, you can use context.GetJobParameter<T> to store arbitrary data on per-job basis

Get all writeable properties of an ADLDS-Class

I'm developing an application which can deal with a MS-ADLDS-Service.
Currently it is possible to create Directory-Entries and assign values to some properties.
Not a realy exciting task until this:
Im my application it's possible (it should be) to configure which properties of a class (for instance: the CN=Person class) should be assigned with values which are evaluated at runtime in my application.
Long story short:
I want to retrieve all (writeable) properties of a class. Without creating and saving a new CN=Person-Object before.
Currently i use my schemaBinding to get the Directory-classSchema-Entry of the Person-Class (CN=Person) from where i read some property-values (like "AllowedAttributesEffective", "mayContain", "AllowedAttributes") - i get the most properties by this way - but some Properties are missing! For instance the "telephoneNumber"-Property (attributeSchema: CN=Telephone-Number)
Does anybody know how to get these properties of a class? ADSI-Edit does this: when i create a new object with adsi-edit i can assign values to all possible properties before committing the new entry.
thanks a lot for any hint!
(.net code is welcome)
I have found the solution for my task!
Some of these properties are "calculated" and not persistent at the directoryentry.
So its meant to call the RefreshCache() Method and pass the needed property names as an string array.
directoryEntry.RefreshCache(new string[] { "allowedAttributesEffective",
"allowedAttributes",
"systemMayContain",
"systemMustContain" });
After that call, the properties have values....
if (directoryEntry.Properties["systemMayContain"]).Value != null)
{
/// Success
}

How can i create a general class to handle all inputs from an input text field

I have a object called WorkflowsAndQueuesInitializerService it defines queues in a workflow and the next step it would route too given a specified call result. I have a method inherited from an interface class that's called CalculateDueDate that takes a from step instance and a next step timespan as parameters. The issue that i am having is being able to generally just override a due date given a input from a input text field with out taking a round trip across multiple class methods. I have a mapped class called NextStep that has a constructor that takes a due date timespan as well. What i would like to achieve is in my class form instance i would just like to pass a value from the input text box and recalculate the duedate without all the hassle is there an easier way to achieve this with the information that has been given?
public override void CollectFormValues(IFormValuesCollection values)
{
this.CalculatedShipDate = TypeConverter.ToNullableDateTime(values["CalculatedShipDate"]);
}
Above is a method that retrieve the form values from the HTTP POST.
This is a transient form instance, which means my application doesn't automatically commit the values of the form back to the database. Normally, CollectFormValues() only save the values into the object, but doesn't commit anything to the database. But because this is a transient form, this method is also responsible for saving the values back to the database.
Also I ahve a class that Retrieve an instance of the class that should be used to calculate the due date for the next StepInstance, below:
public static IDueDateCalculator GetDueDateCalculator( string className )
{
if ( String.IsNullOrWhiteSpace( className ) )
return new DefaultDueDateCalculator();
Assembly assembly = typeof( IDueDateCalculator ).Assembly;
Type calcType = assembly.GetType( className );
return (IDueDateCalculator) Activator.CreateInstance( calcType );
}
Not sure what my best possible solution would be thus why i am comming here for any feedback and/or assistance. Thanks in advance!
If I understand correctly, you want to calculate the due date, but you want to allow it to be overridden by the user as well.
So that's fairly easy.
This is VB, but you should be able to get the idea.
Class Something
Private oDueDate As Nullable(Of DateTime) = Nothing
Private Sub CalculateDueDate
oDueDate = {some calculation between the date and timespans}
End Sub
Public Property DueDate As DateTime
Get
If (Nothing Is oDueDate) OrElse (Not oDueDate.HasValue) Then
CalculateDueDate
End If
Return oDueDate
End Get
Set(value as DateTime)
oDueDate = value
End Set
End Property
End Class

using Telerik testing environment

I am learning how to use the Telerik test environment.
I created a test that runs through my program. One of the steps is to create a repository, into which I will upload data. I would like to run this test numerous times as a load test, so the name needs to be dynamic. I would like to create a name such as "Repository_Date_Time, since no matter how many times I use it, uniqueness is guaranteed.
I created a code step right before the text box insertion step. I would like to generate a string, and then use it in the next step so that the repository is created with a unique name.
Code generated is: this is in the steps within the telerik application
[WebTest_CodedStep] : New Coded Step
Then, within this step, I can hard code stuff:
[CodedStep(#"New Coded Step")]
public void WebTest_CodedStep()
{
}
I want to use something like this: string currentTime = DateTime.Now.ToString("HH:mm:ss");
and then use the saveNow contained data as an ending to a string to make it unique, but it must be done within the following step:
Type 'Moshe-Master Repository Test01' into Item0Textboxchanged
TypedText: Moshe-Master Repository Test01
So that the red name will be substituted by a variable carrying the new string which I creatred.
The TypedText box is the value being typed automatically, and I would like to change it with the generated value from the previous step. Can a TypedText value be dynamic?
Thanks!
EDIT: I just realized that therre is a way to use a variable as input, however, I do not know where I can create it. The location where I can put it as input is in the top right state-chart with all current data being used for that particular step. (bindings) is set to collection at the moment. When I try to change it into a variable it tells me that the variable needs to be created- it does not specify where.

Categories