Пример #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>
        /// 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));

        }
Пример #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 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));

        }
Пример #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));
        }