示例#1
0
        private void GenerateNewCache(QRCodeItem qrCodeItem)
        {
            var newCache = new NewItemPageViewModelCache
            {
                QRCodeItem = qrCodeItem,
                CancellationTokenSource = new CancellationTokenSource()
            };

            _caches.Add(newCache);

            var cancellationToken = newCache.CancellationTokenSource.Token;

            newCache.Task = Task.Factory.StartNew(async() =>
            {
                // Cancel when request
                await Task.Delay(700);
                cancellationToken.ThrowIfCancellationRequested();

                // Save file
                _fileHelper.SaveByteArray(qrCodeItem.GenerateQRCodeByteArray(), qrCodeItem.Path);

                // Cancel when request
                await Task.Delay(300);
                cancellationToken.ThrowIfCancellationRequested();

                // Assign new item
                Item   = qrCodeItem;
                IsBusy = false;
            });
        }
        public ItemDetailPageViewModel(QRCodeItem item = null)
        {
            Title = item?.Data;

            Item  = item;
            IsUrl = Uri.TryCreate(item?.Data, UriKind.Absolute, out Uri uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);

            OpenUrlCommand = new Command(() => Device.OpenUri(new Uri(Item.Data)));
        }
示例#3
0
        public async Task <bool> AddItemAsync(QRCodeItem item)
        {
            if (await _db.QRCodeItems.AnyAsync(qrci => qrci.Data == item.Data))
            {
                return(true);
            }

            await _db.QRCodeItems.AddAsync(item);

            await _db.SaveChangesAsync();

            return(true);
        }
示例#4
0
        public async Task <bool> DeleteItemAsync(QRCodeItem item)
        {
            if (await _db.QRCodeItems.AnyAsync(i => i.Data == item.Data) == false)
            {
                throw new Exception("The item does not exist.");
            }

            _fileHelper.RemoveFile(item.Path);

            _db.QRCodeItems.Remove(item);
            await _db.SaveChangesAsync();

            return(true);
        }
示例#5
0
        public NewItemPageViewModel(string initialInputText)
        {
            using (var scope = AppContainer.Container.BeginLifetimeScope())
            {
                _fileHelper = AppContainer.Container.Resolve <IFileHelper>();
            }

            Title  = "New QR Code";
            IsBusy = false;

            PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == nameof(InputText))
                {
                    IsBusy = true;

                    // Cancel previous generations
                    foreach (var cache in _caches.Where(h => h.CancellationTokenSource.IsCancellationRequested == false))
                    {
                        cache.CancellationTokenSource.Cancel();
                    }

                    if (_inputText == "")
                    {
                        IsBusy = false;
                        Item   = null;

                        return;
                    }

                    GenerateNewCache(new QRCodeItem(_inputText));
                }
            };

            InputText = initialInputText ?? throw new ArgumentNullException(nameof(initialInputText));
        }
示例#6
0
 public Task <bool> UpdateItemAsync(QRCodeItem item)
 {
     throw new NotImplementedException();
 }
示例#7
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // For example, look for an image and place it into an image view.
            // Replace this with something appropriate for the type[s] your extension supports.
            bool imageFound = false;

            foreach (var item in ExtensionContext.InputItems)
            {
                foreach (var itemProvider in item.Attachments)
                {
                    var foundType = _acceptedTypes.FirstOrDefault(at => itemProvider.HasItemConformingTo(at));

                    if (foundType == null)
                    {
                        continue;
                    }


                    itemProvider.LoadItem(foundType, null, (urlObj, error) =>
                    {
                        var url = urlObj.ToString();
                        Console.WriteLine(url);

                        if (url.Length > 256)
                        {
                            var deepLinkingUrl = string.Format("ShareQR://com.ettech.ShareQR?data={0}", url);
                            NSOperationQueue.MainQueue.AddOperation(() =>
                            {
                                _isOpenedInContainingApp = true;

                                OpenURL(new NSUrl(deepLinkingUrl));
                            });
                        }
                        else
                        {
                            dataLabel.Text = url;

                            Task.Factory.StartNew(() =>
                            {
                                _qrCodeItem      = new QRCodeItem(_fileHelper, url);
                                _qrCodeByteArray = _qrCodeItem.GenerateQRCodeByteArray();

                                using (var qrCodeByteBuffer = NSData.FromArray(_qrCodeByteArray))
                                {
                                    var image = UIImage.LoadFromData(qrCodeByteBuffer);
                                    NSOperationQueue.MainQueue.AddOperation(() => imageView.Image = image);
                                }
                            });
                        }
                    });


                    imageFound = true;
                    break;
                }

                if (imageFound)
                {
                    NSOperationQueue.MainQueue.AddOperation(() => saveButton.Enabled = true);

                    break;
                }
            }
        }