|
You have hosted this in a web server then? If so, you simply need to use a pattern like this:
private MyData GetData()
{
HttpCache myCache = HttpContext.Current.Cache;
MyData data = myCache["MyData"];
if (data == null) return GetDataAndStoreInCache();
return data;
}
private MyData GetAndStoreInCache()
{
MyData data = RetrieveDataHere();
HttpContext.Current.Cache.Insert("MyData", data, null, DateTime.Now.AddHours(6), TimeSpan.Zero);
return data;
}
|
|
|
|
|
Thanks for ur reply...
i need to use this code snippet in webservice code right...?
using HttpContext.Current.Cache instead of HttpRuntime.cache or Microsoft.ApplicationBlocks.cache is better?
Correct me if im wrong..pls let me know which is better to use..
-- Modified Thursday, May 26, 2011 2:08 AM
|
|
|
|
|
You would be OK using HttpRuntime.Cache. Basically, HttpContext.Current.Cache is a version of HttpRuntime.Cache. In fact, all that HttpContext.Current.Cache really does is pass the request onto HttpRuntime.Cache (the big difference being that HttpRuntime.Cache is available for all cases, so you can even use it in a console application if you want).
My sample wasn't meant to be used literally, rather it was to demonstrate some possible techniques. As it stands, it's not a totally robust situation as you could enter a situation where between the time of the lookup and the insert into the cache, another process inserts the data into the cache. If you code this robustly, you need to take this into account.
|
|
|
|
|
pradeep455 wrote: installed in many systems.
please define "many".
does the app run fine when there is only one or two clients active?
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
It depends on what the problem is. On a previous job, I had a number of clients (five or so, but could be more) that had to access the same data repeatedly (every minute or so) as they monitored the status of the running system. Because the data required a fair bit of calculation and aggregation I chose to have a Windows Service produce an XML file with the results that the clients could then download at their leisure.
The Service ran on a fifteen-second cycle and produced one of ten files (e.g. SystemStatus.0.xml -- SystemStatus.9.xml) and when it was done it wrote the name of the latest file to the database for the clients to read.
|
|
|
|
|
pradeep455 wrote: Please help me regarding the same..
First step is to actually determine what is causing the slow down.
Attempting to guess bottlenecks is unlikely to be successful.
Did you actually measure the time it took for various parts of your application and server?
|
|
|
|
|
I'm coding up a small script to list users' (all users in our group) permission on each TFS project. I relied on "GetEffectivePermissions" http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.versioncontrolserver.geteffectivepermissions(v=vs.90).aspx
However, after research a little I found out that this API can only be called with "userName" = $YOURSELF$
Any attempt to call "GetEffectivePermission" would result in
TF14014: Cannot query effective item or global permissions for other users.
Any suggestion on how to get around this??
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
<br />
using Microsoft.TeamFoundation;<br />
using Microsoft.TeamFoundation.Client;<br />
using Microsoft.TeamFoundation.VersionControl;<br />
using Microsoft.TeamFoundation.VersionControl.Common;<br />
using Microsoft.TeamFoundation.VersionControl.Client;<br />
<br />
namespace ManageTFS<br />
{<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
<br />
string TFSConnString = "http://SomeSErver:8080/";<br />
IList<string> PermissionOwners = new List<string>();<br />
string UserName = null;<br />
string[] EffectivePermissions = null;<br />
IDictionary<string, IList<string>> PermissionsDict = new Dictionary<string, IList<string>>();<br />
<br />
try<br />
{<br />
TeamFoundationServer TfsInstance = new TeamFoundationServer(TFSConnString);<br />
Console.WriteLine("Connected to TFS " + TFSConnString);<br />
<br />
VersionControlServer vcs = (VersionControlServer)TfsInstance.GetService(typeof(VersionControlServer));<br />
Console.WriteLine("Connected to VersionControlServer");<br />
<br />
TeamProject[] Projects = vcs.GetAllTeamProjects(true);<br />
Console.WriteLine("Retrieved TFS projects from VersionControlServer");<br />
<br />
PermissionOwners.Add("john.doe");<br />
PermissionOwners.Add("bill.clinton");<br />
PermissionOwners.Add("me.me");<br />
foreach(string Owner in PermissionOwners)<br />
{<br />
foreach (TeamProject p in Projects)<br />
{ <br />
Console.WriteLine(p.ServerItem);<br />
EffectivePermissions = vcs.GetEffectivePermissions(Owner, p.ServerItem); (BLOWS UP HERE)<br />
<br />
PermissionsDict.Add(UserName, EffectivePermissions);<br />
}<br />
}<br />
}<br />
catch (Exception Ex)<br />
{<br />
Console.WriteLine(Ex);<br />
}<br />
<br />
return;<br />
}<br />
}<br />
}<br />
dev
|
|
|
|
|
I have a Microsoft Access 2007 database which stores all the necessary data for my application. The person who designed the database, my plant's manager, mentioned in the past (and is still considering) the ability to select multiple "repair codes" for each record. I know that with Access you can create a field which allows multiple values.
The table containing repair codes has the following fields:
ID (unique ID; auto-generated/incremented)
Code (e.g. "Replaced Front Panel")
Cost (currently uses a default value; not significant here)
In the "Repairs" table there is a field which is linked to the Repair Codes table, called "Repair Code." My manager would like the ability to select more than one code from the "Repair Codes" table, in the respective field inside the "Repairs" table.
How would I go about reading and writing multiple values for the field when dealing with records in the "Repairs" table?
I apologize if I did not elaborate well. :-P
Thanks,
Matt U.
------------- EDIT -------------
I forgot to mention that I have played around with the multiple values in Access itself. I know that when you select multiple values, the field's value will display (in Access) as "1, 3, 8" and so forth (or whichever column you tell it to show). Is there anything special I need to do in order to read each value? I can piece together how to ADD multiple values if I know how to SELECT them.
|
|
|
|
|
1. Not really a C# question.
2. This is a many-to-many join situation (N:N), so a bridge table would help...
In the example below, Mike's repair job (#1) included repair codes 1 and 2 (that association is saved in the REPAIR_TO_CODE table). Jane only involved repair code 2, and Bob only repair code 1.
Make sense..?
CODE
---------
ID Code Cost
1 Replaced something $1.00
2 Adjusted something $2.00
REPAIR
---------
ID Customer (Other Fields...)
1 Mike
2 Jane
3 Bob
REPAIR_TO_CODE
----------------
Repair_FK Code_FK
1 1
1 2
2 2
3 1
|
|
|
|
|
Thanks much for the informative reply. As I am quite new to SQL (aside from SELECT, INSERT, UPDATE and DELETE) I will look into this more. I recently started learning a lot about different SQL commands at W3C. JOIN statements are something I have been taking a lot of interest in so this may be a good time to learn hands-on.
Like I said, we are in no rush to use multiple values. It may very well never get to that point anyhow. But I would like to know where to start in case it comes down to it. And by the looks of it, I can almost guarantee my manager will NOT want to fool with it. He is not particularly fond of modifying things to this extent when it is not absolutely necessary. He just likes to daydream about it, haha.
Thanks again, Timothy.
|
|
|
|
|
Search for normalization, that will help you.
Alternatively you could choose a delimeter like a pipe ("|") and seperate the codes with the delimeter in the one field. (eg: code1|code7|code23) However, I would NOT recommend this, but it could be you encounter this device sooner or later. A bridge table is the way to go.
V.
|
|
|
|
|
Look into Master/Detail forms, Matt. You can create a table for RepairEvents as a lookup source, perhaps, and then add a table that describes multiple repair codes for a single event with the RepairEvent ID as a foreign key. It's not really a major change, which should make your manager happy. Keep in mind, though, that if you have a busy database, you're going to quickly run into problems using Access. If you have more than about 5 people who need to use your database, or the .mdb file grows to about 1 GB in size, it's going to blow up on you. You really should start thinking about migrating to SQL Server; the Express version is free, handles multiple users better, and extends your limit to about 10 GB.
I'm working on several such applications in my "free" time, to manage electrical substation inspections, sewer lift station repairs, and water system events, so I know what you're going through. It would be very convenient if each event resulted in just one repair, but that rarely occurs in the real world. Best of luck to you! And when you have it resolved, publish your solution as an article and show the rest of us how you solved the problem.
Will Rogers never met me.
|
|
|
|
|
How we can concatenate the word document, I explain, i would make a single document of 1000 pages (each document is on one page) and then save only a single document instead of 1000, thank you much.
i use this to crate one document :
String[] tbStr2 = s.Split(new Char[] { ';' });
string nb = tbStr2[0];
Object oMissing = System.Reflection.Missing.Value;
Object oTrue = true;
Object oFalse = false;
Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
oWord.Visible = true;
oWord.Visible = false;
Object oTemplatePath = modelee;
oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
bool sympb = false; bool E = false; bool n = false; bool p = false; bool r = false;
foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words)
{if (range.Text.Trim().Contains("$"))
{ int pos = range.Text.Trim().IndexOf("$");
string str = range.Text.Trim().Replace("$", "");
range.Text = str;} }
foreach (Microsoft.Office.Interop.Word.Range range in oWordDoc.Words)
{if (range.Text.Trim().Contains("$$"))
{ int pos = range.Text.Trim().IndexOf("$$");
string str = range.Text.Trim().Replace("$$", "");
range.Text = str;} }
Object oSaveAsFile ="./1.doc";
oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
oWordDoc.Close(ref oFalse, ref oMissing, ref oMissing);
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
|
|
|
|
|
Yes, should be possible. What are you using to "read" the document?
Bastard Programmer from Hell
|
|
|
|
|
A tip you will often see is to record a macro for the operation you want to perform. In your case just find out what code is generated for the Insert File operation.
In Word 2002 the macro code is
Sub Macro1()
Selection.InsertFile FileName:="xxxxx.doc", Range:="", ConfirmConversions:= False, Link:=False, Attachment:=False
End Sub
From the MS Word Visual Basic reference we can get the InsertFile method signature and remove the named arguments to give the conventional method call
Selection.InsertFile("xxxx.doc", "", False, False, False)
which can be easily translated into C#.
Alan.
|
|
|
|
|
Who in their right mind would want to open a 1,000 page document in Word?? That'll take, what, a few hours to do?
|
|
|
|
|
No, only a few seconds if not bloated with a shed load of pictures. E.g. the C# Specification v3.0 is 519 pages and takes about 3 seconds to open over here in the UK.
Alan.
|
|
|
|
|
Damn, must be my machine.
|
|
|
|
|
|
Thank you verry mutch for your answer, so i need to merge the word file in the memory, because i don't want to generate all 1000 files. please help me.
|
|
|
|
|
Hi,
I have a problem in deserializing the xml which is coming from Java side in soap form.
Here is my code..
var responseText = res.XmlDocument.GetElementsByTagName("soap:Body").Item(0).InnerXml;
var memoryStream = new MemoryStream(Encoding.Default.GetBytes(responseText));
var ClsEmpResponse = (Request.ClsEmp.EmpResponse)xmlSerializer.Deserialize(memoryStream);
_oLog.LogStackTrace("*************DAE VIEW REQUEST*************");
_oLog.LogStackTrace(responseText.ToString());
return ClsEmpResponse;
here in this code, am getting the response as it is saved in database(for ex, it contain Nested Condition:3) in responseText.
but after i pass it to the memory stream, it is showing that it contain only 1 condition in the loop in ClsEmpResponse.
ClsEmp is the class contain in Request folder in my application, which is having some fields, where i read and write the data into/from that field.
so can u tell me what is d problem here..
Why it is not taking the exact value which is coming in responseText.
why its not reading the same xml format which is in
|
|
|
|
|
I suspect that it is because you haven't told it what the soap: prefix means.
Here's what I had to do to use the xi: prefix:
System.Xml.XmlNamespaceManager nsm =
new System.Xml.XmlNamespaceManager ( Document.NameTable ) ;
nsm.AddNamespace ( "xi" , "http://www.w3.org/2001/XInclude" ) ;
System.Xml.XmlNode nod ;
while ( ( nod = Document.SelectSingleNode ( "//xi:include" , nsm ) ) != null )
Try something like that.
|
|
|
|
|
Hi,
I would like to know how to make multiple asynchronous web service method calls in the same thread? What if the web service method cannot be checked by IAsyncResult status operation statement but just invoking the MethodNameAsync(X,Y,Z).
What I think is sleeping the thread shouldn't be the way to handle it because lets assume that 20 of form controls inside the form uses web methods to populate themselves and one of the control's value is used as an argument to call another asynchronous method to populate another control in the form .
The problem is I have a few asynchronous call in the same thread and I couldn't figure it out how to create waits between the each asynchronous calls until it gets loaded completely. Is there a way to load all asynchronous methods before the form loads.
if you enlighten me about the solution, I would really appreciate it. This is my first Web Service client issue to solve and I have no experience about it.
Thanks.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
modified on Tuesday, May 24, 2011 9:28 AM
|
|
|
|
|
JUNEYT wrote: Is there a way to load all asynchronous methods before the form loads.
If the calls are truly asynchronous then there should be some notification of completion (like an event).
I use something similar to the DomainContextLoadBatch class found in this article[^]. This class lets you queue up a bunch of asynchronous calls and doesn't notify you until they have all completed. The class as shown is for WCF RIA Services LoadOperation calls, but could easily be modified for other webservice call types.
*edit* If you use that class as a guide, please note that as shown the class is NOT thread safe, so if your webservice calls can complete on other threads you'll need to make sure at least the class' single completion handler is thread safe.
You shouldn't have to sleep and wait...that negates the whole purpose of asynchronous calls...
Mark Salsbery
Microsoft MVP - Visual C++
modified on Tuesday, May 24, 2011 12:03 PM
|
|
|
|
|
List<MyStyle> styles = new List<MyStyle>();
foreach (var item in items)
{
styles.Add(GetMyStyle(item.style));
}
- Regards - J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
|
|
|
|
|