WP7 - Adding Settings page. Reading values from a different page? - windows-phone-7

So I've created a page called "Settings". Obviously in this page is where the settings are for the app. In the Settings page I've added 2 ToggleSwitches and 1 Listpicker. Using the Nokia Developer website on basics of Saving and reading Settings i managed to pull it off so it saves the states of the toggleswitches and listpicker.
The problem i'm having right now is that i need a way to read these saved setting values on the first page when the app starts so it can prepare the app accordingly. Soo far this is what i have in the Settings page:
Imports System.IO.IsolatedStorage
Partial Public Class Settings
Inherits PhoneApplicationPage
Private AppSettings As IsolatedStorageSettings
Public Sub New()
InitializeComponent()
AppSettings = IsolatedStorageSettings.ApplicationSettings
ListPicker1.Items.Add("Saved Notes")
ListPicker1.Items.Add("Important")
End Sub
Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
Try
Tg1.IsChecked = CBool(AppSettings("UseAccentColor"))
Tg2.IsChecked = CBool(AppSettings("GoBack"))
ListPicker1.SelectedIndex = CByte(AppSettings("StartListFalse"))
Catch ex As KeyNotFoundException
AppSettings.Add("UseAccentColor", False)
AppSettings.Add("GoBack", False)
AppSettings.Add("StartListFalse", False)
AppSettings.Save()
End Try
End Sub
Protected Overrides Sub OnNavigatedFrom(e As NavigationEventArgs)
System.Diagnostics.Debug.WriteLine("Exiting, so save now")
AppSettings("UseAccentColor") = Tg1.IsChecked
AppSettings("GoBack") = Tg2.IsChecked
AppSettings("StartListFalse") = ListPicker1.SelectedIndex
AppSettings.Save()
End Sub
End Class
So soo far it saves on exit but i need a way to load these from startup i.e. my MainPage. Like a way to refer to this page and according to these settings change whatever needs to be changed.
How can i do this?
Thanks!

You managed to save Settings to IsolatedStorage, and IsolatedStorage is accesssible from any page of your application. So in MainPage, just read those setting from IsolatedStorage instead of the Settings Page.
EDIT :
You can do it just like in OnNavigatedTo method in Settings Page
Private AppSettings As IsolatedStorageSettings = IsolatedStorageSettings.ApplicationSettings
'Tg1.IsChecked is analog with useAccentColor
Dim useAccentColor As Boolean = CBool(AppSettings("UseAccentColor"))
'Tg2.IsChecked = goBack
Dim goBack As Boolean = CBool(AppSettings("GoBack"))
'ListPicker1.SelectedIndex = startListFalse
Dim startListFalse As Byte = CByte(AppSettings("StartListFalse"))

Related

How to add a new Tab in an Itop 2.4?

I have been trying to add a new tab as displayed in the image. I'm working on iTop 2.4
Can Anyone explain to me how to do this?
You have to create your own iTop extension and use the iApplicationUIExtension::OnDisplayRelations($oObject, WebPage $oPage, $bEditMode = false) API which provides you the current object so you can check its class and display the tab or not. It also gives you access to $oPage object so you can add your content to the tab.
If you are not familiar with iTop extension development, check this page which explains everything (note that it's for iTop 2.7 but the API is the same for iTop 2.4).
Here is an example from the "Approval process automation" extension:
class ApprovalBasePlugin implements iApplicationUIExtension, iApplicationObjectExtension
{
...
public function OnDisplayRelations($oObject, WebPage $oPage, $bEditMode = false)
{
if (!$oObject instanceof Ticket)
{
// skip !
return;
}
...
// Set the new tab name
$oPage->SetCurrentTab(Dict::S('Approval:Tab:Title'));
...
// Add content through the \WebPage APIs
$oPage->add('<div id="'.$sId.'_status" class="approval-exec-status">');
$oPage->add($oScheme->GetDisplayStatus($oPage, $bEditMode));
$oPage->add('</div>');
...
}
...
}

Uniquely identify Mailitem

I need to store a model for every used MailItem. For this I've written following Method
private readonly static Dictionary<string, PermitCustomPaneViewmodel> ViewmodelLookup = new Dictionary<string, PermitCustomPaneViewmodel>();
public static PermitCustomPaneViewmodel CreateOrGet(MailItem c)
{
if (c.EntryID == null)
c.Save();
if (!ViewmodelLookup.ContainsKey(c.EntryID))
{
var vm = new PermitCustomPaneViewmodel(c);
c.Unload += () => ViewmodelLookup.Remove(c.EntryID);
ViewmodelLookup.Add(c.EntryID, vm);
}
return ViewmodelLookup[c.EntryID];
}
When the Model already exists, I look it up and return it. If it was not created, I create it and remove the entry after the MailItem will be unloaded.
However I have observed that the MailItem object will not be vailid all the time untill unload is called. In order to reliable identify the MailItem I used the EntryID. The problem now is this only works if the Item is saved.
So currently I save the Item if no EntryID was found. But this automaticly saves the item under draft.
Is there a way to distingush MailItem's that is not saved in a way so it can be used in a Dictionary<,>.
New created items don't have the EntryID property set. Get the ID assigned by the store provider you must save it. If you need to identify a new MailItem object you may consider adding a user property to the item by using the UserProperties.Add method which reates a new user property in the UserProperties collection. For example:
Sub AddUserProperty()
Dim myItem As Outlook.ContactItem
Dim myUserProperty As Outlook.UserProperty
Set myItem = Application.CreateItem(olContactItem)
Set myUserProperty = myItem.UserProperties _
.Add("LastDateSpokenWith", olDateTime)
myItem.Display
End Sub
Be aware, the Entry ID changes when an item is moved into another store, for example, from your Inbox to a Microsoft Exchange Server public folder, or from one Personal Folders (.pst) file to another .pst file. Solutions should not depend on the EntryID property to be unique unless items will not be moved. Basically it works fine as long as the message is staying in its parent folder or it may be changed if the Outlook item is moved to a different folder (depends on the store provider).
You may also consider using the message id from the message MIME header (PR_INTERNET_MESSAGE_ID and PR_TRANSPORT_MESSAGE_HEADERS). But they are not set on newly created items. These properties are available on the message received from an SMTP server or through the SMTP connector.

Rich Text in a VB6 text box

Does anyone know if there is a way outside of using a 3rd Party text box control, to enter HTML into a VB6 text box.
I havent found anything online.
Hopefully you'll be able to make use of this. We're doing it in .Net to allow a simple edit control on forms to send formatted emails. As such we have a RTF text box with a custom menu for creating the text, then we extract the RTF, convert it to HTML and add it as HTML content as the body of an email. The RTF to HTML conversion uses the code from this article: http://www.codeproject.com/Articles/27431/Writing-Your-Own-RTF-Converter
Here's the wrapper code we use to tie this together - it simply takes an RTF input and directly returns an HTML output:
Imports Itenso.Rtf
Imports Itenso.Rtf.Support
Imports Itenso.Rtf.Parser
Imports Itenso.Rtf.Interpreter
Imports Itenso.Rtf.Converter.Image
Imports Itenso.Rtf.Converter.Html
Imports Itenso.Sys.Application
Namespace Email
Public Class RtfToHtml
Public Function Convert(inText As String) As String
Dim struct = ParseRtf(inText)
Dim doc = InterpretRtf(struct)
Return ConvertHtml(doc)
End Function
Private Function ParseRtf(inText As String) As IRtfGroup
Dim structureBuilder As New RtfParserListenerStructureBuilder
Dim parser = New RtfParser(structureBuilder) With {.IgnoreContentAfterRootGroup = True}
Dim source = New RtfSource(inText)
parser.Parse(source)
Return structureBuilder.StructureRoot
End Function
Private Function InterpretRtf(rtfStructure As IRtfGroup) As IRtfDocument
Dim settings = New RtfInterpreterSettings With {.IgnoreDuplicatedFonts = True, .IgnoreUnknownFonts = True}
Return RtfInterpreterTool.BuildDoc(rtfStructure, settings)
End Function
Private Function ConvertHtml(document As IRtfDocument) As String
Dim settings As New RtfHtmlConvertSettings With {.Title = "Notification Of Shipment",
.IsShowHiddenText = False,
.UseNonBreakingSpaces = True}
Dim converter = New RtfHtmlConverter(document, settings)
'converter.StyleConverter = New RtfEmptyHtmlStyleConverter
Return converter.Convert
End Function
End Class
End Namespace
Depending on your application you could simply wrap this up in an assembly and call it from VB6. We've done this in the past and it's reasonably straightforward. Again, more info if you think it might be useful to you

ASP.NET MVC Override HandleError causes View to not render

In my app I'm using "HandleError" whereby if an error happens, my "Error.vbhtml" view renders. This is working great, except now I want to also log the error. I've built a custom HandleError Class, Inherited the HandleErrorAttribute, and Overridden the OnException method.
Now my error gets logged, but the Error.vbhtml view doesn't get rendered... what praytell am I messing?
Imports System.Web.Mvc
Namespace Mvc.Attributes
Public Class HandleError : Inherits System.Web.Mvc.HandleErrorAttribute
Private ExceptionService As Domain.IExceptionService
Public Sub New()
ExceptionService = New Domain.ExceptionService(New Domain.ExceptionRepository)
End Sub
Public Overrides Sub OnException(ByVal exceptionContext As ExceptionContext)
''# Log the exception if it has not been handled elsewhere
If Not exceptionContext.ExceptionHandled Then
ExceptionService.AddException(exceptionContext.Exception)
ExceptionService.SubmitChanges()
''# Signal to the system that we've handled the exception
exceptionContext.ExceptionHandled = True
End If
End Sub
End Class
End Namespace
I just took a look at the source code of the HandleError method at Codeplex. I scooped some of the code from there
Dim controllerName As String = DirectCast(filterContext.RouteData.Values("controller"), String)
Dim actionName As String = DirectCast(filterContext.RouteData.Values("action"), String)
Dim model As New HandleErrorInfo(filterContext.Exception, controllerName, actionName)
filterContext.Result = New ViewResult() With { _
.ViewName = View, _
.MasterName = Master, _
.ViewData = New ViewDataDictionary(Of HandleErrorInfo)(model), _
.TempData = filterContext.Controller.TempData _
}
filterContext.ExceptionHandled = True
filterContext.HttpContext.Response.Clear()
filterContext.HttpContext.Response.StatusCode = 500
''# Certain versions of IIS will sometimes use their own error page when
''# they detect a server error. Setting this property indicates that we
''# want it to try to render ASP.NET MVC's error page instead.
filterContext.HttpContext.Response.TrySkipIisCustomErrors = True
This appears to work

Session variable getting lost using Firefox, works in IE

I am setting a Session variable in an HttpHandler, and then getting its value in the Page_load event of an ASPX page. I'm setting it using
public void ProcessRequest(HttpContext context)
{
HttpPostedFile file = context.Request.Files["Filedata"];
context.Session["WorkingImage"] = file.FileName;
}
(And before someone suggests that I check the validity of file.FileName, this same problem occurs if I hard-code a test string in there.) It's working just fine in IE, but in Firefox the Session Variable is not found, getting the "Object reference not set to an instance of an object" error in the following code:
protected void Page_Load(object sender, EventArgs e)
{
string loc = Session["WorkingImage"].ToString();
}
Has anyone encountered this problem - and hopefully come up with a means for passing the session variable?
This is for an HTTPHandler? If this by some chance has something to do with Flash, and Flash is making the request, you will be very interested in reading about the Flash Cookie Bug. Basically, Flash only forwards IE cookies.
The easist fix is to call correctCookie at Application_BeginRequest in your Global.asax and put the SessionId in the querystring of the Flash request.
Public Shared Sub correctCookie()
Try
Dim session_cookie_name As String = "ASP.NET_SESSIONID"
Dim session_value As String = HttpContext.Current.Request.QueryString("sid")
If session_value IsNot Nothing Then
UpdateCookie(session_cookie_name, session_value)
End If
Catch ex As Exception
End Try
End Sub
Private Shared Sub UpdateCookie(ByVal cookie_name As String, ByVal cookie_value As String)
Dim cookie As HttpCookie = HttpContext.Current.Request.Cookies.[Get](cookie_name)
If cookie Is Nothing Then
Dim cookie1 As New HttpCookie(cookie_name, cookie_value)
HttpContext.Current.Response.Cookies.Add(cookie1)
Else
cookie.Value = cookie_value
HttpContext.Current.Request.Cookies.[Set](cookie)
End If
End Sub

Resources