public EnregistrementPatrimoineViewModel(INavigation navigation)
        {
            _navigation     = navigation;
            _patrimoine     = new Patrimoine();
            _typePatrimoine = new TypePatrimoine();



            _multiMediaPickerService = DependencyService.Get <IMultiMediaPickerService>();

            EnregistrementCommand = new Command(async() => await EnregistrementDuBien());
            AnnulerCommand        = new Command(async() => await Annuler());


            SelectImagesCommand = new Command(async(obj) =>
            {
                var hasPermission = await CheckPermissionsAsync();
                if (hasPermission)
                {
                    Media = new ObservableCollection <Patrimoine>();
                    await _multiMediaPickerService.PickPhotosAsync();
                }
            });

            _multiMediaPickerService.OnMediaPicked += (s, a) =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    Media.Add(a);
                });
            };

            FetchTypePatrimoine();
        }
Пример #2
0
        /// <summary>
        /// Permet de réccupérer les Membres liés à un bien
        /// </summary>
        /// <example>
        /// <code>
        /// List<Membre> membres = Patrimoine.SesProprietaires();
        ///
        /// </code>
        /// </example>
        /// <param name="patrimoine">Notre bien concerné.</param>
        public static List <Membre> SesProprietaires(this Patrimoine patrimoine)
        {
            var result = new List <Membre>();

            foreach (var tmp in DatabaseHelper.sqliteconnection.Table <ObtenirBien>().Where(t => t.IdPatrimoine == patrimoine.Id).ToList())
            {
                result.Add(tmp.GetMembre());
            }
            return(result);
        }
Пример #3
0
        /// <summary>
        /// Permet d'attribuer un propriétaires à un bien.
        /// </summary>
        /// <example>
        /// <code>
        /// Patrimoine patrimoine = new Patrimoine();
        /// Patrimoine.AjouterProporiétaire(membre)
        ///
        /// </code>
        /// </example>
        /// <param name="membre">Notre membre Concerné.</param>
        /// <param name="patrimoine">Le type de type l'évenement de notre événement .</param>
        public static void AjouterProporiétaire(this Patrimoine patrimoine, Membre membre)
        {
            var ObtenirBien = new ObtenirBien()
            {
                IdPatrimoine = patrimoine.Id,
                IdMembre     = membre.Id
            };

            DatabaseHelper.sqliteconnection.Insert(ObtenirBien);
        }
Пример #4
0
        /// <summary>
        /// Permet de lier un bien à son(ses) propriétaires.
        /// </summary>
        /// <example>
        /// <code>
        /// Membre membre = new Membre();
        /// membre.AttribuerDocument(patrimoine)
        ///
        /// </code>
        /// </example>
        /// <param name="membre">Notre membre Concerné.</param>
        /// <param name="patrimoine">Le type de type l'évenement de notre événement .</param>
        public static void AttribuerPatrimoine(this Membre membre, Patrimoine patrimoine)
        {
            var ObtenirBien = new ObtenirBien()
            {
                IdPatrimoine = patrimoine.Id,
                IdMembre     = membre.Id
            };

            DatabaseHelper.sqliteconnection.Insert(ObtenirBien);
        }
Пример #5
0
        Patrimoine CreateMediaFileFromUri(Android.Net.Uri uri)
        {
            Patrimoine mediaFile = null;
            var        type      = CrossCurrentActivity.Current.Activity.ContentResolver.GetType(uri);

            var path = GetRealPathFromURI(uri);

            if (path != null)
            {
                string        fullPath           = string.Empty;
                string        thumbnailImagePath = string.Empty;
                var           fileName           = System.IO.Path.GetFileNameWithoutExtension(path);
                var           ext           = System.IO.Path.GetExtension(path) ?? string.Empty;
                MediaFileType mediaFileType = MediaFileType.Image;

                if (type.StartsWith(Enum.GetName(typeof(MediaFileType), MediaFileType.Image), StringComparison.CurrentCultureIgnoreCase))
                {
                    var fullImage  = ImageHelpers.RotateImage(path, 1);
                    var thumbImage = ImageHelpers.RotateImage(path, 0.25f);


                    fullPath = FileHelper.GetOutputPath(MediaFileType.Image, TemporalDirectoryName, $"{fileName}{ext}");
                    File.WriteAllBytes(fullPath, fullImage);

                    thumbnailImagePath = FileHelper.GetOutputPath(MediaFileType.Image, TemporalDirectoryName, $"{fileName}-THUMBNAIL{ext}");
                    File.WriteAllBytes(thumbnailImagePath, thumbImage);
                }
                else if (type.StartsWith(Enum.GetName(typeof(MediaFileType), MediaFileType.Video), StringComparison.CurrentCultureIgnoreCase))
                {
                    fullPath = path;
                    var bitmap = ThumbnailUtils.CreateVideoThumbnail(path, ThumbnailKind.MiniKind);

                    thumbnailImagePath = FileHelper.GetOutputPath(MediaFileType.Image, TemporalDirectoryName, $"{fileName}-THUMBNAIL{ext}");
                    var stream = new FileStream(thumbnailImagePath, FileMode.Create);
                    bitmap?.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
                    stream.Close();

                    mediaFileType = MediaFileType.Video;
                }

                if (!string.IsNullOrEmpty(fullPath) && !string.IsNullOrEmpty(thumbnailImagePath))
                {
                    mediaFile = new Patrimoine()
                    {
                        Path        = fullPath,
                        Type        = mediaFileType,
                        PreviewPath = thumbnailImagePath
                    };
                }
            }

            return(mediaFile);
        }
Пример #6
0
        public MiseAjourPatrimoineViewModel(INavigation navigation, int selectedPatrimoineID)
        {
            _navigation    = navigation;
            _patrimoine    = new Patrimoine();
            _patrimoine.Id = selectedPatrimoineID;


            DeleteCommand         = new Command(async() => await DeletePatrimoine());
            EnregistrementCommand = new Command(async() => await ModificationDesInfos());
            AnnulerCommand        = new Command(async() => await retourDePage());


            FetchPatrimoineDetails();
            FetchTypePatrimoine();
        }
Пример #7
0
        public DetailsPatrimoineViewModel(INavigation navigation, int selectedPatrimoineID)
        {
            _navigation     = navigation;
            _patrimoine     = new Patrimoine();
            _patrimoine.Id  = selectedPatrimoineID;
            _typePatrimoine = new TypePatrimoine
            {
                IdTypePatrimoine = selectedPatrimoineID
            };

            DeleteCommand = new Command(async() => await DeletePatrimoine());

            MiseAjourPageCommand = new Command(async() => await ModificationDesInfos());

            FetchMembreDetailsAsync();
        }
Пример #8
0
        public ListFilActualiteViewModel(INavigation navigation)
        {
            _navigation     = navigation;
            _document       = new Document();
            _membre         = new Membre();
            _evenement      = new Evenement();
            _patrimoine     = new Patrimoine();
            _typeMembre     = new TypeMembre();
            _typePatrimoine = new TypePatrimoine();
            _typeDocument   = new TypeDocument();



            AjoutEvenementCommand       = new Command(async() => await AjouterUnEvenement());
            DeleteEvenementCommand      = new Command(async() => await SupprimerUnEvenement());
            AllerAListeEvenementCommand = new Command(async() => await AllerAlaListeDesEvenements());

            AjouterDocumentCommand     = new Command(async() => await AjouterUnDocument());
            SupprimerDocumentCommand   = new Command(async() => await SupprimerUnDocument());
            AllerAListeDocumentCommand = new Command(async() => await AllerAlaListeDesDocuments());

            AjouterMembreCommand     = new Command(async() => await AjouterUnMembre());
            SupprimerMembreCommand   = new Command(async() => await SupprimerUnMembre());
            AllerAListeMembreCommand = new Command(async() => await AllerAlaListeDesMembres());

            AjouterBienCommand           = new Command(async() => await AjouterBien());
            SupprimerPatrimoineCommand   = new Command(async() => await SupprimerPatrimoine());
            AllerAListePatrimoineCommand = new Command(async() => await AllerAListePatrimoine());


            MessagingCenter.Subscribe <App>((App)Application.Current, "ActualiserListe", (sender) =>
            {
                FetchPatrimoine();
                FetchEvenements();
                FetchMembre();
                FetchDocumentsAsync();
            });



            FetchPatrimoine();
            FetchEvenements();
            FetchMembre();
            FetchDocumentsAsync();
        }
Пример #9
0
        async void FinishedPickingAssets(object sender, MultiAssetEventArgs args)
        {
            IList <Patrimoine> results = new List <Patrimoine>();
            TaskCompletionSource <IList <Patrimoine> > tcs = new TaskCompletionSource <IList <Patrimoine> >();

            var options = new PHImageRequestOptions()
            {
                NetworkAccessAllowed = true
            };

            options.Synchronous  = false;
            options.ResizeMode   = PHImageRequestOptionsResizeMode.Fast;
            options.DeliveryMode = PHImageRequestOptionsDeliveryMode.HighQualityFormat;
            bool completed = false;

            for (var i = 0; i < args.Assets.Length; i++)
            {
                var asset = args.Assets[i];

                string fileName = string.Empty;
                if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
                {
                    fileName = PHAssetResource.GetAssetResources(asset).FirstOrDefault().OriginalFilename;
                }

                switch (asset.MediaType)
                {
                case PHAssetMediaType.Video:

                    PHImageManager.DefaultManager.RequestImageForAsset(asset, new SizeF(150.0f, 150.0f),
                                                                       PHImageContentMode.AspectFill, options, async(img, info) =>
                    {
                        var startIndex = fileName.IndexOf(".", StringComparison.CurrentCulture);

                        string path = "";
                        if (startIndex != -1)
                        {
                            path = FileHelper.GetOutputPath(MediaFileType.Image, TemporalDirectoryName, $"{fileName.Substring(0, startIndex)}-THUMBNAIL.JPG");
                        }
                        else
                        {
                            path = FileHelper.GetOutputPath(MediaFileType.Image, TemporalDirectoryName, string.Empty);
                        }

                        if (!File.Exists(path))
                        {
                            img.AsJPEG().Save(path, true);
                        }

                        TaskCompletionSource <string> tvcs = new TaskCompletionSource <string>();

                        var vOptions = new PHVideoRequestOptions();
                        vOptions.NetworkAccessAllowed = true;
                        vOptions.Version      = PHVideoRequestOptionsVersion.Original;
                        vOptions.DeliveryMode = PHVideoRequestOptionsDeliveryMode.FastFormat;


                        PHImageManager.DefaultManager.RequestAvAsset(asset, vOptions, (avAsset, audioMix, vInfo) =>
                        {
                            var vPath = FileHelper.GetOutputPath(MediaFileType.Video, TemporalDirectoryName, fileName);

                            if (!File.Exists(vPath))
                            {
                                AVAssetExportSession exportSession = new AVAssetExportSession(avAsset, AVAssetExportSession.PresetHighestQuality);

                                exportSession.OutputUrl      = NSUrl.FromFilename(vPath);
                                exportSession.OutputFileType = AVFileType.QuickTimeMovie;


                                exportSession.ExportAsynchronously(() =>
                                {
                                    Console.WriteLine(exportSession.Status);

                                    tvcs.TrySetResult(vPath);
                                    //exportSession.Dispose();
                                });
                            }
                        });

                        var videoUrl = await tvcs.Task;
                        var meFile   = new Patrimoine()
                        {
                            Type        = MediaFileType.Video,
                            Path        = videoUrl,
                            PreviewPath = path
                        };
                        results.Add(meFile);
                        OnMediaPicked?.Invoke(this, meFile);

                        if (args.Assets.Length == results.Count && !completed)
                        {
                            completed = true;
                            tcs.TrySetResult(results);
                        }
                    });



                    break;

                default:

                    PHImageManager.DefaultManager.RequestImageData(asset, options, (data, dataUti, orientation, info) =>
                    {
                        string path = FileHelper.GetOutputPath(MediaFileType.Image, TemporalDirectoryName, fileName);

                        if (!File.Exists(path))
                        {
                            Debug.WriteLine(dataUti);
                            var imageData = data;
                            //var image = UIImage.LoadFromData(imageData);

                            //if (imageScale < 1.0f)
                            //{
                            //    //begin resizing image
                            //    image = image.ResizeImageWithAspectRatio((float)imageScale);
                            //}

                            //if (imageQuality < 100)
                            //{
                            //    imageData = image.AsJPEG(Math.Min(imageQuality,100));
                            //}

                            imageData?.Save(path, true);
                        }

                        var meFile = new Patrimoine()
                        {
                            Type        = MediaFileType.Image,
                            Path        = path,
                            PreviewPath = path
                        };

                        results.Add(meFile);
                        OnMediaPicked?.Invoke(this, meFile);
                        if (args.Assets.Length == results.Count && !completed)
                        {
                            completed = true;
                            tcs.TrySetResult(results);
                        }
                    });

                    break;
                }
            }


            mediaPickTcs?.TrySetResult(await tcs.Task);
        }