예제 #1
0
        private void adapterListView_PreviewMouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            try
            {
                RemoteAdapter adapter = UIData.AdapterCollection.ElementAt(this.adapterListView.SelectedIndex);


                System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();

                stringBuilder.AppendLine("Name" + " : " + adapter.Description.Name);
                stringBuilder.AppendLine("ID" + " : " + adapter.Description.ID);
                stringBuilder.AppendLine("Language" + " : " + adapter.Description.Language);


                if (adapter.Description.Parameters != null && adapter.Description.Parameters.Count > 0)
                {
                    stringBuilder.AppendLine("Parameters:");

                    foreach (var entry in adapter.Description.Parameters)
                    {
                        stringBuilder.AppendLine(entry.Name + " , " + entry.Type + " , required:" + entry.Required);
                    }
                }

                System.Windows.MessageBox.Show(stringBuilder.ToString(), adapter.Name);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
예제 #2
0
        public async Task TestFetchingAndSavingDocumentsWithCaseInsensitiveCheck()
        {
            var testName      = "TestFetchingAndSavingDocumentsWithCaseInsensitiveCheck";
            var testInputPath = TestHelper.GetInputFolderPath(testsSubpath, nameof(TestFetchingAndSavingDocumentsWithCaseInsensitiveCheck));

            CdmCorpusDefinition corpus = new CdmCorpusDefinition();

            corpus.SetEventCallback(new EventCallback {
                Invoke = CommonDataModelLoader.ConsoleStatusReport
            }, CdmStatusLevel.Warning);
            var localAdapter = new LocalAdapter(testInputPath);

            corpus.Storage.Mount("local", localAdapter);
            var remoteAdapter = new RemoteAdapter
            {
                Hosts = new Dictionary <string, string>
                {
                    { "contoso", "http://contoso.com" }
                }
            };

            corpus.Storage.Mount("remote", remoteAdapter);
            corpus.Storage.DefaultNamespace = "local";
            corpus.Storage.Unmount("cdm");

            var manifest = await corpus.FetchObjectAsync <CdmManifestDefinition>("empty.Manifest.cdm.json");

            var manifestFromModelJson = await corpus.FetchObjectAsync <CdmManifestDefinition>("Model.json");

            // Swap out the adapter for a fake one so that we aren't actually saving files.
            ConcurrentDictionary <string, string> allDocs = new ConcurrentDictionary <string, string>();
            var testAdapter = new TestStorageAdapter(allDocs);

            corpus.Storage.SetAdapter("local", testAdapter);

            var newManifestName = "empty.MANIFEST.CDM.json";
            await manifest.SaveAsAsync(newManifestName, true);

            // Verify that manifest persistence was called by comparing the saved document to the original manifest.
            var serializedManifest     = allDocs[$"/{newManifestName}"];
            var expectedOutputManifest = TestHelper.GetExpectedOutputFileContent(testsSubpath, testName, manifest.Name);

            TestHelper.AssertSameObjectWasSerialized(expectedOutputManifest, serializedManifest);

            var newManifestFromModelJsonName = "MODEL.json";
            await manifestFromModelJson.SaveAsAsync(newManifestFromModelJsonName, true);

            // Verify that model.json persistence was called by comparing the saved document to the original model.json.
            serializedManifest     = allDocs[$"/{newManifestFromModelJsonName}"];
            expectedOutputManifest = TestHelper.GetExpectedOutputFileContent(testsSubpath, testName, manifestFromModelJson.Name);
            TestHelper.AssertSameObjectWasSerialized(expectedOutputManifest, serializedManifest);
        }
예제 #3
0
        /// <summary>
        /// Fetches the lodable MMUs from the adapters
        /// </summary>
        private void UpdateLoadableMMUs()
        {
            //Create a dictionary which holds the MMU Descriptions and the corresponding addresses
            Dictionary <MMUDescription, List <MIPAddress> > availableMMUs = new Dictionary <MMUDescription, List <MIPAddress> >();

            //Iterate over each adapter (do use for instead for-each due to possible changes of list)
            for (int i = RuntimeData.AdapterInstances.Count - 1; i >= 0; i--)
            {
                RemoteAdapter adapter = RuntimeData.AdapterInstances.Values.ElementAt(i);

                List <MMUDescription> mmuDescriptions = new List <MMUDescription>();
                try
                {
                    mmuDescriptions = adapter.GetLoadableMMUs("default");
                }
                catch (Exception e)
                {
                    Console.WriteLine("Problem receiving loadable MMUs: " + e.Message);
                }

                //Check if MMU is already available and add to dictionary
                foreach (MMUDescription description in mmuDescriptions)
                {
                    MMUDescription match = availableMMUs.Keys.ToList().Find(s => s.ID == description.ID && s.Name == description.Name);

                    if (match == null)
                    {
                        availableMMUs.Add(description, new List <MIPAddress>());
                        match = description;
                    }

                    availableMMUs[match].Add(new MIPAddress(adapter.Address, adapter.Port));
                }
            }

            //Update the MMU descriptions
            RuntimeData.MMUDescriptions.Clear();
            foreach (MMUDescription description in availableMMUs.Keys)
            {
                RuntimeData.MMUDescriptions.TryAdd(description.ID, description);
            }

            //Update the MMU collection in ui thread
            UIData.SetMMUDescriptions(availableMMUs.Keys.ToList());
        }
        static void ConfigureRemoteAdapter()
        {
            // Get the list of hosts from the user.
            Dictionary <string, string> hosts = new Dictionary <string, string>();

            Console.WriteLine("The RemoteAdapter contains a dictionary of hosts. The mapping is from a key to a host. (Ex. { \"contoso\": \"http://contoso.com\" }");
            // The RemoteAdapter can have multiple hosts, so keep asking for values until the user is done.
            while (true)
            {
                Console.WriteLine("Enter the key for the host, or press [enter] if you're done adding hosts. (Ex. \"contoso\").");
                string key = Console.ReadLine().Trim();
                if (string.IsNullOrWhiteSpace(key))
                {
                    // The user doesn't have any more hosts to add.
                    break;
                }

                Console.WriteLine("Enter the host. (Ex. \"http://contoso.com\").");
                string path;
                while (true)
                {
                    path = Console.ReadLine().Trim();
                    if (string.IsNullOrWhiteSpace(path))
                    {
                        Console.WriteLine("Enter the host.");
                    }
                    else
                    {
                        break;
                    }
                }
                hosts.Add(key, path);
            }

            // Default values for the optional parameters used by the remote adapter.
            string timeout         = "2000";
            string maximumTimeout  = "10000";
            string numberOfRetries = "2";

            // Ask the user if optional parameters should be configured, or if defaults should just be used.
            if (ConfigureOptionalParameters("RemoteAdapter"))
            {
                // Configure optional parameters.
                timeout         = GetOptionalParameterValueFromUser("timeout", "RemoteAdapter", timeout /* this is just to show what the value should look like. */);
                maximumTimeout  = GetOptionalParameterValueFromUser("maximum timeout", "RemoteAdapter", maximumTimeout);
                numberOfRetries = GetOptionalParameterValueFromUser("number of retries", "RemoteAdapter", numberOfRetries);
            }

            // Create a remote adapter with the values given by the user.
            var adapter = new RemoteAdapter()
            {
                Timeout         = TimeSpan.FromMilliseconds(int.Parse(timeout)),
                MaximumTimeout  = TimeSpan.FromMilliseconds(int.Parse(maximumTimeout)),
                NumberOfRetries = int.Parse(numberOfRetries),
                Hosts           = hosts
                                  // WaitTimeCallback is another optional parameter and can also be configured here.
            };

            // List the newly configured adapter's properties.
            Console.WriteLine("\nRemoteAdapter configured. Properties of this RemoteAdapter are:");
            // Print the key-value pair for the hosts.
            Console.WriteLine("  Hosts: ");
            foreach (KeyValuePair <string, string> pair in adapter.Hosts)
            {
                Console.WriteLine($"    {{ \"{pair.Key}\": \"{pair.Value}\" }}");
            }
            Console.WriteLine("  Timeout: " + adapter.Timeout.Value.TotalMilliseconds);
            Console.WriteLine("  MaximumTimeout: " + adapter.MaximumTimeout.Value.TotalMilliseconds);
            Console.WriteLine("  NumberOfRetries: " + adapter.NumberOfRetries);
            Console.WriteLine();
        }
예제 #5
0
 /// <summary>
 /// Method is called if a remote adapter switches to inactive
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnRemoteInactive(object sender, RemoteAdapter e)
 {
     UIData.SynchronizeAdapters();
 }
예제 #6
0
 private void RegisterService_OnAdapterRegistered(object sender, RemoteAdapter e)
 {
     e.OnInactive += OnRemoteInactive;
     UIData.SynchronizeAdapters();
 }
예제 #7
0
 private static void RegisterService_OnAdapterRegistered(object sender, RemoteAdapter e)
 {
     System.Console.WriteLine("Adapter registered: " + e.Name);
 }