Beispiel #1
0
        public void B_Get()
        {
            RestController api = new RestController(GetConnectionString());

            ApplicationResultRecords result1 = api.Get();

            Assert.IsTrue(result1.Success);
            Assert.IsTrue(result1.Records.Count() >= 2);

            ApplicationResultRecord result2 = api.Get(result1.Records[0].ID);

            Assert.IsTrue(result2.Success);
            Assert.IsNotNull(result2.Record);
            Assert.IsTrue(result2.Record.ID == result1.Records[0].ID);

            ApplicationResultRecords result3 = api.Get("Test", null);

            Assert.IsTrue(result3.Success);
            Assert.IsNotNull(result3.Records);
            Assert.IsTrue(result3.Records.Count() == 2);
            Assert.IsTrue(result3.Records[0].FirstName == "Test");

            ApplicationResultRecords result4 = api.Get(null, "Two");

            Assert.IsTrue(result4.Success);
            Assert.IsNotNull(result4.Records);
            Assert.IsTrue(result4.Records.Count() == 1);
            Assert.IsTrue(result4.Records[0].LastName == "Two");
        }
Beispiel #2
0
        /*
         * Retrieves Chromedriver versions from the archive
         * Filters for the major versions of the specified browser and returns the latest driver with the same major version
         */
        internal static string GetVersionFromGoogleAPIS(string url, Browser browser, OperatingSystem os)
        {
            RestController restController = new RestController(url);
            var            response       = restController.Get("");
            var            data           = response.DeserialiseAsXML <ListBucketResult>();
            var            version        = data.Contents.Where(x => x.Key.Contains(browser.Version.Split(".")[0]));

            var  osPlatform   = Environment.OSVersion;
            bool sixtyfourBit = Environment.Is64BitOperatingSystem;

            if (!os.Equals(OperatingSystem.WINDOWS) && browser.Name.ToLower().Contains("explorer") && browser.Name.ToLower().Contains("internet"))
            {
                throw new NotImplementedException();
            }

            if (version.Count() == 0)
            {
                throw new Exception("Unable to find a compatible driver for Chrome version " + browser.Version + ", please create a support issue.");
            }


            if (os.Equals(OperatingSystem.WINDOWS))
            {
                return(version.Where(x => x.Key.ToLower().Contains("win32")).FirstOrDefault().Key);
            }
            else if (os.Equals(OperatingSystem.MAC))
            {
                return(version.Where(x => x.Key.ToLower().Contains("mac" + (sixtyfourBit ? "64" : "32"))).FirstOrDefault().Key);
            }
            else
            {
                return(version.Where(x => x.Key.ToLower().Contains("linux" + (sixtyfourBit ? "64" : "32"))).FirstOrDefault().Key);
            }
        }
Beispiel #3
0
        /*
         * Gets the latest Firefox release from Github using the Github API
         * The latest Geckodriver supports backwards to version 60 of Firefox
         */
        internal static string GetFireFoxURL(Browser browser, OperatingSystem os)
        {
            try
            {
                RestController restController = new RestController(firefox_url);
                var            response       = restController.Get("latest");
                GitHubRelease  responseData   = (GitHubRelease)response.DeserialiseResponseTo <GitHubRelease>();

                var  osPlatform   = Environment.OSVersion;
                bool sixtyfourBit = Environment.Is64BitOperatingSystem;


                if (os.Equals(OperatingSystem.WINDOWS))
                {
                    var asset = responseData.Assets.Where(x => x.Name.ToLower().Contains("win32")).FirstOrDefault();
                    return(asset.browser_download_url.AbsoluteUri);
                }
                else if (os.Equals(OperatingSystem.MAC))
                {
                    var asset = responseData.Assets.Where(x => x.Name.ToLower().Contains("macos")).FirstOrDefault();
                    return(asset.browser_download_url.AbsoluteUri);
                }
                else
                {
                    var asset = responseData.Assets.Where(x => x.Name.ToLower().Contains("linux" + (sixtyfourBit ? "64" : "32"))).FirstOrDefault();
                    return(asset.browser_download_url.AbsoluteUri);
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }
Beispiel #4
0
        /*
         * Gets all the Edge Driver versions
         * Microsoft does not use an XML structure which deserialises neatly - open to suggestions -
         * In order to extract the useful information we use Regex to find all the Name tags and then create Version objects to compare
         */
        internal static string GetEdgeURL(Browser browser, OperatingSystem os)
        {
            RestController restController       = new RestController(edge_base);
            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("Accept", "application/xml");
            var response = restController.Get(edge_versions, headers);

            Regex versionRegex = new Regex("(?<=(<Name>))(.*?)(?=(</Name>))");
            var   versionData  = versionRegex.Matches(response.ResponseData);

            if (versionData.Count == 0)
            {
                throw new Exception("Error retrieving Edge Versions - please create a support issue.");
            }

            var versions = versionData.Where(x => x.Value.Split(".")[0].Contains(browser.Version.Split(".")[0]));

            if (versions.Count() == 0)
            {
                throw new Exception("Unable to find a compatible driver for Edge version " + browser.Version + ", please create a support issue.");
            }

            Regex          versionNumberRegex = new Regex(@"\d+(\.\d+)*");
            var            versionNumbers     = versionNumberRegex.Matches(String.Join(' ', versions));
            List <Version> driverVersions     = new List <Version>();

            foreach (Match versionMatch in versionNumbers)
            {
                Version versionNumber = null;
                Version.TryParse(versionMatch.Value, out versionNumber);

                if (versionNumber != null)
                {
                    driverVersions.Add(versionNumber);
                }
            }

            var version = driverVersions.Max(x => x);

            var  osPlatform   = Environment.OSVersion;
            bool sixtyfourBit = Environment.Is64BitOperatingSystem;

            if (os.Equals(OperatingSystem.WINDOWS))
            {
                return(edge_OS(version.ToString(), "win32"));
            }
            else if (os.Equals(OperatingSystem.MAC))
            {
                return(edge_OS(version.ToString(), "mac" + (sixtyfourBit ? "64" : "32")));
            }
            else
            {
                return(edge_OS(version.ToString(), "arm" + (sixtyfourBit ? "64" : "32")));
            }
        }
Beispiel #5
0
        public void C_Delete()
        {
            RestController api = new RestController(GetConnectionString());

            ApplicationResultRecords result1 = api.Get();

            ApplicationResultBase result2 = api.Delete(result1.Records[0].ID);

            Assert.IsTrue(result2.Success);

            ApplicationResultBase result3 = api.Delete(result1.Records[1].ID);

            Assert.IsTrue(result3.Success);

            ApplicationResultRecords result4 = api.Get();

            Assert.IsTrue(result4.Success);
            Assert.IsNull(result4.Records);
        }
Beispiel #6
0
        public static void Run(RestController client, string RestHomeUri, string filter, int itemsPerPage, bool pauseBetweenPages, string repositoryName, bool printResult, string userName)
        {
            // get repository resource
            HomeDocument      home         = client.Get <HomeDocument>(RestHomeUri, null);
            Feed <Repository> repositories = home.GetRepositories <Repository>(new FeedGetOptions {
                Inline = true, Links = true
            });
            Repository repository = repositories.FindInlineEntry(repositoryName);

            // get a collection of users
            GetUsers(repository, filter, itemsPerPage, pauseBetweenPages, printResult);

            OperationsOnUser(repository, userName, itemsPerPage, pauseBetweenPages, printResult);
        }
Beispiel #7
0
        public static D2Repository GetRepository()
        {
            if (Repository != null)
            {
                return(Repository);
            }
            if (UserName == null || Password == null || Docbase == null || RestServiceURL == null)
            {
                return(null);
            }
            RestController client;
            HomeDocument   home;

            if (RestServiceURL == null)
            {
                RestServiceURL = "http://localhost:8080/dctm-rest/services";
            }
            client     = new RestController(UserName, Password);
            home       = client.Get <HomeDocument>(RestServiceURL, null);
            Repository = home.GetRepository <D2Repository>(Docbase);
            return(Repository);
        }
        public static void Run(RestController client, string RestHomeUri, string repositoryName, bool printResult,
                               string groupName, string subGroupName, string userName)
        {
            // get repository resource
            HomeDocument      home         = client.Get <HomeDocument>(RestHomeUri, null);
            Feed <Repository> repositories = home.GetRepositories <Repository>(new FeedGetOptions {
                Inline = true, Links = true
            });
            Repository repository = repositories.FindInlineEntry(repositoryName);

            //create or get group
            Group testGroup = CreateOrGetGroup(repository, groupName, printResult);

            //create or get group
            Group testSubGroup = CreateOrGetGroup(repository, subGroupName, printResult);

            //create or get user
            User testUser = CreateOrGetUser(repository, userName, printResult);

            //add user/sub-group to the parent group
            AddMembersOperations(repository, testGroup, testSubGroup, testUser, printResult);
            //remove user/sub-group from the parent group
            RemoveMembersOperations(repository, testGroup, testSubGroup, testUser, printResult);
        }
        public static void Run(RestController client, string RestHomeUri, string filter, int itemsPerPage, bool pauseBetweenPages, string repositoryName, bool printResult)
        {
            HomeDocument      home         = client.Get <HomeDocument>(RestHomeUri, null);
            Feed <Repository> repositories = home.GetRepositories <Repository>(new FeedGetOptions {
                Inline = true, Links = true
            });
            Repository repository = repositories.FindInlineEntry(repositoryName);

            Console.WriteLine(String.Format("Getting formats for filter '{0}' on repository '{1}', with page size {2}", filter, repository.Name, itemsPerPage));

            // REST call to get the 1st page of formats for the specified filter
            FeedGetOptions options = new FeedGetOptions()
            {
                ItemsPerPage = itemsPerPage, Inline = true, IncludeTotal = true, Filter = String.IsNullOrEmpty(filter) ? null : filter
            };
            Feed <Format> formats = repository.GetFormats <Format>(options);

            if (formats != null)
            {
                int    totalResults = formats.Total;
                double totalPages   = formats.PageCount;
                int    docProcessed = 0;
                for (int i = 0; i < totalPages; i++)
                {
                    Console.WriteLine("**************************** PAGE " + (i + 1) + " *******************************");
                    foreach (Entry <Format> obj in formats.Entries)
                    {
                        StringBuilder values = new StringBuilder();
                        Console.WriteLine(String.Format("Name: {0}, \tExtension: {1}, \tMime: {2}",
                                                        obj.Content.GetPropertyString("name"),
                                                        obj.Content.GetPropertyString("dos_extension"),
                                                        obj.Content.GetPropertyString("mime_type")));
                        Console.WriteLine(values.ToString());
                        docProcessed++;
                    }

                    // REST call to get next page
                    if (totalResults != docProcessed)
                    {
                        formats = formats.NextPage();
                    }
                    Console.WriteLine("*******************************************************************");
                    Console.WriteLine("Page:" + (i + 1) + " Results: " + docProcessed + " out of " + totalResults + " Processed");
                    Console.WriteLine("*******************************************************************");
                    Console.WriteLine("\n\n");
                    if (pauseBetweenPages)
                    {
                        Console.WriteLine("Press 'q' to quit, 'g' to run to end, or any other key to run next page..");
                        ConsoleKeyInfo next = Console.ReadKey();
                        if (next.KeyChar.Equals('q'))
                        {
                            return;
                        }
                        if (next.KeyChar.Equals('g'))
                        {
                            pauseBetweenPages = false;
                        }
                    }
                }
            }
            if (printResult)
            {
                Console.WriteLine(formats == null ? "NULL" : formats.ToString());
            }
        }
        public void TestGet(int id, string expected)
        {
            var restController = new RestController();

            Assert.Equal(expected, restController.Get(id));
        }
        public static void Run(RestController client, string RestHomeUri, string query, int itemsPerPage, bool pauseBetweenPages, string repositoryName, bool printResult)
        {
            HomeDocument      home         = client.Get <HomeDocument>(RestHomeUri, null);
            Feed <Repository> repositories = home.GetRepositories <Repository>(new FeedGetOptions {
                Inline = true, Links = true
            });
            Repository repository = repositories.FindInlineEntry(repositoryName);

            Console.WriteLine(string.Format("Running DQL query '{0}' on repository '{1}', with page size {2}", query, repository.Name, itemsPerPage));

            // REST call to get the 1st page of the dql query
            Feed <PersistentObject> queryResult = repository.ExecuteDQL <PersistentObject>(query, new FeedGetOptions()
            {
                ItemsPerPage = itemsPerPage
            });

            if (queryResult != null)
            {
                int    totalResults = queryResult.Total;
                double totalPages   = queryResult.PageCount;
                int    docProcessed = 0;
                //int pageCount = queryResult.Entries.c
                for (int i = 0; i < totalPages && queryResult != null; i++)
                {
                    Console.WriteLine("**************************** PAGE " + (i + 1) + " *******************************");
                    foreach (Entry <PersistentObject> obj in queryResult.Entries)
                    {
                        StringBuilder values = new StringBuilder();
                        Console.WriteLine(string.Format("  ID: {0} \t\tName: {1}",
                                                        GetAttr(obj.Content, new string[] { "r_object_id" }),
                                                        GetAttr(obj.Content, new string[] { "object_name", "user_name", "group_name", "name" })));
                        Console.WriteLine(values.ToString());
                        docProcessed++;
                    }

                    // REST call to get next page of the dql query
                    if (totalResults != docProcessed)
                    {
                        queryResult = queryResult.NextPage();
                    }
                    Console.WriteLine("*******************************************************************");
                    Console.WriteLine("Page:" + (i + 1) + " Results: " + docProcessed + " out of " + totalResults + " Processed");
                    Console.WriteLine("*******************************************************************");
                    Console.WriteLine("\n\n");
                    if (pauseBetweenPages)
                    {
                        Console.WriteLine("Press 'q' to quit, 'g' to run to end, or any other key to run next page..");
                        ConsoleKeyInfo next = Console.ReadKey();
                        if (next.KeyChar.Equals('q'))
                        {
                            return;
                        }
                        if (next.KeyChar.Equals('g'))
                        {
                            pauseBetweenPages = false;
                        }
                    }
                }
            }
            if (printResult)
            {
                Console.WriteLine(queryResult == null ? "NULL" : queryResult.ToString());
            }
        }
        protected override void OnCreate(Bundle bundle)
        {
            previousIds.Add(ROOT);
            currentId = ROOT;

            long testStart = DateTime.Now.Ticks;

            base.OnCreate(bundle);
            RestController client = new RestController("dmadmin", "xxxxxxx");
            RestService    home   = client.Get <RestService>("http://mm-d7.mccollough.int:8080/rest/services", null);

            if (home == null)
            {
                //WriteOutput("\nUnable to get Rest Service at: " + RestHomeUri + " check to see if the service is available.");
                return;
            }
            home.SetClient(client);
            ProductInfo productInfo = home.GetProductInfo();

            repository = home.GetRepository("McCollough");
            if (repository == null)
            {
                throw new Exception("Unable to login to the repository, please see server logs for more details.");
            }
            GetObjects(
                "select r_object_id, object_name, r_object_type from dm_cabinet", DEFAULT_OPTIONS);

            WriteOutput("Took " + ((DateTime.Now.Ticks - testStart) / TimeSpan.TicksPerMillisecond) + "ms to get RestService and cabinet list");

            UpdateListView();

            // Set our view from the "main" layout resource
            // SetContentView(Resource.Layout.Main);

            // Get our UI controls from the loaded layout:
            //EditText phoneNumberText = FindViewById<EditText>(Resource.Id.PhoneNumberText);
            //Button translateButton = FindViewById<Button>(Resource.Id.TranslateButton);
            //Button callButton = FindViewById<Button>(Resource.Id.CallButton);



            //// Disable the "Call" button
            //callButton.Enabled = false;

            //// Add code to translate number
            //string translatedNumber = string.Empty;

            //translateButton.Click += (object sender, EventArgs e) =>
            //{
            //    // Translate user's alphanumeric phone number to numeric
            //    translatedNumber = Core.PhonewordTranslator.ToNumber(phoneNumberText.Text);
            //    if (String.IsNullOrWhiteSpace(translatedNumber))
            //    {
            //        callButton.Text = "Call";
            //        callButton.Enabled = false;
            //    }
            //    else
            //    {
            //        callButton.Text = "Call " + translatedNumber;
            //        callButton.Enabled = true;
            //    }
            //};

            //callButton.Click += (object sender, EventArgs e) =>
            //{
            //    // On "Call" button click, try to dial phone number.
            //    var callDialog = new AlertDialog.Builder(this);
            //    callDialog.SetMessage("Call " + translatedNumber + "?");
            //    callDialog.SetNeutralButton("Call", delegate {
            //        // Create intent to dial phone
            //        var callIntent = new Intent(Intent.ActionCall);
            //        callIntent.SetData(Android.Net.Uri.Parse("tel:" + translatedNumber));
            //        StartActivity(callIntent);
            //    });
            //    callDialog.SetNegativeButton("Cancel", delegate { });

            //    // Show the alert dialog to the user and wait for response.
            //    callDialog.Show();
            //};
        }
        public static void Run(RestController client, string RestHomeUri, string parent, int itemsPerPage, bool pauseBetweenPages, string repositoryName, bool printResult)
        {
            HomeDocument      home         = client.Get <HomeDocument>(RestHomeUri, null);
            Feed <Repository> repositories = home.GetRepositories <Repository>(new FeedGetOptions {
                Inline = true, Links = true
            });
            Repository repository = repositories.FindInlineEntry(repositoryName);

            Console.WriteLine(String.Format("Getting types for parent '{0}' on repository '{1}', with page size {2}", parent, repository.Name, itemsPerPage));

            // REST call to get the 1st page of the types
            FeedGetOptions options = new FeedGetOptions()
            {
                ItemsPerPage = itemsPerPage, Inline = true, IncludeTotal = true
            };

            if (!String.IsNullOrEmpty(parent))
            {
                options.SetQuery("parent-type", parent);
            }
            options.SetQuery("inherited", false);
            Feed <DmType> types = repository.GetTypes(options);

            if (types != null)
            {
                int    totalResults = types.Total;
                double totalPages   = types.PageCount;
                int    docProcessed = 0;
                for (int i = 0; i < totalPages; i++)
                {
                    Console.WriteLine("**************************** PAGE " + (i + 1) + " *******************************");
                    foreach (Entry <DmType> obj in types.Entries)
                    {
                        StringBuilder values = new StringBuilder();
                        Console.WriteLine(String.Format("Name: {0}, \t\tParent: {1}, \tNon-inherited Attrs: {2}",
                                                        obj.Title,
                                                        String.IsNullOrEmpty(obj.Content.Parent) ? "" : obj.Content.Parent.Substring(obj.Content.Parent.LastIndexOf("/") + 1),
                                                        obj.Content.TypeProperties == null ? 0 : obj.Content.TypeProperties.Count));
                        Console.WriteLine(values.ToString());
                        docProcessed++;
                    }

                    // REST call to get next page of the types
                    if (totalResults != docProcessed)
                    {
                        types = types.NextPage();
                    }
                    Console.WriteLine("*******************************************************************");
                    Console.WriteLine("Page:" + (i + 1) + " Results: " + docProcessed + " out of " + totalResults + " Processed");
                    Console.WriteLine("*******************************************************************");
                    Console.WriteLine("\n\n");
                    if (pauseBetweenPages)
                    {
                        Console.WriteLine("Press 'q' to quit, 'g' to run to end, or any other key to run next page..");
                        ConsoleKeyInfo next = Console.ReadKey();
                        if (next.KeyChar.Equals('q'))
                        {
                            return;
                        }
                        if (next.KeyChar.Equals('g'))
                        {
                            pauseBetweenPages = false;
                        }
                    }
                }
            }
            if (printResult)
            {
                Console.WriteLine(types == null ? "NULL" : types.ToString());
            }
        }
        public static void Run(RestController client, string RestHomeUri, string repositoryName)
        {
            HomeDocument      home         = client.Get <HomeDocument>(RestHomeUri, null);
            Feed <Repository> repositories = home.GetRepositories <Repository>(new FeedGetOptions {
                Inline = true, Links = true
            });
            Repository repository = repositories.FindInlineEntry(repositoryName);

            BatchCapabilities batchCapabilities = repository.GetBatchCapabilities();

            Console.WriteLine("Batch capabilities for this repository:");
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("  - transactional or non-transactional? {0}", batchCapabilities.Transactions);
            Console.WriteLine("  - sequential or non-sequential?       {0}", batchCapabilities.Sequence);
            Console.WriteLine("  - fail on error or continue on error? {0}", batchCapabilities.OnError);
            Console.WriteLine("  - all resources are batch-able except these [{0}] ", String.Join(",", batchCapabilities.NonBatchableResources.ToArray <string>()));
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Press any key to continue batch test..");
            Console.ReadKey();

            Console.WriteLine(String.Format("\r\nPreparing data for the batch.."));
            User currentUser = repository.GetCurrentUser(new SingleGetOptions());

            Console.WriteLine("\t - Fetched current user: "******"user_name"));
            Cabinet homeCabinet = currentUser.GetHomeCabinet(new SingleGetOptions());

            Console.WriteLine("\t - Fetched home cabinet: " + homeCabinet.GetPropertyString("object_name"));

            // start a batch - create 1 folder & 1 document under home cabinet + get dql + create a new relation
            Console.WriteLine("\r\nReady to create a batch with 5 operations:");
            string folderNamePrefix = "BatchTestFolder-";

            Console.WriteLine("\t - (1) create a new folder under home cabinet with name prefix: " + folderNamePrefix);
            string docNamePrefix = "BatchTestDoc-";

            Console.WriteLine("\t - (2) create a new document under home cabinet with name: " + docNamePrefix);
            string dql = "select * from dm_group";

            Console.WriteLine("\t - (3) execute a dql query: " + dql);
            Console.WriteLine("\t - (4) get all relations");
            Console.WriteLine("\t - (5) create a new cabinet with empty name (should fail)");
            Console.WriteLine("Press any key to run batch..");
            Console.ReadKey();

            List <KeyValuePair <string, object> > dqlParams = new List <KeyValuePair <string, object> >();

            dqlParams.Add(new KeyValuePair <string, object>("dql", dql));
            string dqlUri = UriUtil.BuildUri(LinkRelations.FindLinkAsString(repository.Links, LinkRelations.DQL.Rel), dqlParams);

            Batch batch = Batch.CreateFromBuilder()
                          .Description("a sample batch with 4 operations")
                          .BatchSpec(new BatchSpec {
                Transactional = false, Sequential = false, FailOnError = false, ReturnRequest = false
            })
                          .AddOperation <Folder>(
                "batch-opt-1", homeCabinet, LinkRelations.FOLDERS.Rel, "POST", ObjectUtil.NewRandomFolder(folderNamePrefix, "dm_folder")
                )
                          .AddOperation <Document>(
                "batch-opt-2", homeCabinet, LinkRelations.DOCUMENTS.Rel, "POST", ObjectUtil.NewRandomDocument(docNamePrefix, "dm_document")
                )
                          .AddOperation(
                "batch-opt-3", dqlUri, "GET"
                )
                          .AddOperation(
                "batch-opt-4", homeCabinet, LinkRelations.RELATIONS.Rel, "GET"
                )
                          .AddOperation(
                "batch-opt-5", repository, LinkRelations.CABINETS.Rel, "POST", new Cabinet()
                )
                          .Build();

            Batch result = repository.CreateBatch(batch);

            Console.WriteLine("\r\nPrinting batch result..");
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine(String.Format(" - description [{0}]", result.Description));
            Console.WriteLine(String.Format(" - owner       [{0}]", result.Owner));
            Console.WriteLine(String.Format(" - state       [{0}]", result.State));
            Console.WriteLine(String.Format(" - submitted   [{0}]", result.Submitted));
            Console.WriteLine(String.Format(" - started     [{0}]", result.Started));
            Console.WriteLine(String.Format(" - finished    [{0}]", result.Finished));

            foreach (BatchOperation operation in result.Operations)
            {
                Console.WriteLine(String.Format("\r\n - operation    [{0}]", operation.Id));
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(String.Format("\t--> state        [{0}]", operation.State));
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(String.Format("\t--> started      [{0}]", operation.Started));
                Console.WriteLine(String.Format("\t--> finished     [{0}]", operation.Finished));
                Console.WriteLine("\t--> response");
                Console.WriteLine(String.Format("\t-----------> status  [{0}]", operation.Response.Status));

                if (operation.Response.HasError())
                {
                    Error error = operation.Response.GetError();
                    Console.WriteLine(String.Format("\t-----------> entity  [{0}:{1}]", error.Code, error.Message));
                }
                else
                {
                    if (operation.Id.Equals("batch-opt-1") || operation.Id.Equals("batch-opt-2"))
                    {
                        PersistentObject po = operation.Response.GetObject <PersistentObject>();
                        Console.WriteLine(String.Format("\t-----------> entity  [object of URI {0}]", LinkRelations.FindLinkAsString(po.Links, LinkRelations.SELF.Rel)));
                    }
                    else if (operation.Id.Equals("batch-opt-3") || operation.Id.Equals("batch-opt-4"))
                    {
                        Feed <PersistentObject> feed = operation.Response.GetObject <Feed <PersistentObject> >();
                        Console.WriteLine(String.Format("\t-----------> entity  [feed with title {0} and entry count {1}]", feed.Title, feed.Entries.Count));
                    }
                }
            }
            Console.ForegroundColor = ConsoleColor.White;
        }
        public static void Run(RestController client, string RestHomeUri, string terms, int itemsPerPage, bool pauseBetweenPages, string repositoryName, bool printResult)
        {
            HomeDocument      home         = client.Get <HomeDocument>(RestHomeUri, null);
            Feed <Repository> repositories = home.GetRepositories <Repository>(new FeedGetOptions {
                Inline = true, Links = true
            });
            Repository repository = repositories.FindInlineEntry(repositoryName);

            Console.WriteLine(String.Format("Running full-text search for terms '{0}' on repository '{1}', with page size {2}", terms, repository.Name, itemsPerPage));

            // REST call to get the 1st page of the search result
            SearchOptions options = new SearchOptions()
            {
                ItemsPerPage = itemsPerPage, Inline = false, IncludeTotal = true, SearchQuery = terms
            };
            Feed <PersistentObject> searchResult = repository.ExecuteSimpleSearch <PersistentObject>(options);

            if (searchResult != null)
            {
                int    totalResults = searchResult.Total;
                double totalPages   = searchResult.PageCount;
                int    docProcessed = 0;
                for (int i = 0; i < totalPages; i++)
                {
                    Console.WriteLine("**************************** PAGE " + (i + 1) + " *******************************");
                    foreach (Entry <PersistentObject> obj in searchResult.Entries)
                    {
                        StringBuilder values = new StringBuilder();
                        Console.WriteLine(String.Format("Score: {0:0.000},   ID: {1},   Name: {2},    Highlight:\n {3}",
                                                        obj.Score,
                                                        obj.Id,
                                                        obj.Title,
                                                        obj.Summary));
                        Console.WriteLine(values.ToString());
                        docProcessed++;
                    }

                    // REST call to get next page of the search
                    if (totalResults != docProcessed)
                    {
                        searchResult = searchResult.NextPage();
                    }
                    Console.WriteLine("*******************************************************************");
                    Console.WriteLine("Page:" + (i + 1) + " Results: " + docProcessed + " out of " + totalResults + " Processed");
                    Console.WriteLine("*******************************************************************");
                    Console.WriteLine("\n\n");
                    if (pauseBetweenPages)
                    {
                        Console.WriteLine("Press 'q' to quit, 'g' to run to end, or any other key to run next page..");
                        ConsoleKeyInfo next = Console.ReadKey();
                        if (next.KeyChar.Equals('q'))
                        {
                            return;
                        }
                        if (next.KeyChar.Equals('g'))
                        {
                            pauseBetweenPages = false;
                        }
                    }
                }
            }
            if (printResult)
            {
                Console.WriteLine(searchResult == null ? "NULL" : searchResult.ToString());
            }
        }
Beispiel #16
0
        /// <summary>
        ///
        /// </summary>
        public void Start()
        {
            getPreferences();
            long testStart = DateTime.Now.Ticks;
            long tStart    = DateTime.Now.Ticks;

            HomeDocument home = client.Get <HomeDocument>(RestHomeUri, null);

            if (home == null)
            {
                WriteOutput("\nUnable to get Rest Service at: " + RestHomeUri + " check to see if the service is available.");
                return;
            }
            WriteOutput("Took " + ((DateTime.Now.Ticks - testStart) / TimeSpan.TicksPerMillisecond) + "ms to get RestService");
            CurrentRepository = GetCurrentRepository(home, repositoryName);

            ProductInfo productInfo = home.GetProductInfo();

            if (CurrentRepository == null)
            {
                throw new Exception("Unable to login to the CurrentRepository, please see server logs for more details.");
            }
            // Set our default folder and document types.
            CurrentRepository.DocumentType = "dm_document";
            CurrentRepository.FolderType   = "dm_folder";
            NameValueCollection restTests = ConfigurationManager.GetSection("resttests") as NameValueCollection;

            if (!(Boolean.Parse(restTests["CreateTempDocs"].ToString()) || Boolean.Parse(restTests["CreateTempDocs"].ToString())))
            {
                throw new System.Exception("On of the tests that create Documents is required for other tests to run. "
                                           + "You must enable either the CreateTempDocs test and/or the CreateTempDocs test in order to create "
                                           + "documents that can be used in subsequent tests.");
            }

            Tracker = new List <DocumentTracker>();
            foreach (String key in restTests)
            {
                bool preCheckOk = true;
                // This test is not available in versions earlier than 7.2
                double restVersion = Double.Parse((productInfo.Properties.Major.Equals("NA") ? "7.2" : productInfo.Properties.Major));

                if (key.Equals("Search"))
                {
                    if (!(restVersion >= 7.2d))
                    {
                        preCheckOk = false;
                        Console.WriteLine("Documentum Rest Version 7.2 or higher is required to use Search, your version is: "
                                          + restVersion + " Skipping...");
                    }
                }

                // These features do not work on Mono yet, should be fine when .NetCore is released though
                if (key.Equals("ExportParent") || key.Equals("ExportListOfFiles"))
                {
                    if (Type.GetType("Mono.Runtime") != null)
                    {
                        preCheckOk = false;
                        Console.WriteLine("The zip libraries required for [" + key + " ] have failed under Mono, skipping this  test. If you "
                                          + "want to test for yourself, you will have to modify the source to allow it udner (UseCaseTests");
                    }
                }

                if (preCheckOk)
                {
                    if (Boolean.Parse(restTests[key].ToString()))
                    {
                        runTestByName(key);
                    }
                }

                if (pauseBetweenOperations)
                {
                    Console.WriteLine("Press 'q' to quit, 'g' to run to end, or any other key to run next page..");
                    ConsoleKeyInfo next = Console.ReadKey();
                    if (next.KeyChar.Equals('q'))
                    {
                        return;
                    }
                    if (next.KeyChar.Equals('g'))
                    {
                        pauseBetweenOperations = false;
                    }
                }
            }

            WriteOutput("#####################################");
            WriteOutput("COMPLETED TESTS IN: " + ((DateTime.Now.Ticks - testStart) / TimeSpan.TicksPerMillisecond) / 1000 / 60 + "minutes");
            WriteOutput("#####################################");
            System.Diagnostics.Process.Start(testDirectory);

            if (loggerForm != null)
            {
                while (loggerForm.Visible)
                {
                    Application.DoEvents();
                }
            }
        }