Ejemplo n.º 1
0
        public async Task <IEnumerable <RevitElement> > GetRevitElementsInPeriod(string versionId, string startDate, string endDate)
        {
            Regex regex = new Regex(@"^\d{4}-((0\d)|(1[012]))-(([012]\d)|3[01])$");

            if (regex.Match(startDate) == Match.Empty || regex.Match(endDate) == Match.Empty)
            {
                throw new FormatException("Bad format of startDate or endDate.");
            }
            var           route   = new RevitElementRoute(versionId);
            RestSharpBase reqBase = new RestSharpBase(route.GetEleInPeriodUrl, Method.GET);
            RestRequest   req     = reqBase.Request;

            req.AddQueryParameter("startDate", startDate);
            req.AddQueryParameter("endDate", endDate);

            IRestResponse <IEnumerable <RevitElement> > response = await _client.ExecuteAsync <IEnumerable <RevitElement> >(req);

            switch ((int)response.StatusCode)
            {
            case 200:
                return(response.Data);

            default:
                throw new Exception(response.StatusDescription);
            }
        }
Ejemplo n.º 2
0
        public async Task <IEnumerable <RevitElement> > GetAllElementsOfVersion(string versionId)
        {
            var           route   = new RevitElementRoute(versionId);
            RestSharpBase reqBase = new RestSharpBase(route.GetElementsUrl, Method.GET);
            IRestResponse <IEnumerable <RevitElement> > response = await _client.ExecuteAsync <IEnumerable <RevitElement> >(reqBase.Request);

            switch ((int)response.StatusCode)
            {
            case 200:
                return(response.Data);

            default:
                throw new Exception(response.ErrorMessage);
            }
        }
        public IEnumerable <RevitElement> GetRevitElements(Project project, ProjectVersion version)
        {
            RevitElementRoute route   = new RevitElementRoute(project.Id);
            RestRequestBase   reqBase = new RestRequestBase(route.url(), Method.GET);
            RestRequest       req     = reqBase.Request;

            req.AddParameter("version", version.version);
            IRestResponse <RevitElementRes> res = Route.Client.Execute <RevitElementRes>(req);
            string format            = "0000-12-31T23:50:39.000Z"; // datetime format
            var    dateTimeConverter = new IsoDateTimeConverter {
                DateTimeFormat = format, Culture = CultureInfo.InvariantCulture
            };

            //RevitElement revitElement = new RevitElement(Element element);
            RevitElementRes revitElements = JsonConvert.DeserializeObject <RevitElementRes>(res.Content, dateTimeConverter);

            return(revitElements.data);
        }