LLBLGen Pro 5.0 caching with EntityCollectionBase.GetMulti() - caching

I'm using LLBLGen 5.0 and EntityCollectionBase.GetMulti(filter, relation) to retrieve objects in oracle database.
ObjectCollection objects = new ObjectCollection ();
RelationCollection relationsToUse = new RelationCollection();
relationsToUse.Add(ObjectEntity.Relations.Object2EntityUsingObject2Id);
IPredicateExpression filter = new PredicateExpression(ObjectFields.Code == sectionCode);
objects.GetMulti(filter, relationsToUse);
I would like to add caching system to avoid to do request in database many times.
I saw on LLBLGen documentation that it is possible to use cache on LLBLGen with this code:
var customers = new EntityCollection<CustomerEntity>();
using(var adapter = new DataAccessAdapter())
{
var parameters = new QueryParameters()
{
CollectionToFetch = customers,
FilterToUse = CustomerFields.Country=="USA",
CacheResultset = true,
CacheDuration = new TimeSpan(0, 0, 10) // cache for 10 seconds
};
adapter.FetchEntityCollection(parameters);
}
But I'm not able to found class DataAccessAdapter..
Do you have any idea, suggestion to resolve my issue ?
Thanks in advance,

If you created a llblgen project which uses SelfServicing there is no DataAccessAdapter, so project must be created with the Adapter option.
if this is so then it should be in xxxx.DatabaseSpecific
where xxxx is youre project name.

Related

XrmServiceContext object is not getting the latest data from CRM

i have a wcf which connects to crm (on prem) to retrieve an account record. i can see when the entity is retrieved it does not hold the current record i.e. some field will still hold the old column value. i tried with various merge option with no avail. please see the code below
using (XrmServiceContext cContext = new XrmServiceContext(con))
{
Entity ent = cContext.Retrieve(ConstantKVP.AccountSchema.ENTITY_LOGICAL_NAME, AccountId, new ColumnSet(true));
}
any suggestions?
Is it possible the data is being cached?
cContext.TryAccessCache(cache => cache.Mode = OrganizationServiceCacheMode.Disabled);
I took this approach for a CrmOrganizationServiceContext, so perhaps the same theory applies.
After save use clear changes cContext.ClearChanges();
For retrieves use MergeOption.OverwriteChanges
Or
Create a new XrmServiceContext object by passing a newed up organizationservice:
var uncachedOrganizationService = new OrganizationService("Xrm");
var uncachedXrmServiceContext = new XrmServiceContext(uncachedOrganizationService);
var ent = uncachedXrmServiceContext.Retrieve(ConstantKVP.AccountSchema.ENTITY_LOGICAL_NAME,AccountId,new ColumnSet(true));

Dynamically added Raddocks Optimization?

We have a optimization problem regarding rad dock controls. The requirement of project is such that we are creating dynamic raddocks on the fly and adding it to a raddockzone, then we are saving the raddock "type" etc in a mssql db. We also have a collector window/raddockzone in which we have build a functionality where we can drag a dock and save it in collector. As with the first raddockzone we are adding the dock in collector on the fly. Now while adding a dock or moving it to another raddockzones it takes sometime. Our client is comparing it with the example of the demo link : http://demos.telerik.com/aspnet-ajax/dock/examples/content/defaultcs.aspx
Following is our code snippet to add dock on the fly:
private RadDockNew CreateRadDock()
{
//string[] allowedZones = { "RDZCollector", "RadDockZone2" };
int width = Convert.ToInt32((hdnWidth.Value == "") ? "520" : hdnWidth.Value);
RadDockNew dock = new RadDockNew();
dock.DockMode = DockMode.Docked;
dock.UniqueName = Guid.NewGuid().ToString().Replace("-", "a");
dock.ID = string.Format("RadDock{0}", dock.UniqueName);
//dock.Title = dock.UniqueName.Substring(dock.UniqueName.Length - 3);
dock.Width = Unit.Pixel(width);
dock.CssClass = "RadDockZoneMain";
//dock.AllowedZones = allowedZones;
dock.Style.Add("min-height", "290px");
dock.OnClientDockPositionChanged = "DropInCollector";
//dock.EnableViewState = false;
DockCommand cmd = new DockCommand();
cmd.Name = "Setting";
cmd.Text = "Setting";
cmd.OnClientCommand = "showSettings";
dock.Commands.Add(cmd);
DockCommand dc = new DockCommand();
dc.Text = "Trash";
dc.Name = "Trash";
dc.OnClientCommand = "CloseDock";
dc.CssClass = "rdClose";
dc.AutoPostBack = true;
dock.Commands.Add(dc);
DockToggleCommand cmd2 = new DockToggleCommand();
cmd2.CssClass = "rdCollapse";
cmd2.AlternateCssClass = "rdexpand";
cmd2.OnClientCommand = "ChangeImage";
//DockCommand collapse = new DockCommand();
//collapse.Text = "Collapse/Expand";
//collapse.Name = "Collapse/Expand";
//collapse.OnClientCommand = "CollapseDock";
//collapse.CssClass = "rdCollapse";
dock.Commands.Add(cmd2);
return dock;
}
Please tell if there is any way to optimize / make it faster.
Thanks.
I examined the attached code sample and I think that it is correct. My suggestions are to check if the problem persists if you use other storage medium, instead of a database or if there are client script errors on the page, containing the RadDocks.
As the setup of your project seems to be similar to the one, implemented in the My Portal demo, I would recommend using the example in the Code Library article Saving State of Dynamically Created RadDocks in DataBase using Hidden UpdatePanel as a reference.

Updating an Activity in MS CRM via web service?

I've been trying to do this all morning. Anyone have a code snippet (C#) showing how to update an "activity" within CRM via the webservice?
I can CreateReadUpdateDelete with entities, but I'm not sure how to do it with Activities.
Can't find anything on google either...
What are you specifically looking to update? Basically, updating an activity is just like updating any other entity, you just have to use the task entity.
public void CloseTask(CrmService crmsvc, Guid activityid, DateTime start, DateTime end)
{
ColumnSet cols = new ColumnSet();
cols.Attributes = new string[] { "activityid", "statecode" };
task tsk = (task)crmsvc.Retrieve(EntityName.task.ToString(), activityid, cols);
if(tsk.statecode.Value != TaskState.Open)
return;
tsk.actualstart = new CRMDateTime();
tsk.actualstart.value = start.ToString();
tsk.actualend = new CRMDateTime();
tsk.actualend.value = end.ToString();
crmsvc.Update(tsk);
SetStateTaskRequest state = new SetStateTaskRequest();
state.EntityId = activityid;
state.TaskState = TaskState.Completed;
state.TaskStatus = -1; // Let MS CRM decide this property;
SetStateTaskResponse stateSet = (SetStateTaskResponse)crmsvc.Execute(state);
}
Edit: added some sample code. note, I had to modify what I had to strip some proprietary code, so I don't know if this will actually compile. It's close though.
We can also update a Custom Workflow Activity Using Assembly Versioning. Below link gives more information:
http://msdn.microsoft.com/en-us/library/gg328011.aspx

Windows Workflow Foundation 4.0 and Persistence

I'm using the Beta 2 version of Visual Studio 2010 to get a head start on learning to use WF4, and have run into a problem with persistence. In the code below, if I use the commented out creattion of a WorkflowApplication object, persistence works fine. If I use the un-commented creation below, where I pass a dictionary for arguments I want to pass in, then persistence breaks. Any ideas why this may be, and how to fix it?
List<Approver> approversRequired = new List<Approver>();
approversRequired.Add(new Approver("Dept Manager"));
approversRequired.Add(new Approver("Center Manager"));
Dictionary<String, Object> wfArguments = new Dictionary<string, object>();
wfArguments.Add("ApproversRequired", approversRequired);
//WorkflowApplication workflowApp = new WorkflowApplication(
// new WebCARSWorkflow());
WorkflowApplication workflowApp = new WorkflowApplication(
new WebCARSWorkflow(), wfArguments);
InstanceStore instanceStore = new SqlWorkflowInstanceStore(
#"Data Source=.\SQLEXPRESS;Integrated Security=True;Initial Catalog=WorkflowInstanceStore");
InstanceView view = instanceStore.Execute(
instanceStore.CreateInstanceHandle(), new CreateWorkflowOwnerCommand(),
TimeSpan.FromSeconds(30));
instanceStore.DefaultInstanceOwner = view.InstanceOwner;
workflowApp.InstanceStore = instanceStore;
workflowApp.PersistableIdle = (waie) => PersistableIdleAction.Unload;
workflowApp.Run();
WorkflowGuid.Text = workflowApp.Id.ToString();
workflowApp.ResumeBookmark("RequestSubmitted", "Submitted");
Is the Approver you pass in as a parameter decorated with the Serializable or the DataContract attribute?
You can see persitence errors using the Aborted callback
workflowApp.Aborted = e => Console.WriteLine(e.Reason);

Windows Workflow Foundation 4.0 and Tracking

I'm working with the Beta 2 version of Visual Studio 2010 to get some advanced learning using WF4. I've been working with the SqlTracking Sample in the WF_WCF_Samples SDK, and have gotten a pretty good understanding of how to emit and store tracking data in a SQL Database, but haven't seen anything on how to query the data when needed. Does anyone know if there are any .Net classes that are to be used for querying the tracking data, and if so are there any known samples, tutorials, or articles that describe how to query the tracking data?
According to Matt Winkler, from the Microsoft WF4 Team, there isn't any built in API for querying the tracking data, the developer must write his/her own.
These can help:
WorkflowInstanceQuery Class
Workflow Tracking and Tracing
Tracking Participants in .NET 4 Beta 1
Old question, I know, but there is actually a more or less official API in AppFabric: Windows Server AppFabric Class Library
You'll have to find the actual DLL's in %SystemRoot%\AppFabric (after installing AppFabric, of course). Pretty weird place to put it.
The key classes to look are at are SqlInstanceQueryProvider, InstanceQueryExecuteArgs. The query API is asynchronous and can be used something like this (C#):
public InstanceInfo GetWorkflowInstanceInformation(Guid workflowInstanceId, string connectionString)
{
var instanceQueryProvider = new SqlInstanceQueryProvider();
// Connection string to the instance store needs to be set like this:
var parameters = new NameValueCollection()
{
{"connectionString", connectionString}
};
instanceQueryProvider.Initialize("Provider", parameters);
var queryArgs = new InstanceQueryExecuteArgs()
{
InstanceId = new List<Guid>() { workflowInstanceId }
};
// Total ruin the asynchronous advantages and use a Mutex to lock on.
var waitEvent = new ManualResetEvent(false);
IEnumerable<InstanceInfo> retrievedInstanceInfos = null;
var query = instanceQueryProvider.CreateInstanceQuery();
query.BeginExecuteQuery(
queryArgs,
TimeSpan.FromSeconds(10),
ar =>
{
lock (synchronizer)
{
retrievedInstanceInfos = query.EndExecuteQuery(ar).ToList();
}
waitEvent.Set();
},
null);
var waitResult = waitEvent.WaitOne(5000);
if (waitResult)
{
List<InstanceInfo> instances = null;
lock (synchronizer)
{
if (retrievedInstanceInfos != null)
{
instances = retrievedInstanceInfos.ToList();
}
}
if (instances != null)
{
if (instances.Count() == 1)
{
return instances.Single();
}
if (!instances.Any())
{
Log.Warning("Request for non-existing WorkflowInstanceInfo: {0}.", workflowInstanceId);
return null;
}
Log.Error("More than one(!) WorkflowInstanceInfo for id: {0}.", workflowInstanceId);
}
}
Log.Error("Time out retrieving information for id: {0}.", workflowInstanceId);
return null;
}
And just to clarify - this does NOT give you access to the tracking data, which are stored in the Monitoring Database. This API is only for the Persistence Database.

Resources