Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <param name="includeDeleted"></param>
        /// <param name="infoLevel"></param>
        /// <param name="folderInfo"></param>
        /// <returns>-2=Id not found</returns>
        public int GetFolderInfo(long id,
                                 bool includeDeleted,
                                 GetInfoLevel infoLevel,
                                 out FolderInfo folderInfo)
        {
            int status = -1; // way bad on the client api side

            // init out parms
            folderInfo = new FolderInfo(); // init

            string url = URLPrefix + "getfolderinfo?id=" + Uri.EscapeDataString(id.ToString())
                         + @"&includedeleted=" + includeDeleted.ToString().ToLower()
                         + @"&infolevel=" + FF.Common.EnumUtils.StringValueOf(infoLevel).ToLower();

            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

            request.ContentLength = 0;

            if (!String.IsNullOrEmpty(authCookie))
            {
                request.Headers["Cookie"] = authCookie;
            }

            // set type
            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

            AsyncCallback asyncCallback = new AsyncCallback(ProcessHttpResponse);
            IAsyncResult  asyncResult   = request.BeginGetResponse(asyncCallback, request);

            autoEvent.WaitOne();

            if (!String.IsNullOrEmpty(XmlResponse))
            {
                // get status
                var returnStatus = XDocument.Parse(XmlResponse).Element("response").Element("status").Value;

                // if object not found, 404 then return status
                if ("404" == returnStatus)
                {
                    return(404);
                }

                // need to be careful on other tags; for example, a 500 return code might not produce other tags
                // get folder info
                XElement folderElement = null;
                try
                {
                    folderElement = XDocument.Parse(XmlResponse).Element("response").Element("result").Element("folder");
                }
                catch
                {
                    return(-2);
                }

                if (null == folderElement)
                {
                    return(-3);
                }

                try
                {
                    if (null != folderElement.Attribute("name"))
                    {
                        folderInfo.Name = folderElement.Attribute("name").Value;
                    }
                } catch { }

                try
                {
                    long temp;
                    if (null != folderElement.Attribute("objectid"))
                    {
                        if (Int64.TryParse(folderElement.Attribute("objectid").Value, out temp))
                        {
                            folderInfo.ObjectId = temp;
                        }
                    }
                } catch { }

                try
                {
                    bool temp;
                    if (null != folderElement.Attribute("isdeleted"))
                    {
                        if (Boolean.TryParse(folderElement.Attribute("isdeleted").Value, out temp))
                        {
                            folderInfo.IsDeleted = temp;
                        }
                    }
                } catch { }

                try
                {
                    long temp;
                    if (null != folderElement.Attribute("parentid"))
                    {
                        if (Int64.TryParse(folderElement.Attribute("parentid").Value, out temp))
                        {
                            folderInfo.ParentId = temp;
                        }
                    }
                } catch { }

                try
                {
                    if (null != folderElement.Attribute("version"))
                    {
                        folderInfo.Version = folderElement.Attribute("version").Value;
                    }
                } catch { }

                try
                {
                    DateTime temp;
                    if (null != folderElement.Attribute("lastupdated"))
                    {
                        if (DateTime.TryParse(folderElement.Attribute("lastupdated").Value, out temp))
                        {
                            folderInfo.LastUpdated = temp;
                        }
                    }
                } catch { }

                // other folder info
                try
                {
                    if (null != folderElement.Attribute("description"))
                    {
                        folderInfo.Description = folderElement.Attribute("description").Value;
                    }
                }
                catch { }

                try
                {
                    bool temp;
                    if (null != folderElement.Attribute("indexed"))
                    {
                        if (Boolean.TryParse(folderElement.Attribute("indexed").Value, out temp))
                        {
                            folderInfo.Indexed = temp;
                        }
                    }
                }
                catch { }

                try
                {
                    if (null != folderElement.Attribute("createdby"))
                    {
                        folderInfo.CreatedBy = folderElement.Attribute("createdby").Value;
                    }
                }
                catch { }

                try
                {
                    DateTime temp;
                    if (null != folderElement.Attribute("createdtime"))
                    {
                        if (DateTime.TryParse(folderElement.Attribute("createdtime").Value, out temp))
                        {
                            folderInfo.CreatedTime = temp;
                        }
                    }
                }
                catch { }

                try
                {
                    if (null != folderElement.Attribute("deletedby"))
                    {
                        folderInfo.DeletedBy = folderElement.Attribute("deletedby").Value;
                    }
                }
                catch { }

                try
                {
                    DateTime temp;
                    if (null != folderElement.Attribute("deletedtime"))
                    {
                        if (DateTime.TryParse(folderElement.Attribute("deletedtime").Value, out temp))
                        {
                            folderInfo.DeletedTime = temp;
                        }
                    }
                } catch { }

                try
                {
                    int temp;
                    if (null != folderElement.Attribute("state"))
                    {
                        if (Int32.TryParse(folderElement.Attribute("state").Value, out temp))
                        {
                            folderInfo.State = temp;
                        }
                    }
                } catch { }

                // get subfolders
                try
                {
                    foreach (XElement xe in folderElement.Element("folders").Descendants("folder"))
                    {
                        bool       error     = false;
                        FolderInfo subFolder = new FolderInfo();

                        try
                        {
                            if (null != xe.Attribute("name"))
                            {
                                subFolder.Name = xe.Attribute("name").Value;
                            }
                        }
                        catch { error = true; }

                        try
                        {
                            long temp;
                            if (null != xe.Attribute("objectid"))
                            {
                                if (Int64.TryParse(xe.Attribute("objectid").Value, out temp))
                                {
                                    subFolder.ObjectId = temp;
                                }
                            }
                        }
                        catch { error = true; }

                        try
                        {
                            bool temp;
                            if (null != xe.Attribute("isdeleted"))
                            {
                                if (Boolean.TryParse(xe.Attribute("isdeleted").Value, out temp))
                                {
                                    subFolder.IsDeleted = temp;
                                }
                            }
                        } catch { error = true; }

                        try
                        {
                            if (null != xe.Attribute("version"))
                            {
                                subFolder.Version = xe.Attribute("version").Value;
                            }
                        } catch { error = true; }

                        try
                        {
                            DateTime temp;
                            if (null != xe.Attribute("lastupdated"))
                            {
                                if (DateTime.TryParse(xe.Attribute("lastupdated").Value, out temp))
                                {
                                    subFolder.LastUpdated = temp;
                                }
                            }
                        }
                        catch { error = true; }

                        if (false == error)
                        {
                            folderInfo.subFolders.Add(subFolder);
                        }
                    }
                }
                catch { }

                // get subfiles
                try
                {
                    foreach (XElement xe in folderElement.Element("files").Descendants("file"))
                    {
                        bool error = false;
                        FF.ClientREST.FileInfoBasic subFile = new FF.ClientREST.FileInfoBasic();

                        try
                        {
                            if (null != xe.Attribute("name"))
                            {
                                subFile.Name = xe.Attribute("name").Value;
                            }
                        }
                        catch { error = true; }

                        try
                        {
                            long temp;
                            if (null != xe.Attribute("objectid"))
                            {
                                if (Int64.TryParse(xe.Attribute("objectid").Value, out temp))
                                {
                                    subFile.ObjectId = temp;
                                }
                            }
                        }
                        catch { error = true; }

                        try
                        {
                            if (null != xe.Attribute("checksum"))
                            {
                                subFile.Checksum = xe.Attribute("checksum").Value;
                            }
                        }
                        catch { error = true; }

                        try
                        {
                            bool temp;
                            if (null != xe.Attribute("isdeleted"))
                            {
                                if (Boolean.TryParse(xe.Attribute("isdeleted").Value, out temp))
                                {
                                    subFile.IsDeleted = temp;
                                }
                            }
                        }
                        catch { error = true; }

                        try
                        {
                            DateTime temp;
                            if (null != xe.Attribute("createdtime"))
                            {
                                if (DateTime.TryParse(xe.Attribute("createdtime").Value, out temp))
                                {
                                    subFile.CreatedTime = temp;
                                }
                            }
                        }
                        catch { error = true; }

                        try
                        {
                            long temp;
                            if (null != xe.Attribute("revision"))
                            {
                                if (Int64.TryParse(xe.Attribute("revision").Value, out temp))
                                {
                                    subFile.FileRevision = temp;
                                }
                            }
                        }
                        catch { error = true; }

                        try
                        {
                            long temp;
                            if (null != xe.Attribute("sizeinbytes"))
                            {
                                if (Int64.TryParse(xe.Attribute("sizeinbytes").Value, out temp))
                                {
                                    subFile.SizeInBytes = temp;
                                }
                            }
                        }
                        catch { error = true; }

                        try
                        {
                            int temp;
                            if (null != xe.Attribute("state"))
                            {
                                if (Int32.TryParse(xe.Attribute("state").Value, out temp))
                                {
                                    subFile.State = temp;
                                }
                            }
                        }
                        catch { }

                        try
                        {
                            if (null != xe.Attribute("version"))
                            {
                                subFile.Version = xe.Attribute("version").Value;
                            }
                        }
                        catch { }

                        // set parent, it's obvious
                        subFile.ParentId = folderInfo.ObjectId;

                        if (false == error)
                        {
                            folderInfo.subFiles.Add(subFile);
                        }
                    }
                }
                catch { }

                int  returnIntVal;
                bool didParse = Int32.TryParse(returnStatus, out returnIntVal);
                if (didParse)
                {
                    status = returnIntVal;
                }
            }

            return(status);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="includeDeleted"></param>
        /// <param name="infoLevel"></param>
        /// <param name="folderInfo"></param>
        /// <returns>-2=Id not found</returns>
        public int GetFolderInfo(long id,
      bool includeDeleted,
      GetInfoLevel infoLevel,
      out FolderInfo folderInfo)
        {
            int status = -1; // way bad on the client api side

              // init out parms
              folderInfo = new FolderInfo(); // init

              string url = URLPrefix + "getfolderinfo?id=" + Uri.EscapeDataString(id.ToString())
                             + @"&includedeleted=" + includeDeleted.ToString().ToLower()
                             + @"&infolevel=" + FF.Common.EnumUtils.StringValueOf(infoLevel).ToLower();

              HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
              request.ContentLength = 0;

              if (!String.IsNullOrEmpty(authCookie))
            request.Headers["Cookie"] = authCookie;

              // set type
              request.Method = "POST";
              request.ContentType = "application/x-www-form-urlencoded";

              AsyncCallback asyncCallback = new AsyncCallback(ProcessHttpResponse);
              IAsyncResult asyncResult = request.BeginGetResponse(asyncCallback, request);

              autoEvent.WaitOne();

              if (!String.IsNullOrEmpty(XmlResponse))
              {
            // get status
            var returnStatus = XDocument.Parse(XmlResponse).Element("response").Element("status").Value;

            // if object not found, 404 then return status
            if ("404" == returnStatus)
              return 404;

            // need to be careful on other tags; for example, a 500 return code might not produce other tags
            // get folder info
            XElement folderElement = null;
            try
            {
              folderElement = XDocument.Parse(XmlResponse).Element("response").Element("result").Element("folder");
            }
            catch
            {
              return -2;
            }

            if (null == folderElement)
              return -3;

            try
            {
              if (null != folderElement.Attribute("name"))
            folderInfo.Name = folderElement.Attribute("name").Value;
            } catch { }

            try
            {
              long temp;
              if (null != folderElement.Attribute("objectid"))
            if (Int64.TryParse(folderElement.Attribute("objectid").Value, out temp))
              folderInfo.ObjectId = temp;
            } catch { }

            try
            {
              bool temp;
              if (null != folderElement.Attribute("isdeleted"))
            if (Boolean.TryParse(folderElement.Attribute("isdeleted").Value, out temp))
              folderInfo.IsDeleted = temp;
            } catch { }

            try
            {
              long temp;
              if (null != folderElement.Attribute("parentid"))
            if (Int64.TryParse(folderElement.Attribute("parentid").Value, out temp))
              folderInfo.ParentId = temp;
            } catch { }

            try
            {
              if (null != folderElement.Attribute("version"))
            folderInfo.Version = folderElement.Attribute("version").Value;
            } catch { }

            try
            {
              DateTime temp;
              if (null != folderElement.Attribute("lastupdated"))
            if (DateTime.TryParse(folderElement.Attribute("lastupdated").Value, out temp))
              folderInfo.LastUpdated = temp;
            } catch { }

            // other folder info
            try
            {
              if (null != folderElement.Attribute("description"))
            folderInfo.Description = folderElement.Attribute("description").Value;
            }
            catch { }

            try
            {
              bool temp;
              if (null != folderElement.Attribute("indexed"))
            if (Boolean.TryParse(folderElement.Attribute("indexed").Value, out temp))
              folderInfo.Indexed = temp;
            }
            catch { }

            try
            {
              if (null != folderElement.Attribute("createdby"))
            folderInfo.CreatedBy = folderElement.Attribute("createdby").Value;
            }
            catch { }

            try
            {
              DateTime temp;
              if (null != folderElement.Attribute("createdtime"))
            if (DateTime.TryParse(folderElement.Attribute("createdtime").Value, out temp))
              folderInfo.CreatedTime = temp;
            }
            catch { }

            try
            {
              if (null != folderElement.Attribute("deletedby"))
            folderInfo.DeletedBy = folderElement.Attribute("deletedby").Value;
            }
            catch { }

            try
            {
              DateTime temp;
              if (null != folderElement.Attribute("deletedtime"))
            if (DateTime.TryParse(folderElement.Attribute("deletedtime").Value, out temp))
              folderInfo.DeletedTime = temp;
            } catch { }

            try
            {
              int temp;
              if (null != folderElement.Attribute("state"))
            if (Int32.TryParse(folderElement.Attribute("state").Value, out temp))
              folderInfo.State = temp;
            } catch { }

            // get subfolders
            try
            {
              foreach (XElement xe in folderElement.Element("folders").Descendants("folder"))
              {
            bool error = false;
            FolderInfo subFolder = new FolderInfo();

            try
            {
              if (null != xe.Attribute("name"))
                subFolder.Name = xe.Attribute("name").Value;
            }
            catch { error = true; }

            try
            {
              long temp;
              if (null != xe.Attribute("objectid"))
                if (Int64.TryParse(xe.Attribute("objectid").Value, out temp))
                  subFolder.ObjectId = temp;
            }
            catch { error = true;}

            try
            {
              bool temp;
              if (null != xe.Attribute("isdeleted"))
                if (Boolean.TryParse(xe.Attribute("isdeleted").Value, out temp))
                  subFolder.IsDeleted = temp;
            } catch { error = true;}

            try
            {
              if (null != xe.Attribute("version"))
                subFolder.Version = xe.Attribute("version").Value;
            } catch { error = true;}

            try
            {
              DateTime temp;
              if (null != xe.Attribute("lastupdated"))
                if (DateTime.TryParse(xe.Attribute("lastupdated").Value, out temp))
                  subFolder.LastUpdated = temp;
            }
            catch { error = true; }

            if (false == error)
            {
              folderInfo.subFolders.Add(subFolder);
            }
              }
            }
            catch { }

            // get subfiles
            try
            {
              foreach (XElement xe in folderElement.Element("files").Descendants("file"))
              {
            bool error = false;
            FF.ClientREST.FileInfoBasic subFile = new FF.ClientREST.FileInfoBasic();

            try
            {
              if (null != xe.Attribute("name"))
                subFile.Name = xe.Attribute("name").Value;
            }
            catch { error = true; }

            try
            {
              long temp;
              if (null != xe.Attribute("objectid"))
                if (Int64.TryParse(xe.Attribute("objectid").Value, out temp))
                  subFile.ObjectId = temp;
            }
            catch { error = true; }

            try
            {
              if (null != xe.Attribute("checksum"))
                subFile.Checksum = xe.Attribute("checksum").Value;
            }
            catch { error = true; }

            try
            {
              bool temp;
              if (null != xe.Attribute("isdeleted"))
                if (Boolean.TryParse(xe.Attribute("isdeleted").Value, out temp))
                  subFile.IsDeleted = temp;
            }
            catch { error = true; }

            try
            {
              DateTime temp;
              if (null != xe.Attribute("createdtime"))
                if (DateTime.TryParse(xe.Attribute("createdtime").Value, out temp))
                  subFile.CreatedTime = temp;
            }
            catch { error = true; }

            try
            {
              long temp;
              if (null != xe.Attribute("revision"))
                if (Int64.TryParse(xe.Attribute("revision").Value, out temp))
                  subFile.FileRevision = temp;
            }
            catch { error = true; }

            try
            {
              long temp;
              if (null != xe.Attribute("sizeinbytes"))
                if (Int64.TryParse(xe.Attribute("sizeinbytes").Value, out temp))
                  subFile.SizeInBytes = temp;
            }
            catch { error = true; }

            try
            {
              int temp;
              if (null != xe.Attribute("state"))
                if (Int32.TryParse(xe.Attribute("state").Value, out temp))
                  subFile.State = temp;
            }
            catch { }

            try
            {
              if (null != xe.Attribute("version"))
                subFile.Version = xe.Attribute("version").Value;
            }
            catch { }

            // set parent, it's obvious
            subFile.ParentId = folderInfo.ObjectId;

            if (false == error)
            {
              folderInfo.subFiles.Add(subFile);
            }
              }
            }
            catch { }

            int returnIntVal;
            bool didParse = Int32.TryParse(returnStatus, out returnIntVal);
            if (didParse)
              status = returnIntVal;
              }

              return status;
        }