Пример #1
0
        public override void Load(params Relation[] dependency)
        {
            ResourceTypes resTypes = null;
            ResourceGroups resGroups = null;

            foreach (Relation r in dependency) {
                if (r is ResourceTypes) {
                    resTypes = (ResourceTypes)r;
                }
                else if (r is ResourceGroups) {
                    resGroups = (ResourceGroups)r;
                }
            }

            if (resTypes == null) {
                throw new Exception("Resources: depedent object 'ResourceTypes' not found!");
            }
            else if (resGroups == null) {
                throw new Exception("Resources: depedent object 'ResourceGroups' not found!");
            }

            using (SqlConnection connection = new SqlConnection(Util.ConnectionSetting.ConnectionString)) {
                connection.Open();
                string cmd = @"select * from Resources";
                using (SqlCommand command = new SqlCommand(cmd, connection)) {
                    SqlDataReader reader = command.ExecuteReader();
                    Dictionary<int, Tuple> records = new Dictionary<int, Tuple>();
                    while (reader.Read()) {
                        Resource r = new Resource();
                        r.Id = reader.GetFieldValue<int>(0);
                        r.HostName = reader.GetFieldValue<string>(1);
                        r.CacheInstance = reader.GetFieldValue<string>(2);
                        r.Environment = reader.GetFieldValue<string>(3);

                        int resTypeId = reader.GetFieldValue<int>(4);
                        if (resTypes[resTypeId] == null) continue;
                        r.ResourceType = (ResourceType)resTypes[resTypeId];

                        string resGroup = reader.GetFieldValue<string>(5);
                        ResourceGroup g = (ResourceGroup) resGroups[resGroup];
                        r.Group=g;
                        if (g != null) { g.AddResource(r); }

                        r.MonitoringDisabled = reader.GetFieldValue<byte>(6) > 0;
                        r.ExpectedMessageFrequency = (int)reader.GetFieldValue<Int16>(7);
                        r.DisplayName = reader.GetFieldValue<string>(8);
                        records.Add(r.Id, r);
                    }
                    this._records = records;
                }
            }
        }
Пример #2
0
 internal bool AddResource(Resource res)
 {
     if (_resources.ContainsKey(res.Id)) return false;
     _resources.Add(res.Id,res);
     return true;
 }
Пример #3
0
 public bool ContainsResource(Resource res)
 {
     return this.ContainsResource(res.Id);
 }