Esempio n. 1
0
        async void ValidateSignatureAndUpload()
        {
            Dialog.ShowLoading("");

            if (Contract.SignImageSource != null)
            {
                PdfDocument duplicate = (PdfDocument)Contract.Document.Clone();


                var addPage = duplicate.Pages.Add();

                var width = addPage.GetClientSize().Width;

                PdfGraphics graphics = addPage.Graphics;

                PdfBitmap image = new PdfBitmap(new MemoryStream(contract.SignImageSource));

                graphics.DrawImage(image, new RectangleF(20, 40, width / 2, 60));


                MemoryStream m = new MemoryStream();

                duplicate.Save(m);

                var document = await StoreManager.DocumentStore.GetItemByContractId(Contract.Id, "saleContract");

                if (document == null)
                {
                    var documentItem = new Document()
                    {
                        Path = Contract.Id + '/' + "saleContract.pdf", Name = contract.Id + ".pdf", InternalName = "saleContract", ReferenceKind = "contract", ReferenceId = contract.Id, MimeType = "application/pdf"
                    };

                    var uploaded = await StoreManager.DocumentStore.InsertImage(m.ToArray(), documentItem);
                }
                else
                {
                    await PclStorage.SaveFileLocal(m.ToArray(), document.Id);

                    document.ToUpload = true;

                    await StoreManager.DocumentStore.UpdateAsync(document);

                    await StoreManager.DocumentStore.OfflineUploadSync();
                }

                Contract.ToSend = true;

                var isSent = await StoreManager.ContractStore.UpdateAsync(Contract);

                if (isSent)
                {
                    await CoreMethods.DisplayAlert(AppResources.Alert, AppResources.EmailSent, AppResources.Ok);

                    BackButton.Execute(null);
                }
            }

            Dialog.HideLoading();
        }
Esempio n. 2
0
        public App()
        {
            InitializeComponent();

            ProductConstants.Init();

            PclStorage.Init();

            BasePageModel.Init();

            storeManager = DependencyService.Get <IStoreManager>() as StoreManager;

            Init();

            MainPage = new ContentPage();
        }
Esempio n. 3
0
        public async Task <IEnumerable <bool> > PullLatest(string KindId, string Kind)
        {
            await InitializeStore().ConfigureAwait(false);
            await PullLatestAsync().ConfigureAwait(false);

            var items = await GetItemsByKindAndReferenceIdAsync(KindId, Kind);

            List <bool> returnBool = new List <bool>();

            if (items != null)
            {
                foreach (var item in items)
                {
                    var fileName = item.InternalName + "." + item.Extension;
                    var IsExist  = await PclStorage.IsFileExistAsync(fileName, item.ReferenceKind, item.ReferenceId);

                    if (!IsExist && !string.IsNullOrEmpty(item.Path)) // Only download files who have some value in the path field.
                    {
                        var document = await DownLoadDocument(item.Id);

                        if (document != null)
                        {
                            var response = await PclStorage.SaveFileLocal(document, fileName, item.ReferenceKind, item.ReferenceId);

                            if (response == true)
                            {
                                returnBool.Add(true);
                            }
                            else
                            {
                                returnBool.Add(false);
                            }
                        }
                        else
                        {
                            returnBool.Add(false);
                        }
                    }
                    else
                    {
                        returnBool.Add(true);
                    }
                }
            }

            return(returnBool);
        }
        public async override void Init(object initData)
        {
            base.Init(initData);

            documentToDisplay = (DocumentMindurry)initData;

            Title = documentToDisplay.Name;
            var docDownloaded = await PclStorage.LoadFileLocal(documentToDisplay.InternalName + ".pdf", documentToDisplay.ReferenceKind, documentToDisplay.ReferenceId);

            if (docDownloaded != null)
            {
                PdfDocumentStream = new MemoryStream(docDownloaded);
                Visibility        = true;
            }
            else
            {
                Message    = "Une erreur est survenue, Merci de réessayer.";
                Visibility = false;
            }
        }
Esempio n. 5
0
        private async Task PullLatest()
        {
            await InitializeStore().ConfigureAwait(false);

            var items = await GetItemsAsync(true);

            foreach (var item in items)
            {
                var IsExist = await PclStorage.IsFileExistAsync(item.Id);

                if (!IsExist)
                {
                    var document = await DownLoadDocument(item.Id);

                    if (document != null)
                    {
                        var response = await PclStorage.SaveFileLocal(document, item.Id);
                    }
                }
            }
        }
Esempio n. 6
0
        public async Task <bool> InsertImage(byte[] data, Document document)
        {
            if (data == null)
            {
                return(false);
            }

            document.ToUpload = true;

            var response = await PclStorage.SaveFileLocal(data, document.Id);

            var resp = await InsertAsync(document);

            var res = await UploadDocument(data, document);

            if (res)
            {
                document.ToUpload = false;
                await UpdateAsync(document);
            }

            return(res);
        }
Esempio n. 7
0
        public virtual async Task <bool> OfflineUploadSync()
        {
            if (CrossConnectivity.Current.IsConnected)
            {
                await InitializeStore().ConfigureAwait(false);

                var items = await GetItemsAsync(true);

                foreach (var item in items)
                {
                    if (item.ToUpload)
                    {
                        var file = await PclStorage.LoadFileLocal(item.Id);

                        if (file != null)
                        {
                            var isUploaded = await UploadDocument(file, item);

                            if (isUploaded)
                            {
                                item.ToUpload = false;
                                await UpdateAsync(item);
                            }
                        }
                    }
                }

                // await PullLatest();

                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 8
0
        public async override void Init(object initData)
        {
            base.Init(initData);

            Apartment = (Apartment)initData;

            if (!string.IsNullOrEmpty(Apartment.ContactId))
            {
                Contact Contact = await StoreManager.ContactStore.GetItemAsync(Apartment.ContactId);

                if (Contact != null)
                {
                    ContactName = Contact.Name;
                }
            }

            // terraces list
            var terraces = await StoreManager.TerraceStore.GetTerracesByResidenceId(Apartment.ResidenceId, Apartment.Id);

            if (terraces != null && terraces.Any())
            {
                Terraces = new ObservableCollection <Terrace>(terraces);
            }
            // gardens list
            var gardens = await StoreManager.GardenStore.GetGardensByResidenceId(Apartment.ResidenceId, Apartment.Id);

            if (gardens != null && gardens.Any())
            {
                Gardens = new ObservableCollection <Garden>(gardens);
            }
            //Pull document from Azure Storage to  Locastorage if internet
            var current = Connectivity.NetworkAccess;

            if (current == NetworkAccess.Internet)
            {
                var resultPull = await StoreManager.DocumentMindurryStore.PullLatest(Apartment.Id, ReferenceKind.Apartment.ToString().ToLower());
            }
            //Documents
            var docs = await StoreManager.DocumentMindurryStore.GetItemsByKindAndReferenceIdAsync(Apartment.Id, ReferenceKind.Apartment.ToString().ToLower());

            if (docs != null && docs.Any())
            {
                DocumentMindurry documentToDisplay;
                string           fileName;

                var finals = docs.Where(x => x.DocumentType == DocumentType.Definitif.ToString().ToLower());
                if (finals != null && finals.Any())
                {
                    documentToDisplay = finals.First();
                    fileName          = documentToDisplay.InternalName + "." + documentToDisplay.Extension;
                    var docDownloaded = await PclStorage.LoadFileLocal(fileName, ReferenceKind.Apartment.ToString().ToLower(), documentToDisplay.ReferenceId);

                    //  var docDownloaded = await StoreManager.DocumentMindurryStore.DownLoadDocument(documentToDisplay.Id);
                    PdfDocumentStream = new MemoryStream(docDownloaded);
                }
                else
                {
                    var signs = docs.Where(x => x.DocumentType == DocumentType.Signe.ToString().ToLower());
                    if (signs != null && signs.Any())
                    {
                        documentToDisplay = signs.First();
                        fileName          = documentToDisplay.InternalName + "." + documentToDisplay.Extension;
                        var docDownloaded = await PclStorage.LoadFileLocal(fileName, ReferenceKind.Apartment.ToString().ToLower(), documentToDisplay.ReferenceId);

                        //  var docDownloaded = await StoreManager.DocumentMindurryStore.DownLoadDocument(documentToDisplay.Id);
                        PdfDocumentStream = new MemoryStream(docDownloaded);
                    }
                    else
                    {
                        var initials = docs.Where(x => x.DocumentType == DocumentType.Initial.ToString().ToLower());
                        if (initials != null && initials.Any())
                        {
                            documentToDisplay = initials.First();
                            fileName          = documentToDisplay.InternalName + "." + documentToDisplay.Extension;
                            var docDownloaded = await PclStorage.LoadFileLocal(fileName, ReferenceKind.Apartment.ToString().ToLower(), documentToDisplay.ReferenceId);

                            //    var docDownloaded = await StoreManager.DocumentMindurryStore.DownLoadDocument(documentToDisplay.Id);
                            PdfDocumentStream = new MemoryStream(docDownloaded);
                        }
                    }
                }
            }
        }
Esempio n. 9
0
        public async Task <byte[]> GetDocumentDataById(string key)
        {
            var data = await PclStorage.LoadFileLocal(key);

            return(data);
        }