Click here to Skip to main content
15,887,676 members
Home / Discussions / C#
   

C#

 
GeneralILMerge is not working Pin
Ashfaque Hussain3-Jun-14 20:07
Ashfaque Hussain3-Jun-14 20:07 
SuggestionRe: ILMerge is not working Pin
Richard MacCutchan3-Jun-14 21:56
mveRichard MacCutchan3-Jun-14 21:56 
GeneralRe: ILMerge is not working Pin
Ashfaque Hussain3-Jun-14 23:12
Ashfaque Hussain3-Jun-14 23:12 
GeneralRe: ILMerge is not working Pin
Richard MacCutchan3-Jun-14 23:26
mveRichard MacCutchan3-Jun-14 23:26 
GeneralRe: ILMerge is not working Pin
Ashfaque Hussain4-Jun-14 0:58
Ashfaque Hussain4-Jun-14 0:58 
SuggestionRe: ILMerge is not working Pin
Dan Colasanti6-Jun-14 5:26
professionalDan Colasanti6-Jun-14 5:26 
QuestionNAudio display multiple items in mainform listbox Pin
doby483-Jun-14 12:25
doby483-Jun-14 12:25 
AnswerRe: NAudio display multiple items in mainform listbox Pin
Matt T Heffron3-Jun-14 14:12
professionalMatt T Heffron3-Jun-14 14:12 
Caveat: I haven't used NAudio. These suggestions are based on the apparent use of MEF for the plugins. I have not tried any of this. (I am not an MEF guru.)
First: some things that seem clearly wrong.
RecordingPanelPlugin.ConnectionString() (besides having a very misleading name) collects all of the CustomerName column values into a single string. There's nothing keeping them as individual values.
The RecordingPanelPlugin.Name property just returns all of the names concatenated together.
MEF is Importing and creating a single instance of your RecordingPanelPlugin.

You seem to need a "parent" class which creates all of the instances of the RecordingPanelPlugin you want.
Create an interface that MEF can use to instantiate the class that creates the individual instances of RecordingPanelPlugin:
C#
public interface IPluginFactory
{
  List<INAudioPlugin> GetAudioPlugins();
}

Simplify the class RecordingPanelPlugin:
C#
[PartNotDiscoverable]  // Prevent MEF from instantiating this by discovery. We'll instantiate ourself
[Export(typeof(INAudioPlugin))]
public class RecordingPanelPlugin : AudioPlugin
{
  public RecordingPanelPlugin (string name)
  {
    this.Name = name;
  }

  public string Name { get; private set; }
 
  public Control CreatePanel()
  {
    return new RecordingPanel();
  }
}

Then create a class which implements IPluginFactory for the RecordingPanelPlugin:
C#
[Export(typeof(IPluginFactory))]
public class RecordingPanelPluginFactory
{
  private public List<INAudioPlugin> AllRecordingPanelPlugins;
  public List<INAudioPlugin> GetAudioPlugins()
  {
    if (AllRecordingPanelPlugins == null)
    {
      AllRecordingPanelPlugins = new List<INAudioPlugin>();
      using (var conn = new SqlCeConnection("Data Source=MyDatabase.sdf;Password=pass;Persist Security Info=True"))
      {
        conn.Open();
        var comm = new SqlCeCommand("SELECT * FROM main", conn);
        SqlCeDataReader reader = comm.ExecuteReader();
 
        while (reader.Read())
        {
          AllRecordingPanelPlugins.Add(new RecordingPanelPlugin((string)(reader["CustomerName"])));
        }
      }
    }
    return AllRecordingPanelPlugins;
  }
}

Now change the MainForm to have MEF give it all of the IPluginFactorys:
C#
[ImportingConstructor]
public MainForm([ImportMany] IEnumerable<IPluginFactory> factories)
{
  InitializeComponent();
  listBox.DisplayMember = "Name";
  foreach (var factory in factories)
  {
    foreach (var plugin in factory.GetAudioPlugins())
    {
      listBox.Items.Add(plugin);
    }
  }
}


Good luck!
(Remember my caveat above! Wink | ;) )
A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.

GeneralRe: NAudio display multiple items in mainform listbox Pin
doby484-Jun-14 9:25
doby484-Jun-14 9:25 
Questionbutton in circle shape Pin
KD Palekar3-Jun-14 8:34
KD Palekar3-Jun-14 8:34 
AnswerRe: button in circle shape Pin
Pete O'Hanlon3-Jun-14 8:49
mvePete O'Hanlon3-Jun-14 8:49 
GeneralRe: button in circle shape Pin
KD Palekar3-Jun-14 8:59
KD Palekar3-Jun-14 8:59 
GeneralRe: button in circle shape Pin
maheshwarreddy0095-Jun-14 16:25
maheshwarreddy0095-Jun-14 16:25 
GeneralRe: button in circle shape Pin
Pete O'Hanlon5-Jun-14 21:25
mvePete O'Hanlon5-Jun-14 21:25 
GeneralRe: button in circle shape Pin
maheshwarreddy0095-Jun-14 23:05
maheshwarreddy0095-Jun-14 23:05 
GeneralRe: button in circle shape Pin
Pete O'Hanlon5-Jun-14 23:07
mvePete O'Hanlon5-Jun-14 23:07 
GeneralRe: button in circle shape Pin
maheshwarreddy0095-Jun-14 23:10
maheshwarreddy0095-Jun-14 23:10 
GeneralRe: button in circle shape Pin
Pete O'Hanlon5-Jun-14 23:17
mvePete O'Hanlon5-Jun-14 23:17 
GeneralRe: button in circle shape Pin
maheshwarreddy0096-Jun-14 0:38
maheshwarreddy0096-Jun-14 0:38 
AnswerRe: button in circle shape Pin
OriginalGriff3-Jun-14 8:52
mveOriginalGriff3-Jun-14 8:52 
Questiondisable combobox in c# Pin
Member 105170433-Jun-14 1:24
Member 105170433-Jun-14 1:24 
AnswerRe: disable combobox in c# Pin
Pete O'Hanlon3-Jun-14 2:22
mvePete O'Hanlon3-Jun-14 2:22 
AnswerRe: disable combobox in c# Pin
Karthik Holla3-Jun-14 3:51
Karthik Holla3-Jun-14 3:51 
GeneralRe: disable combobox in c# Pin
Pete O'Hanlon3-Jun-14 4:02
mvePete O'Hanlon3-Jun-14 4:02 
GeneralRe: disable combobox in c# Pin
Paul Conrad3-Jun-14 5:39
professionalPaul Conrad3-Jun-14 5:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.