Esempio n. 1
0
        private void AddFileBtn_Click(object sender, EventArgs e)
        {
            var openFileDialog = new OpenFileDialog
            {
                Multiselect = true
            };

            if (openFileDialog.ShowDialog() == true)
            {
                if (!Directory.Exists(Constants.AdditionalDocumentsDirectory))
                {
                    Directory.CreateDirectory(Constants.AdditionalDocumentsDirectory);
                }

                foreach (var ofdFileName in openFileDialog.FileNames)
                {
                    var possiblePathToFile = Path.GetFullPath(Path.Combine(Constants.AdditionalDocumentsDirectory + "/" + Path.GetFileName(ofdFileName)));

                    if (!File.Exists(possiblePathToFile))
                    {
                        File.Copy(ofdFileName, possiblePathToFile);
                    }

                    var fileInfo = new FileInfo(possiblePathToFile);

                    if (!LocalFiles.Contains(fileInfo, new FileInfoEqualityComparer()))
                    {
                        LocalFiles.Add(fileInfo);
                        attachedFilesListView.Items.Add(new ListViewItem(new[] { "Number of contract", fileInfo.Name, fileInfo.FullName }));
                    }
                }
            }

            IsDirty = true;
        }
Esempio n. 2
0
        /// <summary>
        /// Saves and encrypts the contents into a StorageFile with the given name, and the given password.
        /// </summary>
        /// <param name="contents">The contents to encrypt.</param>
        /// <param name="fileName">The filename with which to save the file.</param>
        /// <param name="password">The password that will be used to generate the encryption key.</param>
        /// <returns>If successful, returns the created StorageFile.</returns>
        public async Task <BindableStorageFile> SaveAndEncryptFileAsync(string contents, string fileName, string password)
        {
            using (await f_lock.Acquire())
            {
                if (!_initialized)
                {
                    throw new ServiceNotInitializedException($"{nameof(FileService)} was not initialized before access was attempted.");
                }
                if (contents == null)
                {
                    throw new ArgumentException("File contents cannot be null.");
                }

                string iv = Guid.NewGuid().ToString("N"); // OLD IV code.

                string encryptedContents = LegacyEncryptionManager.Encrypt(contents, password, iv);
                var    savedFile         = await _localFolder.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName);

                await FileIO.WriteTextAsync(savedFile, encryptedContents);

                string savedFileName = savedFile.Name;

                BindableStorageFile bsf = await BindableStorageFile.Create(savedFile);

                LocalFiles.Add(bsf);

                await _ivService.Add(GetParentFolder(bsf.BackingFile), iv, FileLocation.Local);

                return(bsf);
            }
        }
Esempio n. 3
0
 public void ReadLocalFiles()
 {
     LocalFiles.Clear();
     if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Minesweeper"))
     {
         Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Minesweeper");
     }
     String[] rawfiles = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Minesweeper");
     foreach (String s in rawfiles)
     {
         if (s.Contains(".map"))
         {
             LocalFiles.Add(s);
         }
     }
 }
Esempio n. 4
0
        public async Task StopRoamingFile(IBindableStorageFile file)
        {
            using (await f_lock.Acquire())
            {
                if (!LocalFiles.Contains(file))
                {
                    //Backing values
                    string oldPath = GetParentFolder(file.BackingFile);
                    string value   = await _ivService.GetValue(oldPath, FileLocation.Roamed);

                    await _ivService.Remove(oldPath, FileLocation.Roamed);

                    await file.BackingFile.MoveAsync(_localFolder, file.BackingFile.Name, NameCollisionOption.GenerateUniqueName);

                    await _ivService.Add(GetParentFolder(file.BackingFile), value, FileLocation.Local);

                    RoamedFiles.Remove(file);

                    //UI
                    file.IsRoamed = false;
                    LocalFiles.Add(file);
                }
            }
        }
Esempio n. 5
0
        public AdditionalInfoControl(AdditionalInfo model)
        {
            Model = model;
            InitializeComponent();

            #region AddInfo table

            if (Model?.AddInfoTable != null)
            {
                foreach (var addInfo in Model.AddInfoTable)
                {
                    AddInfoListView.Items.Add(new ListViewItem(new[]
                    {
                        addInfo.NumberOfContract,
                        addInfo.Notes,
                        addInfo.OtherParticipants
                    }));
                }
            }

            AddInfoListView.EditTextBox.TextChanged += (sender, args) => IsDirty = true;
            #endregion AddInfo table

            if (!Directory.Exists(Constants.AdditionalDocumentsDirectory))
            {
                Directory.CreateDirectory(Constants.AdditionalDocumentsDirectory);
            }

            var dir   = new DirectoryInfo(Constants.AdditionalDocumentsDirectory);
            var files = dir.GetFiles();

            if (Model?.AttachedFiles != null)
            {
                //var result = Model.AttachedFiles.Intersect(files, new FileInfoEqualityComparer());

                //For changing file path if the user relocate folder with program
                var result = files.Intersect(Model.AttachedFiles, new FileInfoEqualityComparer());

                attachedFilesListView.Items.AddRange(result.Select(c => new ListViewItem(new[]
                {
                    Model.ContractFileInfo.ContainsKey(c.FullName) ? Model?.ContractFileInfo[c.FullName] : "Number of contract", c.Name, c.FullName
                })).ToArray());

                foreach (var item in result)
                {
                    LocalFiles.Add(new FileInfo(item.FullName));
                }
            }
            else
            {
                Model.AttachedFiles = new List <FileInfo>();
            }

            searchTextBox.TextChanged += (sender, args) =>
            {
                attachedFilesListView.Items.Clear(); // clear list items before adding
                // filter the items match with search key and add result to list view

                attachedFilesListView.Items.AddRange(LocalFiles
                                                     .Where(i => string.IsNullOrEmpty(searchTextBox.Text.ToLowerInvariant()) ||
                                                            i.Name.ToLowerInvariant().Contains(searchTextBox.Text.ToLowerInvariant()))
                                                     .Select(c => new ListViewItem(new[] { Model.ContractFileInfo.ContainsKey(c.FullName)
                                                            ? Model?.ContractFileInfo[c.FullName]
                                                            : "Number of contract", c.Name, c.FullName })).ToArray());

                IsDirty = true;
            };

            IsDirty = false;
        }