Persistent data for winform c# - winforms

I have a web poster application and I want to create a "Definition" file for it. Basically just a bunch of strings I import into the program at startup. I want them in an external source so I can update it without changing the executable.
I was thinking of creating a new static class, say "PosterDefinition", and on the startup of the application import the definition file, and set the PosterDefintion values from there.
As for how I will save it, maybe serialize the data from the program itself (a one time process).
Please share your thoughts.
Thanks.

I would suggest that you save it in an XML file. This would allow you to get the data quickly using LINQ-XML. What you could do is make properties that look at the file for making changes. You could cache values in the Application object. After a few requests, or after each one, check on the file. Because LINQ, or better yet PLINQ, excecutes quickly, the requests would not take long.
Here is an example XML document:
<?xml version="1.0" encoding="utf-8"?>
<Definition>
<Item>
<Title>t</Title>
<Something>Pie</Something>
</Item>
</Definition>
And here is how to access the Something of an item with Title t
using System.Xml;
using System.Xml.Linq;
XElement element = XElement.Load("definitions.xml");
XElement item = (from item in element.Elements()
where item.Elements().Where(i => (string)i.Element("Title") == "t")
select item.Element("Something")).First();
I havn't tested this and I am bad at LINQ so check this.

Related

How can I download a PDF file from a form using UI designer?? Bonita

The thing is I have found how upload a document and after that downolad it. But I just want to download it. I want to do it using the UI designer but I dont know how to do it.
Thanks :)
I dont know which tool are you using to design your UI, anyway this is concerning functionality, not design. In that point, i need to know wich language do you want (or can) use. For example, in PHP, it's very simple, you can make something like:
(create php file) downloadpdf.php
1st: (if you want to generate pdf "on the fly":
<?php
function download($foo){
content headers (type, force-download, etc)
database select to get data or harcode it.
echo data
}
?>
and call this function with some id to select from database or something (ignore if you want to hardcode it)
Other option to download a file, if it's stored on server is making a link to this file (statically or dyamically). If you wanna take control to file downloads, check this post:
http://www.media-division.com/the-right-way-to-handle-file-downloads-in-php/
I don't mean that it can be done with UI designer tools, and it's not concerned if it's from a form or not.
Cheers!
You should create link and variable which type is javascript expression. On Variable value write
return "/bonita/portal/" + $data.context.mainDoc_ref.url;
On link URL write your variable and to text
Download: {{context.mainDoc_ref.fileName}}
Here you can find excellent example for this case

How do you specify the SQLite database file in FireDAC's TFDPhysSQLiteDriverLink component?

I'm trying to modify one of the FireDAC sample projects in order to use an existing SQLite file as the database source. The sample works fine unmodified and connects to its database. However, I can't figure out where the database it connects to is specified, in order to change it.
According to the documentation, there should be a Database property on the TFDPhysSQLiteDriverLink component. There isn't: it doesn't exist. I even converted the form to text and looked through all components' customized properties, and there's no path defined anywhere. Nor is there in code - the sample is very small and there's no path defined at all.
The other option on the documentation is to include the FireDAC.Phys.SQLite unit, although that doesn't explain how to set the database, since as far as I can tell that unit just includes the component. And when I search for Database properties (see attached image) none of them in any class in that unit seem to be quite what I'm after. The closest is a string that's for a backup component - I doubt that's what I need. There is a SQLiteDatabase property in the TFDPhysSQLiteConnection class but that's read-only.
List of all Database properties defined in the FireDAC.Phys.SQLite unit
I also tried creating a temporary connection definition at runtime, by double-clicking the TFDConnection component. That only gives an exception:
Exception double-clicking the TFDConnection component
The only solution to this I found is in the XE5 documentation, where it says to set the $(PUBLICDOCUMENTSDIR) environment variable. I already had to do that to get the demo to run (previously, it threw the same exception on the line FDConnection1.Connected := True;; it doesn't now, the demo runs perfectly at runtime.) That change obviously hasn't affected the designer, and I don't even know if I'm looking in the right place, since after all the documentation talks about setting the Database property.
So I'm stumped. Where does it set the database? It's not in the DFM or any streamed properties; it's not in the property defined by the documentation (TFDPhysSQLiteDriverLink.Database doesn't exist, nor does anything that looks like it); it's not in the TFDConnection designtime editor (even though it throws an exception, a file specified as a property here would appear in the streamed DFM, I'd think); it's not in code; ...where else can it be?
(I have never used FireDAC before so am a complete noob, btw. I'm self-teaching via the documentation and samples.)
You don't actually need a TFDPhysSQLiteDriverLink for a minimalist FireDAC project, and using one rather confuses the issue if you're trying to make a connection to a database for the first time.
Try this:
Make a note of the name including path of a Sqlite db.
Start a new VCL project and drop a TFDconnection, TFDQuery, TDataSource & TDBGrid onto its form and connection them up. Set the TDFQuery's Sql to select * from some table you know exists in the db.
Right-click the TFDConnection and select Connection editor from the pop-up.
Set the DriverID to SQLite and insert your db name into the Database Value box.
Open the FDQuery.
If you compile and run the project, you'll get an exception telling you a class factory for a TFDGUIxWaitCursor is missing (this is the sort of thing I love about FireDAC), but that's easily fixed by dropping one onto your form. Notice that you don't have to connect it using the Object Inspector to any of the other FD components.
After that, you can add a TFDPhysSQLiteDriverLink and set its DriverID to the same as for the TFDConnection.
I ussualy roll my own class and handle the OnBeforeConnect event
Something like this
procedure TSQLiteConnection.SQLiteConnectionBeforeConnect(Sender: TObject);
begin
if not(TFile.Exists(DatabaseFilePath)) then
Params.Values['OpenMode'] := 'CreateUTF16'
else
Params.Values['OpenMode'] := 'ReadWrite';
Params.Values['Database'] := DatabaseFilePath;
DriverName := 'SQLite';
end;
The DatabaseFilePath is just a string field of the class, so basically you can put any file path there
TSQLiteConnection is, of course, a TFDConnection descendant

Using itextsharp to set ocg state of existing pdf

I have spent several hours researching this and can't seem to locate the answer.
I have downloaded and referenced itextsharp in my wpf .net application. (VB)
What I am doing is needing to turn off a specific layer (ocg object) in an exisiting .pdf that was created in Autocad that is defaulted on.
I have successfully opened and displayed the .pdf but i can't seem to use the setOCGstate control correctly
pdf name is "random.pdf"
layer name that i can see once i open the .pdf is "Option 1"
where im getting stuck is i know the layer names are stored in an array inside the .pdf. i know the name of the layer i am trying to turn off, so how do i reference that layer and turn it off using the setocgstate.
example code
dim doc1 as New PdfReader("random.pdf")
PdfAction.SetOCGstate ("confused", False)
I've created an example that turns off the visibility of a specific layer. See ChangeOCG
The concept is really simple. You already have a PdfReader object and you want to apply a change to a file. As documented, you create a PdfStamper object. As you want to change an OCG layer, you use the getPdfLayers() method and you select the layer you want to change by name. (In my example, the layer I want to turn off is named "Nested layer 1"). You use the setOn() method to change its status, and you're done:
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
Map<String, PdfLayer> layers = stamper.getPdfLayers();
PdfLayer layer = layers.get("Nested layer 1");
layer.setOn(false);
stamper.close();
reader.close();
This is Java code. Please read it as if it were pseudo-code and adapt it to your language of choice.

can't locate db4o database file

Hello I'm coding a simple CRUDE application that runs perfectly using JSF and DB4O.
I can add and list all the entities normally without errors.
I've used this code to persist the entities
bd = Db4oEmbedded.openFile(configuration, "db.data");
bd.store(client);
bd.commit();
the problem is that I cant locate the db.data file. I,ve done a search in the whole PC and still cant find it.
soo where DB4O store those entities, how is it possible??
thank you.
It must be in your project execution path. Usually db4o file name is called with extension yap. Better you can use relative path to the database file like
String dbPath = "c:/db/project.yap"; // better read from project resource
EmbeddedObjectContainer openFile = Db4oEmbedded.openFile(dbPath);

Change NamespaceManager on Full Text Search GAE

We have an application in GAE, and we are reenginering this to use Full Text. We have to index all data already in the GAE and our application also use namespaces.
We are trying to create a java procedure to be runned by administrator, who has not namespace. In other services, we have created similar java procedures, applying namespace by code, so the idea is to index all data in each namespace. (We use NamespaceFilter to control user domain.)
This is part of code:
private static final Index INDEX = SearchServiceFactory.getSearchService()
.getIndex(IndexSpec.newBuilder().setName("Actividad"));
NamespaceManager.set("userdomain1");
INDEX.add(doc);
Setting namespace is ignored.
Is this the expected behaviour? Is there an alternative way to index all the information in every namespace?
With similar code on datastore it's work fine.
A SearchService object is bound to a namespace, so you need to call NamespaceManager.set() before calling SearchServiceFactory.getSearchService(). Alternatively, call the version of getSearchService() that has a namespace parameter. See:
https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/search/SearchServiceFactory#getSearchService(java.lang.String)

Resources