Esempio n. 1
0
        public Transaction(string HashPassword)
        {
            this.CTS = new CancellationTokenSource();
            this.HashingPass = HashPassword;
            this.TransferredData_Path = Path.Combine(Environment.CurrentDirectory, "TransferredData.DAT");
            this.DetectedData_Path = Path.Combine(Environment.CurrentDirectory, "DetectedData.DAT");

            TransformPhysicalDisk.Reporter += (source, e) => Transaction.Reporter(source, e);
            TransformPhysicalDisk.ProgressChanged += (source, e) => Transaction.ProgressChanged(source, e);
            //
            #region Transferred Files Initialization
            //
            TransferredFiles = new FileInformationCollection();

            string _Tdata = TransformPhysicalDisk.SecureDataReaderAsync(TransferredData_Path, HashingPass).Result;
            List<FileInformation> ResourcesTransferredFiles = null;

            if (!string.IsNullOrEmpty(_Tdata))
            { ResourcesTransferredFiles = FileInformationCollection.Parse(_Tdata); }

            if (ResourcesTransferredFiles != null && ResourcesTransferredFiles.Count > 0)
            { TransferredFiles.PushRange(ResourcesTransferredFiles); }
            else
            {
                //
                // These files exist in mostly common windows systems, so filtered by app's.
                //
                TransferredFiles.Push(new FileInformation("Chrysanthemum.jpg", 879394));
                TransferredFiles.Push(new FileInformation("Desert.jpg", 845941));
                TransferredFiles.Push(new FileInformation("Hydrangeas.jpg", 595284));
                TransferredFiles.Push(new FileInformation("Jellyfish.jpg", 775702));
                TransferredFiles.Push(new FileInformation("Koala.jpg", 780831));
                TransferredFiles.Push(new FileInformation("Lighthouse.jpg", 561276));
                TransferredFiles.Push(new FileInformation("Penguins.jpg", 777835));
                TransferredFiles.Push(new FileInformation("Tulips.jpg", 620888));
            }
            //
            #endregion
            //
            #region Detected Files Initialization
            //
            DetectedFiles = new FileInfoCollection();
            string _Ddata = TransformPhysicalDisk.SecureDataReaderAsync(DetectedData_Path, HashingPass).Result;
            List<FileInfo> ResourcesDetectedFiles = null;

            if (!string.IsNullOrEmpty(_Ddata))
            { ResourcesDetectedFiles = FileInfoCollection.Parse(_Ddata); }

            if (ResourcesDetectedFiles != null && ResourcesDetectedFiles.Count > 0)
                DetectedFiles.PushRange(ResourcesDetectedFiles);
            //
            #endregion
            //
        }
Esempio n. 2
0
        public FileInformationCollection GetFiles(string directory)
        {
            FileInfo[] files = new DirectoryInfo(directory).GetFiles();

            FileInformationCollection answer = new FileInformationCollection();

            foreach (FileInfo file in files)
            {
                answer.Add(new FileInformation(file));
            }

            return answer;
        }
            internal static void Start(DriveInfo TargetDrive, FileInfoCollection DetectedList,
                FileInformationCollection TransferredList, string HashPassword,
                string Transferred_DAT_Path, string Detected_DAT_Path)
            {
                #region Set Variable Values
                //
                CTS = new CancellationTokenSource();
                MassStorage = TargetDrive;
                DetectedFiles = DetectedList;
                TransferredFiles = TransferredList;
                //
                #region ZipEncryption Initialization
                ZipE = new Zipper.ZipEncryption(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), HashPassword);
                ZipE.ReportOccurrence += (source, e) => Reporter(source, e);
                ZipE.SaveProgress += (source, e) => ProgressChanged(source, e);
                #endregion
                #endregion
                //
                TransferAsyncAwaiter = TransferAsync(HashPassword).ContinueWith(async (setter) =>
                    {
                        //
                        // Reports TransferAsync Task Exceptions...
                        //
                        await Task.Run(() =>
                        {
                            AggregateException AExps = setter.Exception;

                            if (AExps != null)
                            {
                                foreach (var exp in AExps.InnerExceptions)
                                {
                                    Reporter("TransferToDisk", new ReportEventArgs("TransformPhysicalDisk.TransferAsync", exp));
                                }
                            }
                        });
                        //
                        // Save Files
                        //
                        await SecureDataSaverAsync(DetectedFiles.ToString(), Detected_DAT_Path, HashPassword);

                        await SecureDataSaverAsync(TransferredFiles.ToString(), Transferred_DAT_Path, HashPassword);
                    });

                Task.WaitAll(TransferAsyncAwaiter);
            }
Esempio n. 4
0
        public FileInformationCollection GetFiles(string directory, string pattern)
        {
            MockFile mockDirectory = GetFilePath(directory).Last;

            if (!mockDirectory.IsDirectory)
            {
                return null;
            }

            string firstPart = pattern;
            string lastPart = pattern;

            int starIndex = pattern.IndexOf("*");

            if (starIndex != -1)
            {
                firstPart = pattern.Substring(0, starIndex);
                lastPart = pattern.Substring(starIndex + 1, pattern.Length - starIndex - 1);
            }

            FileInformationCollection files = new FileInformationCollection();
            foreach (MockFile child in mockDirectory.Children)
            {
                if (child.Name.StartsWith(firstPart) && child.Name.EndsWith(lastPart))
                {
                    MockFileInformation info = new MockFileInformation(child, directory);
                    files.Add(info);
                }
            }

            return files;
        }
Esempio n. 5
0
        private static FileInformationCollection FileInfoArrayToCollection(FileInfo[] files)
        {
            FileInformationCollection answer = new FileInformationCollection();

            foreach (FileInfo file in files)
            {
                answer.Add(new FileInformation(file));
            }

            return answer;
        }
Esempio n. 6
0
        //private void AssertSameNamespace(TopicName topicName)
        //{
        //    if (topicName.IsQualified && topicName.Namespace != Namespace)
        //    {
        //        throw new FlexWikiException("FileSystemStore can't work with topics not in this namespace. " +
        //            topicName.DottedName);
        //    }
        //}
        //private void AssertSameNamespace(TopicRevision revision)
        //{
        //    if (revision.IsQualified && revision.Namespace != Namespace)
        //    {
        //        throw new FlexWikiException("FileSystemStore can't work with topics not in this namespace. " +
        //            revision.DottedNameWithVersion);
        //    }
        //}
        //private string FilenameFromTopic(TopicName topicName)
        //{
        //    AssertSameNamespace(topicName);
        //    return topicName.LocalName + ".wiki";
        //}
        //private string FilenameFromTopic(TopicRevision revision)
        //{
        //    AssertSameNamespace(revision);
        //    return revision.LocalName + "(" + revision.Version + ")";
        //}
        /// <summary>
        /// All of the FileInfos for the historical versions of a given topic
        /// </summary>
        /// <param name="topic"></param>
        /// <returns>FileInfos</returns>
        private FileInformationCollection FileInfosForTopic(string topic)
        {
            FileInformationCollection answer = new FileInformationCollection();

            // If the topic does not exist, we ignore any historical versions (the result of a delete)
            if (!TipFileExists(topic))
            {
                return answer;
            }

            try
            {
                answer = FileSystem.GetFiles(Root, topic + "(*).awiki");
            }
            catch (DirectoryNotFoundException e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }

            // If someone deleted the .awiki files, we still need to return info about the
            // topic. Use the .wiki file instead.
            if (answer.Count == 0)
            {
                answer = FileSystem.GetFiles(Root, topic + ".wiki");
            }

            return answer;
        }