Beispiel #1
0
 /// <summary>
 ///     刷新连接
 /// </summary>
 private void RefreshConnection()
 {
     lstConnection.Items.Clear();
     foreach (var item in MongoConnectionConfig.MongoConfig.ConnectionList.Values)
     {
         if (string.IsNullOrEmpty(item.ReplSetName))
         {
             var t = new ListViewItem(item.ConnectionName);
             t.SubItems.Add(item.Host == string.Empty ? "localhost" : item.Host);
             t.SubItems.Add(item.Port == 0 ? string.Empty : item.Port.ToString());
             t.SubItems.Add(string.Empty);
             t.SubItems.Add((string.IsNullOrEmpty(item.UserName)) ? string.Empty : (item.UserName + "@" + item.DataBaseName));
             lstConnection.Items.Add(t);
         }
         else
         {
             var t = new ListViewItem(item.ConnectionName);
             t.SubItems.Add(item.Host == string.Empty ? "localhost" : item.Host);
             t.SubItems.Add(item.Port == 0 ? string.Empty : item.Port.ToString());
             var replArray = string.Empty;
             foreach (var repl in item.ReplsetList)
             {
                 replArray += repl + ";";
             }
             t.SubItems.Add(replArray);
             t.SubItems.Add((string.IsNullOrEmpty(item.UserName)) ? string.Empty : (item.UserName + "@" + item.DataBaseName));
             lstConnection.Items.Add(t);
         }
     }
     lstConnection.Sort();
     UIAssistant.ListViewColumnResize(lstConnection);
     MongoConnectionConfig.MongoConfig.SaveMongoConfig();
 }
        /// <summary>
        ///     刷新分片区域
        /// </summary>
        private void RefreshShardingZone()
        {
            var             mongoDb   = _prmSvr.GetDatabase(ConstMgr.DatabaseNameConfig);
            MongoCollection ColShards = mongoDb.GetCollection("shards");

            //现存Zone的列表
            cmbTagList.Items.Clear();
            lstExistShardZone.Columns.Clear();
            lstExistShardZone.Columns.Add("Shard Name");
            lstExistShardZone.Columns.Add("Zone Name");
            lstExistShardZone.Items.Clear();
            _tagSet.Clear();
            foreach (var mShard in ColShards.FindAllAs <BsonDocument>())
            {
                if (mShard.Contains("tags"))
                {
                    foreach (var tag in mShard.GetElement("tags").Value.AsBsonArray)
                    {
                        //严格意义上说,不应该在同一个路由里面出现两个同名的标签。
                        if (!_tagSet.ContainsKey(tag.ToString()))
                        {
                            _tagSet.Add(tag.ToString(), mShard.GetElement(ConstMgr.KeyId).Value.ToString());
                            cmbTagList.Items.Add(mShard.GetElement(ConstMgr.KeyId).Value + "." + tag);
                            var Item = new ListViewItem(mShard.GetElement(ConstMgr.KeyId).Value.AsString);
                            Item.SubItems.Add(tag.AsString);
                            lstExistShardZone.Items.Add(Item);
                        }
                    }
                }
            }
            UIAssistant.ListViewColumnResize(lstExistShardZone);
        }
Beispiel #3
0
 private void CmbLanguage_SelectedIndexChanged(object sender, EventArgs e)
 {
     //将数据放入ListView视图
     lstMultiLan.Clear();
     //Header
     lstMultiLan.Columns.Add("统一标示");
     lstMultiLan.Columns.Add(_multiLanguageDictionary.Keys.ElementAt(cmbLanguage.SelectedIndex));
     //Details
     for (var i = 0; i < uuiDs.Count; i++)
     {
         var item = new ListViewItem(uuiDs[i]);
         for (var j = 0; j < _multiLanguageDictionary.Keys.Count; j++)
         {
             if (_multiLanguageDictionary[_multiLanguageDictionary.Keys.ElementAt(cmbLanguage.SelectedIndex)].ContainsKey(uuiDs[i]))
             {
                 item.SubItems.Add(_multiLanguageDictionary[_multiLanguageDictionary.Keys.ElementAt(cmbLanguage.SelectedIndex)][uuiDs[i]]);
             }
             else
             {
                 item.SubItems.Add("");
             }
         }
         lstMultiLan.Items.Add(item);
     }
     UIAssistant.ListViewColumnResize(lstMultiLan);
 }
Beispiel #4
0
        /// <summary>
        ///     普通数据的加载
        /// </summary>
        /// <param name="dataList"></param>
        /// <param name="lstData"></param>
        /// <param name="collectionName"></param>
        private static void SetDataListToListView(List <BsonDocument> dataList, ListView lstData, string collectionName)
        {
            var columnlist = new List <string>();
            //可以让_id 不在第一位,昏过去了,很多逻辑需要调整
            var isSystem = Operater.IsSystemCollection(string.Empty, collectionName);

            if (!isSystem)
            {
                columnlist.Add(ConstMgr.KeyId);
                lstData.Columns.Add(ConstMgr.KeyId);
            }
            foreach (var docItem in dataList)
            {
                var lstItem = new ListViewItem();
                foreach (var item in docItem.Names)
                {
                    if (!columnlist.Contains(item))
                    {
                        columnlist.Add(item);
                        lstData.Columns.Add(item);
                    }
                }
                //Key:_id
                if (!isSystem)
                {
                    BsonElement id;
                    docItem.TryGetElement(ConstMgr.KeyId, out id);
                    if ((id.Value is BsonNull) || (id.Value == null))
                    {
                        lstItem.Text = "[Empty]";
                        lstItem.Tag  = docItem.GetElement(0).Value;
                    }
                    else
                    {
                        lstItem.Text = docItem.GetValue(ConstMgr.KeyId).ToString();
                        //这里保存真实的主Key数据,删除的时候使用
                        lstItem.Tag = docItem.GetValue(ConstMgr.KeyId);
                    }
                }
                else
                {
                    lstItem.Text = docItem.GetValue(columnlist[0]).ToString();
                }
                //OtherItems
                for (var i = isSystem ? 1 : 0; i < columnlist.Count; i++)
                {
                    if (columnlist[i] == ConstMgr.KeyId)
                    {
                        continue;
                    }
                    BsonValue val;
                    docItem.TryGetValue(columnlist[i], out val);
                    lstItem.SubItems.Add(val == null ? "" : ConvertToString(val));
                }
                lstData.Items.Add(lstItem);
            }
            UIAssistant.ListViewColumnResize(lstData);
        }
Beispiel #5
0
 /// <summary>
 ///     用户列表
 /// </summary>
 /// <param name="dataList"></param>
 /// <param name="lstData"></param>
 private static void SetUserListToListView(List <BsonDocument> dataList, ListView lstData)
 {
     //2.4以后的用户,没有ReadOnly属性,取而代之的是roles属性
     //这里为了向前兼容暂时保持ReadOnle属性
     //Ref:http://docs.mongodb.org/manual/reference/method/db.addUser/
     lstData.Clear();
     if (!GuiConfig.IsUseDefaultLanguage)
     {
         lstData.Columns.Add("ID");
         lstData.Columns.Add(GuiConfig.GetText("Common.Username"));
         lstData.Columns.Add(GuiConfig.GetText("Common.Roles"));
         lstData.Columns.Add(GuiConfig.GetText("Common.Credentials"));
         lstData.Columns.Add(GuiConfig.GetText("Common.CustomData"));
     }
     else
     {
         lstData.Columns.Add("ID");
         lstData.Columns.Add("user");
         lstData.Columns.Add("roles");
         lstData.Columns.Add("credentials");
         lstData.Columns.Add("customData");
     }
     foreach (var docFile in dataList)
     {
         var lstItem = new ListViewItem();
         //ID
         lstItem.Text = docFile.GetValue(ConstMgr.KeyId).ToString();
         //User
         lstItem.SubItems.Add(docFile.GetValue("user").ToString());
         //roles
         BsonValue strRoles;
         docFile.TryGetValue("roles", out strRoles);
         lstItem.SubItems.Add(strRoles == null ? "N/A" : strRoles.ToString());
         //密码是Hash表示的,这里没有安全隐患
         //Password和userSource不能同时设置,所以password也可能不存在
         BsonValue credentials;
         docFile.TryGetValue("credentials", out credentials);
         lstItem.SubItems.Add(credentials == null ? "N/A" : credentials.ToString());
         //customData
         BsonValue customData;
         docFile.TryGetValue("customData", out customData);
         lstItem.SubItems.Add(customData == null ? "N/A" : customData.ToString());
         lstData.Items.Add(lstItem);
     }
     UIAssistant.ListViewColumnResize(lstData);
 }
        /// <summary>
        ///     刷新分片范围
        /// </summary>
        private void RefreshShardingRange()
        {
            var             mongoDb = _prmSvr.GetDatabase(ConstMgr.DatabaseNameConfig);
            MongoCollection ColTags = mongoDb.GetCollection("tags");

            lstExistShardRange.Columns.Clear();
            lstExistShardRange.Columns.Add("Tag");
            lstExistShardRange.Columns.Add("Collection");
            lstExistShardRange.Columns.Add("MinDoc");
            lstExistShardRange.Columns.Add("MaxDoc");
            lstExistShardRange.Items.Clear();
            foreach (var mShard in ColTags.FindAllAs <BsonDocument>())
            {
                var Item = new ListViewItem(mShard.GetElement("tag").Value.AsString);
                Item.SubItems.Add(mShard.GetElement(ConstMgr.KeyId).Value.AsBsonDocument.GetElement("ns").Value.ToString());
                Item.SubItems.Add(mShard.GetElement("min").Value.ToString());
                Item.SubItems.Add(mShard.GetElement("max").Value.ToString());
                lstExistShardRange.Items.Add(Item);
            }
            UIAssistant.ListViewColumnResize(lstExistShardRange);
        }
Beispiel #7
0
        /// <summary>
        ///     GFS系统
        /// </summary>
        /// <param name="dataList"></param>
        /// <param name="lstData"></param>
        private static void SetGridFileToListView(List <BsonDocument> dataList, ListView lstData)
        {
            lstData.Clear();
            if (!GuiConfig.IsUseDefaultLanguage)
            {
                lstData.Columns.Add(GuiConfig.GetText(TextType.GfsFilename));
                lstData.Columns.Add(GuiConfig.GetText(TextType.GfsLength));
                lstData.Columns.Add(
                    GuiConfig.GetText(TextType.GfsChunkSize));
                lstData.Columns.Add(
                    GuiConfig.GetText(TextType.GfsUploadDate));
                lstData.Columns.Add(GuiConfig.GetText(TextType.GfsMd5));
                //!MONO
                lstData.Columns.Add("ContentType");
            }
            else
            {
                lstData.Columns.Add("filename");
                lstData.Columns.Add("length");
                lstData.Columns.Add("chunkSize");
                lstData.Columns.Add("uploadDate");
                lstData.Columns.Add("MD5");
                //!MONO
                lstData.Columns.Add("ContentType");
            }
            lstData.SmallImageList = GetSystemIcon.IconImagelist;
            lstData.LargeImageList = GetSystemIcon.IconImagelist;
            lstData.TileSize       = new Size(200, 100);

            foreach (var docFile in dataList)
            {
                var filename = docFile.GetValue("filename").ToString();
                var lstItem  = new ListViewItem();
                lstItem.ImageIndex  = GetSystemIcon.GetIconIndexByFileName(filename, false);
                lstItem.Text        = filename;
                lstItem.ToolTipText = filename;
                lstItem.SubItems.Add(MongoHelper.GetBsonSize(docFile.GetValue("length")));
                lstItem.SubItems.Add(MongoHelper.GetBsonSize(docFile.GetValue("chunkSize")));
                lstItem.SubItems.Add(ConvertToString(docFile.GetValue("uploadDate")));
                lstItem.SubItems.Add(ConvertToString(docFile.GetValue("md5")));
                //!MONO
                lstItem.SubItems.Add(GetSystemIcon.GetContentType(filename));
                lstData.Items.Add(lstItem);
            }
            //自动调节列宽
            UIAssistant.ListViewColumnResize(lstData);
            // 用新的排序方法对ListView排序
            var lvwGfsColumnSorter = new LvwColumnSorter();

            lstData.ListViewItemSorter = lvwGfsColumnSorter;
            lstData.ColumnClick       += (sender, e) =>
            {
                switch (e.Column)
                {
                case 1:
                case 2:
                    lvwGfsColumnSorter.CompareMethod = LvwColumnSorter.SortMethod.SizeCompare;
                    break;

                default:
                    lvwGfsColumnSorter.CompareMethod = LvwColumnSorter.SortMethod.StringCompare;
                    break;
                }
                // 检查点击的列是不是现在的排序列.
                if (e.Column == lvwGfsColumnSorter.SortColumn)
                {
                    // 重新设置此列的排序方法.
                    lvwGfsColumnSorter.Order = lvwGfsColumnSorter.Order == SortOrder.Ascending
                        ? SortOrder.Descending
                        : SortOrder.Ascending;
                }
                else
                {
                    // 设置排序列,默认为正向排序
                    lvwGfsColumnSorter.SortColumn = e.Column;
                    lvwGfsColumnSorter.Order      = SortOrder.Ascending;
                }
                lstData.Sort();
            };
        }