Ejemplo n.º 1
0
        public LogManager(IChatManager chatManager, ICharacterManager characterManager, IMessageManager messageManager, IEventManager eventManager, IMvxFileStore fileManager)
        {
            this.fileManager = fileManager;
            var settings = AppSettings.Instance.Logging;

            serializer = new MessageSerializer(characterManager);
            eventSerializerSettings = new JsonSerializerSettings {
                Converters          = new JsonConverter[] { new CharacterConverter(characterManager), new ChannelMemberConverter(characterManager), new ChannelConverter() },
                TypeNameHandling    = TypeNameHandling.Auto,
                SerializationBinder = new EventSerializationBinder()
            };
            if (settings.LogDirectory == null)
            {
                return;
            }
            eventsLogFile          = Path.Combine(settings.LogDirectory, "EventLog");
            chatManager.Connected += () => {
                logDirectory = Path.Combine(settings.LogDirectory, chatManager.OwnCharacterName);
                fileManager.EnsureFolderExists(logDirectory);
            };
            messageManager.CharacterMessageReceived += (character, message) => {
                if (settings.LogPrivate)
                {
                    LogMessage(GetLogFile(GetLogId(character), false), message);
                }
            };
            messageManager.ChannelMessageReceived += (channel, message) => {
                var isAd = message.MessageType == Message.Type.Ad;
                if (isAd && settings.LogAds || !isAd && settings.LogChannels)
                {
                    LogMessage(GetLogFile(GetLogId(channel), isAd), message);
                }
            };
            eventManager.NewEvent += NewEvent;
        }
Ejemplo n.º 2
0
        private void SaveJSONFile()
        {
            var settings = new JsonSerializerSettings()
            {
                TypeNameHandling     = TypeNameHandling.Auto,
                NullValueHandling    = NullValueHandling.Ignore,
                DefaultValueHandling = DefaultValueHandling.Ignore,
                // TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
            };

            string content = JsonConvert.SerializeObject(this.localDb, Formatting.Indented, settings);

            fileStore.EnsureFolderExists(DbDirectoryPath);
            fileStore.WriteFile(DbFilePath, content);

            SavedDbConfig();
        }
Ejemplo n.º 3
0
        public LocalMappingService()
        {
            _fileStoreAsync = Mvx.Resolve<IMvxFileStoreAsync>();
            _fileStore = Mvx.Resolve<IMvxFileStore>();
            _pathProvider = Mvx.Resolve<IPathProvider>();

            _baseDir = _pathProvider.BaseDirPath;
            _mappingsDir = Path.Combine(_baseDir, "Mappings");

            _fileStore.EnsureFolderExists(_mappingsDir);
        }
        /// <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();
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private string GenerateImagePath()
        {
            if (PictureBytes == null)
            {
                return(null);
            }

            var randomFileName = "Image" + Guid.NewGuid().ToString("N") + ".jpg";

            _fileStore.EnsureFolderExists("Images");
            var path = _fileStore.PathCombine("Images", randomFileName);

            _fileStore.WriteFile(path, PictureBytes);
            return(path);
        }
Ejemplo n.º 6
0
        public string SaveImageToFile(byte[] pictureBytes)
        {
            if (pictureBytes == null)
            {
                return(null);
            }

            var randomFileName = "Image" + Guid.NewGuid().ToString("N") + ".jpg";

            _fileStore.EnsureFolderExists("Images");
            var path = _fileStore.PathCombine("Images", randomFileName);

            _fileStore.WriteFile(path, pictureBytes);
            return(path);
        }
Ejemplo n.º 7
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;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Ensures the file can actually be written to the path and will return the full path as string
        /// </summary>
        /// <param name="folder">The name of the folder</param>
        /// <param name="fullName">The name of the file</param>
        /// <returns>Full path of the file location</returns>
        private string FileChecks(string folder, string fullName)
        {
            try
            {
                _fileStore.EnsureFolderExists(folder);
            }
            catch (Exception ex)
            {
                Mvx.Resolve <IMvxTrace>().Trace(MvxTraceLevel.Error, "ExStorageService.FileChecks", ex.Message + " - " + ex.StackTrace);
            }

            var fullPath = _fileStore.PathCombine(folder, fullName);

            if (_fileStore.Exists(fullPath))
            {
                DeleteFile(folder, fullName);
            }
            return(fullPath);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Ensures the file can actually be written to the path and will return the full path as string
        /// </summary>
        /// <param name="folder">The name of the folder</param>
        /// <param name="fullName">The name of the file</param>
        /// <returns>Full path of the file location</returns>
        private string FileChecks(string folder, string fullName)
        {
            try
            {
                _fileStore.EnsureFolderExists(folder);
            }
            catch (Exception ex)
            {
                Mvx.Resolve <IMvxLog>().ErrorException("ExStorageService.FileChecks", ex);
            }

            var fullPath = _fileStore.PathCombine(folder, fullName);

            if (_fileStore.Exists(fullPath))
            {
                DeleteFile(folder, fullName);
            }
            return(fullPath);
        }
        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;
            }
        }
        public void Initialize(string settingFolder, string settingFile)
        {
            if (string.IsNullOrEmpty(settingFolder) || string.IsNullOrEmpty(settingFile))
            {
                Debug.WriteLine("Couldn't init empty setting folder and setting file name");
                return;
            }

            _settingFolder = settingFolder;
            _settingFile   = settingFile;
            _filePath      = _fileStore.PathCombine(_settingFolder, _settingFile);
            _fileStore.EnsureFolderExists(_settingFolder);

            if (!_fileStore.Exists(_settingFile))
            {
                return;
            }

            if (!_fileStore.TryReadBinaryFile(_settingFile, LoadFrom))
            {
                _resourceLoader.GetResourceStream(_settingFile, inputStream => LoadFrom(inputStream));
            }
        }
Ejemplo n.º 13
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;
            }
        }