Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="entityId"></param>
        /// <param name="pc"></param>
        /// <param name="queryString"></param>
        /// <returns></returns>
        public TEntity GetDetails <TEntity>(long entityId, ArrayList queryString)
            where TEntity : ParaEntityBaseProperties, new()
        {
            if (typeof(TEntity) != typeof(Folder))
            {
                return(ApiUtils.ApiGetEntity <TEntity>(Credentials, entityId, queryString));
            }

            var folder = new TEntity();
            var ar     = ApiCallFactory.ObjectGetDetail <TEntity>(Credentials, entityId);

            if (ar.HasException == false)
            {
                folder             = ParaEntityParser.EntityFill <TEntity>(ar.XmlReceived);
                folder.FullyLoaded = true;
            }
            else
            {
                folder.FullyLoaded = false;
                folder.Id          = 0;
            }

            folder.ApiCallResponse = ar;
            return(folder);
        }
Пример #2
0
        /// <summary>
        /// Fills a Role list object
        /// </summary>
        /// <param name="creds"></param>
        /// <param name="query"></param>
        /// <param name="module"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        internal static ParaEntityList <TEntity> ApiGetEntityList <TModule, TEntity>(ParaCredentials creds,
                                                                                     ParaQuery query)
            where TModule : ParaEntity
            where TEntity : ParaEntityBaseProperties
        {
            var rolesList = new ParaEntityList <TEntity>();
            var ar        = ApiCallFactory.ObjectSecondLevelGetList <TModule, TEntity>(creds, query.BuildQueryArguments());

            if (ar.HasException == false)
            {
                //...Customer/status is sending "entities" not "Entities", which breaks the parser. Unwind and fix the XML
                var xmlStr = ar.XmlReceived.OuterXml;
                if (xmlStr.Contains("<entities"))
                {
                    xmlStr         = xmlStr.Replace("<entities", "<Entities");
                    xmlStr         = xmlStr.Replace("entities>", "Entities>");
                    ar.XmlReceived = ParseXmlDoc(xmlStr);
                }

                rolesList = ParaEntityParser.FillList <TEntity>(ar.XmlReceived);
            }
            rolesList.ApiCallResponse = ar;

            // Checking if the system needs to recursively call all of the data returned.
            if (query.RetrieveAllRecords)
            {
                var continueCalling = true;
                while (continueCalling)
                {
                    if (rolesList.TotalItems > rolesList.Data.Count)
                    {
                        // We still need to pull data
                        // Getting next page's data
                        query.PageNumber = query.PageNumber + 1;

                        ar = ApiCallFactory.ObjectSecondLevelGetList <TModule, TEntity>(creds,
                                                                                        query.BuildQueryArguments());

                        var objectlist = ParaEntityParser.FillList <TEntity>(ar.XmlReceived);

                        if (objectlist.Data.Count == 0)
                        {
                            continueCalling = false;
                        }

                        rolesList.Data.AddRange(objectlist.Data);
                        rolesList.ResultsReturned = rolesList.Data.Count;
                        rolesList.PageNumber      = query.PageNumber;
                    }
                    else
                    {
                        // That is it, pulled all the items.
                        continueCalling           = false;
                        rolesList.ApiCallResponse = ar;
                    }
                }
            }

            return(rolesList);
        }
Пример #3
0
        /// <summary>
        /// Adds or updates the entity on the server.
        /// </summary>
        /// <param name="entity">The entity to save</param>
        /// <returns></returns>
        public ApiCallResponse Update(IMutableEntity entity)
        {
            var pe = entity as ParaEntity;

            Folder          folder = null;
            ApiCallResponse reply  = null;

            if (pe == null)
            {
                folder = entity as Folder;
                if (folder == null)
                {
                    throw new ArgumentException("You can only call this function on a Folder-derived or ParaEntity-derived object.", "entity");
                }

                reply = ApiCallFactory.ObjectCreateUpdate(Credentials, folder.GetType().Name, XmlGenerator.GenerateXml(folder), folder.Id);
            }
            else
            {
                if (pe.Id == 0)
                {
                    throw new ArgumentException("The update operation requires an existing object ID. Populate the entity ID to perform an update.");
                }

                reply = ApiCallFactory.ObjectCreateUpdate(Credentials, pe.GetType().Name, XmlGenerator.GenerateXml(pe), pe.Id);
            }

            return(reply);
        }
Пример #4
0
        /// <summary>
        /// Adds or updates the entity on the server.
        /// </summary>
        /// <param name="entity">The entity to save</param>
        /// <returns></returns>
        public ApiCallResponse Insert(IMutableEntity entity)
        {
            var             pe = entity as ParaEntity;
            ApiCallResponse reply;

            //Check if the object is a ParaEntity, if not its a folder
            if (pe == null)
            {
                var folder = entity as Folder;
                if (folder == null)
                {
                    throw new ArgumentException("You can only call this function on a Folder-derived or ParaEntity-derived object.", "entity");
                }

                reply     = ApiCallFactory.ObjectCreateUpdate(Credentials, folder.GetType().Name, XmlGenerator.GenerateXml(folder), 0);
                folder.Id = reply.Id;
            }
            else
            {
                reply = ApiCallFactory.ObjectCreateUpdate(Credentials, pe.GetType().Name, XmlGenerator.GenerateXml(pe), 0);
                pe.Id = reply.Id;
            }

            return(reply);
        }
Пример #5
0
        /// <summary>
        /// Internal Method to run an Action, independently from the module.
        /// </summary>
        internal static ApiCallResponse ActionRun <TEntity>(Int64 objectId, ParaObjects.Action action, ParaCredentials pc)
            where TEntity : ParaEntity
        {
            var doc = XmlGenerator.GenerateActionXml <TEntity>(action);
            var ar  = ApiCallFactory.ObjectCreateUpdate <TEntity>(pc, doc, objectId);

            return(ar);
        }
Пример #6
0
        /// <summary>
        /// Retrieve the transcript for a particualr chat
        /// </summary>
        /// <param name="chatId"></param>
        /// <param name="paraCredentials"></param>
        /// <returns>A list of chat messages</returns>
        public List <ChatMessage> GetChatTranscript(long chatId)
        {
            var ar = ApiCallFactory.ChatTranscriptGetDetail(Credentials, chatId);

            if (ar.HasException == false)
            {
                return(ParaEntityParser.EntityFill <ParaObjects.Chat>(ar.XmlReceived).Transcript);
            }
            else
            {
                throw new Exception(ar.ExceptionDetails);
            }
        }
Пример #7
0
        internal static ParaEntityList <ParaObjects.Download> ApiGetDownloadEntityList(ParaCredentials pc)
        {
            var entityList = new ParaEntityList <ParaObjects.Download>();
            var ar         = ApiCallFactory.ObjectGetList <ParaObjects.Download>(pc, new ArrayList());

            if (ar.HasException == false)
            {
                entityList = ParaEntityParser.FillListDownload(ar.XmlReceived);
            }
            entityList.ApiCallResponse = ar;

            return(entityList);
        }
Пример #8
0
        /// <summary>
        /// Create a new entity object. This object is not saved to the server until you call Insert with it.
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <returns></returns>
        public TEntity Create <TEntity>() where TEntity : ParaEntityBaseProperties, new()
        {
            var entity = new TEntity();
            var ar     = ApiCallFactory.ObjectGetSchema <TEntity>(Credentials);

            if (ar.HasException == false)
            {
                var purgedSchema = ApiUtils.RemoveStaticFieldsNodes(ar.XmlReceived);
                entity = ParaEntityParser.EntityFill <TEntity>(purgedSchema);
            }

            entity.ApiCallResponse = ar;
            return(entity);
        }
Пример #9
0
        public ParaEntityList <TFolder> GetList <TFolder>(FolderQuery query)
            where TFolder : Folder, new()
        {
            var folderList = new ParaEntityList <TFolder>();
            var ar         = ApiCallFactory.ObjectGetList <TFolder>(Credentials, query.BuildQueryArguments());

            if (ar.HasException == false)
            {
                folderList = ParaEntityParser.FillList <TFolder>(ar.XmlReceived);
            }
            folderList.ApiCallResponse = ar;

            // Checking if the system needs to recursively call all of the data returned.
            if (query.RetrieveAllRecords)
            {
                bool continueCalling = true;
                while (continueCalling)
                {
                    if (folderList.TotalItems > folderList.Data.Count)
                    {
                        // We still need to pull data

                        // Getting next page's data
                        query.PageNumber = query.PageNumber + 1;

                        ar = ApiCallFactory.ObjectGetList <TFolder>(Credentials, query.BuildQueryArguments());

                        var objectlist = ParaEntityParser.FillList <TFolder>(ar.XmlReceived);

                        if (objectlist.Data.Count == 0)
                        {
                            continueCalling = false;
                        }

                        folderList.Data.AddRange(objectlist.Data);
                        folderList.ResultsReturned = folderList.Data.Count;
                        folderList.PageNumber      = query.PageNumber;
                    }
                    else
                    {
                        // That is it, pulled all the items.
                        continueCalling            = false;
                        folderList.ApiCallResponse = ar;
                    }
                }
            }

            return(folderList);
        }
Пример #10
0
        /// <summary>
        /// Internal method to attach a file for the Parature entity
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="pc"></param>
        /// <param name="attachment"></param>
        /// <returns></returns>
        internal static Attachment UploadFile <TEntity>(ParaCredentials pc, System.Net.Mail.Attachment attachment)
            where TEntity : ParaEntity
        {
            var postUrlR     = ApiCallFactory.FileUploadGetUrl <TEntity>(pc);
            var uploadUrlDoc = postUrlR.XmlReceived;
            var postUrl      = AttachmentGetUrlToPost(uploadUrlDoc);

            var upresp = ApiCallFactory.FilePerformUpload(postUrl, attachment);

            var attaDoc = upresp.XmlReceived;

            var attach = ParaEntityParser.EntityFill <Attachment>(attaDoc);

            return(attach);
        }
Пример #11
0
        private static ParaEntityList <T> RetrieveAllEntities <T>(ParaCredentials pc, ParaEntityQuery query)
            where T : ParaEntity, new()
        {
            ApiCallResponse ar;
            var             entityList = new ParaEntityList <T>();

            ar = ApiCallFactory.ObjectGetList <T>(pc, query.BuildQueryArguments());
            if (ar.HasException == false)
            {
                entityList = ParaEntityParser.FillList <T>(ar.XmlReceived);
            }
            entityList.ApiCallResponse = ar;

            var continueCalling = true;

            while (continueCalling)
            {
                if (entityList.TotalItems > entityList.Data.Count)
                {
                    // We still need to pull data
                    // Getting next page's data
                    query.PageNumber = query.PageNumber + 1;

                    ar = ApiCallFactory.ObjectGetList <T>(pc, query.BuildQueryArguments());
                    if (ar.HasException == false)
                    {
                        var objectlist = ParaEntityParser.FillList <T>(ar.XmlReceived);
                        entityList.Data.AddRange(objectlist.Data);
                        entityList.ResultsReturned = entityList.Data.Count;
                        entityList.PageNumber      = query.PageNumber;
                    }
                    else
                    {
                        // There is an error processing request
                        entityList.ApiCallResponse = ar;
                        continueCalling            = false;
                    }
                }
                else
                {
                    // That is it, pulled all the items.
                    continueCalling            = false;
                    entityList.ApiCallResponse = ar;
                }
            }

            return(entityList);
        }
Пример #12
0
        /// <summary>
        /// Retrieve the details for a specific Parature module entity with custom query string arguments
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pc"></param>
        /// <param name="entityId"></param>
        /// <returns></returns>
        internal static T ApiGetEntity <T>(ParaCredentials pc, long entityId, ArrayList arl) where T : ParaEntityBaseProperties, new()
        {
            var entity = new T();
            var req    = ApiCallFactory.ObjectGetDetail <T>(pc, entityId, arl);

            if (req.HasException == false)
            {
                entity             = ParaEntityParser.EntityFill <T>(req.XmlReceived);
                entity.FullyLoaded = true;
            }
            else
            {
                entity.FullyLoaded = false;
                entity.Id          = 0;
            }
            entity.ApiCallResponse = req;
            entity.IsDirty         = false;
            return(entity);
        }
Пример #13
0
        /// <summary>
        /// Retrieve the details for a specific Parature module entity with custom query string arguments
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pc"></param>
        /// <param name="entityId"></param>
        /// <returns></returns>
        internal static ParaObjects.Download ApiGetDownloadEntity(ParaCredentials pc, long entityId,
                                                                  ArrayList arl)
        {
            var entity = new ParaObjects.Download();
            var req    = ApiCallFactory.ObjectGetDetail <ParaObjects.Download>(pc, entityId, arl);

            if (req.HasException == false)
            {
                entity             = ParaEntityParser.EntityFillDownload(req.XmlReceived);
                entity.FullyLoaded = true;
            }
            else
            {
                entity.FullyLoaded = false;
                entity.Id          = 0;
            }
            entity.ApiCallResponse = req;
            entity.IsDirty         = false;
            return(entity);
        }
Пример #14
0
        internal static ParaEntityList <ParaObjects.Download> ApiGetDownloadEntityList(ParaCredentials pc, DownloadQuery query)
        {
            var entityList = new ParaEntityList <ParaObjects.Download>();

            // Checking if the system needs to recursively call all of the data returned.
            if (query.RetrieveAllRecords)
            {
                entityList = RetrieveAllDownloadEntities(pc, query);
            }
            else
            {
                var ar = ApiCallFactory.ObjectGetList <ParaObjects.Download>(pc, query.BuildQueryArguments());
                if (ar.HasException == false)
                {
                    entityList = ParaEntityParser.FillListDownload(ar.XmlReceived);
                }
                entityList.ApiCallResponse = ar;
            }

            return(entityList);
        }
Пример #15
0
        /// <summary>
        /// Internal method to handle the upload of a file to Parature.
        /// </summary>
        internal static Attachment UploadFile <TEntity>(ParaCredentials pc, Byte[] attachment,
                                                        String contentType, String fileName) where TEntity : ParaEntity
        {
            Attachment attach;
            var        postUrl = "";

            postUrl = AttachmentGetUrlToPost(ApiCallFactory.FileUploadGetUrl <TEntity>(pc).XmlReceived);

            if (String.IsNullOrEmpty(postUrl) == false)
            {
                var uploadResponse =
                    ApiCallFactory.FilePerformUpload(postUrl, attachment, contentType, fileName)
                    .XmlReceived;

                attach = new Attachment();

                var uploadResult = ParaEntityParser.EntityFill <UploadResult>(uploadResponse);

                if (!string.IsNullOrEmpty(uploadResult.Error))
                {
                    //There was an error uploading
                    attach.HasException = true;
                    attach.Error        = uploadResult.Error;
                }
                else
                {
                    attach.Name = uploadResult.Result.File.FileName;
                    attach.Guid = uploadResult.Result.File.Guid;
                }
            }
            else
            {
                attach = new Attachment();
            }
            return(attach);
        }
Пример #16
0
 /// <summary>
 /// Deletes the entity from the server.
 /// </summary>
 /// <param name="purge">To delete the entity permanently or not (to the trash instead)</param>
 /// <param name="id">The object ID of the object to trash/delete</param>
 /// <returns></returns>
 public ApiCallResponse Delete <TEntity>(long id, bool purge)
     where TEntity : ParaEntityBaseProperties, new()
 {
     return(ApiCallFactory.ObjectDelete <TEntity>(Credentials, id, purge));
 }