/// <summary>
        /// Get fields XML for a form based on given LinkFields url.
        /// </summary>
        /// <param name="url">LinkFields url</param>
        /// <param name="user">Name of the user.</param>
        /// <returns>String containing fields XML</returns>
        public string GetFields(string url, string user)
        {
            StringBuilder fields = new StringBuilder();

            if (_users.Contains(user))
            {
                WufooData userData = _userList[_users.IndexOf(user)];
                string    response = SubmitRequest(url, userData.ApiKey);
                XElement  xml      = XElement.Parse(response);
                IEnumerable <XElement> fieldsXml = xml.Elements("Field");
                foreach (var field in fieldsXml)
                {
                    // ignore EntryId, DateCreated, CreatedBy, LastUpdated and UpdatedBy fields (those are not real form fields, only part of an entry)
                    string id = field.Element("ID").Value;
                    if (!id.Equals("EntryId") && !id.Equals("DateCreated") && !id.Equals("CreatedBy") && !id.Equals("LastUpdated") && !id.Equals("UpdatedBy"))
                    {
                        fields.Append("<Field>");

                        // append ID, Title and Type (putting them in the desired order)
                        fields.Append(field.Element("ID"));
                        fields.Append(field.Element("Title"));
                        fields.Append(field.Element("Type"));
                        fields.Append(field.Element("Instructions"));
                        fields.Append(field.Element("IsRequired"));
                        fields.Append(field.Element("ClassNames"));
                        fields.Append(field.Element("DefaultVal"));
                        fields.Append(field.Element("Page"));

                        // append subfields
                        if (field.Element("SubFields") != null)
                        {
                            foreach (var child in field.Element("SubFields").Elements())
                            {
                                fields.Append(child);
                            }
                        }

                        // append choises
                        if (field.Element("Choices") != null)
                        {
                            foreach (var child in field.Element("Choices").Elements())
                            {
                                fields.Append(child);
                            }

                            fields.Append(field.Element("HasOtherField"));
                        }

                        fields.Append("</Field>");
                    }
                }
            }
            return(fields.ToString());
        }
示例#2
0
 public ListItem(int publicationId, WufooData data)
 {
     Data = data;
     if (data.IsForm)
     {
         // format of form itemId: [form user]_[form hash]
         string itemId = string.Format("{0}_{1}", data.User, data.Hash);
         _id = Provider.HostServices.CreateEclUri(publicationId, Provider.MountPointId, itemId, DisplayTypeId, EclItemTypes.File);
     }
     else
     {
         // use username as itemId (also available in form itemId) 
         _id = Provider.HostServices.CreateEclUri(publicationId, Provider.MountPointId, data.Title, DisplayTypeId, EclItemTypes.Folder);
     }
 }
        /// <summary>
        /// Returns the list of forms for a user.
        /// </summary>
        /// <param name="user">Name of the user.</param>
        /// <returns>List of forms for a user</returns>
        public List <WufooData> GetForms(string user)
        {
            if (_users.Contains(user))
            {
                WufooData userData = _userList[_users.IndexOf(user)];
                string    response = SubmitRequest(userData.FormsUrl, userData.ApiKey);
                XElement  xml      = XElement.Parse(response);

                IEnumerable <XElement> formsXml = xml.Elements("Form");
                List <WufooData>       forms    = (from f in formsXml select new WufooData(f, user, UserName)).ToList();

                return(forms);
            }

            return(null);
        }
        /// <summary>
        /// Returns the form data.
        /// </summary>
        /// <param name="user">Name of the user this form belongs to</param>
        /// <param name="hash">Hash of the form</param>
        /// <returns>Form data object</returns>
        public WufooData GetForm(string user, string hash)
        {
            if (_users.Contains(user))
            {
                WufooData userData = _userList[_users.IndexOf(user)];
                string    url      = string.Format("{0}forms/{1}.xml", ApiUrl, hash);
                string    response = SubmitRequest(url, user, userData.ApiKey);

                XElement responseXml = XElement.Parse(response);
                XElement formElement = responseXml.Element("Form");
                if (formElement != null)
                {
                    WufooData form = new WufooData(formElement, user, UserName);
                    return(form);
                }
            }
            return(null);
        }
        /// <summary>
        /// Returns a list of users and caches the results so we can reuse username and api key.
        /// </summary>
        /// <returns>List of users</returns>
        public List <WufooData> GetUsers()
        {
            // always clear lists so we have current data (new users could have been created)
            _users    = new List <string>();
            _userList = new List <WufooData>();

            string url = string.Format("{0}users.xml", ApiUrl);

            string   response = SubmitRequest(url, UserName, ApiKey);
            XElement xml      = XElement.Parse(response);

            IEnumerable <XElement> usersXml = xml.Elements("User");

            foreach (XElement userXml in usersXml)
            {
                WufooData data = new WufooData(userXml, UserName);
                _userList.Add(data);
                _users.Add(data.Title);
            }

            return(_userList);
        }
        /// <summary>
        /// Get entries XML for a form based on given LinkEntries url.
        /// </summary>
        /// <param name="url">LinkEntries url</param>
        /// <param name="user">Name of the user.</param>
        /// <returns>String containing entries XML</returns>
        public string GetEntries(string url, string user)
        {
            StringBuilder entries = new StringBuilder();

            if (_users.Contains(user))
            {
                WufooData userData = _userList[_users.IndexOf(user)];
                string    response = SubmitRequest(url, userData.ApiKey);
                XElement  xml      = XElement.Parse(response);
                IEnumerable <XElement> entriesXml = xml.Elements("Entry");
                foreach (var entry in entriesXml)
                {
                    entries.Append("<Entry>");

                    // append EntryId, DateCreated, CreatedBy, DateUpdated and UpdatedBy (putting them in the desired order)
                    entries.Append(entry.Element("EntryId"));
                    entries.Append(entry.Element("DateCreated"));
                    entries.Append(entry.Element("CreatedBy"));
                    entries.Append(entry.Element("DateUpdated"));
                    entries.Append(entry.Element("UpdatedBy"));

                    foreach (var child in entry.Elements())
                    {
                        // append form field data
                        if (!child.Name.LocalName.Equals("EntryId") && !child.Name.LocalName.Equals("DateCreated") && !child.Name.LocalName.Equals("CreatedBy") &&
                            !child.Name.LocalName.Equals("DateUpdated") && !child.Name.LocalName.Equals("UpdatedBy"))
                        {
                            entries.AppendFormat("<Data><FieldId>{0}</FieldId><Value>{1}</Value></Data>", child.Name.LocalName, child.Value);
                        }
                    }

                    entries.Append("</Entry>");
                }
            }
            return(entries.ToString());
        }
        /// <summary>
        /// Returns the form data.
        /// </summary>
        /// <param name="user">Name of the user this form belongs to</param>
        /// <param name="hash">Hash of the form</param>
        /// <returns>Form data object</returns>
        public WufooData GetForm(string user, string hash)
        {
            if (_users.Contains(user))
            {
                WufooData userData = _userList[_users.IndexOf(user)];
                string url = string.Format("{0}forms/{1}.xml", ApiUrl, hash);
                string response = SubmitRequest(url, user, userData.ApiKey);

                XElement responseXml = XElement.Parse(response);
                XElement formElement = responseXml.Element("Form");
                if (formElement != null)
                {
                    WufooData form = new WufooData(formElement, user, UserName);
                    return form;
                }
            }
            return null;
        }
        /// <summary>
        /// Returns a list of users and caches the results so we can reuse username and api key.
        /// </summary>
        /// <returns>List of users</returns>
        public List<WufooData> GetUsers()
        {
            // always clear lists so we have current data (new users could have been created)
            _users = new List<string>();
            _userList = new List<WufooData>();

            string url = string.Format("{0}users.xml", ApiUrl);

            string response = SubmitRequest(url, UserName, ApiKey);
            XElement xml = XElement.Parse(response);

            IEnumerable<XElement> usersXml = xml.Elements("User");
            foreach (XElement userXml in usersXml)
            {
                WufooData data = new WufooData(userXml, UserName);
                _userList.Add(data);
                _users.Add(data.Title);
            }

            return _userList;
        }
示例#9
0
 public User(int publicationId, WufooData data) : base(publicationId, data)
 {
     // if data needs to be fully loaded, do so here
 }
示例#10
0
 public Form(int publicationId, WufooData data) : base(publicationId, data)
 {
     // ToDo: consider using async calls for loading fields and entries
     _fields = Provider.Wufoo.GetFields(data.LinkFields, data.User);
     _entries = Provider.Wufoo.GetEntries(data.LinkEntries, data.User);
 }