Has anyone done that?
Is there anyway of accessing the amp file setting through the code?
Does this help? It's for a custom extension, but should transfer to a custom task ok. I've included code for the Project Center extension, project extension and shared settings classs.Note: You must serialize out exactly the same settings that are deserialized in, otherwise the AMP file will become unreadable."TestExtension_ProjectCenter" Class Library Project -> TestExtension_ProjectCenter.xaml.cs
public partial class TestExtension : UserControl, IProjectExtension
{
// TODO: Set default name and description for your project extension
private string m_displayName = "A Test Extension";
private string m_description = "Test Task Extension";
private Settings m_testExtensionSettings = new Settings();
...
#region IXmlSerializable Members
/// <summary>
/// This method is reserved and should not be used. When implementing the IXmlSerializable interface, you should return null (Nothing in Visual Basic) from this method, and instead, if specifying a custom schema is required, apply the <see cref="T:System.Xml.Serialization.XmlSchemaProviderAttribute"/> to the class.
/// </summary>
/// <returns>
/// An <see cref="T:System.Xml.Schema.XmlSchema"/> that describes the XML representation of the object that is produced by the <see cref="M:System.Xml.Serialization.IXmlSerializable.WriteXml(System.Xml.XmlWriter)"/> method and consumed by the <see cref="M:System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader)"/> method.
/// </returns>
public System.Xml.Schema.XmlSchema GetSchema()
{
return null;
}
/// <summary>
/// Generates an object from its XML representation.
/// TODO: If you change your Project Center class name, replace 'TestExtension_ProjectCenter'
/// with the new class name
/// </summary>
/// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> stream from which the object is deserialized.</param>
public void ReadXml(System.Xml.XmlReader reader)
{
string name = reader.GetAttribute("name");
if (name != null)
DisplayName = name;
string desc = reader.GetAttribute("description");
if (desc != null)
Description = desc;
if (reader.IsEmptyElement)
{
reader.Read();
return;
}
reader.Read();
while (true)
{
if (reader.Name == "Settings")
{
XmlSerializer serializer = new XmlSerializer(typeof(Settings));
m_testExtensionSettings = (Settings)serializer.Deserialize(reader);
}
else if (reader.NodeType == XmlNodeType.EndElement)
{
reader.Read();
break;
}
else if (reader.EOF)
{
break;
}
else
{
// read over possible unknown element
reader.Skip();
}
}
}
/// <summary>
/// Converts an object into its XML representation.
/// </summary>
/// <param name="writer">The <see cref="T:System.Xml.XmlWriter"/> stream to which the object is serialized.</param>
public void WriteXml(System.Xml.XmlWriter writer)
{
// Writes basic assembly information to arcgis mobile project configuration file
writer.WriteAttributeString("name", DisplayName);
writer.WriteAttributeString("description", Description);
// TODO: Writes additional elements if need be
XmlSerializer serializer = new XmlSerializer(typeof(Settings));
serializer.Serialize(writer, m_testExtensionSettings);
}
...
}
"TestExtension_Win" Class Library Project -> TestExtension_Win.cs
public class TestExtension : ProjectExtension
{
private string m_displayName;
private string m_description;
private Assembly m_assembly = Assembly.GetExecutingAssembly();
private Settings m_testExtensionSettings;
/// <summary>
/// Gets/sets Description for your capability
/// </summary>
public string Description
{
get { return m_description; }
set { m_description = value; }
}
/// <summary>
/// Gets/sets DisplayName for your capability
/// </summary>
public string DisplayName
{
get { return m_displayName; }
set { m_displayName = value; }
}
protected override void Initialize()
{
// TODO:
// Note: This method is called by the Project when it's initializing. At this point
// all other Tasks and ProjectExtensions have been instantiated.
string message = String.Format("{0} Initialized", m_assembly.FullName);
ESRI.ArcGIS.Mobile.Client.Windows.MessageBox.ShowDialog(message, m_assembly.GetName().Name);
}
protected override void OnOwnerInitialized()
{
// TODO:
// Note: This method is called by the Project when it's Initialized. At this point
// all other Tasks and ProjectExtensions will have been Initialized
// Do not add/remove ProjectExtensions to the Project or Application during this method.
}
protected override void Uninitialize()
{
// TODO: Dispose or Detach events from application level objects
// Note: This method is called by the Project before the Project is closed.
string message = String.Format("{0} Uninitialized", m_assembly.FullName);
ESRI.ArcGIS.Mobile.Client.Windows.MessageBox.ShowDialog(message, m_assembly.GetName().Name);
}
public override void WriteXml(System.Xml.XmlWriter writer)
{
writer.WriteAttributeString("name", DisplayName);
writer.WriteAttributeString("description", Description);
XmlSerializer serializer = new XmlSerializer(typeof(Settings));
serializer.Serialize(writer, m_testExtensionSettings);
}
public override void ReadXml(System.Xml.XmlReader reader)
{
string name = reader.GetAttribute("name");
if (name != null)
DisplayName = name;
string desc = reader.GetAttribute("description");
if (desc != null)
Description = desc;
if (reader.IsEmptyElement)
{
reader.Read();
return;
}
reader.Read();
while (true)
{
if (reader.Name == "Settings")
{
XmlSerializer serializer = new XmlSerializer(typeof(Settings));
m_testExtensionSettings = (Settings)serializer.Deserialize(reader);
}
else if (reader.NodeType == XmlNodeType.EndElement)
{
reader.Read();
break;
}
else if (reader.EOF)
{
break;
}
else
{
// read over possible unknown element
reader.Skip();
}
}
}
}
"TestExtension_Common" Class Library Project -> Settings.cs
public class Settings
{
private string m_testSetting ="Default Value";
public string TestSetting
{
get
{
return m_testSetting;
}
set
{
m_testSetting = value;
}
}
}