I am currently having an issue where I am trying to do a check in a workflow before saving the custom form content item as a submission. Once the CreateAndPublish workflow is hit, it actually creates the item, but the field values aren't being saved properly.
Here is my workflow:
public class CreateAndPublishActivity : Task {
private readonly IContentManager _contentManager;
public CreateAndPublishActivity(IContentManager contentManager) {
_contentManager = contentManager;
}
public Localizer T { get; set; }
public override bool CanExecute(WorkflowContext workflowContext, ActivityContext activityContext) {
return true;
}
public override IEnumerable<LocalizedString> GetPossibleOutcomes(WorkflowContext workflowContext, ActivityContext activityContext) {
return new[] { T("Done") };
}
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) {
_contentManager.Create(workflowContext.Content.ContentItem, VersionOptions.Published);
yield return T("Done");
}
public override string Name {
get { return "CreateAndPublish"; }
}
public override LocalizedString Category {
get { return T("Content Items"); }
}
public override LocalizedString Description {
get { return T("Create and Publish the content item."); }
}
}
The content item shows up under submissions, but none of the field values are there.
Related
I have a ComboBox containing Unicode symbols, the font is set to a Unicode-Supporting font and it displays them just fine. But the DropDown section seems to use a standard font which cannot display these Unicode symbols. Is there a way to change this inside the properties or do I have to create a customized ComboBox control?
EDIT:
My Code:
public class MainWindow : Form {
...
public BindingList<Sound> Sounds { get; set; } = new BindingList<Sound>();
public MainWindow() {
InitializeComponent();
this.comboBox.DataSource = this.Sounds;
}
...
}
public class Sound {
public char Symbol { get; private set; }
public Sound(char symbol) {
this.Symbol = symbol;
}
public override int GetHashCode() {
return this.Symbol.GetHashCode();
}
public override bool Equals(object obj) {
if(obj is Sound) {
return this.Symbol == ((Sound)obj).Symbol;
}
return base.Equals(obj);
}
public override string ToString() {
return this.Symbol.ToString();
}
public void Play() {
...
}
}
I want to populate a combobox with two different objects using an interface. This is what I currently got. This works but now I would like to have a display member and value member for each object, how would I do so?
In Controller.cs
public List<IMusic> Populate()
{
List<IMusic> newList = new List<IMusic>();
foreach(Track t in tr.GetAllTracks()){
newList.Add(t);
}
foreach (Artist a in ar.GetAllArtists())
{
newList.Add(a);
}
return newList;
}
IMusic.cs
interface IMusic
{
}
The combobox with DataSource:
cBMainScreen_Search.DataSource = controller.Populate();
GetAllTracks() :
public List<Track> GetAllTracks()
{
return db.Track.ToList();
}
GetAllArtists() :
public List<Artist> GetAllArtists()
{
return db.Artist.ToList();
}
Just setup some properties in your interface:
interface IMusic
{
string Display { get; set; }
string Value { get; set; }
}
Then in your Track class (which should implement IMusic):
public string Display
{
get
{
return this.TrackName;
}
set
{
this.TrackName= value;
}
}
public string Value
{
get
{
return this.TrackID;
}
set
{
this.TrackID= value;
}
}
And in your Artist class (also implements IMusic):
public string Display
{
get
{
return this.ArtistName;
}
set
{
this.ArtistName= value;
}
}
public string Value
{
get
{
return this.AritstID;
}
set
{
this.AritstID= value;
}
}
I was wondering if it is possible to dynamically set the table mapping for the linq classes:
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.[Comfort 0601$Contact]")]
public partial class Contact : INotifyPropertyChanging, INotifyPropertyChanged
{
...
The reason I want to change this dynamically or programmatically is because the database I'm using is created by Navision. There the tables have a prefix of the company name to which these tables belong to. Therefor I would like to be able to change that prefix.
[global::System.Data.Linq.Mapping.TableAttribute(Name = "dbo.["+SPResources.Database.Company+"$Contact]")]
whit Company as:
public const string Company = "Comfort 0601";
I've tried this, but it only work if i declared Company as a constant.
The table structure between companies are identical. just the name & content change.
I hope someone can give some advice about this. I'm also not sure if it even is possible.
Think the correct solution for adding table-prefix is to use SQL Server 2005 (Or newer), and then create a db-user for each required prefix, and change default schema for each db-user from "dbo" to something unique.
Another solution is to extend the existing DataContext with the ability to "correct" the MappingSource at runtime:
[Table] // Look no name
public class DbRecord
{
[Column(IsPrimaryKey=true)]
public long Id { get; set; }
}
CustomDataContext.UpdateCustomTable(typeof(DbRecord), "DbTable");
using (CustomDataContext dc = new CustomDataContext(dbConnection))
{
Table<DbRecord> dbTable = dc.GetTable<DbRecord>();
var query = from item in dbTable;
}
This is the custom DataContext (I guess one could easily change it to add a prefix to an existing table-name) (Replace Dictionary with ConcurrentDictionary if in multi-threaded environment):
public class CustomDataContext : DataContext
{
static CustomMappingSource _sharedMappingSource = new CustomMappingSource();
public static void UpdateCustomTable(Type rowType, string tableName)
{
_sharedMappingSource.UpdateCustomTable(rowType, tableName);
}
public CustomDataContext(System.Data.IDbConnection connection) : base(connection, _sharedMappingSource) { }
public CustomDataContext(string fileOrServerOrConnection) : base(fileOrServerOrConnection, _sharedMappingSource) { }
}
internal class CustomMappingSource : MappingSource
{
AttributeMappingSource mapping = new AttributeMappingSource();
Dictionary<Type, string> _customTableNames = new Dictionary<Type, string>();
public void UpdateCustomTable(Type rowType, string tableName)
{
if (string.IsNullOrEmpty(tableName))
throw new ArgumentNullException("TableName");
_customTableNames[rowType] = tableName;
}
protected override MetaModel CreateModel(Type dataContextType)
{
MetaModel oldmodel = mapping.GetModel(dataContextType);
CustomMetaModel newmodel = new CustomMetaModel(oldmodel, _customTableNames);
return newmodel;
}
}
internal class CustomMetaModel : MetaModel
{
MetaModel _orgmodel;
Dictionary<Type, MetaTable> _customtables = new Dictionary<Type, MetaTable>();
Dictionary<Type, string> _tableNames = new Dictionary<Type, string>();
public CustomMetaModel(MetaModel orgmodel, Dictionary<Type, string> tableNames)
{
_orgmodel = orgmodel;
_tableNames = tableNames;
}
public override MetaType GetMetaType(Type type)
{
MetaTable metaTable;
if (_customtables.TryGetValue(type, out metaTable))
return metaTable.RowType;
else
return _orgmodel.GetMetaType(type);
}
public override MetaTable GetTable(Type rowType)
{
MetaTable customMetaTable;
if (_customtables.TryGetValue(rowType, out customMetaTable))
return customMetaTable;
if (_tableNames.ContainsKey(rowType))
{
MetaTable orgtable = _orgmodel.GetTable(rowType);
MetaType orgrowtype = orgtable.RowType;
CustomMetaType newRowType = new CustomMetaType(orgrowtype, this);
_customtables.Add(rowType, new CustomMetaTable(orgtable, this, newRowType, _tableNames[rowType]));
newRowType.MetaTable = _customtables[rowType];
return newRowType.MetaTable;
}
return _orgmodel.GetTable(rowType);
}
#region MetaModel Forwards
public override Type ContextType { get { return _orgmodel.ContextType; } }
public override string DatabaseName { get { return _orgmodel.DatabaseName; } }
public override MappingSource MappingSource { get { return _orgmodel.MappingSource; } }
public override Type ProviderType { get { return _orgmodel.ProviderType; } }
public override MetaFunction GetFunction(System.Reflection.MethodInfo method) { return _orgmodel.GetFunction(method); }
public override IEnumerable<MetaFunction> GetFunctions() { return _orgmodel.GetFunctions(); }
public override IEnumerable<MetaTable> GetTables() { return _orgmodel.GetTables(); }
#endregion
}
internal class CustomMetaTable : MetaTable
{
MetaTable _orgtable;
MetaModel _metamodel;
MetaType _rowtype;
string _tableName;
public CustomMetaTable(MetaTable orgtable, MetaModel metamodel, MetaType rowtype, string tableName)
{
_orgtable = orgtable;
_metamodel = metamodel;
_rowtype = rowtype;
_tableName = tableName;
}
public override MetaModel Model { get { return _metamodel; } }
public override MetaType RowType { get { return _rowtype; } }
public override string TableName { get { return _tableName; } }
#region MetaTable Forwards
public override System.Reflection.MethodInfo DeleteMethod { get { return _orgtable.DeleteMethod; } }
public override System.Reflection.MethodInfo InsertMethod { get { return _orgtable.InsertMethod; } }
public override System.Reflection.MethodInfo UpdateMethod { get { return _orgtable.UpdateMethod; } }
#endregion
}
internal class CustomMetaType : MetaType
{
MetaType _orgtype;
MetaModel _metamodel;
public MetaTable MetaTable { get; set; }
public CustomMetaType(MetaType orgtype, MetaModel metamodel)
{
_orgtype = orgtype;
_metamodel = metamodel;
}
public override MetaTable Table { get { return MetaTable; } }
public override MetaModel Model { get { return _metamodel; } }
#region MetaType Forwards
public override System.Collections.ObjectModel.ReadOnlyCollection<MetaAssociation> Associations { get { return _orgtype.Associations; } }
public override bool CanInstantiate { get { return _orgtype.CanInstantiate; } }
public override System.Collections.ObjectModel.ReadOnlyCollection<MetaDataMember> DataMembers { get { return _orgtype.DataMembers; } }
public override MetaDataMember DBGeneratedIdentityMember { get { return _orgtype.DBGeneratedIdentityMember; } }
public override System.Collections.ObjectModel.ReadOnlyCollection<MetaType> DerivedTypes { get { return _orgtype.DerivedTypes; } }
public override MetaDataMember Discriminator { get { return _orgtype.Discriminator; } }
public override bool HasAnyLoadMethod { get { return _orgtype.HasAnyLoadMethod; } }
public override bool HasAnyValidateMethod { get { return _orgtype.HasAnyValidateMethod; } }
public override bool HasInheritance { get { return _orgtype.HasInheritance; } }
public override bool HasInheritanceCode { get { return _orgtype.HasInheritanceCode; } }
public override bool HasUpdateCheck { get { return _orgtype.HasUpdateCheck; } }
public override System.Collections.ObjectModel.ReadOnlyCollection<MetaDataMember> IdentityMembers { get { return _orgtype.IdentityMembers; } }
public override MetaType InheritanceBase { get { return _orgtype.InheritanceBase; } }
public override object InheritanceCode { get { return _orgtype.InheritanceCode; } }
public override MetaType InheritanceDefault { get { return _orgtype.InheritanceDefault; } }
public override MetaType InheritanceRoot { get { return _orgtype.InheritanceRoot; } }
public override System.Collections.ObjectModel.ReadOnlyCollection<MetaType> InheritanceTypes { get { return _orgtype.InheritanceTypes; } }
public override bool IsEntity { get { return _orgtype.IsEntity; } }
public override bool IsInheritanceDefault { get { return _orgtype.IsInheritanceDefault; } }
public override string Name { get { return _orgtype.Name; } }
public override System.Reflection.MethodInfo OnLoadedMethod { get { return _orgtype.OnLoadedMethod; } }
public override System.Reflection.MethodInfo OnValidateMethod { get { return _orgtype.OnValidateMethod; } }
public override System.Collections.ObjectModel.ReadOnlyCollection<MetaDataMember> PersistentDataMembers { get { return _orgtype.PersistentDataMembers; } }
public override Type Type { get { return _orgtype.Type; } }
public override MetaDataMember VersionMember { get { return _orgtype.VersionMember; } }
public override MetaDataMember GetDataMember(System.Reflection.MemberInfo member) { return _orgtype.GetDataMember(member); }
public override MetaType GetInheritanceType(Type type) { return _orgtype.GetInheritanceType(type); }
public override MetaType GetTypeForInheritanceCode(object code) { return _orgtype.GetTypeForInheritanceCode(code); }
#endregion
}
The answers of Brian and Gert are possible solutions for this problem. But changing the mapping at run-time is just not possible (as Brian mentioned).
As our project progressed we decided that if we would need another company name (which would mean that that build is for a different customer) we would just rebuild the project. That decision made the following solution possible:
We commented out the original mappings generated by Visual Studio:
//[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.[Comfort 0601$Contact]")]
public partial class Contact : INotifyPropertyChanging, INotifyPropertyChanged
{
...
Because we have our own partial class for every Linq class, we added the modified mapping at the top of our own class:
[global::System.Data.Linq.Mapping.TableAttribute(Name = "dbo.["+SPResources.Database.Company+"$Contact]")]
public partial class Contact
{
where our company will be:
public const string Company = "Comfort 0601";
If a rebuild is needed for a different company we simply change the Company variable.
Note: This only works properly if you don't change your *.dbml file in VS. If you do, VS will automatically undo your changes.
Edit: As time has passed and I started to look more into the Entity Framework I found a more specific and suitable solution for this problem: http://www.codeproject.com/Articles/421643/How-to-Use-MVC-Net-on-the-Dynamics-NAV-Database-St
You could use SQLMetal to custom generate the code for each entities. You cannot apply attributes dynamically at runtime, so this would be the best option.
If you'd work code-first you could use fluent mapping you can use the ToTable() method to configure the database table at runtime (see under Changing the Database Table Name). E.g. in a OnModelCreating() override of your DbContext derivative:
string company = "Comfort 0601";
modelBuilder.Entity<Contact>().ToTable(company + "Contact");
modelBuilder.Entity<....
modelBuilder.Entity<....
You could take the company name from a config file.
I have created a new Custom Control inheriting from Bar control of DevComponents.DotNetBar controls. Next, I have created a new dock tab in it and have added my other controls to it.
After I compile my Custom Control and add my created Custom Control in a new Windows Form, Dock Tab Controls are editable at design time.
I don't want that anybody can edit these controls (Dock Tab Controls) in design time. How can I disable editing the controls at design time from the form (not the same as editing the control itself)?
public partial class barFloorsGrouping : Bar
{
public barFloorsGrouping()
{
InitializeComponent();
}
[ReadOnly(true)]
public new System.Windows.Forms.AccessibleRole AccessibleRole
{
get { return base.AccessibleRole; }
private set { base.AccessibleRole = System.Windows.Forms.AccessibleRole.ToolBar; }
}
[Browsable(false), ReadOnly(true)]
public new bool AlwaysDisplayDockTab
{
get { return base.AlwaysDisplayDockTab; }
private set { base.AlwaysDisplayDockTab = true; }
}
[Browsable(false), ReadOnly(true)]
public new bool AlwaysDisplayKeyAccelerators
{
get { return base.AlwaysDisplayKeyAccelerators; }
private set { base.AlwaysDisplayKeyAccelerators = true; }
}
[ReadOnly(true)]
public new bool AntiAlias
{
get { return base.AntiAlias; }
private set { base.AntiAlias = true; }
}
[Browsable(false), ReadOnly(true)]
public new bool AutoCreateCaptionMenu
{
get { return base.AutoCreateCaptionMenu; }
}
[ReadOnly(true)]
public new bool AutoHide
{
get { return base.AutoHide; }
}
[Browsable(false), ReadOnly(true)]
public new bool AutoHideTabTextAlwaysVisible
{
get { return base.AutoHideTabTextAlwaysVisible; }
}
[Browsable(false), ReadOnly(true)]
public new bool AutoSyncBarCaption
{
get { return base.AutoSyncBarCaption; }
private set { base.AutoSyncBarCaption = true; }
}
[Browsable(false), ReadOnly(true)]
public new eBarType BarType
{
get { return base.BarType; }
private set { base.BarType = eBarType.DockWindow; }
}
[ReadOnly(true)]
public new bool CanAutoHide
{
get { return base.CanAutoHide; }
}
[ReadOnly(true)]
public new bool CanDockTab
{
get { return base.CanDockTab; }
private set { base.CanDockTab = false; }
}
[ReadOnly(true)]
public new bool CanUndock
{
get { return base.CanUndock; }
private set { base.CanUndock = false; }
}
[Browsable(false), ReadOnly(true)]
public new bool CloseSingleTab
{
get { return base.CloseSingleTab; }
}
[Browsable(false), ReadOnly(true)]
public new bool DisplayMoreItemsOnMenu
{
get { return base.DisplayMoreItemsOnMenu; }
private set { base.DisplayMoreItemsOnMenu = true; }
}
[ReadOnly(true)]
public new DockStyle Dock
{
get { return base.Dock; }
}
[Browsable(false), ReadOnly(true)]
public new bool DockTabCloseButtonVisible
{
get { return base.DockTabCloseButtonVisible; }
}
[Browsable(false), ReadOnly(true)]
public new bool FadeEffect
{
get { return base.FadeEffect; }
private set { base.FadeEffect = true; }
}
[Browsable(false), ReadOnly(true)]
public new eGrabHandleStyle GrabHandleStyle
{
get { return base.GrabHandleStyle; }
private set { base.GrabHandleStyle = eGrabHandleStyle.Caption; }
}
[Browsable(false), ReadOnly(true)]
public new eLayoutType LayoutType
{
get { return base.LayoutType; }
private set { base.LayoutType = eLayoutType.DockContainer; }
}
[Browsable(false), ReadOnly(true)]
public new bool MenuBar
{
get { return base.MenuBar; }
}
[Browsable(false), ReadOnly(true)]
public new bool TabNavigation
{
get { return base.TabNavigation; }
private set { base.TabNavigation = true; }
}
[Browsable(false), ReadOnly(true)]
public new bool WrapItemsDock
{
get { return base.WrapItemsDock; }
private set { base.WrapItemsDock = true; }
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
}
}
You must extend the design mode behavior by using ParentControlDesigner Class. ParentControlDesigner Class provides a base class for designers of controls that can contain child controls.
So, for achieve to your Goal, you must implement design-time services for a component by DesignerAttribute as the following (Just add below code before the written class):
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))]
public partial class barFloorsGrouping : Bar
{
...
}
EDIT: As always I work in asp.net and webforms... This answer is for WebForms
You would need to override the GetDesignTimeHtml of the WebControl.
see MSDN docs
It sounds to me like you haven't done a lot of server control creation so you are in for a lot of fun...
Below is my implementation of the state pattern. In order to persist the State object to my database with NHibernate, I am assigning each state class an enum value. This is stored as a private field on the entity, and mapped to a integer field in my database table.
I want to know whether this is a good implementation as I will be using the state pattern throughout my application and want to get it right the first time. Thanks
public class Order
{
private OrderStatusEnum _statusId;
public virtual Guid Id { get; set; }
private OrderState _status;
public virtual OrderState Status {
get
{
if (_status == null)
_status = GetState(_statusId);
return _status;
}
set
{
_status = value;
_statusId = _status.Id;
}
}
private OrderState GetState(OrderStatusEnum status)
{
switch (_statusId) {
case OrderStatusEnum.Pending:
return new Submitted(this);
case OrderStatusEnum.Completed:
return new Completed(this);
default:
return new NewOrder(this);
}
}
}
public abstract class OrderState
{
private readonly Order _order;
public OrderState(Order order) {
_order = order;
}
internal Order Order { get { return _order; } }
public abstract OrderStatusEnum Id { get; }
public virtual void Submit() {
throw new InvalidOperationException(
string.Format("Can't Submit a {0} Order", this.GetType().Name)
);
}
public virtual void Complete() {
throw new InvalidOperationException(
string.Format(string.Format("Can't Cancel a {0} Order", this.GetType().Name))
);
}
protected internal void _Submit() {
Order.Status = new Submitted(Order);
}
protected internal void _Complete() {
Order.Status = new Completed(Order);
}
}
public class NewOrder : OrderState
{
public NewOrder(Order order) : base(order) { }
public override OrderStatusEnum Id {
get { return OrderStatusEnum.New; }
}
public override void Submit() {
_Submit();
}
}
public class Submitted : OrderState
{
public Submitted(Order order) : base(order) { }
public override OrderStatusEnum Id {
get { return OrderStatusEnum.Pending; }
}
public override void Complete() {
_Complete();
}
}
public class Completed : OrderState
{
public Completed(Order order) : base(order) { }
public override OrderStatusEnum Id {
get { return OrderStatusEnum.Completed; }
}
}
public enum OrderStatusEnum {
New = 1,
Pending = 2,
Completed = 3
}
Not sure whether to answer or add a comment, but your approach worked very well for me in a similar situation.
I also experimented with the approach described here using the Tarantino framework, but I found it easier to extend from your code.