Click here to Skip to main content
15,924,038 members
Home / Discussions / C#
   

C#

 
Questionchat application Pin
Member 107629805-Jun-14 11:15
Member 107629805-Jun-14 11:15 
AnswerRe: chat application Pin
Mycroft Holmes5-Jun-14 12:51
professionalMycroft Holmes5-Jun-14 12:51 
GeneralRe: chat application Pin
Member 107629805-Jun-14 20:08
Member 107629805-Jun-14 20:08 
GeneralRe: chat application Pin
Mycroft Holmes5-Jun-14 22:31
professionalMycroft Holmes5-Jun-14 22:31 
GeneralRe: chat application Pin
Member 107629806-Jun-14 9:48
Member 107629806-Jun-14 9:48 
AnswerRe: chat application Pin
ZurdoDev5-Jun-14 16:20
professionalZurdoDev5-Jun-14 16:20 
GeneralRe: chat application Pin
Mycroft Holmes5-Jun-14 22:29
professionalMycroft Holmes5-Jun-14 22:29 
GeneralRe: chat application Pin
ZurdoDev6-Jun-14 1:24
professionalZurdoDev6-Jun-14 1:24 
AnswerRe: chat application Pin
Marco Bertschi6-Jun-14 9:21
protectorMarco Bertschi6-Jun-14 9:21 
GeneralRe: chat application Pin
Member 107629806-Jun-14 9:42
Member 107629806-Jun-14 9:42 
QuestionI can not convert WriteAllBytes to something can be used Progress Bar?? Pin
Hades104-Jun-14 1:27
Hades104-Jun-14 1:27 
AnswerRe: I can not convert WriteAllBytes to something can be used Progress Bar?? Pin
Richard MacCutchan4-Jun-14 2:48
mveRichard MacCutchan4-Jun-14 2:48 
GeneralRe: I can not convert WriteAllBytes to something can be used Progress Bar?? Pin
Eddy Vluggen4-Jun-14 2:58
professionalEddy Vluggen4-Jun-14 2:58 
GeneralRe: I can not convert WriteAllBytes to something can be used Progress Bar?? Pin
Hades104-Jun-14 4:15
Hades104-Jun-14 4:15 
SuggestionRe: I can not convert WriteAllBytes to something can be used Progress Bar?? Pin
GuyThiebaut4-Jun-14 6:21
professionalGuyThiebaut4-Jun-14 6:21 
QuestionProblem with Deleting rows in MSI database - with particular value reference alone Pin
Mohan Subramani3-Jun-14 23:19
Mohan Subramani3-Jun-14 23:19 
AnswerRe: Problem with Deleting rows in MSI database - with particular value reference alone Pin
Mohan Subramani4-Jun-14 3:09
Mohan Subramani4-Jun-14 3:09 
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.

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.