Alternative to TheDefault and ConstructedBy methods in Unity - inversion-of-control

Basically what i'd like to do is injecting what's in HttpContext.Current.User everytime I ask for an IPrincipal. This is the code in StructureMap:
ForRequestedType<IPrincipal>()
.CacheBy(InstanceScope.Hybrid)
.TheDefault.Is.ConstructedBy(ctx => HttpContext.Current.User)
How do I achieve the same in Unity?.

this can be done using InjectionFactory in Unity 2.0 or StaticFactoryExtension in previous version of Unity.
var container = new UnityContainer(); // unity 2.0
container.RegisterType<IPrincipal>(new InjectionFactory(_ => HttpContext.Current.User));

Related

Please help to solve a task on php

Got the following task:
create a prototype of the game - get the code below to work. Game is the class of the game, and Tile is a tile in the game (an individual area that has coordinates). Implement the missing classes and methods so that the result is a playing field as in the comments (there should be a house, trees, lawn and flowers).
class Game
{
}
class Tile
{
}
$game = new Game([
new House(0,0), //house
new Tree(1,0), //tree
new Tree(2,0), //tree
new Lawn(0,1), //lawn
new Lawn(0,2), //lawn
new Lawn(0,3), //lawn
new Lawn(0,3), //lawn
new Flower(3,0), //flower
new Flower(1,3), //flower
]);
/*
0 1 2 3
0 🏠 🌳 🌳 🌼
1 🌿
2 🌿
3 🌿 🌼
*/"
Could you please suggest what method can be used to display the specified playing field?
I suppose that this task can be solved by specific method but I have no clue.

How to implement mapbox SDK v10 to android app written in Java?

I am trying to implement Mapbox SDK v10 in my android app that's completely written in Java.
I have been able to show the map and even the camera points to my current location but when I am trying to put a marker on the map I can't find the relevant codes in java because only kotlin codes are present
// Create an instance of the Annotation API and get the PointAnnotationManager. val annotationApi = mapView?.annotations val pointAnnotationManager = annotationApi?.createPointAnnotationManager(mapView) // Set options for the resulting symbol layer. val pointAnnotationOptions: PointAnnotationOptions = PointAnnotationOptions() // Define a geographic coordinate. .withPoint(Point.fromLngLat(18.06, 59.31)) // Specify the bitmap you assigned to the point annotation // The bitmap will be added to map style automatically. .withIconImage(YOUR_ICON_BITMAP) // Add the resulting pointAnnotation to the map. pointAnnotationManager?.create(pointAnnotationOptions)
So I have 2 questions-
1)How can I put an annotation or marker on the map using java?
2)On the other hand I have been able to use Mapbox SDK v9 successfully ,but it's marked as legacy so can I still use this SDK in my app or there can be some problem in the future if I use SDK v9?
These are the codes for adding a marker, polyline of polygon in mapbox10 java:
private void AddMarker(Point point)
{
AnnotationPlugin annotationApi = AnnotationPluginImplKt.getAnnotations(mapView);
CircleAnnotationManager circleAnnotationManager = CircleAnnotationManagerKt.createCircleAnnotationManager(annotationApi, new AnnotationConfig());
CircleAnnotationOptions circleAnnotationOptions = new CircleAnnotationOptions()
.withPoint(point)
.withCircleRadius(7.0)
.withCircleColor("#ee4e8b")
.withCircleStrokeWidth(1.0)
.withDraggable(true)
.withCircleStrokeColor("#ffffff");
circleAnnotationManager.create(circleAnnotationOptions);
}
private void DrawPolyLine() {
AnnotationPlugin annotationApi = AnnotationPluginImplKt.getAnnotations(mapView);
PolylineAnnotationManager polylineAnnotationManager = PolylineAnnotationManagerKt.createPolylineAnnotationManager(annotationApi,new AnnotationConfig());
PolylineAnnotationOptions polylineAnnotationOptions = new PolylineAnnotationOptions()
.withPoints(pointList)
.withLineColor("#ee4e8b")
.withLineWidth(4);
polylineAnnotationManager.create(polylineAnnotationOptions);
}
private void DrawPolygon(List<Point> myPointList) {
List<Point> pointList = myPointList;
pointList.add(myPointList.get(0));
List<List<Point>> polygonList = new ArrayList<>();
polygonList.add(pointList);
polygonAnnotationManager = PolygonAnnotationManagerKt.createPolygonAnnotationManager(annotationApi,new AnnotationConfig());
PolygonAnnotationOptions polygonAnnotationOptions = new PolygonAnnotationOptions()
.withPoints(polygonList)
.withFillColor("#ee4e8b")
.withFillOpacity(0.5);
PolygonAnnotation polygonAnnotation = polygonAnnotationManager.create(polygonAnnotationOptions);
}
remember for marker annotation we have to types: Point annotation and Circle annotation but their implementation of them are the same.

How do I open a game compiled for WebGL in Unity in Blazor?

I have created a Blazor Server project. In it, I wanted to put my WebGL game created in Unity3d on a separate page. In the end, after doing everything according to the example, I still can't get it to work. Although, I think, all things considered, but I see that the code markup index.html from WebGL game is different from other examples and there I haven't found a line of code:
unityInstance = UnityLoader.instantiate("unityContainer", "unity/WebGL/Build/WebGL.loader.js", { onProgress: UnityProgress });
I think I hooked it up right:
<script src="~/unity/WebGL/Build/WebGL.loader.js"></script>
#*<script src="~/unity/WebGL/Build/WebGL.framework.js.gz"></script>*#
<script src="~/unity/WebGL/run.js"></script>
I believe I wrote the mime type correctly:
var provider = new FileExtensionContentTypeProvider();
provider.Mappings.Remove(".data.gz");
provider.Mappings[".data.gz"] = "application/octet-stream";
provider.Mappings.Remove(".wasm.gz");
provider.Mappings[".wasm.gz"] = "application/wasm";
provider.Mappings.Remove(".js.gz");
provider.Mappings[".js.gz"] = "application/javascript";
provider.Mappings.Remove(".symbols.json.gz");
provider.Mappings[".symbols.json.gz"] = "application/octet-stream";
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "unity", "WebGL", "Build")),
RequestPath = "/Build",
ContentTypeProvider = provider
});
app.UseStaticFiles();
The error in the JavaScript console reads:
UnityLoader is not defined
If interested, here is my entire project:
https://github.com/EgorPavlovich/FPS.Servers.Test
I had to use the index.html file from the game build

how to longPress in Appium 1.7?

I am new to appium and using its version 1.7
i have to long press a webelement in my native app on android version 7.0
It shows all the methods are depreciated except for longPress(LongPressOptions longpressoptions) and longPress(PointOption longpressoptions).
so i started using it like below
I am using it like below
public static RemoteWebDriver driver;
driver = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
WebElement homeScrSwipe = driver.findElementById("pulldown_image");
TouchAction ta = new TouchAction((PerformsTouchActions) driver);
ta.longPress(homeScrSwipe, Duration.ofMillis(5000)).release().perform();
but it always gives me below error
The method longPress(WebElement, Duration) from the type TouchAction is deprecated.
If someone could let me know what is this longPressOptions in both the methods that would be of great help
Try this code
it may help you
TouchAction ta = new TouchAction(driver);
ta.longPress(x,y).moveTo(x,y).release().perform();
longPress(x,y) are Coordinates of mobile screen and moveTo(x,y) are to how many points you want swipe
for appium 1.7.1
android java client jar 5.0.4
Happy Testing
WebElement webElement = appiumDriver.findElement(By.xpath(element));
TouchAction Action = new TouchAction(appiumDriver);
// Action.longPress(webElement).perform();
Action.longPress(webElement).release().perform();
public static void touchDown(MobileElement element) {
new TouchAction(AppiumDriverCapabilitiesUtilities.driver).longPress(element2).release().perform();
}
TouchAction action1 = new TouchAction(((MobileDriver) Driver));
action1.longPress(LongPressOptions.longPressOptions().withElement(ElementOption.element(Element))).waitAction(WaitOptions.waitOptions(Duration.ofMillis(500))).release();

White Automation framework throws an exception when using "White.Core.Desktop" Class

I am using White Framework for automation. when I trying to get desktop instance I got exception "The type initializer for 'White.Core.Desktop' threw an exception."
My code looks like :
var window = White.Core.Desktop.Instance.Windows().Find(obj => obj.Title.Contains("TestAppHome"));
Is there any way to capture the window without exception that is without using White.Core.Desktop class?
Any help would be greatly appreciated !
Try this one:
List<White.Core.UIItems.WindowItems.Window> windows = WindowFactory.Desktop.DesktopWindows();
var window = windows.Find(w => w.Title.Contains("TestAppHome"));
Try this. You can directly launch the target application and get it's UI elements rather than search all UI elements in Desktop. I think this is very efficient.
static void Main(string[] args)
{
Application app = Application.Launch(#"C:\Testing\Sample.txt"); //Target application
var appWindow = app.GetWindow("Sample - Notepad");
appWindow.RightClick();
PopUpMenu popupMenu = appWindow.Popup;
var saveOptionMenuItem = popupMenu.ItemBy(SearchCriteria.ByText("Open IME"));
saveOptionMenuItem.Click();
}