Exemplo n.º 1
0
        public string PostDoc(ImageNowDoc doc)
        {
            client  = new RestClient($"{conf.intServer.uri}/document/");
            request = new RestRequest(Method.POST);
            request.AddHeader("content-type", "application/xml");
            request.AddParameter("application/xml", doc.CreatePostDocXML(), ParameterType.RequestBody);
            SetCommonHeaders();
            response = client.Execute(request);

            if (response.StatusCode != System.Net.HttpStatusCode.Created)
            {
                return(response.Content);
            }
            string location = response.Headers[3].Value.ToString();

            string[] delims = { "document/" };
            string[] parts  = location.Split(delims, StringSplitOptions.None);
            string   docid  = "";

            //After 50 documents have been added (100 operations on the same session hash)
            //A header gets added to response, Connection=close
            try
            {
                docid = parts[1];
            }
            catch (IndexOutOfRangeException)
            {
                location = response.Headers[4].Value.ToString();
                parts    = location.Split(delims, StringSplitOptions.None);
                docid    = parts[1];
            }
            return(docid);
        }
Exemplo n.º 2
0
        public void MultiDocRapidFire(string n, string l, string d, string f1, string f2, string f3, string f4, string f5, string dt, int repeat, string queueid, BackgroundWorker bw)
        {
            RestCall rest = new RestCall(conf);

            conf.intServer.sessionHash = rest.GetConnection();
            if (conf.intServer.sessionHash.Length != 41)
            {
                MessageBox.Show($"Failed to get connection.\r\n{conf.intServer.sessionHash}");
                return;
            }

            decimal count = 0;

            for (int i = 0; i < repeat; i++)
            {
                ImageNowDoc doc;
                if (d.Contains("Folder"))
                {
                    doc = new ImageNowDoc(Guid.NewGuid().ToString(), l, d, f1, f2, f3, f4, Guid.NewGuid().ToString(), dt);
                }
                else
                {
                    doc = new ImageNowDoc(n, l, d, f1, f2, f3, f4, Guid.NewGuid().ToString(), dt);
                }

                string docid = rest.PostDoc(doc);
                if (docid.Length != 23)
                {
                    MessageBox.Show($"Failed to create document.\r\n{docid}");
                    return;
                }

                string queueResponse = "";
                if (!string.IsNullOrEmpty(queueid))
                {
                    queueResponse = rest.RouteDoc(docid, queueid);
                }

                if (!queueResponse.Equals("success"))
                {
                    MessageBox.Show($"Failed to route document.\r\n{queueResponse}");
                }

                count++;
                bw.ReportProgress((int)((count / repeat) * 100));
            }
            string responseContent2 = rest.DeleteConnection();

            if (!responseContent2.Equals("success"))
            {
                MessageBox.Show($"Failed to clear sessions.\r\nNo reason to be alarmed, by default the sessions will clear in one hour.\r\n{responseContent2}");
            }
            MessageBox.Show("Documents created.");
        }
Exemplo n.º 3
0
        public void MultiDocMultiFile(string n, string l, string d, string f1, string f2, string f3, string f4, string f5, string dt, int repeat, bool recursive, string queueid, BackgroundWorker bw)
        {
            RestCall rest = new RestCall(conf);

            conf.intServer.sessionHash = rest.GetConnection();
            if (conf.intServer.sessionHash.Length != 41)
            {
                MessageBox.Show($"Failed to get connection.\r\n{conf.intServer.sessionHash}");
                return;
            }

            string[] files;
            if (recursive)
            {
                files = Directory.GetFiles(conf.folderPath, "*", SearchOption.AllDirectories);
            }
            else
            {
                files = Directory.GetFiles(conf.folderPath);
            }

            decimal total = files.Length * repeat;
            decimal count = 0;

            for (int i = 0; i < repeat; i++)
            {
                foreach (string s in files)
                {
                    string      shortFilename = GetShortFileName(s);
                    string      longFilename  = Path.GetFileName(s);
                    ImageNowDoc doc;
                    if (d.Contains("Folder"))
                    {
                        doc = new ImageNowDoc(Guid.NewGuid().ToString(), l, d, f1, f2, f3, shortFilename, Guid.NewGuid().ToString(), dt);
                    }
                    else
                    {
                        doc = new ImageNowDoc(n, l, d, f1, f2, f3, shortFilename, Guid.NewGuid().ToString(), dt);
                    }

                    string docid = rest.PostDoc(doc);
                    if (docid.Length != 23)
                    {
                        MessageBox.Show($"Failed to create document.\r\n{docid}");
                        return;
                    }
                    else
                    {
                        byte[] fileBytes        = File.ReadAllBytes(s);
                        string responseContent1 = rest.PostDocPage(docid, fileBytes, longFilename);
                        if (!responseContent1.Equals("success"))
                        {
                            MessageBox.Show($"Failed to add page to document.\r\n{responseContent1}");
                            return;
                        }
                    }

                    string queueResponse = "";
                    if (!string.IsNullOrEmpty(queueid))
                    {
                        queueResponse = rest.RouteDoc(docid, queueid);
                    }

                    if (!queueResponse.Equals("success"))
                    {
                        MessageBox.Show($"Failed to route document.\r\n{queueResponse}");
                    }

                    count++;
                    bw.ReportProgress((int)((count / total) * 100));
                }
            }
            string responseContent2 = rest.DeleteConnection();

            if (!responseContent2.Equals("success"))
            {
                MessageBox.Show($"Failed to clear sessions.\r\nNo reason to be alarmed, by default they will clear themselves in one hour.\r\n{responseContent2}");
            }
            MessageBox.Show("Documents created and pages added.");
        }