public WFeature[] GetChosenFeatures(string username, string password, int serviceInstanceId)
        {
            Contract.Requires(!String.IsNullOrEmpty(username));
            Contract.Requires(!String.IsNullOrEmpty(password));

            SocialTFSEntities db = new SocialTFSEntities();
            User user = CheckCredentials(db, username, password);
            if (user == null)
                return new WFeature[0];

            List<WFeature> result = new List<WFeature>();

            foreach (FeaturesType item in ServiceFactory.getService(
                db.ServiceInstance.Where(si => si.pk_id == serviceInstanceId).Single().Service.name).GetPublicFeatures())
            {
                WFeature feature = new WFeature()
                {
                    Name = item.ToString(),
                    Description = FeaturesManager.GetFeatureDescription(item),
                    IsChosen = db.ChosenFeature.Where(cf => cf.fk_serviceInstance == serviceInstanceId &&
                        cf.fk_user == user.pk_id).Select(cf => cf.fk_feature).Contains(item.ToString())
                };
                result.Add(feature);
            }

            return result.ToArray();
        }
        public WFeature[] GetChosenFeatures(string username, string password, int serviceInstanceId)
        {
            Contract.Requires(!String.IsNullOrEmpty(username));
            Contract.Requires(!String.IsNullOrEmpty(password));

            ConnectorDataContext db = new ConnectorDataContext();
            User user = CheckCredentials(db, username, password);
            if (user == null)
                return new WFeature[0];

            ILog log = LogManager.GetLogger("PanelLogger");
            log.Info(user.id + ",CF");

            List<WFeature> result = new List<WFeature>();

            Stopwatch w1 = Stopwatch.StartNew();
            ServiceInstance sInstance = db.ServiceInstances.Where(si => si.id == serviceInstanceId).Single();
            w1.Stop();
            ILog log1 = LogManager.GetLogger("QueryLogger");
            log1.Info(" Elapsed time: " + w1.Elapsed + ", service instance's id: " + serviceInstanceId + ", select service instance to get the chosen features");

            foreach (FeaturesType item in ServiceFactory.getService(sInstance.Service.name).GetPublicFeatures())
            {
                Stopwatch w2 = Stopwatch.StartNew();
                bool chosen = db.ChosenFeatures.Where(cf => cf.serviceInstance == serviceInstanceId && cf.user == user.id).Select(cf => cf.feature).Contains(item.ToString());
                w2.Stop();
                ILog log2 = LogManager.GetLogger("QueryLogger");
                log2.Info(" Elapsed time: " + w2.Elapsed + ", service istance's id: " + serviceInstanceId + ", user id: " + user.id + ", check if a chosen feature has been chosen by an user");
                WFeature feature = new WFeature()
                {
                    Name = item.ToString(),
                    Description = FeaturesManager.GetFeatureDescription(item),
                    IsChosen = chosen
                };
                result.Add(feature);
            }

            return result.ToArray();
        }