public void Delete(string mediaId, MediaObjectTypeEnum mediaType)
        {
            string mediaPath        = ImagePathManager.GetMediaFilename(mediaId, mediaType, false);
            string mediaPreviewPath = ImagePathManager.GetMediaFilename(mediaId, mediaType, true);

            try
            {
                string fileToDelete = Path.Combine(_pictureDir, mediaPath);
                if (File.Exists(fileToDelete))
                {
                    File.Delete(fileToDelete);
                }
            }
            catch (Exception)
            {
            }
            try
            {
                string fileToDelete = Path.Combine(_pictureDir, mediaPreviewPath);
                if (File.Exists(fileToDelete))
                {
                    File.Delete(fileToDelete);
                }
            }
            catch (Exception)
            {
            }
        }
Exemple #2
0
        internal void AddMediaItem(string mediaId, MediaObjectTypeEnum mediaType)
        {
            ViewRoutePointMediaObject media = new ViewRoutePointMediaObject();

            media.RoutePointMediaObjectId = mediaId;
            media.RoutePointId            = Id;
            media.Version   = 1;
            media.MediaType = mediaType;
            mediaManager.Save(media);
            load(Id);
        }
Exemple #3
0
        private async Task <bool> uploadMedia(string routePointId, string mediaId, MediaObjectTypeEnum mediaMediaType, bool loadOnlyPreviewImg)
        {
            string filename     = ImagePathManager.GetMediaFilename(mediaId, mediaMediaType, loadOnlyPreviewImg);
            bool   uploadResult = await _routePointMediaObjectsApi.SendImage(routePointId, mediaId, mediaMediaType, loadOnlyPreviewImg);

            if (!uploadResult)
            {
                HandleError.Process("SyncRoute", "ErrorUploadMedia", new Exception("ErrorUploadMedia"), false, $"filename:[{filename}], status:[{_routePointMediaObjectsApi.LastHttpStatusCode.ToString()}]");
            }

            return(uploadResult);
        }
 internal void FillFromWSModel(SharedModelsWS.RoutePointMediaObject mediaObject)
 {
     if (mediaObject != null)
     {
         _id              = mediaObject.Id;
         _routePointId    = mediaObject.RoutePointId;
         _filename        = $"img_{_id}.jpg";
         _filenamePreview = $"img_{_id}_preview.jpg";
         _version         = mediaObject.Version;
         _isDeleted       = mediaObject.IsDeleted;
         _mediaType       = (MediaObjectTypeEnum)mediaObject.MediaType;
     }
 }
        public void TryDeleteFile(string routePointMediaObjectId, MediaObjectTypeEnum mediaType, bool isPreview = false)
        {
            string filename = ImagePathManager.GetImagePath(routePointMediaObjectId, mediaType, isPreview);

            if (File.Exists(filename))
            {
                try
                {
                    File.Delete(filename);
                }
                catch (Exception e)
                {
                    HandleError.Process("RoutePointMediaObjectManager", "TryDeleteFile", e, false);
                }
            }
        }
Exemple #6
0
 private void refreshMediaObjects()
 {
     _mediaObjects = mediaManager.GetMediaObjectsByRoutePointId(_id)?.ToList();
     if ((_mediaObjects != null) && (_mediaObjects.Count > 0))
     {
         var routePointMediaObject = _mediaObjects[0];
         _imagePath        = ImagePathManager.GetImagePath(routePointMediaObject.RoutePointMediaObjectId, (MediaObjectTypeEnum)routePointMediaObject.MediaType);
         _imagePreviewPath = ImagePathManager.GetImagePath(routePointMediaObject.RoutePointMediaObjectId, (MediaObjectTypeEnum)routePointMediaObject.MediaType, true);
         _imageMediaId     = routePointMediaObject.RoutePointMediaObjectId;
         _imageMediaType   = (MediaObjectTypeEnum)routePointMediaObject.MediaType;
     }
     else
     {
         _imagePath        = routePointManager.GetDefaultImageFilename(_id);
         _imagePreviewPath = routePointManager.GetDefaultImagePreviewFilename(_id);
         _imageMediaId     = string.Empty;
     }
 }
Exemple #7
0
        private async Task <bool> downloadMedia(string routePointId, string mediaId, MediaObjectTypeEnum mediaMediaType, bool loadOnlyPreviewImg)
        {
            bool   downloadResult  = false;
            string filename        = ImagePathManager.GetMediaFilename(mediaId, mediaMediaType, loadOnlyPreviewImg);
            string pathToMediaFile = ImagePathManager.GetImagePath(mediaId, mediaMediaType, loadOnlyPreviewImg);

            downloadResult = File.Exists(pathToMediaFile);
            if (!downloadResult)
            {
                downloadResult = await _routePointMediaObjectsApi.GetImage(routePointId, mediaId, ImagePathManager.GetPicturesDirectory(), filename);

                if (!downloadResult)
                {
                    HandleError.Process("SyncRoute", "ErrorDownloadMedia", new Exception("ErrorDownloadMedia"), false, $"filename:[{filename}], status:[{_routePointMediaObjectsApi.LastHttpStatusCode.ToString()}]");
                }
            }

            return(downloadResult);
        }
        public void Load(string mediaId)
        {
            var mediaObject = manager.GetMediaObjectById(mediaId);

            if (mediaObject != null)
            {
                _id                   = mediaObject.RoutePointMediaObjectId;
                _routePointId         = mediaObject.RoutePointId;
                _filename             = $"img_{_id}.jpg";
                _filenamePreview      = $"img_{_id}_preview.jpg";
                _version              = mediaObject.Version;
                _originalServerSynced = mediaObject.OriginalServerSynced;
                _previewServerSynced  = mediaObject.PreviewServerSynced;
                _serverSyncedDate     = mediaObject.ServerSyncedDate;
                _isDeleted            = mediaObject.IsDeleted;
                _mediaType            = (MediaObjectTypeEnum)mediaObject.MediaType;
                _processed            = mediaObject.Processed;
                _processResultText    = mediaObject.ProcessResultText;
            }
        }
Exemple #9
0
        private async Task <HttpStatusCode> syncMediaFileAsync(string routePointId, string mediaId, string pathToPicturesDirectory, MediaObjectTypeEnum mediaType, bool isPreview)
        {
            bool result = false;

            string filename        = ImagePathManager.GetMediaFilename(mediaId, mediaType, isPreview);
            string pathToMediaFile = ImagePathManager.GetImagePath(mediaId, mediaType, isPreview);

            if (!File.Exists(pathToMediaFile))
            {
                result = await _routePointMediaObjectsApi.GetImage(routePointId, mediaId, pathToPicturesDirectory, filename);

                _log.AddStringEvent($"get image point:{routePointId},  media:{mediaId}, filename:{filename}, result http status:{_routePointMediaObjectsApi.LastHttpStatusCode}");
            }
            else
            {
                result = await _routePointMediaObjectsApi.SendImage(routePointId, mediaId, mediaType, isPreview);

                _log.AddStringEvent($"send image point:{routePointId},  media:{mediaId}, filename:{filename}, result http status:{_routePointMediaObjectsApi.LastHttpStatusCode}");
            }

            return(_routePointMediaObjectsApi.LastHttpStatusCode);
        }
Exemple #10
0
        private async Task <HttpStatusCode> updateMediaFileAsync(string routePointId, string routePointMediaObjectId, MediaObjectTypeEnum mediaType, bool isPreview)
        {
            string pathToMediaFilesDirectory = ImagePathManager.GetPicturesDirectory();

            return(await syncMediaFileAsync(routePointId, routePointMediaObjectId, pathToMediaFilesDirectory, mediaType, isPreview));
        }
Exemple #11
0
        public async Task <bool> SendImage(string routePointId, string routePointMediaObjectId, MediaObjectTypeEnum mediaType, bool isPreview = false)
        {
            bool   sendResult      = false;
            string nameMediafile   = ImagePathManager.GetMediaFilename(routePointMediaObjectId, mediaType, isPreview);
            string pathToMediaFile = ImagePathManager.GetImagePath(routePointMediaObjectId, mediaType, isPreview);

            if (File.Exists(pathToMediaFile))
            {
                int maxRetryCount = 3;
                for (int triesCount = 0; triesCount < maxRetryCount; triesCount++)
                {
                    sendResult = await TryToSendFileAsync(pathToMediaFile, nameMediafile, routePointId, routePointMediaObjectId);

                    if (sendResult)
                    {
                        return(sendResult);
                    }
                    else
                    {
                        Thread.Sleep(30); //ToDo: останавливает основной поток, UI будет тупить, надо на таймер переделать
                        HandleError.Process("RoutePointMediaObjectApiRequest", "SendImage", new Exception($"Retry send {nameMediafile}"), false);
                        if (triesCount >= maxRetryCount - 1)
                        {
                            HandleError.Process("RoutePointMediaObjectApiRequest", "SendImage", new Exception($"Error send {nameMediafile}"), false);
                        }
                    }
                }
            }
            else
            {
                HandleError.Process("RoutePointMediaObjectApiRequest", "SendImage", new Exception($"File {pathToMediaFile} not found"), false);
            }
            return(sendResult);
        }