Example #1
0
        public static CommandLineArguments Init(string[] args)
        {
            CommandLineDictionary d = CommandLineDictionary.FromArguments(args);

            if (d == null || d.ContainsKey("?") || d.ContainsKey("help"))
            {
                return(null);
            }

            CommandLineArguments a = new CommandLineArguments();

            a.ParseArguments(args);

            if (a.Interval == null)
            {
                return(null);
            }

            if (a.Pid == null && a.ProcessName == null)
            {
                return(null);
            }

            return(a);
        }
        [InlineData("/runId=10", "/runId = 10")] // doc bug!
        public void TestValidArguments(string arg1, string arg2)
        {
            string[] args           = new string[] { arg1, arg2 };
            CommandLineDictionary d = CommandLineDictionary.FromArguments(args);

            Assert.Equal <int>(2, d.Count);
        }
 public void TestDuplicatedArguments(string arg1, string arg2)
 {
     string[] args = new string[] { arg1, arg2 };
     Assert.Throws <ArgumentException>(
         delegate
     {
         CommandLineDictionary d = CommandLineDictionary.FromArguments(args);
     });
 }
        public void TestCommonUsageWithCustomKeyAndValueCharacters()
        {
            string[] args = new string[] { "-verbose", "-runid:10" };

            CommandLineDictionary d = CommandLineDictionary.FromArguments(args, '-', ':');

            Assert.True(d.ContainsKey("verbose"));
            Assert.True(d.ContainsKey("runid"));
            Assert.Equal <int>(10, Int32.Parse(d["runid"], CultureInfo.InvariantCulture));
            Assert.Equal <string>("-verbose -runid:10", d.ToString()); // bug!
            Assert.Equal <int>(2, d.Count);
        }
        public void TestCommonUsage()
        {
            string[] args = new string[] { "/verbose", "/runid=10" };

            CommandLineDictionary d = CommandLineDictionary.FromArguments(args);

            Assert.True(d.ContainsKey("verbose"));
            Assert.True(d.ContainsKey("runid"));
            Assert.Equal <int>(10, Int32.Parse(d["runid"], CultureInfo.InvariantCulture));
            Assert.Equal <string>("/verbose /runid=10", d.ToString());
            Assert.Equal <int>(2, d.Count);
        }
Example #6
0
        /// <summary>
        /// Provides an entry point for Crash Reporting tool.
        /// </summary>
        public static int Main(string[] args)
        {
            try
            {
                CommandLineDictionary dictionary = CommandLineDictionary.FromArguments(args);
                int pid = int.Parse(dictionary["PID"], CultureInfo.InvariantCulture);
                ReportCrash(pid);
            }
            //This process must not crash in event of failure
            //otherwise we risk recursive crashing sequence which could get ugly.
            catch (Exception e)
            {
                Log(e.ToString());
            }

            return(0);
        }
Example #7
0
        static int Main(string[] args)
        {
            _args = new Arguments();
            try
            {
                CommandLineDictionary cmdlineDict = CommandLineDictionary.FromArguments(args, '-', ':');

                _args.ParseArguments(args, cmdlineDict);
            }
            catch (Exception e)
            {
                return Usage("Oops. Something bad happened with the parameters that you gave me.\n\n" + e.Message);
            }

            if (_args.Usage)
                return Usage();

            if (string.IsNullOrEmpty(_args.Target))
                return Usage("Must specify a target to connect to. Use: [emulator|xde]/[device|phone]");

            if (string.IsNullOrEmpty(_args.App) && string.IsNullOrEmpty(_args.Xap))
                return Usage("Must specify one of either -app or -xap");

            if (!string.IsNullOrEmpty(_args.App) && !string.IsNullOrEmpty(_args.Xap))
                return Usage("Confused me, you have. Should I use -app or -xap?");

            if (!_args.Install && !_args.Update && !_args.Launch && !_args.UnInstall && string.IsNullOrEmpty(_args.Get) && string.IsNullOrEmpty(_args.Put))
                return Usage("Yawn. You haven't asked me to install, update or launch the app, so what do you want me to do?");

            int rv = 0;

            try
            {
                rv = DoWork();
            }
            catch (ConsoleMessageException e)
            {
                System.Console.Error.WriteLine(e.Message);
                rv = 1;
            }

            return rv;
        }
Example #8
0
        /// <summary>
        /// Login to the RRC server and perform some OSLC actions
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            CommandLineDictionary cmd = CommandLineDictionary.FromArguments(args);

            if (!ValidateOptions(cmd))
            {
                logger.Error("Syntax:  /url=https://<server>:port/<context>/ /user=<user> /password=<password> /project=\"<project_area>\"");
                logger.Error("Example: /url=https://exmple.com:9443/rm /user=ADMIN /password=ADMIN /project=\"JKE Banking (Requirements Management)\"");
                return;
            }

            String webContextUrl = cmd["url"];
            String user          = cmd["user"];
            String passwd        = cmd["password"];
            String projectArea   = cmd["project"];

            try {
                //STEP 0: Need to accept all SSL certificates for DotNet Open Auth to be able to do it's OAuth token generation UNLESS
                //the SSL certificate from CLM is a from a trusted certificate authority.
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(OslcClient.AcceptAllServerCertificates);

                //STEP 1: Initialize a Jazz rootservices helper and indicate we're looking for the RequirementManagement catalog
                JazzRootServicesHelper helper = new JazzRootServicesHelper(webContextUrl, OSLCConstants.OSLC_RM_V2);

                //STEP 2: Create a new OSLC OAuth capable client, the parameter of following call should be provided
                //This is a bit of a hack for readability.  It is assuming RRC is at context /rm.  Could use a regex or UriBuilder instead.
                String          authUrl = webContextUrl.Replace("/rm", "/jts"); // XXX - should be ReplaceFirst(), if it existed
                JazzOAuthClient client  = helper.InitOAuthClient("123456789", "secret", user, passwd, authUrl);

                //STEP 3: Get the URL of the OSLC ChangeManagement catalog
                String catalogUrl = helper.GetCatalogUrl();

                //STEP 4: Find the OSLC Service Provider for the project area we want to work with
                String serviceProviderUrl = client.LookupServiceProviderUrl(catalogUrl, projectArea);

                //STEP 5: Get the Query Capabilities URL so that we can run some OSLC queries
                String queryCapability = client.LookupQueryCapability(serviceProviderUrl,
                                                                      OSLCConstants.OSLC_RM_V2,
                                                                      OSLCConstants.RM_REQUIREMENT_TYPE);
                //STEP 6: Create base requirements
                //Get the Creation Factory URL for change requests so that we can create one
                Requirement requirement        = new Requirement();
                String      requirementFactory = client.LookupCreationFactory(
                    serviceProviderUrl, OSLCConstants.OSLC_RM_V2,
                    requirement.GetRdfTypes()[0].ToString());

                //Get Feature Requirement Type URL
                ResourceShape featureInstanceShape = RmUtil.LookupRequirementsInstanceShapes(
                    serviceProviderUrl, OSLCConstants.OSLC_RM_V2,
                    requirement.GetRdfTypes()[0].ToString(), client, "Feature");

                Uri rootFolder = null;
                //Get Collection Type URL
                RequirementCollection collection = new RequirementCollection();
                ResourceShape         collectionInstanceShape = RmUtil.LookupRequirementsInstanceShapes(
                    serviceProviderUrl, OSLCConstants.OSLC_RM_V2,
                    collection.GetRdfTypes()[0].ToString(), client, "Personal Collection");

                String req01URL     = null;
                String req02URL     = null;
                String req03URL     = null;
                String req04URL     = null;
                String reqcoll01URL = null;

                String primaryText = null;
                if ((featureInstanceShape != null) && (requirementFactory != null))
                {
                    // Create REQ01
                    requirement.SetInstanceShape(featureInstanceShape.GetAbout());
                    requirement.SetTitle("Req01");

                    // Decorate the PrimaryText
                    primaryText = "My Primary Text";
                    XElement obj = RmUtil.ConvertStringToHTML(primaryText);
                    requirement.GetExtendedProperties().Add(RmConstants.PROPERTY_PRIMARY_TEXT, obj);

                    requirement.SetDescription("Created By OSLC4Net");
                    requirement.AddImplementedBy(new Link(new Uri("http://google.com"), "Link in REQ01"));
                    //Create the change request
                    HttpResponseMessage creationResponse = client.CreateResource(
                        requirementFactory, requirement,
                        OslcMediaType.APPLICATION_RDF_XML,
                        OslcMediaType.APPLICATION_RDF_XML);
                    req01URL = creationResponse.Headers.Location.ToString();
                    creationResponse.ConsumeContent();

                    // Create REQ02
                    requirement = new Requirement();
                    requirement.SetInstanceShape(featureInstanceShape.GetAbout());
                    requirement.SetTitle("Req02");
                    requirement.SetDescription("Created By OSLC4Net");
                    requirement.AddValidatedBy(new Link(new Uri("http://bancomer.com"), "Link in REQ02"));
                    //Create the change request
                    creationResponse = client.CreateResource(
                        requirementFactory, requirement,
                        OslcMediaType.APPLICATION_RDF_XML,
                        OslcMediaType.APPLICATION_RDF_XML);

                    req02URL = creationResponse.Headers.Location.ToString();
                    creationResponse.ConsumeContent();

                    // Create REQ03
                    requirement = new Requirement();
                    requirement.SetInstanceShape(featureInstanceShape.GetAbout());
                    requirement.SetTitle("Req03");
                    requirement.SetDescription("Created By OSLC4Net");
                    requirement.AddValidatedBy(new Link(new Uri("http://outlook.com"), "Link in REQ03"));
                    //Create the change request
                    creationResponse = client.CreateResource(
                        requirementFactory, requirement,
                        OslcMediaType.APPLICATION_RDF_XML,
                        OslcMediaType.APPLICATION_RDF_XML);
                    req03URL = creationResponse.Headers.Location.ToString();
                    creationResponse.ConsumeContent();

                    // Create REQ04
                    requirement = new Requirement();
                    requirement.SetInstanceShape(featureInstanceShape.GetAbout());
                    requirement.SetTitle("Req04");
                    requirement.SetDescription("Created By OSLC4Net");

                    //Create the Requirement
                    creationResponse = client.CreateResource(
                        requirementFactory, requirement,
                        OslcMediaType.APPLICATION_RDF_XML,
                        OslcMediaType.APPLICATION_RDF_XML);
                    req04URL = creationResponse.Headers.Location.ToString();
                    creationResponse.ConsumeContent();

                    // Now create a collection
                    // Create REQ04
                    collection = new RequirementCollection();

                    collection.AddUses(new Uri(req03URL));
                    collection.AddUses(new Uri(req04URL));

                    collection.SetInstanceShape(collectionInstanceShape.GetAbout());
                    collection.SetTitle("Collection01");
                    collection.SetDescription("Created By OSLC4Net");
                    //Create the change request
                    creationResponse = client.CreateResource(
                        requirementFactory, collection,
                        OslcMediaType.APPLICATION_RDF_XML,
                        OslcMediaType.APPLICATION_RDF_XML);
                    reqcoll01URL = creationResponse.Headers.Location.ToString();
                    creationResponse.ConsumeContent();
                }

                // Check that everything was properly created
                if (req01URL == null ||
                    req02URL == null ||
                    req03URL == null ||
                    req04URL == null ||
                    reqcoll01URL == null)
                {
                    throw new Exception("Failed to create an artifact");
                }

                // GET the root folder based on First requirement created
                HttpResponseMessage getResponse = client.GetResource(req01URL, OslcMediaType.APPLICATION_RDF_XML);
                requirement = getResponse.Content.ReadAsAsync <Requirement>(client.GetFormatters()).Result;
                String etag1 = getResponse.Headers.ETag.ToString();
                // May not be needed getResponse.ConsumeContent();
                //Save the Uri of the root folder in order to used it easily
                rootFolder = (Uri)requirement.GetExtendedProperties()[RmConstants.PROPERTY_PARENT_FOLDER];

                String changedPrimaryText = (String )requirement.GetExtendedProperties()[RmConstants.PROPERTY_PRIMARY_TEXT];
                if (changedPrimaryText == null)
                {
                    // Check with the workaround
                    changedPrimaryText = (String )requirement.GetExtendedProperties()[PROPERTY_PRIMARY_TEXT_WORKAROUND];
                }

                if ((changedPrimaryText != null) && (!changedPrimaryText.Contains(primaryText)))
                {
                    logger.Error("Error getting primary Text");
                }

                //QUERIES
                // SCENARIO 01  Do a query for type= Requirements
                OslcQueryParameters queryParams = new OslcQueryParameters();
                queryParams.SetPrefix("rdf=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>");
                queryParams.SetWhere("rdf:type=<http://open-services.net/ns/rm#Requirement>");
                OslcQuery       query  = new OslcQuery(client, queryCapability, 10, queryParams);
                OslcQueryResult result = query.Submit();
                bool            processAsDotNetObjects = false;
                int             resultsSize            = result.GetMembersUrls().Length;
                ProcessPagedQueryResults(result, client, processAsDotNetObjects);
                Console.WriteLine("\n------------------------------\n");
                Console.WriteLine("Number of Results for SCENARIO 01 = " + resultsSize + "\n");


                // SCENARIO 02  Do a query for type= Requirements and for it folder container = rootFolder
                queryParams = new OslcQueryParameters();
                queryParams.SetPrefix("nav=<http://com.ibm.rdm/navigation#>,rdf=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>");
                queryParams.SetWhere("rdf:type=<http://open-services.net/ns/rm#Requirement> and nav:parent=<" + rootFolder + ">");
                query  = new OslcQuery(client, queryCapability, 10, queryParams);
                result = query.Submit();
                processAsDotNetObjects = false;
                resultsSize            = result.GetMembersUrls().Length;
                ProcessPagedQueryResults(result, client, processAsDotNetObjects);
                Console.WriteLine("\n------------------------------\n");
                Console.WriteLine("Number of Results for SCENARIO 02 = " + resultsSize + "\n");

                // SCENARIO 03	Do a query for title
                queryParams = new OslcQueryParameters();
                queryParams.SetPrefix("dcterms=<http://purl.org/dc/terms/>");
                queryParams.SetWhere("dcterms:title=\"Req04\"");
                query                  = new OslcQuery(client, queryCapability, 10, queryParams);
                result                 = query.Submit();
                resultsSize            = result.GetMembersUrls().Length;
                processAsDotNetObjects = false;
                ProcessPagedQueryResults(result, client, processAsDotNetObjects);
                Console.WriteLine("\n------------------------------\n");
                Console.WriteLine("Number of Results for SCENARIO 03 = " + resultsSize + "\n");

                // SCENARIO 04	Do a query for the link that is implemented
                queryParams = new OslcQueryParameters();
                queryParams.SetPrefix("oslc_rm=<http://open-services.net/ns/rm#>");
                queryParams.SetWhere("oslc_rm:implementedBy=<http://google.com>");
                query                  = new OslcQuery(client, queryCapability, 10, queryParams);
                result                 = query.Submit();
                resultsSize            = result.GetMembersUrls().Length;
                processAsDotNetObjects = false;
                ProcessPagedQueryResults(result, client, processAsDotNetObjects);
                Console.WriteLine("\n------------------------------\n");
                Console.WriteLine("Number of Results for SCENARIO 04 = " + resultsSize + "\n");

                // SCENARIO 05	Do a query for the links that is validated
                queryParams = new OslcQueryParameters();
                queryParams.SetPrefix("oslc_rm=<http://open-services.net/ns/rm#>");
                queryParams.SetWhere("oslc_rm:validatedBy in [<http://bancomer.com>,<http://outlook.com>]");
                query                  = new OslcQuery(client, queryCapability, 10, queryParams);
                result                 = query.Submit();
                resultsSize            = result.GetMembersUrls().Length;
                processAsDotNetObjects = false;
                ProcessPagedQueryResults(result, client, processAsDotNetObjects);
                Console.WriteLine("\n------------------------------\n");
                Console.WriteLine("Number of Results for SCENARIO 05 = " + resultsSize + "\n");

                // SCENARIO 06 Do a query for it container folder and for the link that is implemented
                queryParams = new OslcQueryParameters();
                queryParams.SetPrefix("nav=<http://com.ibm.rdm/navigation#>,oslc_rm=<http://open-services.net/ns/rm#>");
                queryParams.SetWhere("nav:parent=<" + rootFolder + "> and oslc_rm:validatedBy=<http://bancomer.com>");
                query                  = new OslcQuery(client, queryCapability, 10, queryParams);
                result                 = query.Submit();
                resultsSize            = result.GetMembersUrls().Length;
                processAsDotNetObjects = false;
                ProcessPagedQueryResults(result, client, processAsDotNetObjects);
                Console.WriteLine("\n------------------------------\n");
                Console.WriteLine("Number of Results for SCENARIO 06 = " + resultsSize + "\n");


                // GET resources from req03 in order edit its values
                getResponse = client.GetResource(req03URL, OslcMediaType.APPLICATION_RDF_XML);
                requirement = getResponse.Content.ReadAsAsync <Requirement>(client.GetFormatters()).Result;
                // Get the eTAG, we need it to update
                String etag = getResponse.Headers.ETag.ToString();
                getResponse.ConsumeContent();
                requirement.SetTitle("My new Title");
                requirement.AddImplementedBy(new Link(new Uri("http://google.com"), "Link created by an Eclipse Lyo user"));

                // Update the requirement with the proper etag
                HttpResponseMessage updateResponse = client.UpdateResource(req03URL,
                                                                           requirement, OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_RDF_XML, etag);

                updateResponse.ConsumeContent();

                /*Do a query in order to see if the requirement have changed*/
                // SCENARIO 07 Do a query for the new title just changed
                queryParams = new OslcQueryParameters();
                queryParams.SetPrefix("dcterms=<http://purl.org/dc/terms/>");
                queryParams.SetWhere("dcterms:title=\"My new Title\"");
                query                  = new OslcQuery(client, queryCapability, 10, queryParams);
                result                 = query.Submit();
                resultsSize            = result.GetMembersUrls().Length;
                processAsDotNetObjects = false;
                ProcessPagedQueryResults(result, client, processAsDotNetObjects);
                Console.WriteLine("\n------------------------------\n");
                Console.WriteLine("Number of Results for SCENARIO 07 = " + resultsSize + "\n");

                // SCENARIO 08	Do a query for implementedBy links
                queryParams = new OslcQueryParameters();
                queryParams.SetPrefix("oslc_rm=<http://open-services.net/ns/rm#>");
                queryParams.SetWhere("oslc_rm:implementedBy=<http://google.com>");
                query                  = new OslcQuery(client, queryCapability, 10, queryParams);
                result                 = query.Submit();
                resultsSize            = result.GetMembersUrls().Length;
                processAsDotNetObjects = false;
                ProcessPagedQueryResults(result, client, processAsDotNetObjects);
                Console.WriteLine("\n------------------------------\n");
                Console.WriteLine("Number of Results for SCENARIO 08 = " + resultsSize + "\n");
            } catch (RootServicesException re) {
                logger.Error("Unable to access the Jazz rootservices document at: " + webContextUrl + "/rootservices", re);
            } catch (Exception e) {
                logger.Error(e.Message, e);
            }
        }
Example #9
0
        /// <summary>
        /// Login to the RQM server and perform some OSLC actions
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            CommandLineDictionary cmd = CommandLineDictionary.FromArguments(args);

            if (!ValidateOptions(cmd))
            {
                logger.Error("Syntax:  /url=https://<server>:port/<context>/ /user=<user> /password=<password> /project=\"<project_area>\"");
                logger.Error("Example: /url=https://exmple.com:9443/qm /user=ADMIN /password=ADMIN /project=\"JKE Banking (Quality Management)\"");
                return;
            }

            String webContextUrl = cmd["url"];
            String user          = cmd["user"];
            String passwd        = cmd["password"];
            String projectArea   = cmd["project"];

            try {
                //STEP 1: Initialize a Jazz rootservices helper and indicate we're looking for the QualityManagement catalog
                //RQM contains both Quality and Change Management providers, so need to look for QM specifically
                JazzRootServicesHelper helper = new JazzRootServicesHelper(webContextUrl, OSLCConstants.OSLC_QM_V2);

                //STEP 2: Create a new Form Auth client with the supplied user/password
                JazzFormAuthClient client = helper.InitFormClient(user, passwd);

                //STEP 3: Login in to Jazz Server
                if (client.FormLogin() == HttpStatusCode.OK)
                {
                    //STEP 4: Get the URL of the OSLC QualityManagement catalog
                    String catalogUrl = helper.GetCatalogUrl();

                    //STEP 5: Find the OSLC Service Provider for the project area we want to work with
                    String serviceProviderUrl = client.LookupServiceProviderUrl(catalogUrl, projectArea);

                    //STEP 6: Get the Query Capabilities URL so that we can run some OSLC queries
                    String queryCapability = client.LookupQueryCapability(serviceProviderUrl,
                                                                          OSLCConstants.OSLC_QM_V2,
                                                                          OSLCConstants.QM_TEST_RESULT_QUERY);

                    //SCENARIO A: Run a query for all TestResults with a status of passed with OSLC paging of 10 items per
                    //page turned on and list the members of the result
                    OslcQueryParameters queryParams = new OslcQueryParameters();
                    queryParams.SetWhere("oslc_qm:status=\"com.ibm.rqm.execution.common.state.passed\"");
                    OslcQuery query = new OslcQuery(client, queryCapability, 10, queryParams);

                    OslcQueryResult result = query.Submit();

                    bool processAsDotNetObjects = true;
                    ProcessPagedQueryResults(result, client, processAsDotNetObjects);

                    Console.WriteLine("\n------------------------------\n");

                    //SCENARIO B:  Run a query for a specific TestResult selecting only certain
                    //attributes and then print it as raw XML.  Change the dcterms:title below to match a
                    //real TestResult in your RQM project area
                    OslcQueryParameters queryParams2 = new OslcQueryParameters();
                    queryParams2.SetWhere("dcterms:title=\"Consistent_display_of_currency_Firefox_DB2_WAS_Windows_S1\"");
                    queryParams2.SetSelect("dcterms:identifier,dcterms:title,dcterms:creator,dcterms:created,oslc_qm:status");
                    OslcQuery query2 = new OslcQuery(client, queryCapability, queryParams2);

                    OslcQueryResult     result2     = query2.Submit();
                    HttpResponseMessage rawResponse = result2.GetRawResponse();
                    ProcessRawResponse(rawResponse);
                    rawResponse.ConsumeContent();

                    //SCENARIO C:  RQM TestCase creation and update
                    TestCase testcase = new TestCase();
                    testcase.SetTitle("Accessibility verification using a screen reader");
                    testcase.SetDescription("This test case uses a screen reader application to ensure that the web browser content fully complies with accessibility standards");
                    testcase.AddTestsChangeRequest(new Link(new Uri("http://cmprovider/changerequest/1"), "Implement accessibility in Pet Store application"));

                    //Get the Creation Factory URL for test cases so that we can create a test case
                    String testcaseCreation = client.LookupCreationFactory(
                        serviceProviderUrl, OSLCConstants.OSLC_QM_V2,
                        testcase.GetRdfTypes()[0].ToString());

                    //Create the test case
                    HttpResponseMessage creationResponse = client.CreateResource(
                        testcaseCreation, testcase,
                        OslcMediaType.APPLICATION_RDF_XML);
                    creationResponse.ConsumeContent();
                    String testcaseLocation = creationResponse.Headers.Location.ToString();
                    Console.WriteLine("Test Case created a location " + testcaseLocation);

                    //Get the test case from the service provider and update its title property
                    testcase = client.GetResource(testcaseLocation,
                                                  OslcMediaType.APPLICATION_RDF_XML).Content.ReadAsAsync <TestCase>(client.GetFormatters()).Result;
                    testcase.SetTitle(testcase.GetTitle() + " (updated)");

                    //Create a partial update URL so that only the title will be updated.
                    //Assuming (for readability) that the test case URL does not already contain a '?'
                    String updateUrl = testcase.GetAbout() + "?oslc.properties=dcterms:title";

                    //Update the test case at the service provider
                    client.UpdateResource(updateUrl, testcase,
                                          OslcMediaType.APPLICATION_RDF_XML).ConsumeContent();
                }
            } catch (RootServicesException re) {
                logger.Error("Unable to access the Jazz rootservices document at: " + webContextUrl + "/rootservices", re);
            } catch (Exception e) {
                logger.Error(e.Message, e);
            }
        }
Example #10
0
        public static void Main()
        {
            string productName             = "Daisy_Tobi";
            string tobiAppRefProviderToken = "TobiAppRefProvider";

            bool firstInstance;
            var  theMutex = new Mutex(false, "Local\\" + productName, out firstInstance);

            try
            {
                string[] appParamters = null;

                bool clickOnce = ApplicationDeployment.IsNetworkDeployed;
                if (clickOnce)
                {
                    appParamters = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData;
                }
                else
                {
                    appParamters = Environment.GetCommandLineArgs();
                }
                bool hasParameters = appParamters != null &&
                                     (clickOnce ? appParamters.Length > 0
                                     : appParamters.Length > 1);

                string filePath = "";

                if (hasParameters)
                {
                    if (clickOnce)
                    {
                        try
                        {
                            filePath = new Uri(appParamters[0]).LocalPath;
                        }
                        catch
                        {
                            filePath = "";
                            MessageBox.Show("CANNOT PARSE URI: " + appParamters[0]);
                        }
                    }
                    else
                    {
                        try
                        {
                            //Tobi.exe /verbose /debuglevel=3
                            var dict = CommandLineDictionary.FromArguments(appParamters.Skip(1), '/', '=');

                            //bool verbose = d.ContainsKey("verbose");
                            //int testId = Int32.Parse(d["debuglevel"]);

                            string open;
                            dict.TryGetValue("open", out open);

                            if (!string.IsNullOrEmpty(open))
                            {
                                filePath = open;
                            }
                        }
                        catch
                        {
                            filePath = appParamters[1];
                        }
                    }
                }

                if (firstInstance)
                {
                    IChannel theChannel = new System.Runtime.Remoting.Channels.Ipc.IpcChannel(productName);
                    try
                    {
                        ChannelServices.RegisterChannel(theChannel, false);

                        var app = new App();
                        app.InitializeComponent();

                        DebugFix.Assert(app == Application.Current);

                        RemotingServices.Marshal(new AppRefProvider(app
                                                                    //, app.Dispatcher
                                                                    ), tobiAppRefProviderToken, typeof(AppRefProvider));

                        if (!string.IsNullOrEmpty(filePath))
                        {
                            app.ParameterOpenFilePath = filePath;
                        }

                        app.Run();
                    }
                    catch (SocketException ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        ChannelServices.UnregisterChannel(theChannel);
                    }
                }
                else
                {
                    if (
#if DEBUG
                        true ||
#endif //DEBUG
                        !string.IsNullOrEmpty(filePath))
                    {
#if DEBUG
                        MessageBox.Show("DEBUG: Tobi instance already running >> " + filePath);
#endif //DEBUG

                        try
                        {
                            AppRefProvider appRefProvider =
                                (AppRefProvider)RemotingServices.Connect(
                                    typeof(AppRefProvider),
                                    "ipc://" + productName + "/" + tobiAppRefProviderToken);

                            appRefProvider.TryOpenFile(filePath);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
            finally
            {
                theMutex.Close();
            }
        }
Example #11
0
        /// <summary>
        /// Login to the RTC server and perform some OSLC actions
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            CommandLineDictionary cmd = CommandLineDictionary.FromArguments(args);

            if (!ValidateOptions(cmd))
            {
                logger.Error("Syntax:  /url=https://<server>:port/<context>/ /user=<user> /password=<password> /project=\"<project_area>\"");
                logger.Error("Example: /url=https://exmple.com:9443/ccm /user=ADMIN /password=ADMIN /project=\"JKE Banking (Change Management)\"");
                return;
            }

            String webContextUrl = cmd["url"];
            String user          = cmd["user"];
            String passwd        = cmd["password"];
            String projectArea   = cmd["project"];

            try {
                //STEP 1: Initialize a Jazz rootservices helper and indicate we're looking for the ChangeManagement catalog
                //RTC contains a service provider for CM and SCM, so we need to indicate our interest in CM
                JazzRootServicesHelper helper = new JazzRootServicesHelper(webContextUrl, OSLCConstants.OSLC_CM_V2);

                //STEP 2: Create a new Form Auth client with the supplied user/password
                JazzFormAuthClient client = helper.InitFormClient(user, passwd);

                //STEP 3: Login in to Jazz Server
                if (client.FormLogin() == HttpStatusCode.OK)
                {
                    //STEP 4: Get the URL of the OSLC ChangeManagement catalog
                    String catalogUrl = helper.GetCatalogUrl();

                    //STEP 5: Find the OSLC Service Provider for the project area we want to work with
                    String serviceProviderUrl = client.LookupServiceProviderUrl(catalogUrl, projectArea);

                    //STEP 6: Get the Query Capabilities URL so that we can run some OSLC queries
                    String queryCapability = client.LookupQueryCapability(serviceProviderUrl,
                                                                          OSLCConstants.OSLC_CM_V2,
                                                                          OSLCConstants.CM_CHANGE_REQUEST_TYPE);

                    //SCENARIO A: Run a query for all open ChangeRequests with OSLC paging of 10 items per
                    //page turned on and list the members of the result
                    OslcQueryParameters queryParams = new OslcQueryParameters();
                    queryParams.SetWhere("oslc_cm:closed=false");
                    queryParams.SetSelect("dcterms:identifier,dcterms:title,oslc_cm:status");
                    OslcQuery query = new OslcQuery(client, queryCapability, 10, queryParams);

                    OslcQueryResult result = query.Submit();

                    bool processAsJavaObjects = true;
                    ProcessPagedQueryResults(result, client, processAsJavaObjects);

                    Console.WriteLine("\n------------------------------\n");

                    //SCENARIO B:  Run a query for a specific ChangeRequest selecting only certain
                    //attributes and then print it as raw XML.  Change the dcterms:identifier below to match a
                    //real workitem in your RTC project area
                    OslcQueryParameters queryParams2 = new OslcQueryParameters();
                    queryParams2.SetWhere("dcterms:identifier=\"10\"");
                    queryParams2.SetSelect("dcterms:identifier,dcterms:title,dcterms:creator,dcterms:created,oslc_cm:status");
                    OslcQuery query2 = new OslcQuery(client, queryCapability, queryParams2);

                    OslcQueryResult     result2     = query2.Submit();
                    HttpResponseMessage rawResponse = result2.GetRawResponse();
                    ProcessRawResponse(rawResponse);
                    rawResponse.ConsumeContent();

                    //SCENARIO C:  RTC Workitem creation and update
                    ChangeRequest changeRequest = new ChangeRequest();
                    changeRequest.SetTitle("Implement accessibility in Pet Store application");
                    changeRequest.SetDescription("Image elements must provide a description in the 'alt' attribute for consumption by screen readers.");
                    changeRequest.AddTestedByTestCase(new Link(new Uri("http://qmprovider/testcase/1"), "Accessibility verification using a screen reader"));
                    changeRequest.AddDctermsType("task");

                    //Get the Creation Factory URL for change requests so that we can create one
                    String changeRequestCreation = client.LookupCreationFactory(
                        serviceProviderUrl, OSLCConstants.OSLC_CM_V2,
                        changeRequest.GetRdfTypes()[0].ToString());

                    //Create the change request
                    HttpResponseMessage creationResponse = client.CreateResource(
                        changeRequestCreation, changeRequest,
                        OslcMediaType.APPLICATION_RDF_XML,
                        OslcMediaType.APPLICATION_RDF_XML);

                    if (creationResponse.StatusCode != HttpStatusCode.Created)
                    {
                        String errorString = creationResponse.Content.ReadAsStringAsync().Result;
                        Console.Error.WriteLine("Failed to create change request: " + errorString);
                        return;
                    }

                    String changeRequestLocation = creationResponse.Headers.Location.ToString();
                    creationResponse.ConsumeContent();
                    Console.WriteLine("Change Request created a location " + changeRequestLocation);


                    //Get the change request from the service provider and update its title property
                    changeRequest = client.GetResource(changeRequestLocation,
                                                       OslcMediaType.APPLICATION_RDF_XML).Content.ReadAsAsync <ChangeRequest>(client.GetFormatters()).Result;
                    changeRequest.SetTitle(changeRequest.GetTitle() + " (updated)");

                    //Create a partial update URL so that only the title will be updated.
                    //Assuming (for readability) that the change request URL does not already contain a '?'
                    String updateUrl = changeRequest.GetAbout() + "?oslc.properties=dcterms:title";

                    //Update the change request at the service provider
                    HttpResponseMessage updateResponse = client.UpdateResource(
                        updateUrl, changeRequest,
                        OslcMediaType.APPLICATION_RDF_XML,
                        OslcMediaType.APPLICATION_RDF_XML);

                    updateResponse.ConsumeContent();
                }
            } catch (RootServicesException re) {
                logger.Error("Unable to access the Jazz rootservices document at: " + webContextUrl + "/rootservices", re);
            } catch (Exception e) {
                logger.Error(e.Message, e);
            }
        }
Example #12
0
        public static void ProcessCommandLineArgs(string[] args)
        {
            var cmds = CommandLineDictionary.FromArguments(args, '-', '=');
            var arg  = "";

            if ((cmds.Count == 0) || cmds.TryGetValue("h", out arg) || cmds.TryGetValue("help", out arg))
            {
                Console.WriteLine(@"

    ++++++++++++++++++++++++++++++++++++++
    +++++++ RMS.Prototype.NGFM.CLI +++++++
    ++++++++++++++++++++++++++++++++++++++

    Usage:
        RMS.Prototype.NGFM.CLI.exe
            -d=<string>     - directory or file path with input protobuf-format files
            -gu=<string>    - directory or file path with GU input csv files
            [-s=<string>]   - SQL server name, default '(local)'
            [-log]          - write messages to log-file in 'Log' sub directory
            [-h] or [-help] - show this helper 
            [-singlecore]          - execute in single Thread

    Command line example (single thread):
        RMS.Prototype.NGFM.CLI.exe -d='D:\NGFM_work\NGFM_CLI_testdata' -gu='D:\NGFM_work\NGFM_CLI_testdata'");

                IsInitialized = false;
                return;
            }

            #region Getting command line parameters

            //Input directory or input file name:
            InputFile = null;

            if (cmds.TryGetValue("d", out arg))
            {
                FileAttributes attr = File.GetAttributes(arg);
                if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    InputDirectory = arg;
                }
                else
                {
                    InputDirectory = Path.GetDirectoryName(arg);
                    InputFile      = arg;
                }
                OutputDirectory    = IOUtilities.CreateSubdirectory(InputDirectory, OutputSubdirectory);
                OutputLogDirectory = IOUtilities.CreateSubdirectory(InputDirectory, OutputLogSubdirectory);
                GUInputDirectory   = IOUtilities.CreateSubdirectory(InputDirectory, GUInputSubdirectory);
                GUInputFile        = "*.csv";
            }

            if (cmds.TryGetValue("gu", out arg))
            {
                FileAttributes attr = File.GetAttributes(arg);
                if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    GUInputDirectory = arg;
                }
                else
                {
                    GUInputDirectory = Path.GetDirectoryName(arg);
                    GUInputFile      = Path.GetFileName(arg);
                }
            }

            //-----------------------------------

            #endregion

            IsInitialized = true;
        }