public bool parseXmlResponse(byte[] response)
        {
            XmlTextReader reader = new XmlTextReader(new MemoryStream(response));
            reader.Namespaces = true;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        if (reader.Name.EndsWith(DavProperty.MULTISTATUS))
                        {
                            multistatus = new Multistatus(reader);
                        }
                        break;
                }
            }

            return true;
        }
Пример #2
0
        private void fillFilteredResponses(Multistatus multistatus)
        {
            filteredResponses.Clear();
            ArrayList responses = multistatus.getResponses();
            for (int i = 0; i < responses.Count; i++)
            {
                DavResponse response = (DavResponse)responses[i];

                ResourceTypeProperty resourceTypeProp = (ResourceTypeProperty)response.getProperty(DavProperty.RESOURCETYPE);
                if (resourceTypeProp != null && resourceTypeProp.getResourceType() == ResourceTypeProperty.RESOURCE)
                {
                    filteredResponses.Add(response);
                }
            }
        }
Пример #3
0
        private void btn_search_Click(object sender, EventArgs e)
        {
            this.context = application.getContext();

            if (context == null) {
                MessageBox.Show("Cannot load paramethers,\n please run Settings first.", "Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }

            try
            {
                SearchCommand searchcomm = new SearchCommand(context);
                SQLQuery query = new SQLQuery();

                searchcomm.setResourcePath("/" + application.getWorkspaceName());
                String query_string = "select * from nt:base where contains(*, '" + box_search.Text + "')";
                //String query_string = box_search.Text;
                query.setQuery(query_string);
                searchcomm.setQuery(query);

                int status = searchcomm.execute();
                if (status == DavStatus.MULTISTATUS)
                {
                    this.multistatus = searchcomm.getMultistatus();
                    DrawFileList();
                } else {
                    Utils.showMessageStatus(status);
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("Error! Can't connect to the server!", Utils.CAPTION,
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #4
0
        public void fillFileList(String remotePath, Multistatus multistatus)
        {
            ArrayList responses = multistatus.getResponses();

            fillFilteredResponses(multistatus);

            listFiles.Items.Clear();

            try
            {
                for (int i = 0; i < filteredResponses.Count; i++)
                {
                    DavResponse response = (DavResponse)filteredResponses[i];

                    String displayName = "";
                    String size = "";
                    String mimeType = "";
                    String modified = "";

                    DisplayNameProperty displayNameProp = (DisplayNameProperty)response.getProperty(DavProperty.DISPLAYNAME);
                    ResourceTypeProperty resourceTypeProp = (ResourceTypeProperty)response.getProperty(DavProperty.RESOURCETYPE);
                    LastModifiedProperty lastModifiedProp = (LastModifiedProperty)response.getProperty(DavProperty.GETLASTMODIFIED);
                    ContentLenghtProperty getContentLengthProp = (ContentLenghtProperty)response.getProperty(DavProperty.GETCONTENTLENGTH);

                    WebDavProperty versionNameProp = response.getProperty("D:" + DavProperty.VERSIONNAME);

                    WebDavProperty mimeTypeProperty = response.getProperty("jcr:mimeType");

                    String pattern = "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'";

                    if (displayNameProp != null)
                    {
                        displayName = displayNameProp.getDisplayName();

                        if (lastModifiedProp != null)
                        {
                            modified = ParseDate(lastModifiedProp.getLastModified());

                        }

                        if (mimeTypeProperty != null) {
                            mimeType = mimeTypeProperty.getTextContent();
                        }

                        if (getContentLengthProp != null)
                        {
                            long fileSize = System.Convert.ToInt64(getContentLengthProp.getContentLenght());

                            if (fileSize < 1024)
                            {
                                size = fileSize.ToString();
                            }
                            else if (fileSize < (1024 * 1024))
                            {
                                fileSize = fileSize >> 10;
                                size += fileSize;
                                size += "K";
                            }
                            else
                            {
                                String kb = "" + (fileSize >> 10) % 1024;
                                while (kb.Length < 3)
                                {
                                    kb = "0" + kb;
                                }
                                fileSize = fileSize >> 20;
                                size += fileSize;
                                size += ".";
                                size += kb.ToCharArray()[0];
                                size += "M";
                            }

                        }

                        int imageId = getImageIdByMimeType(mimeTypeProperty);

                        ListViewItem viewItem = new ListViewItem(new string[] {
                            displayName,
                            size,
                            mimeType,
                            modified}, imageId);

                        listFiles.Items.Add(viewItem);
                    }
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("EXCEPTION " + exc.Message + " : " + exc.StackTrace);
            }
        }