예제 #1
0
            public void CloneResultsInClonedDocument()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary();

                initialMetadata.Add("Foo", "Bar");
                DocumentFactory documentFactory = new DocumentFactory(initialMetadata);
                CustomDocumentFactory <TestDocument> customDocumentFactory = new CustomDocumentFactory <TestDocument>(documentFactory);
                TestExecutionContext context        = new TestExecutionContext();
                CustomDocument       sourceDocument = (CustomDocument)customDocumentFactory.GetDocument(context);

                // When
                IDocument resultDocument = customDocumentFactory.GetDocument(
                    context,
                    sourceDocument,
                    new Dictionary <string, object>
                {
                    { "Baz", "Bat" }
                });

                // Then
                CollectionAssert.AreEquivalent(
                    new Dictionary <string, object>
                {
                    { "Foo", "Bar" }
                },
                    sourceDocument);
                CollectionAssert.AreEquivalent(
                    new Dictionary <string, object>
                {
                    { "Foo", "Bar" },
                    { "Baz", "Bat" }
                },
                    resultDocument);
            }
            public void ReturnsMetadataWithoutSettings()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary();

                initialMetadata.Add("A", "a");
                Document document = new Document(initialMetadata);
                Document cloned   = new Document(document, new MetadataItems {
                    { "B", "b" }
                });

                // When
                string initialA = document.String("A");
                string initialB = document.String("B");
                string clonedA  = cloned.String("A");
                string clonedB  = cloned.String("B");
                string withoutA = cloned.WithoutSettings.String("A");
                string withoutB = cloned.WithoutSettings.String("B");

                // Then
                Assert.AreEqual("a", initialA);
                Assert.IsNull(initialB);
                Assert.AreEqual("a", clonedA);
                Assert.AreEqual("b", clonedB);
                Assert.IsNull(withoutA);
                Assert.AreEqual("b", withoutB);
            }
예제 #3
0
            // We need to build the tree from the bottom up so that the children don't have to be lazy
            // This also sorts the children once they're created
            public async Task GenerateOutputDocumentsAsync(CreateTree tree, IExecutionContext context)
            {
                // Recursively build output documents for children
                foreach (TreeNode child in Children)
                {
                    await child.GenerateOutputDocumentsAsync(tree, context);
                }

                // We're done if we've already created the output document
                if (OutputDocument != null)
                {
                    return;
                }

                // Sort the child documents since they're created now
                Children.Sort((x, y) => tree._sort(x.OutputDocument, y.OutputDocument));

                // Create this output document
                MetadataDictionary metadata = new MetadataDictionary();

                if (tree._childrenKey != null)
                {
                    metadata.Add(tree._childrenKey, Children.Select(x => x.OutputDocument).ToImmutableArray());
                }
                if (tree._treePathKey != null)
                {
                    metadata.Add(tree._treePathKey, TreePath);
                }
                if (InputDocument == null)
                {
                    // There's no input document for this node so we need to make a placeholder
                    metadata.Add(Keys.TreePlaceholder, true);
                    OutputDocument = await tree._placeholderFactory(TreePath, metadata, context) ?? context.CreateDocument(metadata);
                }
                else
                {
                    OutputDocument = InputDocument.Clone(metadata);
                }
            }
예제 #4
0
            public void GetsInitialDocumentWithInitialMetadata()
            {
                // Given
                MetadataDictionary initialMetadata = new MetadataDictionary();

                initialMetadata.Add("Foo", "Bar");
                DocumentFactory documentFactory = new DocumentFactory(initialMetadata);
                CustomDocumentFactory <TestDocument> customDocumentFactory = new CustomDocumentFactory <TestDocument>(documentFactory);
                IExecutionContext context = Substitute.For <IExecutionContext>();

                // When
                IDocument resultDocument = customDocumentFactory.GetDocument(context);

                // Then
                Assert.IsInstanceOf <TestDocument>(resultDocument);
                CollectionAssert.AreEqual(new Dictionary <string, object>
                {
                    { "Foo", "Bar" }
                }, resultDocument);
            }
        protected override void ProcessRecord()
        {
            var taggedAudioFile = new TaggedAudioFile(AudioFile);

            if (Key != null && Key.Length > 0)
            {
                var result = new MetadataDictionary();
                foreach (string key in Key)
                {
                    string value;
                    if (taggedAudioFile.Metadata.TryGetValue(key, out value))
                    {
                        result.Add(key, value);
                    }
                }
                WriteObject(result);
            }
            else
            {
                WriteObject(taggedAudioFile.Metadata);
            }
        }
예제 #6
0
        static int Main(string[] args)
        {
            // Use this key.
            string keyId = "HVzG52Kj3to";

            // Get the user's home path and password persistor from the environment.
            String homePath = Environment.GetEnvironmentVariable("USERPROFILE");

            String persistorPassword = Environment.GetEnvironmentVariable("IONIC_PERSISTOR_PASSWORD");

            if (persistorPassword == null || persistorPassword.Length == 0)
            {
                Console.WriteLine("Please provide the persistor password as env variable: IONIC_PERSISTOR_PASSWORD");
                WaitForInput();
                Environment.Exit(1);
            }

            // Create an agent object to talk to Ionic.
            Agent agent = new Agent();

            // Create a password persistor for agent initialization.
            try
            {
                DeviceProfilePersistorPassword persistor = new DeviceProfilePersistorPassword();
                persistor.FilePath = homePath + "\\.ionicsecurity\\profiles.pw";
                persistor.Password = persistorPassword;

                agent.SetMetadata(Agent.MetaApplicationName, "SetRequestMetadata Sample");
                agent.Initialize(persistor);
            }
            catch (SdkException sdkExp)
            {
                Console.WriteLine("Agent initialization error: " + sdkExp.Message);
                WaitForInput();
                Environment.Exit(1);
            }

            // Create some request metadata.
            MetadataDictionary requestMetadata = new MetadataDictionary();

            requestMetadata.Add("application-status", "active");

            // Fetch a single key from the agent.
            GetKeysResponse.Key key = null;
            try
            {
                key = agent.GetKey(keyId, requestMetadata).Keys[0];
            }
            catch (SdkException sdkExp)
            {
                Console.WriteLine("Error fetching key {0}: {1}", keyId, sdkExp.Message);
                WaitForInput();
                Environment.Exit(1);
            }

            Console.WriteLine("Key ID             : " + key.Id);
            Console.WriteLine("Key Bytes          : " + BitConverter.ToString(key.KeyBytes).Replace("-", String.Empty));
            Console.WriteLine("Fixed Attributes   : " + JsonDump(key.Attributes));
            Console.WriteLine("Mutable Attributes : " + JsonDump(key.MutableAttributes));

            WaitForInput();
            return(0);
        }