I have a little app that initially requests a user id. This user id is then sent as a parameter to a stored procedure that returns values from a database. What I would like for this app to do is to refresh those same values every 30 seconds. My issue is that when I refresh, I lose the user id. Is there something simple that I'm missing here?
public ActionResult Report()
{
string operatorCode = Request.Form.GetValues("txtOperator")[0].ToString();
ViewBag.operatorName = (from e in db.employees
where e.operator_code == operatorCode
select e.name).Max().ToString();
ViewData["operatorCode"] = operatorCode;
var results = db.lex_sp_Select_Paintline_FinRew_Operator(operatorCode);
Response.AddHeader("Refresh", "10");
return View(results.ToList());
}
I think the main reason for the null value is due to the fact that you are trying to refresh an HttpPost, rather than a request (the refresh header is not intended for POSTS). I'd suggest as an alternative, that you change your process to be a request, which would result in only needing to change the invoking code (to a get) and changing the Report action to:
string operatorCode = Request.QueryString["txtOperator"];
this should give you the desired result, tho at the expense of the action now being a get rather than a post. You could also store the operatorCode in Session (tho this may not scale very well). The final option that I can see, would be to run an ajax request on a setInterval() and use that process to send a POST to the controller action.
How about storing in temp session and then using it from there when you lost it?
string operatorCode = Request.Form.GetValues("txtOperator")[0].ToString();
TempData["operatorCode"] = operatorCode;
if (!String.IsNullOrEmpty(operatorCode))
{
TempData["operatorCode"] = operatorCode;
ViewBag.operatorName = (from e in db.employees
where e.operator_code == operatorCode
select e.name).Max().ToString();
ViewData["operatorCode"] = operatorCode;
var results = db.lex_sp_Select_Paintline_FinRew_Operator(operatorCode);
Response.AddHeader("Refresh", "10");
return View(results.ToList());
}
else
{
var tempCode = TempData["operatorCode"]
ViewData["operatorCode"] = tempCode;
var results = db.lex_sp_Select_Paintline_FinRew_Operator(tempCode);
Response.AddHeader("Refresh", "10");
return View(results.ToList());
}
Related
I wrote this simple query:
var connectionString = String.Format("Url={0}; Username={1}; Password={2}; Domain={3}", url, username, password, domain);
var myConnection = CrmConnection.Parse(connectionString);
CrmOrganizationServiceContext _service = new CrmOrganizationServiceContext(myConnection);
var whoAmI = _service.Execute(new WhoAmIRequest());
var query = new QueryExpression
{
EntityName = "phonecall",
ColumnSet = new ColumnSet(true)
};
query.PageInfo = new PagingInfo
{
Count = 20,
PageNumber = 1,
PagingCookie = null
};
query.Orders.Add(new OrderExpression
{
AttributeName = "actualstart",
OrderType = OrderType.Descending
});
query.Criteria = new FilterExpression() { FilterOperator = LogicalOperator.And };
query.Criteria.AddCondition("call_caller", ConditionOperator.In, lines);
var entities = _service.RetrieveMultiple(query).Entities;
I have a program which runs this query every minute. On the first execution the correct results are displayed but for subsequent queries the results never change as I update records in CRM.
If I restart my program the results refresh correctly again on the first load.
Why are the results not updating as records are modified in CRM?
It is the CrmOrganizationServiceContext that is doing the caching - I found the following worked a treat and the results of my RetrieveMultiple are no longer cached :)
Context = new CrmOrganizationServiceContext(CrmConnection.Parse(connectionString));
Context.TryAccessCache(cache => cache.Mode = OrganizationServiceCacheMode.Disabled);
RetrieveMultiple always brings back fresh results so there must be some other aspect of your program which is causing stale data to be displayed.
I am running this script for getting all form fields of a indd file.
var _ALL_FIELDS = "";
var allFields = myDocument.formFields;
for(var i=0;i<allFields.length;i++){
var tf = allFields[i];
alert(tf.id);
alert(tf.label);
alert(tf.name);
alert(_ALL_FIELDS = _ALL_FIELDS +\",\"+ tf.name);
}
What i have done is, created a soap-java based client and calling the runscript method.
Now i am able to get these fields but how to send these fields back to the client i.e. how to write this in response and then at client side how to read it from response.
Code for calling runscript method is:-
Service inDesignService = new ServiceLocator();
ServicePortType inDesignServer = inDesignService.getService(new URL(parsedArgs.getHost()));
IntHolder errorNumber = new IntHolder(0);
StringHolder errorString = new StringHolder();
DataHolder results = new DataHolder();
inDesignServer.runScript(runScriptParams, errorNumber, errorString, results);
Also I have found in docs that runScript method returns RunScriptResponse but in my case it's returning void.
http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/indesign/sdk/cs6/server/ids-solutions.pdf
It looks like you want to return an array of formField names. You could take advantage of the everyItem() collection interface method in your javascript:
var result = myDocument.formFields.everyItem().name;
result;
The javascript will return the last value in the called script, so just to make it completely obvious, the last line is just the value to be returned.
On the Java side, the runScript method is passing the results variable as the 4th parameter, and that's where you'll find your response. So, after your code snippet, you might have something like this:
List<String> formFieldNames = new ArrayList<String>();
if (results.value.getData() != null) {
Data[] resultsArray = (Data[]) results.value.getData();
for (int i = 0; i < resultsArray.length; i++) {
formFieldNames.add(resultsArray[i].getData().toString());
}
}
I'm trying to use executeQueryLocally in a query that has 'withParamters', but it seems that I get locally cached data even when using new values in the 'withParameters'. It is as if 'executeQueryLocally' ignores values in 'withParameters'.
here is the code in the client side:
var query = EntityQuery.from('ProductsFilteredByCategory')
.withParameters({ categoryId: categoryId })
.select("productId,name,desc,shopPrice,webPrice")
.orderBy('name');
var p = manager.executeQueryLocally(query);
if (p.length > 5) {
productsObservable(p);
return Q.resolve();
}
here is the code for 'ProductsFilteredByCategory' on the server side:
[HttpGet]
public IQueryable<Product> ProductsFilteredByCategory(int categoryId)
{
Category category = _contextProvider.Context.Categories.Include("Products").Include("SubCategories").First(c => c.CategoryId == categoryId);
var prods = from p in category.Products select p;
category.SubCategories.ForEach(sc => prods = prods.Concat(_contextProvider.Context.Categories.Include("Products").First(c => c.CategoryId == sc.CategoryId).Products));
return prods.AsQueryable();
}
what happens is that after I retrieve the data once with 'p.length > 5' being true, in every subsequent call 'p.length > 5' is still true even when 'categoryId' is different, so the data that is bound to the observable is loaded once and never changes.
Thanks for your help !
Elior
The EntityQuery.withParameters method is NOT intended for local query use. (We should probably document this better).
WithParameters sends application domain specific parameters that can only be interpreted on the server. Unlike with 'where', 'orderBy', 'take' etc, there is no global interpretation that can be determined for a withParameters call. It can only be understood within the context of the server side method that accepts the parameters.
I currently have a LINQ query written in one my controllers that I want to return a single blog post (based off a model) with corresponding comments and topics.
This is what I currently have as my query which I used to return a list of all my blog posts for the home page. I added "where p.id == id (which is the parameter taken in by the ActionResult to fetch the correct post.
var post = from p in db.Set<BlogPost>()
where p.id == id
select new PostViewModel
{
Id = p.id,
Title = p.Title,
DateCreated = p.DateCreated,
Content = p.Content,
Topics = p.Topics,
Comments = p.Comments,
CommentCount = p.Comments.Count
};
return View(post);
The return currently is sending an IQueryable when I just want it to be a single post. Currently I have a foreach in my razor view which is useless and wrong but it works. How can I change this to do what I want?
You can do:
return View(post.SingleOrDefault());
Or if you want to have an exception in the case list is empty:
return View(post.Single());
Just add First() or Single() (which one is right for you depends on context) to your query:
return View(post.First());
It sound like you want to use First or Single:
return View(post.Single());
The difference between them is that Single will throw an exception if more than one matching row is found.
Just do post.First() that should do the trick. Really any function that produces a concrete value will work. First, FirstOrDefault, Single, SingleOrDefault, ToList, or ToArray
I have included the links to each method so you can see what works for you. It sounds like you will want a First or Single variation, depending on if you want errors if more than one post is pulled
replace your LINQ with this
var post = (from p in db.Set<BlogPost>()
where p.id == id
select new PostViewModel
{
Id = p.id,
Title = p.Title,
DateCreated = p.DateCreated,
Content = p.Content,
Topics = p.Topics,
Comments = p.Comments,
CommentCount = p.Comments.Count
}).FirstOrDefault();
i'm developing a Windows Phone 7 app and I use Windows Live authentication to access the user contacts. I have a webservice, with the following method:
public IEnumerable<LiveIDContact> GetContactsInformationYield(string LocationID, string DelegationToken)
{
string uriTemplate = "https://livecontacts.services.live.com/#L#{0}/rest/LiveContacts/Contacts";
var xdoc = WindowsLiveContactAPIRequest(LocationID, DelegationToken, uriTemplate);
var contacts = (from contact in xdoc.Descendants("Contact")
select contact).ToArray();
foreach (var con in contacts)
{
RetrieveCID(LocationID, DelegationToken, con);
LiveIDContact c = new LiveIDContact()
{
ID = con.Element("ID").Value,
DisplayName = con.Element("Profiles").Element("Personal").Element("DisplayName").Value,
CID = (con.Element("CID") != null ? con.Element("CID").Value : "")
};
yield return c;
}
}
How i invoke the methode in the app:
public void GetContactInformationAsync()
{
LiveIDClient.GetContactsInformationYieldAsync(LocationID, ConsentToken);
}
Here is the problem, when I invoke this methode and i wait on the complete event. It takes 4 to 5 minutes to update the list of contacts in my app.(Performance issue). Is there any way that an event occurs on every yield return ? So i can update my list from that event?
I couldn't find the answer anywhere so lets hope somebody knows the answer.
Is this making a separate HTTP call for every single contact? If so, then I think you simply need to redesign the webservice so that it makes a call for, say, every hundred contacts.