protected async override void OnResume() { base.OnResume(); // If we haven't already loaded the products from the store, do it now if (listView.Adapter == null && !isFetching) { isFetching = true; ShowLoadingDialog(Resource.String.loading_data); try { // Fetch the collections var collections = await SampleApplication.GetCollectionsAsync(); DismissLoadingDialog(); OnFetchedCollections(collections.ToList()); } catch (ShopifyException ex) { OnError(ex.Error); } isFetching = false; } }
// Fetching shipping rates requires communicating with 3rd party shipping servers, so we need to poll until all the rates have been fetched. private void FetchShippingRates() { SampleApplication.GetShippingRates( (shippingRates, response) => { if (response.Status == (int)HttpStatus.Accepted) { // Poll until the server either fails or returns HttpStatus.SC_ACCEPTED pollingHandler.PostDelayed(() => { FetchShippingRates(); }, PollDelay); } else if (response.Status == (int)HttpStatus.Ok) { isFetching = false; OnFetchedShippingRates(shippingRates.ToList()); } else { isFetching = false; // Handle error OnError(response.Reason); } }, error => { isFetching = false; // Handle error OnError(error); }); }
// When the user selects a product, create a new checkout for that product. private async Task CreateCheckoutAsync(Product product) { ShowLoadingDialog(Resource.String.syncing_data); try { var checkout = await SampleApplication.CreateCheckoutAsync(product); DismissLoadingDialog(); // If the selected product requires shipping, show the list of shipping rates so the user can pick one. // Otherwise, skip to the discounts activity (gift card codes and discount codes). if (checkout.RequiresShipping) { StartActivity(new Intent(this, typeof(ShippingRateListActivity))); } else { StartActivity(new Intent(this, typeof(DiscountActivity))); } } catch (ShopifyException ex) { OnError(ex.Error); } }
// For our sample native checkout, we use a hardcoded credit card. private async void OnNativeCheckoutButtonClicked(object sender, EventArgs e) { // Create the card to send to Shopify. This is hardcoded here for simplicity, but the user should be prompted for their credit card information. var creditCard = new CreditCard { FirstName = "Dinosaur", LastName = "Banana", Month = "2", Year = "20", VerificationValue = "123", Number = "4242424242424242" }; ShowLoadingDialog(Resource.String.completing_checkout); try { await SampleApplication.StoreCreditCardAsync(creditCard); var checkout = await SampleApplication.CompleteCheckoutAsync(); DismissLoadingDialog(); await PollCheckoutCompletionStatusAsync(checkout); } catch (ShopifyException ex) { OnError(ex.Error); } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs e) { #if DEBUG if (Debugger.IsAttached) { DebugSettings.EnableFrameRateCounter = true; } #endif // Associate main region states with corresponding native pages LifecycleHelper.RegisterView<MainPage>().ForState(MainRegionView.Main); LifecycleHelper.RegisterView<SecondPage>().ForState(MainRegionView.Second); LifecycleHelper.RegisterView<ThirdPage>().ForState(MainRegionView.Third); LifecycleHelper.RegisterView<FourthPage>().ForState(MainRegionView.Fourth); // Register the sub-pages of the third page LifecycleHelper.RegisterView<ThrirdOnePage>().ForState(ThirdStates.One); LifecycleHelper.RegisterView<ThirdTwoPage>().ForState(ThirdStates.Two); LifecycleHelper.RegisterView<ThirdThreePage>().ForState(ThirdStates.Three); LifecycleHelper.RegisterView<ThirdFourPage>().ForState(ThirdStates.Four); // Register the page to be used in the additional window LifecycleHelper.RegisterView<SeparatePage>().ForState(SecondaryRegionView.Main); var core = new SampleApplication(); var wm = new WindowManager(core); await core.Startup(builder => { builder.Register<UWPSpecial,ISpecial>(); }); }
protected override void OnResume() { base.OnResume(); // If we haven't already loaded the products from the store, do it now if (listView.Adapter == null && !isFetching) { isFetching = true; ShowLoadingDialog(Resource.String.loading_data); // Fetch the collections SampleApplication.GetCollections( (collections, response) => { isFetching = false; DismissLoadingDialog(); OnFetchedCollections(collections.ToList()); }, (error) => { isFetching = false; OnError(error); }); } }
protected async override void OnResume() { base.OnResume(); // If we haven't already loaded the products from the store, do it now if (listView.Adapter == null && !isFetching) { isFetching = true; ShowLoadingDialog(Resource.String.loading_data); try { IEnumerable <Product> products; if (collectionId != null) { products = await SampleApplication.GetProductsAsync(collectionId); } else { products = await SampleApplication.GetAllProductsAsync(); } DismissLoadingDialog(); OnFetchedProducts(products.ToList()); } catch (ShopifyException ex) { OnError(ex.Error); } isFetching = false; } }
protected override void OnResume() { base.OnResume(); // If we haven't already loaded the products from the store, do it now if (listView.Adapter == null && !isFetching) { isFetching = true; ShowLoadingDialog(Resource.String.loading_data); var success = new Action <IEnumerable <Product>, Response>((products, response) => { isFetching = false; DismissLoadingDialog(); OnFetchedProducts(products.ToList()); }); var failure = new Action <RetrofitError>(error => { isFetching = false; OnError(error); }); if (collectionId != null) { SampleApplication.GetProducts(collectionId, success, failure); } else { SampleApplication.GetAllProducts(success, failure); } } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs e) { #if DEBUG if (Debugger.IsAttached) { DebugSettings.EnableFrameRateCounter = true; } #endif var rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { NavigationHelper.Register<PageStates, MainPage>(PageStates.Main); NavigationHelper.Register<PageStates, SecondPage>(PageStates.Second); NavigationHelper.Register<PageStates, ThirdPage>(PageStates.Third); NavigationHelper.Register<SecondaryStates, SeparatePage>(SecondaryStates.Main); var core = new SampleApplication(); await core.Startup(builder => { builder.RegisterType<Special>().As<ISpecial>(); }); var region = core.RegionManager.RegionByType<MainWindow>(); var fn = new FrameNavigation<PageStates, PageTransitions>(rootFrame, region); await region.Startup(core.RegionManager); var wm = new WindowManager(core); // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter //rootFrame.Navigate(typeof(MainPage), e.Arguments); } // Ensure the current window is active Window.Current.Activate(); }
// When the user selects a shipping rate, set that rate on the checkout and proceed to the discount activity. private void OnShippingRateSelected(ShippingRate shippingRate) { ShowLoadingDialog(Resource.String.syncing_data); SampleApplication.SetShippingRate(shippingRate, delegate { DismissLoadingDialog(); StartActivity(new Intent(this, typeof(DiscountActivity))); }, OnError); }
public void Ensure_exception_logged_as_error() { var mockLog = new Mock <ILog <SampleApplication> >(); var application = new SampleApplication(mockLog.Object); application.MethodThatHandlesException(); mockLog.Verify(x => x.LogError(It.IsAny <Exception>(), "An error occurred"), Times.Once); }
public void Application_started_logged() { var mockLog = new Mock <ILog <SampleApplication> >(); var application = new SampleApplication(mockLog.Object); application.Start(); mockLog.Verify(x => x.LogInformation("Application started"), Times.Once); }
private static async Task SampleApplication() { var myApp = new SampleApplication(new DataServiceWrapper(), new NotificationWrapper()); myApp.PublishNotification("My app started"); await myApp.GetData(); await myApp.SetData(); await myApp.GetData(); }
// Add the gift card code to the checkout and update the order summary when the request completes. private void AddGiftCardCode(string giftCardCode) { ShowLoadingDialog(Resource.String.syncing_data); SampleApplication.AddGiftCard(giftCardCode, delegate { DismissLoadingDialog(); UpdateOrderSummary(); }, delegate { DismissLoadingDialog(); Toast.MakeText(this, GetString(Resource.String.gift_card_error, giftCardCode), ToastLength.Long).Show(); }); }
// Add the discount code to the checkout and update the order summary when the request completes. private async Task SetDiscountCodeAsync(string discountCode) { ShowLoadingDialog(Resource.String.syncing_data); try { await SampleApplication.SetDiscountCodeAsync(discountCode); UpdateOrderSummary(); } catch (ShopifyException ex) { Toast.MakeText(this, GetString(Resource.String.discount_error, discountCode), ToastLength.Long).Show(); } DismissLoadingDialog(); }
// Add the gift card code to the checkout and update the order summary when the request completes. private async Task AddGiftCardCodeAsync(string giftCardCode) { ShowLoadingDialog(Resource.String.syncing_data); try { await SampleApplication.AddGiftCardAsync(giftCardCode); UpdateOrderSummary(); } catch (ShopifyException ex) { Toast.MakeText(this, GetString(Resource.String.gift_card_error, giftCardCode), ToastLength.Long).Show(); } DismissLoadingDialog(); }
protected override async void OnCreate(Bundle bundle) { base.OnCreate(bundle); var core = new SampleApplication(); var fn = new AcitivityNavigation<PageStates, PageTransitions>(this, core); fn.Register<MainActivity>(PageStates.Main); fn.Register<SecondActivity>(PageStates.Second); //fn.Register<ThirdActivity>(PageStates.Third); await core.Startup(builder => { builder.RegisterType<Special>().As<ISpecial>(); }); }
// Add the discount code to the checkout and update the order summary when the request completes. private void SetDiscountCode(string discountCode) { ShowLoadingDialog(Resource.String.syncing_data); SampleApplication.SetDiscountCode(discountCode, delegate { DismissLoadingDialog(); UpdateOrderSummary(); }, delegate { DismissLoadingDialog(); Toast.MakeText(this, GetString(Resource.String.discount_error, discountCode), ToastLength.Long).Show(); }); }
// When the user selects a shipping rate, set that rate on the checkout and proceed to the discount activity. private async Task OnShippingRateSelectedAsync(ShippingRate shippingRate) { ShowLoadingDialog(Resource.String.syncing_data); try { await SampleApplication.SetShippingRateAsync(shippingRate); DismissLoadingDialog(); StartActivity(new Intent(this, typeof(DiscountActivity))); } catch (ShopifyException ex) { OnError(ex.Error); } }
// Fetching shipping rates requires communicating with 3rd party shipping servers, so we need to poll until all the rates have been fetched. private async Task FetchShippingRatesAsync() { try { IEnumerable <ShippingRate> shippingRates; while ((shippingRates = await SampleApplication.GetShippingRatesAsync()) == null) { await Task.Delay(PollDelay); } OnFetchedShippingRates(shippingRates.ToList()); } catch (ShopifyException ex) { OnError(ex.Error); } isFetching = false; }
protected override void OnShown(EventArgs e) { _application = new SampleApplication(this); _picture = new PixelPicture { Width = 16, Height = 16 }; _scriptEnvironment = new SampleScriptEnvironment(logTextBox); _scriptEnvironment.AddType("color", typeof(Color)); _scriptEnvironment.AddValue("picture", _picture); _scriptEnvironment.AddValue("application", _application); base.OnShown(e); this.ProcessCommandLine(); }
// When the user selects a product, create a new checkout for that product. private void CreateCheckout(Product product) { ShowLoadingDialog(Resource.String.syncing_data); SampleApplication.CreateCheckout(product, (checkout, response) => { DismissLoadingDialog(); // If the selected product requires shipping, show the list of shipping rates so the user can pick one. // Otherwise, skip to the discounts activity (gift card codes and discount codes). if (checkout.RequiresShipping) { StartActivity(new Intent(this, typeof(ShippingRateListActivity))); } else { StartActivity(new Intent(this, typeof(DiscountActivity))); } }, OnError); }
private async void StartApplication() { // Handle when your app starts LifecycleHelper.RegisterView<MainPage>().ForState(MainRegionView.Main); LifecycleHelper.RegisterView<SecondPage>().ForState(MainRegionView.Second); LifecycleHelper.RegisterView<ThirdPage>().ForState(MainRegionView.Third); LifecycleHelper.RegisterView<SeparatePage>().ForState(SecondaryRegionView.Main); var core = new SampleApplication(); var wm = new WindowManager(MainPage as CustomNavigationPage, core); await core.Startup( builder => { builder.Register<XFormsSpecial, ISpecial>(); }); // (MainPage as NavigationPage).Navigation.PushAsync(new MainPage()); }
// For our sample native checkout, we use a hardcoded credit card. private void OnNativeCheckoutButtonClicked(object sender, EventArgs e) { // Create the card to send to Shopify. This is hardcoded here for simplicity, but the user should be prompted for their credit card information. var creditCard = new CreditCard { FirstName = "Dinosaur", LastName = "Banana", Month = "2", Year = "20", VerificationValue = "123", Number = "4242424242424242" }; ShowLoadingDialog(Resource.String.completing_checkout); SampleApplication.StoreCreditCard(creditCard, delegate { // When the credit card has successfully been added, complete the checkout and begin polling. SampleApplication.CompleteCheckout((checkout, response) => { DismissLoadingDialog(); PollCheckoutCompletionStatus(checkout); }, OnError); }, OnError); }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used when the application is launched to open a specific file, to display /// search results, and so forth. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs e) { #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { this.DebugSettings.EnableFrameRateCounter = true; } #endif Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); // TODO: change this value to a cache size that is appropriate for your application rootFrame.CacheSize = 1; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { // TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { var core = new SampleApplication(); var fn = new FrameNavigation<PageStates, PageTransitions>(rootFrame, core); fn.Register<MainPage>(PageStates.Main); fn.Register<SecondPage>(PageStates.Second); fn.Register<ThirdPage>(PageStates.Third); await core.Startup(); //#if WINDOWS_PHONE_APP // // Removes the turnstile navigation for startup. // if (rootFrame.ContentTransitions != null) // { // this.transitions = new TransitionCollection(); // foreach (var c in rootFrame.ContentTransitions) // { // this.transitions.Add(c); // } // } // rootFrame.ContentTransitions = null; // rootFrame.Navigated += this.RootFrame_FirstNavigated; //#endif // // When the navigation stack isn't restored navigate to the first page, // // configuring the new page by passing required information as a navigation // // parameter // if (!rootFrame.Navigate(typeof(MainPage), e.Arguments)) // { // throw new Exception("Failed to create initial page"); // } } // Ensure the current window is active Window.Current.Activate(); }
static int Main(string[] args) { if (args.Length != 2) { Console.WriteLine($"ImageTint <image-path> <out>: Tints the image at <image-path> and saves it to <out>."); return(1); } string inPath = args[0]; string outPath = args[1]; // This demo uses WindowState.Hidden to avoid popping up an unnecessary window to the user. VeldridStartup.CreateWindowAndGraphicsDevice( new WindowCreateInfo { WindowInitialState = WindowState.Hidden, }, new GraphicsDeviceOptions(), out Sdl2Window window, out GraphicsDevice gd); DisposeCollectorResourceFactory factory = new DisposeCollectorResourceFactory(gd.ResourceFactory); ImageSharpTexture inputImage = new ImageSharpTexture(inPath, false); Texture inputTexture = inputImage.CreateDeviceTexture(gd, factory); TextureView view = factory.CreateTextureView(inputTexture); Texture output = factory.CreateTexture(TextureDescription.Texture2D( inputImage.Width, inputImage.Height, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.RenderTarget)); Framebuffer framebuffer = factory.CreateFramebuffer(new FramebufferDescription(null, output)); DeviceBuffer vertexBuffer = factory.CreateBuffer(new BufferDescription(64, BufferUsage.VertexBuffer)); Vector4[] quadVerts = { new Vector4(-1, 1, 0, 0), new Vector4(1, 1, 1, 0), new Vector4(-1, -1, 0, 1), new Vector4(1, -1, 1, 1), }; gd.UpdateBuffer(vertexBuffer, 0, quadVerts); ShaderSetDescription shaderSet = new ShaderSetDescription( new[] { new VertexLayoutDescription( new VertexElementDescription("Position", VertexElementSemantic.Position, VertexElementFormat.Float2), new VertexElementDescription("TextureCoordinates", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2)) }, new[] { SampleApplication.LoadShader(factory, "TintShader", ShaderStages.Vertex, "VS"), SampleApplication.LoadShader(factory, "TintShader", ShaderStages.Fragment, "FS") }); ResourceLayout layout = factory.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("Input", ResourceKind.TextureReadOnly, ShaderStages.Fragment), new ResourceLayoutElementDescription("Sampler", ResourceKind.Sampler, ShaderStages.Fragment), new ResourceLayoutElementDescription("Tint", ResourceKind.UniformBuffer, ShaderStages.Fragment))); Pipeline pipeline = factory.CreateGraphicsPipeline(new GraphicsPipelineDescription( BlendStateDescription.SingleOverrideBlend, DepthStencilStateDescription.Disabled, RasterizerStateDescription.Default, PrimitiveTopology.TriangleStrip, shaderSet, layout, framebuffer.OutputDescription)); DeviceBuffer tintInfoBuffer = factory.CreateBuffer(new BufferDescription(16, BufferUsage.UniformBuffer)); gd.UpdateBuffer( tintInfoBuffer, 0, new TintInfo( new Vector3(1f, 0.2f, 0.1f), // Change this to modify the tint color. 0.25f)); ResourceSet resourceSet = factory.CreateResourceSet( new ResourceSetDescription(layout, view, gd.PointSampler, tintInfoBuffer)); // RenderTarget textures are not CPU-visible, so to get our tinted image back, we need to first copy it into // a "staging Texture", which is a Texture that is CPU-visible (it can be Mapped). Texture stage = factory.CreateTexture(TextureDescription.Texture2D( inputImage.Width, inputImage.Height, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Staging)); CommandList cl = factory.CreateCommandList(); cl.Begin(); cl.SetFramebuffer(framebuffer); cl.SetFullViewports(); cl.SetVertexBuffer(0, vertexBuffer); cl.SetPipeline(pipeline); cl.SetGraphicsResourceSet(0, resourceSet); cl.Draw(4, 1, 0, 0); cl.CopyTexture( output, 0, 0, 0, 0, 0, stage, 0, 0, 0, 0, 0, stage.Width, stage.Height, 1, 1); cl.End(); gd.SubmitCommands(cl); gd.WaitForIdle(); // When a texture is mapped into a CPU-visible region, it is often not laid out linearly. // Instead, it is laid out as a series of rows, which are all spaced out evenly by a "row pitch". // This spacing is provided in MappedResource.RowPitch. // It is also possible to obtain a "structured view" of a mapped data region, which is what is done below. // With a structured view, you can read individual elements from the region. // The code below simply iterates over the two-dimensional region and places each texel into a linear buffer. // ImageSharp requires the pixel data be contained in a linear buffer. MappedResourceView <Rgba32> map = gd.Map <Rgba32>(stage, MapMode.Read); // Rgba32 is synonymous with PixelFormat.R8_G8_B8_A8_UNorm. Rgba32[] pixelData = new Rgba32[stage.Width * stage.Height]; for (int y = 0; y < stage.Height; y++) { for (int x = 0; x < stage.Width; x++) { int index = (int)(y * stage.Width + x); pixelData[index] = map[x, y]; } } gd.Unmap(stage); // Resources should be Unmapped when the region is no longer used. Image <Rgba32> outputImage = Image.LoadPixelData(pixelData, (int)stage.Width, (int)stage.Height); outputImage.Save(outPath); factory.DisposeCollector.DisposeAll(); gd.Dispose(); window.Close(); return(0); }
private void LaunchProductDetailsActivity(Product product) { SampleApplication.LaunchProductDetailsActivity(this, product, theme); }