how to manage the data in an xml file in wp7? - windows-phone-7

I have written a simple wp7 application. i am using wcf service to interact with the database. Now i want to store a part of user's info in the mobile also. this info needs to be accessible across the wp7 app.
I found multiple ways to do this like : isolated storage, resource files or static data in the app.xaml
Which one would be more suitable? as i may wish to edit the data in future...i may not opt for packaged files as they are read-only. also do not wish to lose data by storing in isolated storage.
Please suggest the most suitable option for me
Thanks in advance
Bindu

It sounds like you want to store downloaded data between uses of the app. In this case Isolated Storage is probably your best bet. It will remain in the phone's non-volatile memory and you will not lose it.
Details here

Resource files and static data in the app.xaml won't work for you since you want to be able to change these items at a later date since these will be read only.
I don't know what you are referring to when you say "lose data" by storing in IsolatedStorage. This is your best bet and is actually really easy to do. Here is an example of saving a simple boolean:
private void SaveSettings()
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
settings["VibrationOn"] = VibrationOn;
}
Then to load it later:
private void LoadSettings()
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
bool vo;
if (settings.TryGetValue<bool>("VibrationOn", out vo))
VibrationOn = vo;
else
VibrationOn = true;
}
You would call your LoadSettings() method in the Application_Launching and Application_Activated events and then your SaveSettings() in the Application_Deactivated and Application_Closing events within your App.xaml.cs.
You can also serialize objects or write whole files.

Related

How to access View Template Properties for Revit and compare them in Real Time?

I am trying to list the view template’s properties so we can compare them with another old template.
For example what model elements are hidden or have overrides in a given template or which Revit links have been hidden or overridden in a given template.
View Template
(https://www.google.com/search?q=view+template+revit&rlz=1C1GGRV_enUS770US770&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjLndrd2cTbAhVESq0KHX1cAPwQ_AUICygC&biw=1536&bih=824#imgrc=Q0v-pV7Nxl4kfM:)
I’m looking to devise a View Template Compare tool and access to the owner and creator of them.
public void ApplyViewTemplateToActiveView()
{
Document doc = this.ActiveUIDocument.Document;
View viewTemplate = (from v in new FilteredElementCollector(doc)
.OfClass(typeof(View))
.Cast<View>()
where v.IsTemplate == true && v.Name == "MyViewTemplate"
select v)
.First();
using (Transaction t = new Transaction(doc,"Set View Template"))
{
t.Start();
doc.ActiveView.ViewTemplateId = viewTemplate.Id;
t.Commit();
}
}
With Revit API you can access with:
GetTemplateParameterIds Method / ViewTemplateId Property
The Revit API exposes almost all the ViewTemplate properties.
For instance this method returns all the Visibility/Graphic Overrides for a specific category:
https://apidocs.co/apps/revit/2019/ed267b82-56be-6e3b-0c6d-4de7df1ed312.htm
The only thing I couldn't get for a ViewTemplate are the "includes", but all the rest seems to be there.
Update:
The list or properties "not included" can be retrieved with GetNonControlledTemplateParameterIds().
Yes, and no.
Yes, I guess you can use Forge Model Derivative API to export RVT file and then build a dashboard around the View Templates data. That's assuming that View Templates data actually gets exported when the model is translated. That data is not attached to any geometry so I would not be surprised if it was skipped. The question here is why? This is like renting a 16-wheel truck to move a duffel bag across the street.
No, if your intention is to directly interact with the RVT model. Forge can view it, but to push anything back or request changes to the model, is not available yet. Then again, I am not even sure that the view template data is available via model derivative exports.
This brings me another alternative. Why not just collect the data using Revit API, the standard way and then push it out to a Database and build on top of that? There is no reason to employ Forge for any of that.
Thanks Jeremy, I had dig into your amazing website and also some solution that Konrad post in the Dynamo Forum about this. In Revit seems pretty achievable, you filter the View that is View Template and then extracts these properties, is it correct?.
I am wondering if someone can point me in the right direction with Forge.
Some amazing guys are developing a BQL https://www.retriever.works/.
BQL(Building Query Language) is a query language for buildings, similar to how SQL is a query language for databases. It is fast and flexible. BQL helps improve efficiency for QA/QC (quality assurance and quality control), and building data extraction without leaving Revit. I am also trying these and I would like to understand if there are some works where I could start with Forge next week about this.

How to retain data even after app is closed in windows phone?

In my app i'm having two variables, which i want to retain even after my application is closed.
Which would be the right way to accompolish it?
You can store the values in an IsolatedStorage. There is a very nice article on MSDN regarding the persistance of information on Windows Phone. You can read it here http://msdn.microsoft.com/en-us/library/gg680266(v=pandp.11).aspx
The example shown by Microsoft looks something like this:
private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg";
private const string CAR_KEY = "FuelTracker.Car";
private static readonly IsolatedStorageSettings appSettings =
IsolatedStorageSettings.ApplicationSettings;
public static void SaveCar(Action errorCallback)
{
try
{
appSettings[CAR_KEY] = Car;
appSettings.Save();
DeleteTempCarPhoto();
SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback);
NotifyCarUpdated();
}
catch (IsolatedStorageException)
{
errorCallback();
}
}
The process of reading the information is very much the same. Go through the article and adopt it for your own needs.
There are a number of different storages available on Windows Phone 7.x as well as Windows Phone 8
If these two values of yours are settings, you want to preserve, I recommend you to use the IsolatedStorageSettings. This is a simple key / value store to save and load variables after restart your app. See the the following sample of MSDN (How to create settings)
See a list of other API's and samples on when and how to use it here (Data for Windows Phone on MSDN)

Static Properties with Session in ASP.NET

There are several posts about this online but none seem to provide a definitive answer. My question is this. If I have static properties declared that solely get/set Session values is that thread safe or will it potentially cause problems? In my app I have added static properties to my Global.asax to serve as a sort of central entry point for accessing certain values, for example I store the current client like this:
public static string CurrentClient {
get {
return HttpContext.Current.Session[Constants.SESSION_CURRENT_CLIENT] as string;
}
set {
HttpContext.Current.Session[Constants.SESSION_CURRENT_CLIENT] = value;
}
}
Note how I am not setting any static variables in my get/set, I am merely referencing the current session.
The application is setup so that it is installed as a single webapp in IIS but it will service multiple different 'instances'. Basically depending on what subdomain you come in on, it will then set all these Session variables as required. So for example:
client1.mydomain.com will set:
Global.CurrentClient = "client1";
client2.mydomain.com will set:
Global.CurrentClient = "client2";
This seems like it should work fine and be thread safe and the two subdomains will not trip over one another because they should each have unique sessions but that's exactly what seems to be happening. I get requests to client1.mydomain.com using CurrentClient="client2" for some reason.
What's going on here gang?
You seem to have a bad case of static-phobia. You shouldn't listen to people who spread FUD just because they don't understand what they're doing.
Static properties are essentially static methods. They do not store any state by themselves. Auto-properties are of course an exception, but you don't seem to be using them.
As long as you access any shared state in your static properties in a thread-safe manner, you won't have any problems.
What comes to your sessions getting "mixed up", are you sure the session cookie is being set at the correct level? If you set it at the mydomain.com level, it's going to be shared across all the subdomains. Also, are you sure it's even necessary to store this stuff in the session? Wouldn't it be the easiest to just compare the current domain with your list of clients on every request?

how to save and load a object in a windows phone 7 app?

is it possible in a WP7 app to save some objects which i create and then load it when the app is started again?
You'll want to look to store persistent items into IsolatedStorage. You can see an overview and an example of how to use IsolatedStorage here. There are also a range of examples on this site, showing how to save different types of objects.
Here's an example storing a string, but you should be able to store any type of object this way.
Add IsolatedStorage to your references:
using System.IO.IsolatedStorage;
In your class:
private string myString;
In the Loaded event for your page:
try
{
myString = (string)IsolatedStorageSettings.ApplicationSettings["myString"];
}
catch
{
IsolatedStorageSettings.ApplicationSettings.Add("myString", "this value is a string");
}
and later, when you want to save:
IsolatedStorageSettings.ApplicationSettings["myString"] = myString;
try after
the example code above to add this.
IsolatedStorageSettings.ApplicationSettings.save

Reliable and efficient way to handle Azure Table Batch updates

I have an IEnumerable that I'd like to add to Azure Table in the most efficient way possible. Since every batch write has to be directed to the same PartitionKey, with a limit of 100 rows per write...
Does anyone want to take a crack at implementing this the "right" way as referenced in the TODO section? I'm not sure why MSFT didn't finish the task here...
Also I'm not sure if error handling will complicate this, or the correct way to implement it. Here is the code from the Microsoft Patterns and Practices team for Windows Azure "Tailspin Toys" demo
public void Add(IEnumerable<T> objs)
{
// todo: Optimize: The Add method that takes an IEnumerable parameter should check the number of items in the batch and the size of the payload before calling the SaveChanges method with the SaveChangesOptions.Batch option. For more information about batches and Windows Azure table storage, see the section, "Transactions in aExpense," in Chapter 5, "Phase 2: Automating Deployment and Using Windows Azure Storage," of the book, Windows Azure Architecture Guide, Part 1: Moving Applications to the Cloud, available at http://msdn.microsoft.com/en-us/library/ff728592.aspx.
TableServiceContext context = this.CreateContext();
foreach (var obj in objs)
{
context.AddObject(this.tableName, obj);
}
var saveChangesOptions = SaveChangesOptions.None;
if (objs.Distinct(new PartitionKeyComparer()).Count() == 1)
{
saveChangesOptions = SaveChangesOptions.Batch;
}
context.SaveChanges(saveChangesOptions);
}
private class PartitionKeyComparer : IEqualityComparer<TableServiceEntity>
{
public bool Equals(TableServiceEntity x, TableServiceEntity y)
{
return string.Compare(x.PartitionKey, y.PartitionKey, true, System.Globalization.CultureInfo.InvariantCulture) == 0;
}
public int GetHashCode(TableServiceEntity obj)
{
return obj.PartitionKey.GetHashCode();
}
}
Well, we (the patterns & practices team) just optimized for showing other things we considered useful. The code above is not really a "general purpose library", but rather a specific method for the sample that uses it.
At that moment we thought that adding that extra error handling would not add much, and we diceided to keep it simple, but....we might have been wrong.
Anyway, if you follow the link in the //TODO:, you will find another section of a previous guide we wrote that talks a little bit more on error handling in "complex" storage transactions (not in the "ACID" form though as transactions "ala DTC" are not supported in Windows Azure Storage).
Link is this: http://msdn.microsoft.com/en-us/library/ff803365.aspx
The limitations are listed in more detail there:
Only one instance of the entity should be present in the batch
Max 100 entities or 4 MB payload
Same PartitionKey (which is being handled in the code: notice that "batch" is only specified if there's a single Partition key)
etc.
Adding some extra error handling should not overcomplicate things too much, but depends on the type of app you are building on top of this and your preference to handle this higher or lower in your app stack. In our example, the app would never expect > 100 entities anyway, so it would simply bubble the exception up if that situation happens (because it should be truly exceptional). Same with the total size. The use cases implemented in the app make it impossible to have the same entity in the same collection, so again, that should never happen (and if it happens, it wouls simply throw)
All "entity group transactions" limitations are documented here: http://msdn.microsoft.com/en-us/library/dd894038.aspx
Let us know how it goes! I'm also interested to know if other pieces of the guide were useful for you.

Resources