Exemplo n.º 1
0
        /// <summary>
        /// Return the list of name of all attachements of a given entity
        /// </summary>
        /// <param name="idDocument"></param>
        /// <returns></returns>
        public override IList <string> GetAttachmentNames(string idDocument)
        {
            var result = new List <string>();
            var entityAttachmentDir = fileStore.PathCombine(AttachmentsDirectoryPath, idDocument);

            if (fileStore.FolderExists(entityAttachmentDir))
            {
                var fullFilePath = fileStore.GetFilesIn(entityAttachmentDir);
                result = fullFilePath.Select(file => file.Substring(file.LastIndexOf("\\", StringComparison.Ordinal) + 1)).ToList();
            }
            return(result);
        }
Exemplo n.º 2
0
        public void AddBookToLibrary(Book mybook)
        {
            try
            {
                FillLibrary();

                if (_myLibrary == null)
                {
                    _myLibrary = new List <Book>();
                    _myLibrary.Add(mybook);
                }
                else
                {
                    if (CheckInLibrary(mybook))
                    {
                        _myLibrary.Remove(mybook);
                        if (CheckInLibrary(mybook))
                        {
                            List <Book> l = _myLibrary;
                            _myLibrary = new List <Book>();
                            foreach (Book b in l)
                            {
                                if (b.id != mybook.id)
                                {
                                    _myLibrary.Add(b);
                                }
                            }
                        }
                    }
                    else
                    {
                        _myLibrary.Add(mybook);
                    }
                }

                if (!_fileStore.FolderExists("MyBookApp"))
                {
                    _fileStore.EnsureFolderExists("MyBookApp");
                }
                _fileStore.WriteFile("MyBookApp/Library", JsonConvert.SerializeObject(_myLibrary));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        //Save naar file
        public static void SaveToFile(string Togglevalue)
        {
            try
            {
                if (!_fileStore.FolderExists(_folderName))
                {
                    _fileStore.EnsureFolderExists(_folderName);
                }

                // Tekst = Togglevalue;

                _fileStore.WriteFile(_folderName + "/" + _fileName, Togglevalue);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void SaveToFile()
        {
            string _folderName = "NewJob";
            string _fileName   = "Location";

            try
            {
                if (!_fileStore.FolderExists(_folderName))
                {
                    _fileStore.EnsureFolderExists(_folderName);
                }
                var json = JsonConvert.SerializeObject(Location);
                _fileStore.WriteFile(_folderName + "/" + _fileName, json);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Initialize the temp folder with every attachments copies
        /// </summary>
        public void CreateAttachmentsCopies()
        {
            IList <Log>   logs        = repo.GetAll();
            IMvxFileStore fileStore   = Mvx.Resolve <IMvxFileStore>();
            string        tempDirPath = @"./TempAttachments";

            // Create/Clear temp dir
            if (fileStore.FolderExists(tempDirPath))
            {
                fileStore.DeleteFolder(tempDirPath, true);
            }
            fileStore.EnsureFolderExists(tempDirPath);


            foreach (Log log in logs)
            {
                IList <string> attachmentsNames = repo.GetAttachmentNames(log.Id);
                if (attachmentsNames.Count > 0)
                {
                    fileStore.EnsureFolderExists(tempDirPath + "/" + log.Id);
                }
                foreach (string attachmentName in attachmentsNames)
                {
                    Stream stream = repo.GetAttachment(log.Id, attachmentName);
                    stream.Seek(0, SeekOrigin.Begin);
                    StreamReader sr = new StreamReader(stream);
                    //fileStore.WriteFile(tempDirPath + "/" + log.Id + "/" + attachmentName, sr.ReadToEnd());
                    int    b        = stream.ReadByte();
                    Stream tempFile = fileStore.OpenWrite(tempDirPath + "/" + log.Id + "/" + attachmentName);
                    while (b != -1)
                    {
                        tempFile.WriteByte((byte)b);
                        b = stream.ReadByte();
                    }
                }
            }
        }
Exemplo n.º 6
0
        public async void GetMorningJuice()
        {
            try
            {
                Recipes = await _recipeService.GetRecipes();

                int counter = Recipes.Count;

                Random   rnd          = new Random();
                int      RandomNumber = rnd.Next(1, counter);
                string   rndNumToStr  = RandomNumber.ToString();
                DateTime dateAndTime  = DateTime.Now;
                string   day          = dateAndTime.ToString("dd/MM/yyyy");
                string   folderValue  = (day + "," + rndNumToStr);
                var      _folderName  = "TextFilesFolder1";
                var      _fileName    = "MorningJuice";

                if (!_fileStore.FolderExists(_folderName))
                {
                    _fileStore.EnsureFolderExists(_folderName);
                }

                //Content van de file uitlezen
                string value = string.Empty;
                _fileStore.TryReadTextFile(_folderName + "/" + _fileName, out (value));
                string   CheckFileContent = value;
                string[] TextFileList;

                //Als er niets in zit, default data in steken
                if (CheckFileContent == null)
                {
                    _fileStore.WriteFile(_folderName + "/" + _fileName, "00/00/00,0");
                    string d = "00/00/00,0";
                    TextFileList = d.Split(',');
                }
                else
                {
                    TextFileList = CheckFileContent.Split(',');
                }

                if (TextFileList[0] != day)
                {
                    try
                    {
                        //File verwijderen om overbodige data te verwijderen.
                        _fileStore.DeleteFile(_folderName + "/" + _fileName);
                        //File aanmaken.
                        if (!_fileStore.FolderExists(_folderName))
                        {
                            _fileStore.EnsureFolderExists(_folderName);
                        }

                        _fileStore.WriteFile(_folderName + "/" + _fileName, folderValue);
                        string NewValue = string.Empty;
                        _fileStore.TryReadTextFile(_folderName + "/" + _fileName, out (NewValue));
                        string NValue = NewValue;

                        List <string> NewTextFileList = new List <string>(
                            NValue.Split(new string[] { "," }, StringSplitOptions.None));

                        int numVall        = Int32.Parse(NewTextFileList[1]);
                        int NewRandomValue = numVall;
                        MorningContent = await _recipeService.GetRecipeById(NewRandomValue);

                        RaisePropertyChanged(() => MorningContent);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
                else
                {
                    int numVall        = Int32.Parse(TextFileList[1]);
                    int NewRandomValue = numVall;
                    MorningContent = await _recipeService.GetRecipeById(NewRandomValue);

                    RaisePropertyChanged(() => MorningContent);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }