private static void InitLayerMappings(ref LayerConfiguration configuration, int layerCount) { var sceneObjects = Utilities.GetAllGameObjectsInScene(); List <GameObject> currentObjectList; configuration._objectLayerMappings = new Dictionary <Layer, List <GameObject> >(layerCount); for (int i = 0; i < sceneObjects.Length; ++i) { var sceneObject = sceneObjects[i]; var objectLayer = FindLayerForUnityLayer(sceneObject.layer); Debug.AssertFormat(objectLayer != null, "Unrecognized layer {0} for scene object {1}", objectLayer, sceneObject.layer); if (configuration._objectLayerMappings.TryGetValue(objectLayer, out currentObjectList)) { // If we already have a list for this layer going, add to it. currentObjectList.Add(sceneObject); } else { // If we don't have an entry for this layer, // create a new one and add the object. currentObjectList = new List <GameObject>(1); currentObjectList.Add(sceneObject); configuration._objectLayerMappings.Add(objectLayer, currentObjectList); } } }
public void Initialize(string layerYaml) { var yaml = YamlParser.ParseHelper(layerYaml); var deserializer = new DeserializerBuilder().Build(); LayerConfiguration = deserializer.Deserialize <LayerConfiguration>(yaml); }
private static LayerEntry DefaultLayerEntry(SystemPath source, AbsoluteUnixPath destination) { return(new LayerEntry( source, destination, LayerConfiguration.DefaultFilePermissionsProvider(source, destination), LayerConfiguration.DefaultModifiedTime)); }
public static void AddActiveScene() { var configuration = GetConfigurationForScene(SceneManagerEditor.CurrentScene); LayerConfiguration.Init(ref configuration); Debug.LogFormat("LayerManager: Initializing configuration for current scene {0}", SceneManagerEditor.CurrentScene.Name); }
public async Task TestBuildAsync() { SystemPath layerDirectory = Paths.Get(TestResources.GetResource("core/layer").ToURI()); SystemPath blobA = Paths.Get(TestResources.GetResource("core/blobA").ToURI()); ReproducibleLayerBuilder layerBuilder = new ReproducibleLayerBuilder( LayerConfiguration.CreateBuilder() .AddEntryRecursive( layerDirectory, AbsoluteUnixPath.Get("/extract/here/apple/layer")) .AddEntry(blobA, AbsoluteUnixPath.Get("/extract/here/apple/blobA")) .AddEntry(blobA, AbsoluteUnixPath.Get("/extract/here/banana/blobA")) .Build() .LayerEntries); // Writes the layer tar to a temporary file. IBlob unwrittenBlob = layerBuilder.Build(); SystemPath temporaryFile = temporaryFolder.NewFile().ToPath(); using (Stream temporaryFileOutputStream = new BufferedStream(Files.NewOutputStream(temporaryFile))) { await unwrittenBlob.WriteToAsync(temporaryFileOutputStream).ConfigureAwait(false); } // Reads the file back. TarInputStream tarArchiveInputStream = new TarInputStream(Files.NewInputStream(temporaryFile)); VerifyNextTarArchiveEntryIsDirectory(tarArchiveInputStream, "extract/"); VerifyNextTarArchiveEntryIsDirectory(tarArchiveInputStream, "extract/here/"); VerifyNextTarArchiveEntryIsDirectory(tarArchiveInputStream, "extract/here/apple/"); VerifyNextTarArchiveEntry(tarArchiveInputStream, "extract/here/apple/blobA", blobA); VerifyNextTarArchiveEntryIsDirectory(tarArchiveInputStream, "extract/here/apple/layer/"); VerifyNextTarArchiveEntryIsDirectory(tarArchiveInputStream, "extract/here/apple/layer/a/"); VerifyNextTarArchiveEntryIsDirectory(tarArchiveInputStream, "extract/here/apple/layer/a/b/"); VerifyNextTarArchiveEntry( tarArchiveInputStream, "extract/here/apple/layer/a/b/bar", Paths.Get(TestResources.GetResource("core/layer/a/b/bar").ToURI())); VerifyNextTarArchiveEntryIsDirectory(tarArchiveInputStream, "extract/here/apple/layer/c/"); VerifyNextTarArchiveEntry( tarArchiveInputStream, "extract/here/apple/layer/c/cat", Paths.Get(TestResources.GetResource("core/layer/c/cat").ToURI())); VerifyNextTarArchiveEntry( tarArchiveInputStream, "extract/here/apple/layer/foo", Paths.Get(TestResources.GetResource("core/layer/foo").ToURI())); VerifyNextTarArchiveEntryIsDirectory(tarArchiveInputStream, "extract/here/banana/"); VerifyNextTarArchiveEntry(tarArchiveInputStream, "extract/here/banana/blobA", blobA); }
private BuildAndCacheApplicationLayerStep( IBuildConfiguration buildConfiguration, ProgressEventDispatcher.Factory progressEventDispatcherFactory, string layerType, LayerConfiguration layerConfiguration) { this.buildConfiguration = buildConfiguration; this.progressEventDispatcherFactory = progressEventDispatcherFactory; this.layerType = layerType; this.layerConfiguration = layerConfiguration; listenableFuture = Task.Run(CallAsync); }
private static LayerConfiguration GetConfigurationForScene(SceneWrapper scene) { LayerConfiguration outConfiguration = null; if (LayerManager.IsEmpty()) { LayerManager.Init(); } if (scene.IsNull || !_layerConfigurations.TryGetValue(scene, out outConfiguration)) { Debug.LogErrorFormat("LayerManager: Unable to get configuration for scene {0}", scene.Name); } return(outConfiguration); }
/** * Lists the files in the {@code resourcePath} resources directory and builds a {@link * LayerConfiguration} from those files. */ private static ILayerConfiguration MakeLayerConfiguration( string resourcePath, string pathInContainer) { IEnumerable <SystemPath> fileStream = Files.List(Paths.Get(TestResources.GetResource(resourcePath).ToURI())); { LayerConfiguration.Builder layerConfigurationBuilder = LayerConfiguration.CreateBuilder(); foreach (SystemPath i in fileStream) { ((Func <SystemPath, LayerConfiguration.Builder>)(sourceFile => layerConfigurationBuilder.AddEntry( sourceFile, AbsoluteUnixPath.Get(pathInContainer + sourceFile.GetFileName()))))(i); } return(layerConfigurationBuilder.Build()); } }
public static void Init() { var numScenes = SceneManagerEditor.SceneCount; LayerManager.Clear(); LayerManager._layerConfigurations = new Dictionary <SceneWrapper, LayerConfiguration>(numScenes); for (int i = 0; i < numScenes; ++i) { var configuration = new LayerConfiguration(); _layerConfigurations.Add(SceneManagerEditor.GetSceneAtIndex(i), configuration); } LayerManager.AddActiveScene(); }
private static void InitSceneLayers(ref LayerConfiguration configuration) { configuration._layers = new List <Layer>(); for (int i = 0; i < 32; ++i) { var layerName = LayerMask.LayerToName(i); if (layerName != UNASSIGNED) { var layer = new Layer(i, true, layerName); layer.OnActiveChanged += HandleOnLayerChangeActive; configuration._layers.Add(layer); } } }
public static IForwardLayer Produce(LayerConfiguration config) { switch (config) { case ActivationLayerConfiguration c: return(new ActivationForwardLayer(c.ActivatorType, c.MessageShape)); case ConvolutionLayerConfigurtion c: var layer1 = new ConvolutionForwardLayer( c.MessageShape, c.KernelSize, c.NumberOfKernels); layer1.SetWeights(c.Weights); layer1.SetBiases(c.Biases); return(layer1); case FlattenLayerConfiguration c: return(new FlattenForwardLayer(c.MessageShape)); case DenseLayerConfiguration c: var layer2 = new DenseForwardLayer( c.MessageShape, c.NumberOfNeurons, c.EnableBias); layer2.SetWeights(c.Weights); layer2.SetBiases(c.Biases); return(layer2); case InputLayerConfiguration c: return(new InputForwardLayer(c.MessageShape)); case PoolingLayerConfiguration c: return(new PoolingForwardLayer(c.MessageShape, c.KernelSize)); case SoftmaxLayerConfiguration c: var layer3 = new SoftMaxForwardLayer(c.MessageShape); return(layer3); default: throw new Exception("Config type is not supported"); } }
/** <summary>Finds the location of the sublayers object in the specified configuration; in case no sublayers object is associated to this object, its virtual position is indicated.</summary> <param name="configuration">Configuration context.</param> <returns><code>null</code>, if this layer is outside the specified configuration.</returns> */ private LayersLocation FindLayersLocation( LayerConfiguration configuration ) { /* NOTE: As layers are only weakly tied to configurations, their sublayers have to be sought through the configuration structure tree. */ PdfDirectObject levelLayerObject = null; PdfArray levelObject = configuration.Layers.BaseDataObject; IEnumerator<PdfDirectObject> levelIterator = levelObject.GetEnumerator(); Stack<object[]> levelIterators = new Stack<object[]>(); PdfDirectObject thisObject = BaseObject; PdfDirectObject currentLayerObject = null; while(true) { if(!levelIterator.MoveNext()) { if(levelIterators.Count == 0) break; object[] levelItems = levelIterators.Pop(); levelObject = (PdfArray)levelItems[0]; levelIterator = (IEnumerator<PdfDirectObject>)levelItems[1]; levelLayerObject = (PdfDirectObject)levelItems[2]; currentLayerObject = null; } else { PdfDirectObject nodeObject = levelIterator.Current; PdfDataObject nodeDataObject = PdfObject.Resolve(nodeObject); if(nodeDataObject is PdfDictionary) { if(nodeObject.Equals(thisObject)) /* NOTE: Sublayers are expressed as an array immediately following the parent layer node. */ return new LayersLocation(levelLayerObject, levelObject, levelObject.IndexOf(thisObject) + 1, levelIterators); currentLayerObject = nodeObject; } else if(nodeDataObject is PdfArray) { levelIterators.Push(new object[]{levelObject, levelIterator, levelLayerObject}); levelObject = (PdfArray)nodeDataObject; levelIterator = levelObject.GetEnumerator(); levelLayerObject = currentLayerObject; currentLayerObject = null; } } } return null; }
public void TestBuilder() { const string expectedBaseImageServerUrl = "someserver"; const string expectedBaseImageName = "baseimage"; const string expectedBaseImageTag = "baseimagetag"; const string expectedTargetServerUrl = "someotherserver"; const string expectedTargetImageName = "targetimage"; const string expectedTargetTag = "targettag"; ISet <string> additionalTargetImageTags = ImmutableHashSet.Create("tag1", "tag2", "tag3"); ISet <string> expectedTargetImageTags = ImmutableHashSet.Create("targettag", "tag1", "tag2", "tag3"); IList <CredentialRetriever> credentialRetrievers = new List <CredentialRetriever> { () => Maybe.Of(Credential.From("username", "password")) }; Instant expectedCreationTime = Instant.FromUnixTimeSeconds(10000); IList <string> expectedEntrypoint = new[] { "some", "entrypoint" }; IList <string> expectedProgramArguments = new[] { "arg1", "arg2" }; IDictionary <string, string> expectedEnvironment = ImmutableDic.Of("key", "value"); ImmutableHashSet <Port> expectedExposedPorts = ImmutableHashSet.Create(Port.Tcp(1000), Port.Tcp(2000)); IDictionary <string, string> expectedLabels = ImmutableDic.Of("key1", "value1", "key2", "value2"); const ManifestFormat expectedTargetFormat = ManifestFormat.OCI; SystemPath expectedApplicationLayersCacheDirectory = Paths.Get("application/layers"); SystemPath expectedBaseImageLayersCacheDirectory = Paths.Get("base/image/layers"); IList <ILayerConfiguration> expectedLayerConfigurations = new List <ILayerConfiguration> { LayerConfiguration.CreateBuilder() .AddEntry(Paths.Get("sourceFile"), AbsoluteUnixPath.Get("/path/in/container")) .Build() }; const string expectedCreatedBy = "createdBy"; ImageConfiguration baseImageConfiguration = ImageConfiguration.CreateBuilder( ImageReference.Of( expectedBaseImageServerUrl, expectedBaseImageName, expectedBaseImageTag)) .Build(); ImageConfiguration targetImageConfiguration = ImageConfiguration.CreateBuilder( ImageReference.Of( expectedTargetServerUrl, expectedTargetImageName, expectedTargetTag)) .SetCredentialRetrievers(credentialRetrievers) .Build(); ContainerConfiguration containerConfiguration = ContainerConfiguration.CreateBuilder() .SetCreationTime(expectedCreationTime) .SetEntrypoint(expectedEntrypoint) .SetProgramArguments(expectedProgramArguments) .SetEnvironment(expectedEnvironment) .SetExposedPorts(expectedExposedPorts) .SetLabels(expectedLabels) .Build(); BuildConfiguration.Builder buildConfigurationBuilder = BuildConfiguration.CreateBuilder() .SetBaseImageConfiguration(baseImageConfiguration) .SetTargetImageConfiguration(targetImageConfiguration) .SetAdditionalTargetImageTags(additionalTargetImageTags) .SetContainerConfiguration(containerConfiguration) .SetApplicationLayersCacheDirectory(expectedApplicationLayersCacheDirectory) .SetBaseImageLayersCacheDirectory(expectedBaseImageLayersCacheDirectory) .SetTargetFormat(ImageFormat.OCI) .SetAllowInsecureRegistries(true) .SetLayerConfigurations(expectedLayerConfigurations) .SetToolName(expectedCreatedBy); BuildConfiguration buildConfiguration = buildConfigurationBuilder.Build(); Assert.IsNotNull(buildConfiguration.GetContainerConfiguration()); Assert.AreEqual( expectedCreationTime, buildConfiguration.GetContainerConfiguration().GetCreationTime()); Assert.AreEqual( expectedBaseImageServerUrl, buildConfiguration.GetBaseImageConfiguration().GetImageRegistry()); Assert.AreEqual( expectedBaseImageName, buildConfiguration.GetBaseImageConfiguration().GetImageRepository()); Assert.AreEqual( expectedBaseImageTag, buildConfiguration.GetBaseImageConfiguration().GetImageTag()); Assert.AreEqual( expectedTargetServerUrl, buildConfiguration.GetTargetImageConfiguration().GetImageRegistry()); Assert.AreEqual( expectedTargetImageName, buildConfiguration.GetTargetImageConfiguration().GetImageRepository()); Assert.AreEqual( expectedTargetTag, buildConfiguration.GetTargetImageConfiguration().GetImageTag()); Assert.AreEqual(expectedTargetImageTags, buildConfiguration.GetAllTargetImageTags()); Assert.AreEqual( Credential.From("username", "password"), buildConfiguration .GetTargetImageConfiguration() .GetCredentialRetrievers() [0] .Retrieve() .OrElseThrow(() => new AssertionException(""))); Assert.AreEqual( expectedProgramArguments, buildConfiguration.GetContainerConfiguration().GetProgramArguments()); Assert.AreEqual( expectedEnvironment, buildConfiguration.GetContainerConfiguration().GetEnvironmentMap()); Assert.AreEqual( expectedExposedPorts, buildConfiguration.GetContainerConfiguration().GetExposedPorts()); Assert.AreEqual(expectedLabels, buildConfiguration.GetContainerConfiguration().GetLabels()); Assert.AreEqual(expectedTargetFormat, buildConfiguration.GetTargetFormat()); Assert.AreEqual( expectedApplicationLayersCacheDirectory, buildConfigurationBuilder.GetApplicationLayersCacheDirectory()); Assert.AreEqual( expectedBaseImageLayersCacheDirectory, buildConfigurationBuilder.GetBaseImageLayersCacheDirectory()); Assert.IsTrue(buildConfiguration.GetAllowInsecureRegistries()); Assert.AreEqual(expectedLayerConfigurations, buildConfiguration.GetLayerConfigurations()); Assert.AreEqual( expectedEntrypoint, buildConfiguration.GetContainerConfiguration().GetEntrypoint()); Assert.AreEqual(expectedCreatedBy, buildConfiguration.GetToolName()); }
public void TestAddEntryRecursive_permissionsAndTimestamps() { SystemPath testDirectory = TestResources.GetResource("core/layer"); SystemPath testFile = TestResources.GetResource("core/fileA"); FilePermissions permissions1 = FilePermissions.FromOctalString("111"); FilePermissions permissions2 = FilePermissions.FromOctalString("777"); Instant timestamp1 = Instant.FromUnixTimeSeconds(123); Instant timestamp2 = Instant.FromUnixTimeSeconds(987); FilePermissions permissionsProvider(SystemPath _, AbsoluteUnixPath destination) => destination.ToString().StartsWith("/app/layer/a", StringComparison.Ordinal) ? permissions1 : permissions2; Instant timestampProvider(SystemPath _, AbsoluteUnixPath destination) => destination.ToString().StartsWith("/app/layer/a", StringComparison.Ordinal) ? timestamp1 : timestamp2; ILayerConfiguration layerConfiguration = LayerConfiguration.CreateBuilder() .AddEntryRecursive( testDirectory, AbsoluteUnixPath.Get("/app/layer/"), permissionsProvider, timestampProvider) .AddEntryRecursive( testFile, AbsoluteUnixPath.Get("/app/fileA"), permissionsProvider, timestampProvider) .Build(); ImmutableHashSet <LayerEntry> expectedLayerEntries = ImmutableHashSet.Create( new LayerEntry( testDirectory, AbsoluteUnixPath.Get("/app/layer/"), permissions2, timestamp2), new LayerEntry( testDirectory.Resolve("a"), AbsoluteUnixPath.Get("/app/layer/a/"), permissions1, timestamp1), new LayerEntry( testDirectory.Resolve("a/b"), AbsoluteUnixPath.Get("/app/layer/a/b/"), permissions1, timestamp1), new LayerEntry( testDirectory.Resolve("a/b/bar"), AbsoluteUnixPath.Get("/app/layer/a/b/bar/"), permissions1, timestamp1), new LayerEntry( testDirectory.Resolve("c/"), AbsoluteUnixPath.Get("/app/layer/c"), permissions2, timestamp2), new LayerEntry( testDirectory.Resolve("c/cat/"), AbsoluteUnixPath.Get("/app/layer/c/cat"), permissions2, timestamp2), new LayerEntry( testDirectory.Resolve("foo"), AbsoluteUnixPath.Get("/app/layer/foo"), permissions2, timestamp2), new LayerEntry(testFile, AbsoluteUnixPath.Get("/app/fileA"), permissions2, timestamp2)); CollectionAssert.AreEquivalent( expectedLayerEntries, ImmutableHashSet.CreateRange(layerConfiguration.LayerEntries)); }
public void ShouldSerialize() { var layerConfiguration = new LayerConfiguration() { Version = "1.0", Layers = new List <Layer> { { new Layer { Name = "rules", Contexts = new List <Context> { new Context { Endpoint = new System.Uri("https://virtualsociety.nl/zorgtoeslag/v1.0/zorgtoeslag.routing.yaml") } } } }, { new Layer { Name = "uxcontent", Contexts = new List <Context> { new Context { Endpoint = new System.Uri("https://virtualsociety.nl/zorgtoeslag/v1.0/zorgtoeslag.uxcontent.nl.yaml") }, new Context { Endpoint = new System.Uri("https://virtualsociety.nl/zorgtoeslag/v1.0/zorgtoeslag.uxcontent.en.yaml"), Language = LanguageCode.EN }, new Context { Endpoint = new System.Uri("https://virtualsociety.nl/zorgtoeslag/v1.0/zorgtoeslag.uxcontent.ar.yaml"), Language = LanguageCode.AR } } } }, { new Layer { Name = "routing", Contexts = new List <Context> { new Context { Endpoint = new System.Uri("https://virtualsociety.nl/zorgtoeslag/v1.0/zorgtoeslag.routing.yaml") } } } } } }; var serializer = new Serializer(); var result = serializer.Serialize(layerConfiguration); Assert.Equal(@"version: 1.0.0 layers: rules: - context: https://virtualsociety.nl/zorgtoeslag/v1.0/zorgtoeslag.routing.yaml language: uxcontent: - context: https://virtualsociety.nl/zorgtoeslag/v1.0/zorgtoeslag.uxcontent.nl.yaml language: - context: https://virtualsociety.nl/zorgtoeslag/v1.0/zorgtoeslag.uxcontent.en.yaml language: EN - context: https://virtualsociety.nl/zorgtoeslag/v1.0/zorgtoeslag.uxcontent.ar.yaml language: AR routing: - context: https://virtualsociety.nl/zorgtoeslag/v1.0/zorgtoeslag.routing.yaml language: ", result); }
public override void OnApplyTemplate() { MapContentControlContainer = GetTemplateChild(PART_MAP_CONTENT_CONTAINER_CONTROL) as ContentControl; if (MapContentControlContainer != null) { MapContentControl = new MapContents(); MapContentControl.Name = PART_MAP_CONTENT_CONTROL; MapContentControl.Map = View.Map; MapContentControl.Configuration = new MapContentsConfiguration { ContextMenuToolPanelName = "EditModeLayerConfigurationContextMenu", Mode = Mode.TopLevelLayersOnly }; if (MapContentControlContainer.Resources != null) { MapContentControl.ScrollViewerStyle = MapContentControlContainer.Resources["BuilderMapContentsScrollViewerStyle"] as Style; MapContentControl.SelectionColorBrush = MapContentControlContainer.Resources["BuilderSelectedLayerColorBrush"] as Brush; MapContentControl.SelectionOutlineColorBrush = MapContentControlContainer.Resources["BuilderSelectedLayerOutlineColorBrush"] as Brush; MapContentControl.ToggleButtonStyle = MapContentControlContainer.Resources["MapContentsControlNodeToggleButton"] as Style; } // Push foreground and background to map contents Binding b = new Binding("Foreground") { Source = this }; MapContentControl.SetBinding(MapContents.ForegroundProperty, b); b = new Binding("Background") { Source = this }; MapContentControl.SetBinding(MapContents.BackgroundProperty, b); MapContentControlContainer.Content = MapContentControl; } layerConfigurationLayout = GetTemplateChild(PART_CONFIGURE_LAYER_CONTROL_LAYOUT) as Grid; LayerConfiguration = GetTemplateChild("LayerConfigurationDialog") as LayerConfiguration; if (LayerConfiguration != null) { LayerConfiguration.View = View.Instance; } mapContentLayerConfigurationLayout = GetTemplateChild(PART_MAP_CONTENTS_LAYER_CONFIGURATION_LAYOUT) as Grid; if (mapContentLayerConfigurationLayout != null) { mapContentLayerConfigurationLayout.Loaded -= mapContentLayerConfigurationLayout_Loaded; mapContentLayerConfigurationLayout.Loaded += mapContentLayerConfigurationLayout_Loaded; mapContentLayerConfigurationLayout.SizeChanged -= mapContentLayerConfigurationLayout_SizeChanged; mapContentLayerConfigurationLayout.SizeChanged += mapContentLayerConfigurationLayout_SizeChanged; } mapContentsLayout = GetTemplateChild(PART_MAP_CONTENT_CONTROL_LAYOUT) as Grid; btnConfigurationComplete = GetTemplateChild(PART_CONFIGURE_COMPLETE_BUTTON) as Button; _layerConfigToolbar = GetTemplateChild(PART_TOOLPANEL) as ToolPanel; _allLayersConfigToolbar = GetTemplateChild(PART_ALLLAYERSTOOLPANEL) as ToolPanel; _mapContentsContenxtMenuToolbar = GetTemplateChild(PART_EDIT_MODE_LAYER_CONFIGURATION_CONTEXT_MENU) as ToolPanel; _layerConfigPanel = GetTemplateChild(PART_LAYERCONFIGPANEL) as FrameworkElement; InitializeToolbars(); // hide the layer configuration elements until we need them RemoveLayerConfigurationVisualElements(); }
public static void Init(ref LayerConfiguration configuration) { LayerConfiguration.InitSceneLayers(ref configuration); LayerConfiguration.InitLayerMappings(ref configuration, configuration._layers.Count); }