コード例 #1
0
        /// <summary>
        /// CREATE new item, replace if it exists. URI identifies the context for the item in question.
        /// No parameters are required for POST, just thepayload.
        /// </summary>

        private void DoDelete(FileRequestData rdata)
        {
            bool   modified = false;
            bool   created  = false;
            string path     = String.Empty;

            Rest.Log.DebugFormat("{0} REST File handler, Method = <{1}> ENTRY", MsgId, rdata.method);

            if (rdata.Parameters.Length > 1)
            {
                try
                {
                    path = rdata.path.Substring(rdata.Parameters[0].Length + qPrefix.Length + 2);

                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                }
                catch (Exception e)
                {
                    Rest.Log.DebugFormat("{0} Exception during file processing : {1}", MsgId,
                                         e.Message);
                    rdata.Fail(Rest.HttpStatusCodeNotFound, String.Format("invalid parameters : {0} {1}",
                                                                          path, e.Message));
                }
            }
            else
            {
                Rest.Log.DebugFormat("{0} Invalid parameters: <{1}>", MsgId, rdata.path);
                rdata.Fail(Rest.HttpStatusCodeNotFound, "invalid parameters");
            }

            if (created)
            {
                rdata.appendStatus(String.Format("<p> Created file {0} <p>", path));
                rdata.Complete(Rest.HttpStatusCodeCreated);
            }
            else
            {
                if (modified)
                {
                    rdata.appendStatus(String.Format("<p> Modified file {0} <p>", path));
                    rdata.Complete(Rest.HttpStatusCodeOK);
                }
                else
                {
                    rdata.Complete(Rest.HttpStatusCodeNoContent);
                }
            }

            rdata.Respond(String.Format("File {0} : Normal completion", rdata.method));
        }
コード例 #2
0
        /// <summary>
        /// The only parameter we recognize is a UUID.If an asset with this identification is
        /// found, it's content, base-64 encoded, is returned to the client.
        /// </summary>

        private void DoGet(FileRequestData rdata)
        {
            string path = String.Empty;

            Rest.Log.DebugFormat("{0} REST File handler, Method = <{1}> ENTRY", MsgId, rdata.method);

            if (rdata.Parameters.Length > 1)
            {
                try
                {
                    path = rdata.path.Substring(rdata.Parameters[0].Length + qPrefix.Length + 2);
                    if (File.Exists(path))
                    {
                        Rest.Log.DebugFormat("{0}  File located <{1}>", MsgId, path);
                        Byte[] data = File.ReadAllBytes(path);
                        rdata.initXmlWriter();
                        rdata.writer.WriteStartElement(String.Empty, "File", String.Empty);
                        rdata.writer.WriteAttributeString("name", path);
                        rdata.writer.WriteBase64(data, 0, data.Length);
                        rdata.writer.WriteFullEndElement();
                    }
                    else
                    {
                        Rest.Log.DebugFormat("{0} Invalid parameters: <{1}>", MsgId, path);
                        rdata.Fail(Rest.HttpStatusCodeNotFound, String.Format("invalid parameters : {0}", path));
                    }
                }
                catch (Exception e)
                {
                    Rest.Log.DebugFormat("{0} Invalid parameters: <{1}>", MsgId, e.Message);
                    rdata.Fail(Rest.HttpStatusCodeNotFound, String.Format("invalid parameters : {0} {1}",
                                                                          path, e.Message));
                }
            }

            rdata.Complete();
            rdata.Respond(String.Format("File <{0}> : Normal completion", rdata.method));
        }
コード例 #3
0
        /// <summary>
        /// CREATE new item, replace if it exists. URI identifies the context for the item in question.
        /// No parameters are required for POST, just thepayload.
        /// </summary>

        private void DoDelete(FileRequestData rdata)
        {

            bool modified = false;
            bool created  = false;
            string path   = String.Empty;

            Rest.Log.DebugFormat("{0} REST File handler, Method = <{1}> ENTRY", MsgId, rdata.method);

            if (rdata.Parameters.Length > 1)
            {
                try
                {
                    path = rdata.path.Substring(rdata.Parameters[0].Length+qPrefix.Length+2);

                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                }
                catch (Exception e)
                {
                    Rest.Log.DebugFormat("{0} Exception during file processing : {1}", MsgId, 
                          e.Message);
                    rdata.Fail(Rest.HttpStatusCodeNotFound, String.Format("invalid parameters : {0} {1}",
                          path, e.Message));
                }
            }
            else
            {
                Rest.Log.DebugFormat("{0} Invalid parameters: <{1}>", MsgId, rdata.path);
                rdata.Fail(Rest.HttpStatusCodeNotFound, "invalid parameters");
            }

            if (created)
            {
                rdata.appendStatus(String.Format("<p> Created file {0} <p>", path));
                rdata.Complete(Rest.HttpStatusCodeCreated);
            }
            else
            {
                if (modified)
                {
                    rdata.appendStatus(String.Format("<p> Modified file {0} <p>", path));
                    rdata.Complete(Rest.HttpStatusCodeOK);
                }
                else
                {
                    rdata.Complete(Rest.HttpStatusCodeNoContent);
                }
            }

            rdata.Respond(String.Format("File {0} : Normal completion", rdata.method));

        }
コード例 #4
0
        /// <summary>
        /// CREATE new item, replace if it exists. URI identifies the context for the item in question.
        /// No parameters are required for POST, just thepayload.
        /// </summary>

        private void DoPost(FileRequestData rdata)
        {

            bool modified = false;
            bool created  = false;
            string path   = String.Empty;

            Rest.Log.DebugFormat("{0} REST File handler, Method = <{1}> ENTRY", MsgId, rdata.method);

            if (rdata.Parameters.Length > 1)
            {
                try
                {
                    path = rdata.path.Substring(rdata.Parameters[0].Length+qPrefix.Length+2);
                    bool maymod = File.Exists(path);
                    
                    rdata.initXmlReader();
                    XmlReader xml = rdata.reader;

                    if (!xml.ReadToFollowing("File"))
                    {
                        Rest.Log.DebugFormat("{0} Invalid request data: <{1}>", MsgId, rdata.path);
                        rdata.Fail(Rest.HttpStatusCodeBadRequest,"invalid request data");
                    }

                    Byte[] data = Convert.FromBase64String(xml.ReadElementContentAsString("File", ""));

                    File.WriteAllBytes(path,data);
                    modified =   maymod;
                    created  = ! maymod;
                }
                catch (Exception e)
                {
                    Rest.Log.DebugFormat("{0} Exception during file processing : {1}", MsgId, 
                          e.Message);
                }
            }
            else
            {
                Rest.Log.DebugFormat("{0} Invalid parameters: <{1}>", MsgId, rdata.path);
                rdata.Fail(Rest.HttpStatusCodeNotFound, "invalid parameters");
            }

            if (created)
            {
                rdata.appendStatus(String.Format("<p> Created file {0} <p>", path));
                rdata.Complete(Rest.HttpStatusCodeCreated);
            }
            else
            {
                if (modified)
                {
                    rdata.appendStatus(String.Format("<p> Modified file {0} <p>", path));
                    rdata.Complete(Rest.HttpStatusCodeOK);
                }
                else
                {
                    rdata.Complete(Rest.HttpStatusCodeNoContent);
                }
            }

            rdata.Respond(String.Format("File {0} : Normal completion", rdata.method));

        }
コード例 #5
0
        /// <summary>
        /// The only parameter we recognize is a UUID.If an asset with this identification is
        /// found, it's content, base-64 encoded, is returned to the client.
        /// </summary>

        private void DoGet(FileRequestData rdata)
        {

            string path = String.Empty;

            Rest.Log.DebugFormat("{0} REST File handler, Method = <{1}> ENTRY", MsgId, rdata.method);

            if (rdata.Parameters.Length > 1)
            {
                try
                {
                    path = rdata.path.Substring(rdata.Parameters[0].Length+qPrefix.Length+2);
                    if (File.Exists(path))
                    {
                        Rest.Log.DebugFormat("{0}  File located <{1}>", MsgId, path);
                        Byte[] data = File.ReadAllBytes(path);
                        rdata.initXmlWriter();
                        rdata.writer.WriteStartElement(String.Empty,"File",String.Empty);
                        rdata.writer.WriteAttributeString("name", path);
                        rdata.writer.WriteBase64(data,0,data.Length);
                        rdata.writer.WriteFullEndElement();
                    }
                    else
                    {
                        Rest.Log.DebugFormat("{0} Invalid parameters: <{1}>", MsgId, path);
                        rdata.Fail(Rest.HttpStatusCodeNotFound, String.Format("invalid parameters : {0}", path));
                    }
                }
                catch (Exception e)
                {
                    Rest.Log.DebugFormat("{0} Invalid parameters: <{1}>", MsgId, e.Message);
                    rdata.Fail(Rest.HttpStatusCodeNotFound, String.Format("invalid parameters : {0} {1}", 
                                     path, e.Message));
                }
            }

            rdata.Complete();
            rdata.Respond(String.Format("File <{0}> : Normal completion", rdata.method));

        }
コード例 #6
0
        /// <summary>
        /// CREATE new item, replace if it exists. URI identifies the context for the item in question.
        /// No parameters are required for POST, just thepayload.
        /// </summary>

        private void DoPost(FileRequestData rdata)
        {
            bool   modified = false;
            bool   created  = false;
            string path     = String.Empty;

            Rest.Log.DebugFormat("{0} REST File handler, Method = <{1}> ENTRY", MsgId, rdata.method);

            if (rdata.Parameters.Length > 1)
            {
                try
                {
                    path = rdata.path.Substring(rdata.Parameters[0].Length + qPrefix.Length + 2);
                    bool maymod = File.Exists(path);

                    rdata.initXmlReader();
                    XmlReader xml = rdata.reader;

                    if (!xml.ReadToFollowing("File"))
                    {
                        Rest.Log.DebugFormat("{0} Invalid request data: <{1}>", MsgId, rdata.path);
                        rdata.Fail(Rest.HttpStatusCodeBadRequest, "invalid request data");
                    }

                    Byte[] data = Convert.FromBase64String(xml.ReadElementContentAsString("File", ""));

                    File.WriteAllBytes(path, data);
                    modified = maymod;
                    created  = !maymod;
                }
                catch (Exception e)
                {
                    Rest.Log.DebugFormat("{0} Exception during file processing : {1}", MsgId,
                                         e.Message);
                }
            }
            else
            {
                Rest.Log.DebugFormat("{0} Invalid parameters: <{1}>", MsgId, rdata.path);
                rdata.Fail(Rest.HttpStatusCodeNotFound, "invalid parameters");
            }

            if (created)
            {
                rdata.appendStatus(String.Format("<p> Created file {0} <p>", path));
                rdata.Complete(Rest.HttpStatusCodeCreated);
            }
            else
            {
                if (modified)
                {
                    rdata.appendStatus(String.Format("<p> Modified file {0} <p>", path));
                    rdata.Complete(Rest.HttpStatusCodeOK);
                }
                else
                {
                    rdata.Complete(Rest.HttpStatusCodeNoContent);
                }
            }

            rdata.Respond(String.Format("File {0} : Normal completion", rdata.method));
        }