|
1) What makes you think there's a problem? -- I agree with and my users are ok with this
2)What are the odds that 2 people are running the exact same query at the same time? -- Different users will be using the same query for at least 7- 8 times in a day
3) How do you ensure you are not caching and then returning -- Right now I am using HttpContext.Current.Cache.Get and comparing the parameter value which is not great. It will only work if the same user. But I want to implement at the application level.
Thanks
|
|
|
|
|
#3. No, you missed the point.
When you cache the data from a search query, then the database is updated with new data, how are you going to detect this and invalidate the cached copy of the data so a new search of the same query terms results in an updated dataset?
THIS is what you have to watch out for.
|
|
|
|
|
When you cache the data from a search query, then the database is updated with new data, how are you going to detect this and invalidate the cached copy of the data so a new search of the same query terms results in an updated dataset? God question this is not transactional data and we update data once in a day so i will just cache the query for the half day or 4 hours only.
|
|
|
|
|
Yeah, that's not going to work. Putting an arbitrary value on an items "time to live" will just result in search queries that could be out of date for a smaller period of time.
The code that updates the database has to be able to invalidate cached data. But you have a problem. How is your code going to know which cached queries are affected by a single update to the database?
Caching search queries is a bad idea.
|
|
|
|
|
Dave is absolutely right - by trying to cache data outside of the DB that you are sourcing from, you need to catch everything that happens to your DB and invalid specific portions of your cache if the change might have affected the results of a query. Otherwise, your cached data becomes increasingly out of date and useless.
For example, I issue a stock level request for Product A, and you return "2".
Next time I ask, it's in your cache, so you return "2" without going to the DB.
Then Joe over there sells one, and the DB gets updated to "1"
I ask again, it's in your cache, so you return "2" without going to the DB.
Joe sells anoth, and the DB gets updated to "0"
I ask again, it's in your cache, so you return "2" without going to the DB.
So the customer I'm talking to "knows" there are 2 in stock - and buys one. What happens now?
Unless you "stand in the middle" and pass each query through or serve them from your cache while intelligently invalidating the caches as appropriate, your data gets more and more irrelevant.
And that is going to slow down the whole process as well, because now you have effectively two sources of data processing every single command!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I'm curious - your answer to 1 seems to imply that you and your users don't perceive a problem!
What is the latency on your results return, it seems to me that a query on a 900k should be trivial from a database POV. If it IS the database then look at indexing the user table, if the latency is the network then you have a different problem which should be resolved by your network people not by caching search results.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
hello Code project i have created dictionary with key value pairs form a text file and i want to display the value of a key to a textbox
and edit the value in the textbox and on a button click save to the file this is the code i have so far just not sure how to add to textbox and save it out.
public class BO3_weapon_editor
{
public static string outvalue { get; set; }
public void processfile(string file)
{
Dictionary<string, string> dic = new Dictionary<string, string>();
string data;
{
using (StreamReader reader = new StreamReader(file))
{
string line;
while ((line = reader.ReadToEnd()) != null)
{
var patt = @"(?m)\s*""(.+?)""\s+""(.*?)""\s*";
foreach (Match m in Regex.Matches(line, patt))
{
var k = m.Groups[1].Value;
var v = m.Groups[2].Value;
if (false == dic.ContainsKey(k)) dic[k] = v; else dic[k] += "," + v;
}
outvalue = dic["adsUpAnim"];
}
}
}
}
}
any help would be much appricated.
|
|
|
|
|
It's pretty simple:
textbox1.Text = yourdictionary[key];
yourdictionary[key] = textbox1.Text;
string[] lines = yourdictionary
.Select(kvp=> string.Concat(kvp.Key, "\t", kvp.Value))
.ToArray();
File.WriteAllLines("fullfilename.txt", lines);
Note: i've used tab between key and value. You can replace this separator with another one.
modified 4-Oct-18 2:41am.
|
|
|
|
|
You can read a value from a textBox very simply, by using it's Text property:
string myString = mMyTextBox.Text; And you can use that anywhere you wanted - as the key value for a dictionary for example:
value = myDictionary[myTextBox.Text];
But ... the code you show creates the dictionary, but it then throws it away again, as it is only stored as a local variable in your processfile method. You need to decide what you want to do with your dictionary, and either return it from the method (if it's going to be relatively temporary), store it in a class level variable (if it's going to be needed for the whole life of the class instance), or in a static class level variable (if you need to share it between several instance of the class).
BTW: sort out your indentation! it's a mess, which means the code is probably a mess as well: Visual Studio helps you with the indentation as you go along, so bad indentation normally means your code doesn't compile because the system doesn't understand it!
And never do this:
if (false == dic.ContainsKey(k)) dic[k] = v; else dic[k] += "," + v; There are two things wrong here:
if (false == x) ... That's messy and hard to read. Us etehis instead:
if (!x) ... The other is this:
if (x) y; else z; Indent it, and (certainly while you are a beginner) always use brackets:
if (x)
{
y;
}
else
{
z;
} It doesn't matter what bracketing style you use, as long as you are consistent:
if (x)
{
y;
}
else
{
z;
} Works as well.
So your code ends up as:
if (!dic.ContainsKey(k))
{
dic[k] = v;
}
else
{
dic[k] += "," + v;
} But for advanced users, we'd go with:
dic[k] = dic.ContainsKey(k)) ? dic[k] + "," + v : v;
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You probably need to make use of another control than TextBox since there will be more than one pair in the Dictionary. Perhaps take a look at ListBox or DataGridView .
You can loop through the Dictionary like this:
foreach (string s in dic.Keys)
{
}
Once user edits are done, on the button click you can again get all the values and write then to a file. You can opt to use StreamWriter for it.
using (StreamWriter writer = new StreamWriter("file path here"))
{
writer.WriteLine("line to write here");
}
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
You may wish to consider another data structure if you have the possibility of duplicate keys.
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
Hi
I'm trying to implement an OPC client to connect to the FactoryTalk Gateway opc server from Rockwell.
I get an example and I am trying to use it but with some problems.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace RsLinx_OPC_Client
{
public partial class Form1 : Form
{
#region Variables for OPC client
private Opc.URL url;
private Opc.Da.Server server;
private OpcCom.Factory fact = new OpcCom.Factory();
private Opc.Da.Subscription groupRead;
private Opc.Da.Subscription groupWrite;
private Opc.Da.SubscriptionState groupState;
private Opc.Da.SubscriptionState groupStateWrite;
private Opc.Da.Item[] items = new Opc.Da.Item[3];
#endregion
MyOPCObject myOpcObject = new MyOPCObject();
public Form1()
{
InitializeComponent();
}
private void btnConnect_Click(object sender, EventArgs e)
{
url = new Opc.URL("opcda://localhost/FactoryTalk Gateway");
server = new Opc.Da.Server(fact, null);
server.Connect(url, new Opc.ConnectData(new System.Net.NetworkCredential()));
groupState = new Opc.Da.SubscriptionState();
groupState.Name = "Group";
groupState.UpdateRate = 1000;
groupState.Active = true;
groupRead = (Opc.Da.Subscription)server.CreateSubscription(groupState);
groupRead.DataChanged += new Opc.Da.DataChangedEventHandler(group_DataChanged);
items[0] = new Opc.Da.Item();
items[0].ItemName = "[UNTITLED_1]N7:0,L2";
items[1] = new Opc.Da.Item();
items[1].ItemName = "[UNTITLED_1]N11:0,L10";
items[2] = new Opc.Da.Item();
items[2].ItemName = "[UNTITLED_1]B3:0,L2";
items = groupRead.AddItems(items);
groupStateWrite = new Opc.Da.SubscriptionState();
groupStateWrite.Name = "Group Write";
groupStateWrite.Active = false;
groupWrite = (Opc.Da.Subscription)server.CreateSubscription(groupStateWrite);
}
EXception is thrown in the
server.Connect(url, new Opc.ConnectData(new System.Net.NetworkCredential()));
The exception in italian tells that
Quote: Eccezione non gestita di tipo 'System.IO.FileNotFoundException' in OpcNetApi.dll
Ulteriori informazioni: Impossibile caricare il file o l'assembly 'OpcRcw.Dx, Version=1.0.1.21, Culture=neutral, PublicKeyToken=9a40e993cbface53' o una delle relative dipendenze. Impossibile trovare il file specificato.
Which means that it is impossible to load file or assembly 'OpcRcw.Dx, Version=1.0.1.21, Culture=neutral, PublicKeyToken=9a40e993cbface53' or relevant dependecies
Can somebody help?
Regards
|
|
|
|
|
It is not that it is impossible, but that a file cannot be found. The English translation is a fairly common exception:
Quote: Unhandled exception of type 'System.IO.FileNotFoundException' in OpcNetApi.dll
Additional Information: Unable to load file or assembly 'OpcRcw.Dx, Version = 1.0.1.21, Culture = neutral, PublicKeyToken = 9a40e993cbface53' or one of its dependencies. The specified file could not be found.
So, you need to find out why the file OpcRcw.Dx, with the related version, cannot be found in the expected library locations.
|
|
|
|
|
In this folder
Quote: C:\Windows\Microsoft.NET\assembly\GAC_MSIL\OpcNetApi\v4.0_2.1.106.0__78aea80f6827b5ab
I found OpcNetApi.dll
In the
Quote: C:\Windows\Microsoft.NET\assembly\GAC_MSIL\OpcRcw.Dx\v4.0_1.0.2.0__78aea80f6827b5ab
I found OpcRcw.Dx.dll
So at least positive is that files exist. May be missing some registration? I installed everything with the proper installation/licensing process.
|
|
|
|
|
The version information does not match the values in your error message. So somehow either the calling DLL is trying to get the wrong version, or the wrong version was installed. In either case you will need to go back to the suppliers of this software to get the correct versions.
|
|
|
|
|
Is the highlighted part of the folder name containing the dll the version number?
Quote: C:\Windows\Microsoft.NET\assembly\GAC_MSIL\OpcRcw.Dx\v4.0_1.0.2.0__78aea80f6827b5ab
Or better where do I get it?
|
|
|
|
|
The final values in that path certainly look like the version and PublicKeyToken. But since they are different from the values in the error message it looks certain that you have the wrong version of this or the DLL installed. As I said before, you need to go back to the people who produce this software to get the correct version(s).
|
|
|
|
|
Is the library 32-bit only? Is your app compiled as AnyCPU or x64?
Or the other way around? Is the library 64-bit only and your app compiled as x86?
Are there any documented dependencies for this library? Are those installed?
UPDATE
Well, a little Google comes up with this:
.NET api: can't find opcnetapi.dll | Classic OPC: DA, A&E, HDA, XML-DA, etc. | Forum - OPC Foundation[^]
The Rcw version is for .NET 1.x, which will not work on .NET 2.0 and above. Also, it seems the installers put out by Opc are known to be bad.
|
|
|
|
|
I am out of office now. I will collect the info asap.
Regards
|
|
|
|
|
Operating system is windows 10 pro , 64bit, processor x64 based
I am compiling app as x86.
I do not know how to find if library is 32 or 64 bit only
|
|
|
|
|
Run up a "Visual Studio X86 native tools command line".
Use CD to change to the folder containing the DLL file.
Type this: "dumpbin /headers nameofthedllfile.DLL" and press enter.
if you scroll back to the beginning of the output, it will give you the PE file details,
which will look like this for a x86 DLL:
PE signature found
File Type: DLL
FILE HEADER VALUES
14C machine (x86)
3 number of sections
546DE7F8 time date stamp Thu Nov 20 13:09:12 2014
0 file pointer to symbol table
0 number of symbols
E0 size of optional header
2102 characteristics
Executable
32 bit word machine
DLL And like this for a x64:
PE signature found
File Type: DLL
FILE HEADER VALUES
8664 machine (x64)
2 number of sections
5BB6183D time date stamp Thu Oct 04 14:40:13 2018
0 file pointer to symbol table
0 number of symbols
F0 size of optional header
2022 characteristics
Executable
Application can handle large (>2GB) addresses
DLL
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
From the type given in the error message, "OpcRcw.Dx", and the quick Google search I did, you're trying to use the .NET 1.x version of the library which will not work in any app compiled against .NET 2.0 and above.
|
|
|
|
|
I see that the calling code is searching for a specific version of OpcRcw.Dx.dll
Now is it the calling code wrongly searching an old/uncompatible version or is it simply the OpcRcw.Dx.dll of an old version and so to be replaced?
|
|
|
|
|
You set a reference to the RCW version in your project, so that's the version the code is looking for.
|
|
|
|
|
I took the "new" OPC libraries from the folder I was speaking some posts ago installed I guess by the factory talk gateway and they are version
2.1.106.0 . Then I copied them within the opportune "solution" folder overwriting the old ones. Then I added the reference to them to the app. Now I get compiling errors that I cannot decode. I attach here one of them.
It is in italian so I try to translate
It was impossible to resolve reference "OpcNetApi, ...." because it was compiled with framework
".NETFramework,Version=v4.5.1" This is successive to the current destination framework v4.0
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3274: non è stato possibile risolvere il riferimento primario "OpcNetApi, Version=2.1.106.0, Culture=neutral, PublicKeyToken=78aea80f6827b5ab, processorArchitecture=MSIL" perché è stato compilato con il framework".NETFramework,Version=v4.5.1". Questa versione è successiva a quella del framework di destinazione corrente ".NETFramework,Version=v4.0,Profile=Client".
|
|
|
|