Esempio n. 1
0
        public bool UpdateArchiveFolder(ArchiveFolderDTO message)
        {
            List <ArchiveFolderDTO> result = new List <ArchiveFolderDTO>();

            using (var projectContext = new DataAccess.MyProjectEntities())
            {
                ArchiveFolder dbitem = null;
                if (message.ID != 0)
                {
                    dbitem = projectContext.ArchiveFolder.First(x => x.ID == message.ID);
                }
                else
                {
                    dbitem = new ArchiveFolder();
                }
                dbitem.Name = message.Name;
                dbitem.TableDrivedEntityID = (message.EntityID == 0 ? (int?)null : message.EntityID);
                if (dbitem.ID == 0)
                {
                    projectContext.ArchiveFolder.Add(dbitem);
                }
                projectContext.SaveChanges();
            }
            return(true);
        }
Esempio n. 2
0
        public async Task <ArchiveFolder> AddArchiveFolder(string archiveFolderName, string userId)
        {
            if (archiveFolderName?.Length > ArchiveFolder.MaxNameLength)
            {
                throw new ArgumentOutOfRangeException(nameof(archiveFolderName));
            }


            var user = DbContext.Users
                       .Include(x => x.ArchiveFolders)
                       .FirstOrDefault(x => x.Id == userId);

            if (user != null)
            {
                var newFolder = new ArchiveFolder()
                {
                    Name   = archiveFolderName,
                    User   = user,
                    UserId = user.Id
                };

                user.ArchiveFolders.Add(newFolder);
                await DbContext.SaveChangesAsync();

                return(newFolder);
            }

            return(null);
        }
        private void BuildDirectoryListings()
        {
            uint totalFiles = 0;

            if (ArchiveOpen == 1)
            {
                totalFiles = ArchiveHead1.FileCount;
            }
            else if (ArchiveOpen == 2)
            {
                totalFiles = ArchiveHead2.FileCount;
            }
            else
            {
                return;
            }

            DirectoryListings      = new ArchiveFolder();
            DirectoryListings.Name = "z:";

            for (int i = 0; i < totalFiles; i++)
            {
                string[] subs;
                string   tmpDIR   = "";
                string   tmpFName = "";

                if (ArchiveOpen == 1)
                {
                    tmpDIR = ArchiveFiles1[i].FullPath;
                }
                tmpFName = ArchiveFiles1[i].Name;
                if (ArchiveOpen == 2)
                {
                    tmpDIR = ArchiveFiles2[i].FullPath;
                }
                tmpFName = ArchiveFiles2[i].Name;

                tmpDIR = tmpDIR.Substring(0, tmpDIR.Length - tmpFName.Length);

                tmpDIR = tmpDIR.Replace('\\', '/') + "/";
                int oldLen = tmpDIR.Length;
                do
                {
                    oldLen = tmpDIR.Length; tmpDIR = tmpDIR.Replace("//", "/");
                }while (tmpDIR.Length != oldLen);

                subs = tmpDIR.Split('/');
                if (subs[0] != "")
                {
                    AddDIRListing(subs, 0, tmpFName, ref DirectoryListings, i);
                }
                else
                {
                    AddDIRListing(subs, 1, tmpFName, ref DirectoryListings, i);
                }
            }
        }
Esempio n. 4
0
        private string CreateTestArchive(Guid sessionId)
        {
            var tmpName = Path.GetTempFileName();

            var timeData   = new[] { 1L, 2L, 3L };
            var timeColumn = new DataColumn(
                new DataField <long>("time"),
                timeData);

            var numbersData   = new[] { 42d, 1337d, 6.022e23 };
            var numbersColumn = new DataColumn(
                new DataField <double>("cool_numbers"),
                numbersData);

            var schema = new Schema(timeColumn.Field, numbersColumn.Field);

            var json = new JObject {
                ["meta"] = new JObject(), ["user"] = new JObject()
            };


            using (var ms = new MemoryStream())
            {
                using (var parquetWriter = new ParquetWriter(schema, ms))
                    using (var groupWriter = parquetWriter.CreateRowGroup())
                    {
                        groupWriter.WriteColumn(timeColumn);
                        groupWriter.WriteColumn(numbersColumn);
                    }

                ms.Position = 0;

                using (var parquetReader = new ParquetReader(ms))
                {
                    var tableInformation = new ArchiveTableInformation()
                    {
                        Columns = new List <DataField>(parquetReader.Schema.GetDataFields()),
                        Time    = timeColumn.Field
                    };
                    var table = new ArchiveTable(json, parquetReader, tableInformation, "testData");

                    var archive = Archive.Create(tmpName);

                    var session = ArchiveSession.Create(archive, "testName");
                    var folder  = ArchiveFolder.Create(archive, sessionId, "testFolder");

                    folder.AddChild(table);
                    session.AddChild(folder);
                    archive.AddSession(session);

                    archive.WriteFile().Wait();
                    archive.Close();
                }
            }

            return(tmpName);
        }
Esempio n. 5
0
        private ArchiveFolderDTO ToArchiveFolderDTO(ArchiveFolder item)
        {
            ArchiveFolderDTO result = new ArchiveFolderDTO();

            result.ID       = item.ID;
            result.Name     = item.Name;
            result.EntityID = item.TableDrivedEntityID ?? 0;

            return(result);
        }
Esempio n. 6
0
        public void Init()
        {
            //Set global credentials for SDK
            //--- Open 'TestCredentials.resx' to edit the values ---\\
            ConnectionCredentials.AccessToken  = TestCredentials.Access_Token;
            ConnectionCredentials.ClientSecret = TestCredentials.Client_Secret;

            IArchiveConnector connector = new ArchiveConnector();

            testRootFolder = connector.GetFolder("TestArchive") ?? connector.CreateFolder("TestArchive");
        }
Esempio n. 7
0
        public void ShouldOpenNewInstanceInAnotherDirectory()
        {
            var defaultConfig  = new ArchiveFolderConfiguration();
            var archiveFolder1 = new ArchiveFolder(archiveFileName, defaultConfig);
            var first          = archiveFolder1.Extract();
            var archiveFolder2 = new ArchiveFolder(archiveFileName, defaultConfig);
            var second         = archiveFolder2.Extract();

            archiveFolder1.DeleteFolder();
            archiveFolder2.DeleteFolder();
            Assert.NotEqual(first, second);
        }
Esempio n. 8
0
        private void buttonPrevFolder_Click(object sender, EventArgs e)
        {
            if (parentFolders.Count == 0)
            {
                return;
            }

            currentFolder = parentFolders[parentFolders.Count - 1];
            parentFolders.RemoveAt(parentFolders.Count - 1);

            UpdateFileView();
        }
Esempio n. 9
0
        public void ShouldExtractRecursively()
        {
            var whales = @"./resources/whales.zip";
            var config = new ArchiveFolderConfiguration()
            {
                OutputPath    = "./whales",
                Overwrite     = true,
                ShouldCleanup = false
            };
            var archiveFolder = new ArchiveFolder(whales, config);
            var action        = Record.Exception(() => archiveFolder.Extract());

            Assert.Null(action);
            Assert.True(File.Exists("./whales/extra/extra.txt"));
        }
Esempio n. 10
0
        private string GetDIRList(ref string[] path, int pathI, ref ArchiveFolder folder)
        {
            //Console.WriteLine(folder.Name + " == " + path[pathI] + "; " + (path.Length - 2).ToString() + "; " + pathI.ToString());

            //if (pathI < path.Length - 2)
            //{
            for (int i = 0; i < folder.SubFolderCount; i++)
            {
                if (folder.SubFolders[i].Name == path[pathI + 1])
                {
                    return(GetDIRList(ref path, pathI + 1, ref folder.SubFolders[i]));
                }
            }
            //}
            //Console.WriteLine("2) " + folder.Name + " == " + path[pathI] + "; " + (path.Length - 2).ToString() + "; " + pathI.ToString());

            string listRet = string.Empty;

            if ((pathI == (path.Length - 2)) && (folder.Name == path[pathI]))
            {
                listRet += "[DIR] ." + Convert.ToChar(0x0a);
                listRet += "[DIR] .." + Convert.ToChar(0x0a);

                for (int i = 0; i < folder.SubFolderCount; i++)
                {
                    listRet += "[DIR] " + folder.SubFolders[i].Name + Convert.ToChar(0x0a);
                }
                for (int i = 0; i < folder.FileCount; i++)
                {
                    if (ArchiveOpen == 1)
                    {
                        listRet += "[FILE] " + folder.FileIndexes[i].ToString("X4") + " " + ArchiveFiles1[folder.FileIndexes[i]].Name + Convert.ToChar(0x0a);
                    }

                    else if (ArchiveOpen == 2)
                    {
                        listRet += "[FILE] " + folder.FileIndexes[i].ToString("X4") + " " + ArchiveFiles2[folder.FileIndexes[i]].Name + Convert.ToChar(0x0a);
                    }
                }

                return(listRet);
            }

            listRet += "[DIR] ." + Convert.ToChar(0x0a);
            listRet += "[DIR] .." + Convert.ToChar(0x0a);
            return(listRet);
        }
Esempio n. 11
0
        public void ShouldAllowArchiveOverwrite()
        {
            var whales        = "./resources/whales.zip";
            var defaultConfig = new ArchiveFolderConfiguration()
            {
                OutputPath    = "./whales",
                ShouldCleanup = false,
                Overwrite     = true
            };
            var archiveFolder = new ArchiveFolder(whales, defaultConfig);

            archiveFolder.Extract();
            archiveFolder = new ArchiveFolder(whales, defaultConfig);
            var action = Record.Exception(() => archiveFolder.Extract());

            Assert.Null(action);
        }
Esempio n. 12
0
        private void extractFolder(ArchiveFolder folder, string outPath)
        {
            if (!Directory.Exists(outPath))
            {
                Directory.CreateDirectory(outPath);
            }

            foreach (var subFolder in folder.SubFolders)
            {
                extractFolder(subFolder, Path.Combine(outPath, subFolder.Name));
            }

            foreach (var file in folder.Files)
            {
                file.Save(Path.Combine(outPath, file.Name));
            }
        }
Esempio n. 13
0
        public void ShouldKeepArchive()
        {
            var customConfig = new ArchiveFolderConfiguration()
            {
                OutputPath    = "./CustomFolder",
                ShouldCleanup = false
            };

            if (Directory.Exists(customConfig.OutputPath))
            {
                Directory.Delete(customConfig.OutputPath, true);
            }
            var archiveFolder = new ArchiveFolder(archiveFileName, customConfig);
            var outputPath    = archiveFolder.Extract();

            archiveFolder.DeleteFolder();
            Assert.True(Directory.Exists(customConfig.OutputPath));
        }
Esempio n. 14
0
        private void fileView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                string selectedItem = fileView.SelectedItems[0].Text;

                foreach (ArchiveFolder folder in currentFolder.Folders)
                {
                    if (folder.Name == selectedItem)
                    {
                        parentFolders.Add(currentFolder);
                        currentFolder = folder;
                        UpdateFileView();
                        break;
                    }
                }
            }
        }
        private void AddDIRListing(string[] fPath, int fIndex, string fName, ref ArchiveFolder CurrentDIR, int FileIndex)
        {
            string debugStr = "";

            for (int i = 0; i < CurrentDIR.SubFolderCount; i++)
            {
                if (CurrentDIR.SubFolders[i].Name == fPath[fIndex])
                {
                    if (fIndex == fPath.Length - 1)
                    {
                        for (int i2 = 0; i2 < fIndex; i2++)
                        {
                            debugStr += fPath[i2] + "/";
                        }
                        Console.WriteLine("(To-Do 1) Add File: " + debugStr);
                        return;
                    }
                    else
                    {
                        AddDIRListing(fPath, fIndex + 1, fName, ref CurrentDIR.SubFolders[i], FileIndex);
                        return;
                    }
                }
            }
            if (fIndex == fPath.Length - 1)
            {
                if (fName.Length > 0)
                {
                    CurrentDIR.FileCount++;
                    Array.Resize(ref CurrentDIR.FileIndexes, CurrentDIR.FileCount);
                    CurrentDIR.FileIndexes[CurrentDIR.FileCount - 1] = FileIndex;
                }
                return;
            }

            CurrentDIR.SubFolderCount++;
            Array.Resize(ref CurrentDIR.SubFolders, CurrentDIR.SubFolderCount);

            CurrentDIR.SubFolders[CurrentDIR.SubFolderCount - 1].Name = fPath[fIndex];

            int subI = CurrentDIR.SubFolderCount - 1;

            AddDIRListing(fPath, fIndex + 1, fName, ref CurrentDIR.SubFolders[subI], FileIndex);
        }
Esempio n. 16
0
        private TreeNode createNode(ArchiveFolder folder)
        {
            var nodes = new List <TreeNode>();

            foreach (var subfolder in folder.SubFolders)
            {
                nodes.Add(createNode(subfolder));
            }

            foreach (var file in folder.Files)
            {
                nodes.Add(createNode(file));
            }

            return(new TreeNode(folder.Name, nodes.ToArray())
            {
                Tag = folder
            });
        }
Esempio n. 17
0
 public override AbstractFolder AbstractCreateFolder(string folderName)
 {
     var newFolder = new ArchiveFolder(AbstractPath, InnerPath + folderName);
     return newFolder;
 }
Esempio n. 18
0
        public void SaveSingleDataArchive()
        {
            Guid sessionId = Guid.NewGuid(); // Todo fake sessionId

            var tmpName = Path.GetTempFileName();

            var timeData   = new[] { 1L, 2L, 3L };
            var timeColumn = new DataColumn(
                new DataField <long>("time"),
                timeData);

            var numbersData   = new[] { 42d, 1337d, 6.022e23 };
            var numbersColumn = new DataColumn(
                new DataField <double>("cool_numbers"),
                numbersData);

            var schema = new Schema(timeColumn.Field, numbersColumn.Field);

            var json = new JObject {
                ["meta"] = new JObject(), ["user"] = new JObject()
            };


            using (var ms = new MemoryStream())
            {
                using (var parquetWriter = new ParquetWriter(schema, ms))
                    using (var groupWriter = parquetWriter.CreateRowGroup())
                    {
                        groupWriter.WriteColumn(timeColumn);
                        groupWriter.WriteColumn(numbersColumn);
                    }
                ms.Position = 0;

                using (var parquetReader = new ParquetReader(ms)) {
                    var tableInformation = new ArchiveTableInformation()
                    {
                        Columns = new List <DataField>(parquetReader.Schema.GetDataFields()),
                        Time    = timeColumn.Field
                    };
                    var table = new ArchiveTable(json, parquetReader, tableInformation, "testData");

                    var archive = Archive.Create(tmpName);

                    var session = ArchiveSession.Create(archive, "testName");
                    var folder  = ArchiveFolder.Create(archive, sessionId, "testFolder");

                    folder.AddChild(table);
                    session.AddChild(folder);
                    archive.AddSession(session);

                    try
                    {
                        archive.WriteFile().Wait();
                    }
                    catch (Exception)
                    {
                        Assert.True(false);
                    }

                    archive.Close();

                    using (var fr = new FileReader(tmpName))
                    {
                        var openTask = Archive.Open(fr);
                        openTask.Wait();
                        var newArchive = openTask.Result;
                        AssertArchivesEqual(archive, newArchive);

                        Assert.Equal("testName", session.Name);
                        Assert.Single(newArchive.Sessions.First().Children);
                        var readFolder = newArchive.Sessions.First().Children.First();
                        Assert.Equal("testFolder", readFolder.Name);
                        Assert.Single(readFolder.Children);

                        var child = readFolder.Children.First();
                        Assert.Single(child.DataPoints);

                        Assert.IsAssignableFrom <ArchiveTable>(child);
                        var tableChild = (ArchiveTable)child;

                        var dataPoint = tableChild.DataPoints.First();
                        var context   = new TimeSynchronizedContext();
                        context.AvailableTimeRangeChanged +=
                            (sender, from, to) => context.SetSelectedTimeRange(from, to);

                        var viewer = context.GetDataViewerFor(dataPoint);
                        viewer.Wait();
                        var dataViewer = viewer.Result;

                        Assert.IsAssignableFrom <ITimeSeriesViewer>(dataViewer);
                        var timeViewer = (ITimeSeriesViewer)dataViewer;

                        var data = timeViewer.GetCurrentData <double>();
                        Assert.Equal("cool_numbers", dataViewer.DataPoint.Name);

                        Assert.Equal(timeData, data.X.ToArray());
                        Assert.Equal(numbersData, data.Y.ToArray());

                        newArchive.Close();
                    }
                }
            }

            File.Delete(tmpName);
        }
Esempio n. 19
0
    public async Task Init()
    {
        var connector = FortnoxClient.ArchiveConnector;

        testRootFolder = await connector.GetFolderAsync("TestArchive");
    }
        private void DelFile(ref ArchiveFolder parent, string[] path, int pathI, string fName)
        {
            if (pathI == path.Length - 2)
            {
                for (int i = 0; i < parent.FileCount; i++)
                {
                    if (ArchiveOpen == 1)
                    {
                        if (ArchiveFiles1[parent.FileIndexes[i]].Name == fName)
                        {
                            int fIndex = parent.FileIndexes[i];

                            for (int i2 = i; i2 < parent.FileCount - 1; i2++)
                            {
                                parent.FileIndexes[i2] = parent.FileIndexes[i2 + 1];
                            }
                            Array.Resize(ref parent.FileIndexes, parent.FileIndexes.Length - 1);
                            parent.FileCount--;

                            int totIndex = Convert.ToInt32(ArchiveHead1.FileCount);
                            for (int i2 = fIndex; i2 < totIndex - 1; i2++)
                            {
                                ArchiveFiles1[i2] = ArchiveFiles1[i2 + 1];
                            }
                            ArchiveHead1.FileCount--;

                            return;
                        }
                    }
                    else if (ArchiveOpen == 2)
                    {
                        if (ArchiveFiles2[parent.FileIndexes[i]].Name == fName)
                        {
                            int fIndex = parent.FileIndexes[i];

                            for (int i2 = i; i2 < parent.FileCount - 1; i2++)
                            {
                                parent.FileIndexes[i2] = parent.FileIndexes[i2 + 1];
                            }
                            Array.Resize(ref parent.FileIndexes, parent.FileIndexes.Length - 1);
                            parent.FileCount--;

                            int totIndex = Convert.ToInt32(ArchiveHead2.FileCount);
                            for (int i2 = fIndex; i2 < totIndex - 1; i2++)
                            {
                                ArchiveFiles2[i2] = ArchiveFiles2[i2 + 1];
                            }

                            ArchiveHead2.FileCount--;
                            Array.Resize(ref ArchiveFiles2, ArchiveFiles2.Length - 1);

                            return;
                        }
                    }
                }
                return;
            }

            for (int i = 0; i < parent.SubFolderCount; i++)
            {
                if (parent.SubFolders[i].Name == path[pathI + 1])
                {
                    DelFile(ref parent.SubFolders[i], path, pathI + 1, fName);
                    return;
                }
            }
        }
Esempio n. 21
0
 public void LoadArchive(string path)
 {
     archive       = Archive.Load(path);
     rootFolder    = archive.GetFileHierarchy();
     currentFolder = rootFolder;
 }
Esempio n. 22
0
        public override void AbstractOpen()
        {
            DirectoriesList.Clear();
            FilesList.Clear();

            var arc = ZipFile.Open(AbstractPath, ZipArchiveMode.Update);
           
                var existingFolders = new List<string>();

                foreach (var item in arc.Entries)
                {
                    if (item.FullName.LastIndexOf(@"/", System.StringComparison.Ordinal) == item.FullName.Length - 1)
                    {
                        if (InnerPath == "")
                        {
                            if (
                                existingFolders.Contains(item.FullName.Substring(0,
                                    item.FullName.IndexOf(@"/", System.StringComparison.Ordinal) + 1)) ||
                                item.FullName.Substring(0,
                                    item.FullName.IndexOf(@"/", System.StringComparison.Ordinal) + 1) == "") continue;
                            var newFolder = new ArchiveFolder(AbstractPath, item.FullName.Substring(0, item.FullName.IndexOf(@"/", System.StringComparison.Ordinal) + 1));
                            DirectoriesList.Add(newFolder);
                            existingFolders.Add(item.FullName.Substring(0, item.FullName.IndexOf(@"/", System.StringComparison.Ordinal) + 1));
                        }
                        else
                        {
                            if (item.FullName.IndexOf(InnerPath, System.StringComparison.Ordinal) >= 0)
                            {
                                var inPath = item.FullName.Replace(InnerPath, "");
                                if (!existingFolders.Contains(inPath.Substring(0, inPath.IndexOf(@"/", System.StringComparison.Ordinal) + 1)) &&
                                    inPath.Substring(0, inPath.IndexOf(@"/", System.StringComparison.Ordinal) + 1) != "")
                                {
                                    var newFolder = new ArchiveFolder(AbstractPath, item.FullName);
                                    DirectoriesList.Add(newFolder);
                                    existingFolders.Add(inPath.Substring(0, inPath.IndexOf(@"/", System.StringComparison.Ordinal) + 1));
                                }
                            }
                        }
                    }
                    else
                    {
                        if (InnerPath == "")
                        {
                            if (item.FullName.IndexOf(@"/", System.StringComparison.Ordinal) < 0)
                            {
                                var newFile = new ArchiveFile(item.FullName, item);
                                FilesList.Add(newFile);
                            }
                        }
                        else
                        {
                            if (item.FullName.IndexOf(InnerPath, System.StringComparison.Ordinal) >= 0)
                            {
                                var inPath = item.FullName.Replace(InnerPath, "");
                                if (inPath.IndexOf(@"/", System.StringComparison.Ordinal) < 0)
                                {
                                    var newFile = new ArchiveFile(item.FullName, item);
                                    FilesList.Add(newFile);
                                }
                            }
                        }
                    }
                }

            }