Ejemplo n.º 1
0
        /// <summary>
        /// Returns the AF Attribute specified by the WebID.
        /// </summary>
        /// <param name="ID">The unique ID of the AF attribute</param>
        /// <returns></returns>
        public LazyObjects.AFAttribute Find(LazyPI.Common.Connection Connection, string ID)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
            var request = new RestRequest("/attributes/{webId}");

            request.AddUrlSegment("webId", ID);
            var response = webConnection.Client.Execute <ResponseModels.AFAttribute>(request);

            if (response.ErrorException != null)
            {
                throw new ApplicationException("Error finding attribute by ID. (See Inner Details)", response.ErrorException);
            }

            var data = response.Data;

            return(new LazyObjects.AFAttribute(Connection, data.WebID, data.Name, data.Description, data.Path));
        }
Ejemplo n.º 2
0
        //TODO: Implement GetAttributes

        //TODO: Implement GetCategories

        /// <summary>
        /// Get the attribute's value. This call is intended for use with attributes that have no data reference only. For attributes with a data reference, consult the documentation for Streams.
        /// </summary>
        /// <param name="attrWID">The WebID of the AF Attribute to be read.</param>
        /// <returns></returns>
        public LazyObjects.AFValue GetValue(LazyPI.Common.Connection Connection, string AttrID)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
            var request = new RestRequest("/attributes/{webId}/value");

            request.AddUrlSegment("webId", AttrID);
            var response = webConnection.Client.Execute <ResponseModels.AFValue>(request);

            if (response.ErrorException != null)
            {
                throw new ApplicationException("Error retrieving value from attribute. (See Inner Details)", response.ErrorException);
            }

            ResponseModels.AFValue data = response.Data;

            return(new LazyObjects.AFValue(data.Timestamp, data.Value, data.UnitsAbbreviation, data.Good, data.Questionable, data.Substituted));
        }
Ejemplo n.º 3
0
        public LazyObjects.AFAttributeTemplate FindByPath(LazyPI.Common.Connection Connection, string Path)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
            var request = new RestRequest("/attributetemplates");

            request.AddParameter("path", Path, ParameterType.GetOrPost);

            var response = webConnection.Client.Execute <LazyPI.WebAPI.ResponseModels.AFAttributeTemplate>(request);

            if (response.ErrorException != null)
            {
                throw new ApplicationException("Error finding attribute template by path. (See Inner Details)", response.ErrorException);
            }

            var data = response.Data;

            return(new LazyObjects.AFAttributeTemplate(Connection, data.WebId, data.Id, data.Name, data.Description, data.Path));
        }
Ejemplo n.º 4
0
        public bool IsExtendible(LazyPI.Common.Connection Connection, string TemplateID)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
            var request = new RestRequest("/elementtemplates/{webId}");

            request.AddUrlSegment("webId", TemplateID);

            var response = webConnection.Client.Execute <ResponseModels.AFElementTemplate>(request);

            if (response.ErrorException != null)
            {
                throw new ApplicationException("Error checking if element template is extendible. (See Inner Details)", response.ErrorException);
            }

            var data = response.Data;

            return(data.AllowElementToExtend);
        }
Ejemplo n.º 5
0
        public string GetEventFrameTemplate(LazyPI.Common.Connection Connection, string FrameID)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
            var request = new RestRequest("/eventframes/{webId}");

            request.AddUrlSegment("webId", FrameID);

            var response = webConnection.Client.Execute <ResponseModels.AFEventFrame>(request);

            if (response.ErrorException != null)
            {
                throw new ApplicationException("Error finding event frame by ID. (See Inner Details)", response.ErrorException);
            }

            ResponseModels.AFEventFrame data = response.Data;

            return(data.TemplateName);
        }
Ejemplo n.º 6
0
        public LazyObjects.AFEventFrame FindByPath(LazyPI.Common.Connection Connection, string Path)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
            var request = new RestRequest("/eventframes");

            request.AddParameter("path", Path);

            var response = webConnection.Client.Execute <ResponseModels.AFEventFrame>(request);

            if (response.ErrorException != null)
            {
                throw new ApplicationException("Error finding element by path. (See Inner Details)", response.ErrorException);
            }

            var data = response.Data;

            return(new LazyObjects.AFEventFrame(Connection, data.WebID, data.Name, data.Description, data.Path));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a new AFAttribute in the parent element referenced by parentWID.
        /// </summary>
        /// <param name="ParentID"></param>
        /// <param name="Attr">The definition of the new attribute.</param>
        /// <returns>Returns true if create completed.</returns>
        public bool Create(LazyPI.Common.Connection Connection, string ParentID, LazyObjects.AFAttribute Attr)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
            var request = new RestRequest("/attributes/{webId}", Method.POST);

            request.AddUrlSegment("webId", ParentID);

            //Copy to api object
            ResponseModels.AFAttribute clientAttr = new ResponseModels.AFAttribute();
            clientAttr.Name        = Attr.Name;
            clientAttr.Description = Attr.Description;

            request.AddBody(clientAttr);

            var statusCode = webConnection.Client.Execute(request).StatusCode;

            return((int)statusCode == 201);
        }
Ejemplo n.º 8
0
        public IEnumerable <LazyObjects.AFServer> List(LazyPI.Common.Connection Connection)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
            var request  = new RestRequest("/assetservers");
            var response = webConnection.Client.Execute <ResponseModels.ResponseList <ResponseModels.AFServer> >(request);

            if (response.ErrorException != null)
            {
                throw new ApplicationException("Error finding database by ID. (See Inner Details)", response.ErrorException);
            }

            List <LazyObjects.AFServer> results = new List <LazyObjects.AFServer>();

            foreach (var server in response.Data.Items)
            {
                results.Add(new LazyObjects.AFServer(Connection, server.WebId, server.Id, server.Name, server.Description, server.IsConnected, server.ServerVersion, server.Path));
            }

            return(results);
        }
Ejemplo n.º 9
0
        //TODO: Implement GetAttributes

        //TODO: Implement GetCategories

        /// <summary>
        /// Assumes that the attribute is of type PIPoint and returns the PIPoint.
        /// </summary>
        /// <param name="Connection"></param>
        /// <param name="AttrID"></param>
        /// <returns></returns>
        /// <remarks>This is kind of hacky...</remarks>
        public LazyObjects.PIPoint GetPoint(LazyPI.Common.Connection Connection, string AttrID)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
            var request = new RestRequest("/attributes/{webId}");

            request.AddUrlSegment("webId", AttrID);
            var attrResponse = webConnection.Client.Execute <ResponseModels.AFAttribute>(request);

            string pointLink = attrResponse.Data.Links["Point"];
            int    pos       = pointLink.LastIndexOf("/") + 1;
            string webID     = pointLink.Substring(pos, pointLink.Length - pos);

            request = new RestRequest("/points/{webId}");
            request.AddUrlSegment("webId", webID);
            var pointResponse = webConnection.Client.Execute <ResponseModels.DataPoint>(request);

            ResponseModels.DataPoint point = pointResponse.Data;

            LazyObjects.PIPoint result = new LazyObjects.PIPoint(Connection, point.WebId, point.Id, point.Name, point.Description, point.Path, point.PointType, point.PointClass, point.Future);
            return(result);
        }
Ejemplo n.º 10
0
        public bool Update(LazyPI.Common.Connection Connection, LazyObjects.AFElement Element)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
            var request = new RestRequest("/elements/{webId}", Method.PATCH);

            request.AddUrlSegment("webId", Element.ID);

            ResponseModels.AFElement temp = new ResponseModels.AFElement();
            temp.WebID         = Element.ID;
            temp.Name          = Element.Name;
            temp.Description   = Element.Description;
            temp.Path          = Element.Path;
            temp.CategoryNames = Element.Categories.ToList();
            temp.TemplateName  = Element.Template.Name;

            request.AddBody(temp);

            var statusCode = webConnection.Client.Execute(request).StatusCode;

            return((int)statusCode == 204);
        }
Ejemplo n.º 11
0
        public bool CreateElementTemplate(LazyPI.Common.Connection Connection, string ParentID, LazyObjects.AFElementTemplate Template)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
            var request = new RestRequest("/elementtemplates/{webId}/attributetemplates", Method.POST);

            request.AddUrlSegment("webId", ParentID);

            ResponseModels.AFElementTemplate temp = new ResponseModels.AFElementTemplate();

            temp.WebId                = temp.Id;
            temp.Name                 = Template.Name;
            temp.Description          = Template.Description;
            temp.Path                 = Template.Path;
            temp.CategoryNames        = Template.Categories.ToList();
            temp.AllowElementToExtend = Template.IsExtendable;

            request.AddBody(temp);

            var statusCode = webConnection.Client.Execute(request).StatusCode;

            return((int)statusCode == 201);
        }
Ejemplo n.º 12
0
        public IEnumerable <LazyPI.LazyObjects.AFDatabase> GetDatabases(LazyPI.Common.Connection Connection, string AFServerID)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
            var request = new RestRequest("/assetservers/{webId}/assetdatabases");

            request.AddUrlSegment("webId", AFServerID);

            var response = webConnection.Client.Execute <ResponseModels.ResponseList <ResponseModels.AFDB> >(request);

            if (response.ErrorException != null)
            {
                throw new ApplicationException("Error searching for servers. (See Inner Details)", response.ErrorException);
            }

            List <LazyObjects.AFDatabase> results = new List <LazyObjects.AFDatabase>();

            foreach (var element in response.Data.Items)
            {
                results.Add(new LazyObjects.AFDatabase(Connection, element.WebId, element.Id, element.Name, element.Description, element.Path));
            }

            return(results);
        }
Ejemplo n.º 13
0
        public IEnumerable <string> GetCategories(LazyPI.Common.Connection Connection, string FrameID)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
            var request = new RestRequest("/eventframes/{webId}/categories");

            request.AddUrlSegment("webId", FrameID);

            var response = webConnection.Client.Execute <List <ResponseModels.ElementCategory> >(request);

            if (response.ErrorException != null)
            {
                throw new ApplicationException("Error retrieving event frame categories. (See Inner Details)", response.ErrorException);
            }

            var           data    = response.Data;
            List <string> results = new List <string>();

            foreach (ResponseModels.ElementCategory category in data)
            {
                results.Add(category.Name);
            }

            return(results);
        }
Ejemplo n.º 14
0
        public IEnumerable <LazyObjects.AFAttribute> GetAttributes(LazyPI.Common.Connection Connection, string ParentID, string NameFilter = "*", string CategoryName = "*", string TemplateName = "*", string ValueType = "*", bool SearchFullHierarchy = false, string SortField = "Name", string SortOrder = "Ascending", int StartIndex = 0, bool ShowExcluded = false, bool ShowHidden = false, int MaxCount = 1000)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
            var request = new RestRequest("/elements/{webId}/attributes");

            request.AddUrlSegment("webId", ParentID);
            request.AddParameter("nameFilter", NameFilter);
            request.AddParameter("categoryName", CategoryName);
            request.AddParameter("templateName", TemplateName);
            request.AddParameter("valueType", ValueType);
            request.AddParameter("searchFullHierarchy", SearchFullHierarchy);
            request.AddParameter("sortField", SortField);
            request.AddParameter("sortOrder", SortOrder);
            request.AddParameter("startIndex", StartIndex);
            request.AddParameter("showExcluded", ShowExcluded);
            request.AddParameter("showHidden", ShowHidden);
            request.AddParameter("maxCount", MaxCount);

            var response = webConnection.Client.Execute <ResponseModels.ResponseList <ResponseModels.AFAttribute> >(request);

            if (response.ErrorException != null)
            {
                throw new ApplicationException("Error searching for element attributes. (See Inner Details)", response.ErrorException);
            }

            var data = response.Data;

            List <LazyObjects.AFAttribute> resultList = new List <LazyObjects.AFAttribute>();

            foreach (var result in data.Items)
            {
                resultList.Add(LazyObjects.AFAttribute.Find(Connection, result.WebID));
            }

            return(resultList);
        }
Ejemplo n.º 15
0
        public IEnumerable <LazyObjects.AFElement> GetElements(LazyPI.Common.Connection Connection, string RootID, string NameFilter = "*", string CategoryName = "*", string TemplateName = "*", LazyPI.Common.ElementType ElementType = LazyPI.Common.ElementType.Any, bool SearchFullHierarchy = false, string SortField = "Name", string SortOrder = "Ascending", int StartIndex = 0, int MaxCount = 1000)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
            var request = new RestRequest("/elements/{webId}/elements");

            request.AddUrlSegment("webId", RootID);

            if (NameFilter != "*")
            {
                request.AddParameter("nameFilter", NameFilter);
            }

            if (TemplateName != "*")
            {
                request.AddParameter("templateName", TemplateName);
            }

            if (ElementType != Common.ElementType.Any)
            {
                request.AddParameter("elementType", ElementType);
            }

            if (SearchFullHierarchy)
            {
                request.AddParameter("searchFullHierarchy", SearchFullHierarchy);
            }

            if (SortField != "Name")
            {
                request.AddParameter("sortField", SortField);
            }

            if (SortOrder != "Ascending")
            {
                request.AddParameter("sortOrder", SortOrder);
            }

            if (StartIndex != 0)
            {
                request.AddParameter("startIndex", StartIndex);
            }

            if (MaxCount != 1000)
            {
                request.AddParameter("maxCount", MaxCount);
            }

            var response = webConnection.Client.Execute <ResponseModels.ResponseList <ResponseModels.AFElement> >(request);

            if (response.ErrorException != null)
            {
                throw new ApplicationException("Error searching for child elements of and element. (See Inner Details)", response.ErrorException);
            }

            var data = response.Data;

            List <LazyObjects.AFElement> results = new List <LazyObjects.AFElement>();

            foreach (var element in data.Items)
            {
                results.Add(new LazyObjects.AFElement(Connection, element.WebId, element.Id, element.Name, element.Description, element.Path));
            }

            return(results);
        }
Ejemplo n.º 16
0
 public void Initialize()
 {
     System.Security.SecureString pwd = new System.Security.SecureString();
     conn = new WebAPIConnection(AuthenticationType.Basic, "", "", pwd);
 }