コード例 #1
0
        /// <summary>
        /// Adds the ToolStripMenuItems representing connections to the
        /// ToolStripDropDownButton
        /// </summary>
        /// <param name="btn">ToolStripDropDownButton where to add connections</param>
        private void AddActionsList(ToolStripDropDownButton btn)
        {
            var list = new List <ToolStripItem>();

            if (ConnectionManager.Instance.ConnectionsList.Connections.Count > 0)
            {
                ConnectionManager.Instance.ConnectionsList.Connections.Sort();

                foreach (ConnectionDetail cDetail in ConnectionManager.Instance.ConnectionsList.Connections)
                {
                    ToolStripMenuItem item = new ToolStripMenuItem();
                    item.Text = cDetail.ConnectionName;
                    item.Tag  = cDetail;

                    if (cDetail.UseOnline)
                    {
                        item.Image =
                            RessourceManager.GetImage(
                                "McTools.Xrm.Connection.WinForms.Resources.CRMOnlineLive_16.png");
                    }
                    else if (cDetail.UseOsdp)
                    {
                        item.Image =
                            RessourceManager.GetImage(
                                "McTools.Xrm.Connection.WinForms.Resources.CRMOnlineLive_16.png");
                    }
                    else if (cDetail.UseIfd)
                    {
                        item.Image =
                            RessourceManager.GetImage(
                                "McTools.Xrm.Connection.WinForms.Resources.server_key.png");
                    }
                    else
                    {
                        item.Image =
                            RessourceManager.GetImage(
                                "McTools.Xrm.Connection.WinForms.Resources.server.png");
                    }

                    BuildActionItems(item);
                    list.Add(item);
                }

                list.Add(new ToolStripSeparator());
            }

            var newConnectionItem = new ToolStripMenuItem();

            newConnectionItem.Text   = "Create new connection";
            newConnectionItem.Image  = ((System.Drawing.Image)(resources.GetObject("server_add")));
            newConnectionItem.Click += newConnectionItem_Click;
            list.Add(newConnectionItem);

            if (InvokeRequired)
            {
                Invoke(new Action(() =>
                {
                    btn.DropDownItems.Clear();
                    btn.DropDownItems.AddRange(list.ToArray());
                }));
            }
            else
            {
                btn.DropDownItems.Clear();
                btn.DropDownItems.AddRange(list.ToArray());
            }
        }
コード例 #2
0
        /// <summary>
        /// Adds the ToolStripMenuItems representing connections to the
        /// ToolStripDropDownButton
        /// </summary>
        /// <param name="btn">ToolStripDropDownButton where to add connections</param>
        private void AddActionsList(ToolStripDropDownButton btn)
        {
            var list       = new List <ToolStripItem>();
            int filesCount = ConnectionsList.Instance.Files.Count;

            if (filesCount == 0)
            {
                var defaultFilePath = Path.Combine(new FileInfo(ConnectionsList.ConnectionsListFilePath).DirectoryName, "ConnectionsList.Default.xml");

                CrmConnections cc = new CrmConnections("Default");
                cc.SerializeToFile(defaultFilePath);

                ConnectionsList.Instance.Files.Add(new ConnectionFile(cc)
                {
                    Path = defaultFilePath, LastUsed = DateTime.Now
                });
                ConnectionsList.Instance.Save();
            }

            foreach (var file in ConnectionsList.Instance.Files)
            {
                var connections = CrmConnections.LoadFromFile(file.Path);
                connections.Connections.Sort();

                var fileItem = new ToolStripMenuItem(file.Name);
                fileItem.Tag = file;
                if (!mergeConnectionFiles && filesCount > 1)
                {
                    list.Add(fileItem);
                }

                foreach (var cDetail in connections.Connections)
                {
                    ToolStripMenuItem item = new ToolStripMenuItem();
                    item.Text = cDetail.ConnectionName;
                    item.Tag  = cDetail;

                    if (cDetail.UseOnline)
                    {
                        item.Image =
                            RessourceManager.GetImage(
                                "McTools.Xrm.Connection.WinForms.Resources.CRMOnlineLive_16.png");
                    }
                    else if (cDetail.UseOsdp)
                    {
                        item.Image =
                            RessourceManager.GetImage(
                                "McTools.Xrm.Connection.WinForms.Resources.CRMOnlineLive_16.png");
                    }
                    else if (cDetail.UseIfd)
                    {
                        item.Image =
                            RessourceManager.GetImage(
                                "McTools.Xrm.Connection.WinForms.Resources.server_key.png");
                    }
                    else
                    {
                        item.Image =
                            RessourceManager.GetImage(
                                "McTools.Xrm.Connection.WinForms.Resources.server.png");
                    }

                    BuildActionItems(item);
                    if (!mergeConnectionFiles && filesCount > 1)
                    {
                        fileItem.DropDownItems.Add(item);
                    }
                    else
                    {
                        list.Add(item);
                    }
                }

                if (!mergeConnectionFiles && filesCount > 1)
                {
                    if (fileItem.DropDownItems.Count > 0)
                    {
                        fileItem.DropDownItems.Add(new ToolStripSeparator());
                    }
                }

                var newConnectionItem = new ToolStripMenuItem();
                newConnectionItem.Text   = "Create new connection";
                newConnectionItem.Image  = (Image)resources.GetObject("server_add");
                newConnectionItem.Click += newConnectionItem_Click;

                if (!mergeConnectionFiles && filesCount > 1)
                {
                    fileItem.DropDownItems.Add(newConnectionItem);
                }
            }

            if (mergeConnectionFiles || filesCount == 1)
            {
                if (list.Count > 0)
                {
                    list.Add(new ToolStripSeparator());
                }

                var newConnectionItem = new ToolStripMenuItem();
                newConnectionItem.Text   = "Create new connection";
                newConnectionItem.Image  = (Image)resources.GetObject("server_add");
                newConnectionItem.Click += newConnectionItem_Click;

                list.Add(newConnectionItem);
            }

            if (InvokeRequired)
            {
                Invoke(new Action(() =>
                {
                    btn.DropDownItems.Clear();
                    btn.DropDownItems.AddRange(list.ToArray());
                }));
            }
            else
            {
                btn.DropDownItems.Clear();
                btn.DropDownItems.AddRange(list.ToArray());
            }
        }