public static EnumeratorDistributorClient <byte[]> Start(WebCamInfo webCamInfo)
        {
            string monikerName = webCamInfo.InternalName;

            EnumeratorDistributor <byte[]> distributor;

            lock (fDictionary)
            {
                FormWebCam form;
                if (fDictionary.TryGetValue(monikerName, out form))
                {
                    distributor = form.Distributor;
                }
                else
                {
                    IFastEnumerator <byte[]> realEnumerator;

                    switch (monikerName)
                    {
                    case "Fake_Black":
                        realEnumerator = new FakeWebCamEnumerator(Color.Black);
                        break;

                    case "Fake_Blue":
                        realEnumerator = new FakeWebCamEnumerator(Color.Blue);
                        break;

                    default:
                        realEnumerator = new WebCamEnumerator(monikerName);
                        break;
                    }

                    distributor = new EnumeratorDistributor <byte[]>(realEnumerator);
                    form        = new FormWebCam(FormMain.fNickName, webCamInfo.DisplayName, monikerName, distributor);
                    fDictionary.Add(monikerName, form);
                    form.Show();
                }
            }

            return(distributor.CreateClient());
        }
Exemple #2
0
        private void startWebCamToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // creates a copy of the userList, so the Show of the forms will
            // not cause problems when there are other events (which are processed
            // in the middle of the following foreach.
            var userList = listUsers.SelectedItems.OfType <string>().ToList();

            foreach (string userItem in userList)
            {
                string       user = userItem.Substring(0, userItem.LastIndexOf(" - "));
                WebCamInfo[] availableWebCams;

                if (user == fNickName)
                {
                    availableWebCams = ActiveWebCams.ListAllWebCams();
                }
                else
                {
                    availableWebCams = fClient.ListWebCams(user);
                }

                if (availableWebCams == null)
                {
                    MessageBox.Show("User " + user + " is no more connected.");
                    continue;
                }

                WebCamInfo webCamInfo;
                switch (availableWebCams.Length)
                {
                case 0:
                    MessageBox.Show("User " + user + " has no active web-cams.");
                    continue;

                case 1:
                    webCamInfo = availableWebCams[0];
                    break;

                default:
                    webCamInfo = p_SelectWebCam(availableWebCams);

                    if (webCamInfo == null)
                    {
                        continue;
                    }

                    break;
                }

                string     displayName = webCamInfo.DisplayName;
                string     monikerName = webCamInfo.InternalName;
                FormWebCam form;
                fActiveWebCams.TryGetValue(new KeyValuePair <string, string>(user, monikerName), out form);
                if (form != null)
                {
                    form.BringToFront();
                    continue;
                }

                IFastEnumerator <byte[]> enumerator;
                try
                {
                    if (user == fNickName)
                    {
                        enumerator = ActiveWebCams.Start(webCamInfo);
                        continue;
                    }
                    else
                    {
                        enumerator = fClient.ReceiveWebCam(user, webCamInfo);
                    }
                }
                catch
                {
                    continue;
                }

                if (enumerator == null)
                {
                    continue;
                }

                form = new FormWebCam(user, displayName, monikerName, enumerator);
                form.Show();
            }
        }