Esempio n. 1
0
        public void PostAttachment(Attachment attachment, out string errorMessage)
        {
            errorMessage = string.Empty;

            TDSettings.ConnectionRow connection = MyZillaSettingsDataSet.GetInstance().GetConnectionById(_connectionId);

            string myZillaUrl = connection.URL;

            MyZilla.BL.Utils.HttpHelper httpDialog = new HttpHelper(_connectionId, connection.Charset);

            try
            {
                string result = httpDialog.PostAttachment(attachment , myZillaUrl );

                string token = "";
                int startToken = result.IndexOf("token");
                if (startToken > 0)
                {
                    int stopTokenEntry = result.Substring(startToken).IndexOf(">");
                    if (stopTokenEntry > 0)
                    {
                        string res = result.Substring(startToken, stopTokenEntry);
                        if (!string.IsNullOrEmpty(res))
                        {
                            if (res.Contains("value="))
                            {
                                token = res.Substring(res.IndexOf("value=") + "value=".Length);
                                token = token.Replace("\"", "");
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(token))
                    attachment.Token = token;

                if (result.IndexOf("Changes Submitted") >= 0)
                {
                    errorMessage = string.Empty;
                }
                else
                {
                    int pos1 = result.IndexOf("<title>");
                    int pos2 = result.IndexOf("</title>");

                    errorMessage = result.Substring(pos1 +"<title>".Length, pos2 -( pos1 -1  + "</title>".Length ));
                }

            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }
        }