public async Task DeleteFile(ViewFile file)
        {
            await _graphServiceClient.Me.Drive.Special.AppRoot.ItemWithPath(file.Name.Split('.').First() + ".json")
            .Request().DeleteAsync();

            await _graphServiceClient.Me.Drive.Special.AppRoot.ItemWithPath(file.Name).Request().DeleteAsync();
        }
예제 #2
0
        public async Task <MemoryStream> DownloadFile(ViewFile file, string receiverEmail, RSAParameters receiverKey)
        {
            using (var encryptedStream = new MemoryStream())
                using (var jsonFileData = new MemoryStream())
                {
                    var decryptedStream = new MemoryStream();
                    await DownloadFile(file.JsonFileId, jsonFileData);

                    var fileData = FileDataHelpers.DownloadFileData(jsonFileData, receiverEmail);

                    await DownloadFile(file.Id, encryptedStream);

                    var senderKey = new RSAParameters
                    {
                        Exponent = fileData.SenderPublicKey.Expontent,
                        Modulus  = fileData.SenderPublicKey.Modulus
                    };
                    var isValid = SafeCloudFile.VerifySignedFile(encryptedStream, fileData.FileSign, senderKey);
                    if (!isValid)
                    {
                        throw new Exception("Invalid file sign!");
                    }

                    SafeCloudFile.Decrypt(encryptedStream, decryptedStream, fileData.UserKeys[receiverEmail], receiverKey);

                    return(decryptedStream);
                }
        }
예제 #3
0
        protected ViewChart FillChartData(Int64 id /*chart id.*/, int width, int height, Guid userId)
        {
            ViewChart viewchart = BaseChartRepository.GetChart(id, userId);

            ViewBag.Width  = (width != -1) ? width : viewchart.Width;
            ViewBag.Height = (height != -1) ? height : viewchart.Height;

            if (viewchart.ChartType.TrimEnd().ToLower() == Diagram.ToLower())
            {
                //  the reference to document is meaningful only for diagrams,
                //  so it can be null
                if (viewchart.DocID != null)
                {
                    List <String> states = ChartRepository.ExportDataElementStates((long)viewchart.DocID, userId);
                    ViewBag.DataStates = states;
                }
                else
                {
                    ViewBag.DataStates = new List <String>();
                }
            }
            else
            {
                var fileNames     = new List <String>();
                var statFileNames = new List <String>();

                var l = viewchart.DataSetType.Trim().ToLower() == LastSeconds?
                        BaseChartRepository.GetPointsVsAcqTime_Stat_LastSeconds(id, userId, viewchart.DataSetMaxCount) :
                            BaseChartRepository.GetPointsVsAcqTime_Stat_Last(id, userId, viewchart.DataSetMaxCount);

                for (int i = 0; i < l.Count(); i++)
                {
                    ViewFile vf = l[i];
                    if (vf.Content.ToLower() == "dataset")
                    {
                        fileNames.Add(vf.FileName);
                    }
                    else if (vf.Content.ToLower() == "datastat")
                    {
                        statFileNames.Add(vf.FileName);
                    }
                }
                ViewBag.FileNames     = fileNames;
                ViewBag.StatFileNames = statFileNames;
            }

            return(viewchart);
        }
예제 #4
0
 public void FS_View(Auth auth, ViewFile request, ViewFile_Logic logic, CommonResponse ecr, string[] token, string uri)
 {
     if (auth.AuthResult(token, uri))
                                         {
                                                         if (uri.IndexOf("/file/list") > 0)
                                                         {
                                                                         ecr.data.results = logic.Get_List(request);
                                                         }
                                                         ecr.meta.code = 200;
                                                         ecr.meta.message = "OK";
                                         }
                                         else
                                         {
                                                         ecr.meta.code = 401;
                                                         ecr.meta.message = "Unauthorized";
                                         }
 }
예제 #5
0
 public void FS_View(Auth auth, ViewFile request, ViewFile_Logic logic, CommonResponse ecr, string[] token, string uri)
 {
     if (auth.AuthResult(token, uri))
     {
         if (uri.IndexOf("/file/list") > 0)
         {
             ecr.data.results = logic.Get_List(request);
         }
         ecr.meta.code    = 200;
         ecr.meta.message = "OK";
     }
     else
     {
         ecr.meta.code    = 401;
         ecr.meta.message = "Unauthorized";
     }
 }
        public async Task <MemoryStream> DownloadFile(ViewFile file, string receiverEmail, RSAParameters receiverKey)
        {
            var decryptedStream = new MemoryStream();
            var jsonFileData    = await _graphServiceClient.Me.Drive.Special.AppRoot
                                  .ItemWithPath(file.Name.Split('.').First() + ".json")
                                  .Content.Request().GetAsync() as MemoryStream;

            if (jsonFileData == null)
            {
                throw new Exception("Error while downloading json file!");
            }

            var fileData = FileDataHelpers.DownloadFileData(jsonFileData, receiverEmail);

            var encryptedStream = await _graphServiceClient.Me.Drive.Special.AppRoot.ItemWithPath(file.Name).Content
                                  .Request()
                                  .GetAsync() as MemoryStream;

            if (encryptedStream == null)
            {
                throw new Exception("Error while downloading encrypted file!");
            }

            var senderKey = new RSAParameters
            {
                Exponent = fileData.SenderPublicKey.Expontent,
                Modulus  = fileData.SenderPublicKey.Modulus
            };

            encryptedStream.Position = 0;
            var isValid = SafeCloudFile.VerifySignedFile(encryptedStream, fileData.FileSign, senderKey);

            if (!isValid)
            {
                throw new Exception("Invalid file sign!");
            }

            SafeCloudFile.Decrypt(encryptedStream, decryptedStream, fileData.UserKeys[receiverEmail], receiverKey);

            jsonFileData.Close();
            encryptedStream.Close();

            return(decryptedStream);
        }
      public async Task <IActionResult> Create(ViewFile model)
      {
          if (ModelState.IsValid)
          {
              string uniqueFilename = null;
              if (model.formFile != null)
              {
                  string ext = System.IO.Path.GetExtension(model.formFile.FileName);
                  if (ext == ".pdf")
                  {
                      string upload = System.IO.Path.Combine(_env.WebRootPath, "images");
                      uniqueFilename = Guid.NewGuid().ToString() + "_" + model.formFile.FileName;
                      string filepath = System.IO.Path.Combine(upload, uniqueFilename);
                      model.formFile.CopyTo(new System.IO.FileStream(filepath, System.IO.FileMode.Create));
                      //string filepath = $"{_env.WebRootPath}/images/{model.formFile.FileName}";
                      //var stream = System.IO.File.Create(filepath);
                      //model.formFile.CopyTo(stream);
                  }
                  else
                  {
                      TempData["Error"] = "Only Pdf files are allowed";
                      return(RedirectToAction("Create", "YogaTables"));
                  }
              }


              YogaTable newfile = new YogaTable
              {
                  YogaId   = model.YogaId,
                  YogaName = model.YogaName,
                  YogaStep = uniqueFilename,
                  Ydfk     = model.Ydfk,
                  YdfkId   = model.YdfkId,
              };
              _context.Add(newfile);
              await _context.SaveChangesAsync();

              return(RedirectToAction(nameof(Index)));
          }


          return(View());
      }
예제 #8
0
        private static ViewFile ViewFileCreator(string filepath, FileInfo infoFile, string[] names, string FileState, string Description, string Version)
        {
            //Creating viewer object to show info
            ViewFile viewer = new ViewFile()
            {
                Extension       = infoFile.Extension.ToUpper(),
                FileSize        = (infoFile.Length / 1024).ToString() + " kB",
                PartNo          = infoFile.Name.Substring(0, 7),
                SourceLocation  = filepath,
                FileName        = infoFile.Name,
                SiteFound       = false,
                Supplier        = "",
                Version         = Version,
                FileDescription = Description,
                Status          = FileState,
                FolderName      = ""
            };

            return(viewer);
        }
예제 #9
0
        private void listBoxFiles_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                return;
            }
            var index = listBoxFiles.IndexFromPoint(e.Location);

            if (index != ListBox.NoMatches)
            {
                listBoxFiles.SelectedIndex = index;
                _selectedFile = listBoxFiles.Items[index] as ViewFile;
                fileContextMenuStrip.Show(Cursor.Position);
                fileContextMenuStrip.Visible = true;
            }
            else
            {
                fileContextMenuStrip.Visible = false;
            }
        }
        public async Task <MemoryStream> DownloadFile(ViewFile file, string receiverEmail, RSAParameters receiverKey)
        {
            using (var encryptedStream = new MemoryStream())
                using (var jsonFileData = new MemoryStream())
                {
                    var decryptedStream          = new MemoryStream();
                    var jsonFileDownloadProgress =
                        await _driveService.Files.Get(file.JsonFileId).DownloadAsync(jsonFileData);

                    if (jsonFileDownloadProgress.Status != DownloadStatus.Completed)
                    {
                        throw new Exception("Error while downloading json file!");
                    }

                    var fileData = FileDataHelpers.DownloadFileData(jsonFileData, receiverEmail);

                    var encryptedFileDownloadProgress =
                        await _driveService.Files.Get(file.Id).DownloadAsync(encryptedStream);

                    if (encryptedFileDownloadProgress.Status != DownloadStatus.Completed)
                    {
                        throw new Exception("Error while downloading encrypted file!");
                    }

                    var senderKey = new RSAParameters
                    {
                        Exponent = fileData.SenderPublicKey.Expontent,
                        Modulus  = fileData.SenderPublicKey.Modulus
                    };
                    encryptedStream.Position = 0;
                    var isValid = SafeCloudFile.VerifySignedFile(encryptedStream, fileData.FileSign, senderKey);
                    if (!isValid)
                    {
                        throw new Exception("Invalid file sign!");
                    }

                    SafeCloudFile.Decrypt(encryptedStream, decryptedStream, fileData.UserKeys[receiverEmail], receiverKey);

                    return(decryptedStream);
                }
        }
예제 #11
0
        protected virtual object EvalViewFile(ParseTree tree, params object[] paramlist)
        {
            var result = new ViewFile();

            result.FileName = (string)this.GetValue(tree, TokenType.ObjectName, 0);

            int i = 0;

            while (true)
            {
                var prop = (Property)this.GetValue(tree, TokenType.Property, i++);
                if (prop == null)
                {
                    break;
                }

                if (!string.IsNullOrEmpty(prop.Name))
                {
                    result.AddProperty(prop.Name, prop.Value);
                }
            }

            return(result);
        }
예제 #12
0
        private void FormatFiles(string[] DroppedFiles, string[] SupplierArray)
        {
            foreach (string filepath in DroppedFiles)
            {
                //Creating FileInfo object of path
                FileInfo infoFile = new FileInfo(filepath);

                string[] names       = infoFile.Name.Split(new Char[] { '_', '.' });
                string   FileState   = "";
                string   Description = "";
                string   version     = "";

                if (infoFile.Extension == ".stl")
                {
                    Description = "STL";
                    FileState   = "None";
                    version     = "None";
                }
                if (names.Length == 5)
                {
                    amountOfSplits = 3;
                    Description    = "";
                    switch (names[amountOfSplits])
                    {
                    case "C":
                    case "c":
                        FileState = "Concept";
                        break;

                    case "D":
                    case "d":
                        FileState = "Design";
                        break;

                    case "P":
                    case "p":
                        FileState = "Pre-Released";
                        break;

                    case "R":
                    case "r":
                        FileState = "Released";
                        break;

                    default:
                        FileState = "Null";
                        break;
                    }
                    version = names[(names.Length - 4)] + "." + names[(names.Length - 3)];
                }
                if (names.Length == 3)
                {
                    Description = "Deco Spec";
                    FileState   = "None";
                    version     = "None";
                }


                if (names.Length != 5 && names.Length != 3 && Description != "STL")
                {
                    FileState = "Error";
                }


                ViewFile viewer = ViewFileCreator(filepath, infoFile, names, FileState, Description, version);

                //Add the newFilename property
                if (viewer.Extension == ".PDF")
                {
                    if (viewer.Version == "None")
                    {
                        viewer.NewFileName = $"{names[0]}_deco.pdf";
                    }
                    else
                    {
                        viewer.NewFileName = viewer.NewFileName = $"{names[0]}D_{names[1]}_{names[2]}{viewer.Extension}";
                    }
                }
                else if (viewer.Extension == ".STL")
                {
                    viewer.NewFileName = infoFile.Name;
                }
                else
                {
                    viewer.NewFileName = viewer.NewFileName = $"{viewer.PartNo}_{names[1]}_{names[2]}{viewer.Extension}";
                }

                //Looping through every dropped file
                string filename = viewer.PartNo;

                var query = from lib in DocuSetsList
                            where lib.Contains(filename)
                            select lib;

                var foundDirectories = query.ToList();

                bool haselements = foundDirectories.Any();
                if (viewer.Extension == ".STL")
                {//STL File
                    string localsite = null;
                    localsite = names[1];

                    _source.Add(new ViewFile
                    {
                        FileDescription = "STL",
                        Extension       = infoFile.Extension.ToUpper(),
                        FileSize        = (infoFile.Length / 1024).ToString() + " kB",
                        PartNo          = infoFile.Name.Substring(0, 7),
                        SourceLocation  = filepath,
                        FileName        = infoFile.Name,
                        CopySite        = localsite,
                        SiteFound       = true,
                        Version         = "None",
                        Status          = "None",
                        Supplier        = localsite.ToString().ToUpper(),
                        FolderName      = (string.Equals(localsite, "lth")) ? @"https://galaxis.axis.com/sites/Suppliers/Manufacturing/LTH/File%20Library" : @"https://galaxis.axis.com/sites/Suppliers/Manufacturing/3DPrint/File%20Library",
                        NewFileName     = infoFile.Name
                    });
                }

                else if (haselements)
                {
                    for (int i = 0; i < foundDirectories.Count; i++)
                    {
                        if (viewer.Status == "None" && viewer.Extension != ".stl")
                        {
                            var supplier = foundDirectories[i].Split(new Char[] { '/' });
                            _source.Add(new ViewFile
                            {
                                //FileDescription = "Deco Spec",
                                FileDescription = (names[0].Length > 7) ? "Variant" : "Deco Spec",
                                Extension       = infoFile.Extension.ToUpper(),
                                FileSize        = (infoFile.Length / 1024).ToString() + " kB",
                                PartNo          = infoFile.Name.Substring(0, 7),
                                SourceLocation  = filepath,
                                FileName        = infoFile.Name,
                                CopySite        = foundDirectories[i].ToString(),
                                SiteFound       = true,
                                Version         = "None",
                                Status          = "None",
                                Supplier        = supplier[4],
                                FolderName      = @"https://galaxis.axis.com/" + foundDirectories[i].ToString(),
                                NewFileName     = $"{names[0]}_deco.pdf"
                            });
                        }
                        else if (viewer.Extension != ".STL")
                        {
                            var supplier = foundDirectories[i].Split(new Char[] { '/' });
                            _source.Add(new ViewFile
                            {
                                Extension      = infoFile.Extension.ToUpper(),
                                FileSize       = (infoFile.Length / 1024).ToString() + " kB",
                                PartNo         = infoFile.Name.Substring(0, 7),
                                SourceLocation = filepath,
                                FileName       = infoFile.Name,
                                CopySite       = foundDirectories[i].ToString(),
                                SiteFound      = true,
                                Version        = names[1] + "." + names[2],
                                Status         = FileState,
                                Supplier       = supplier[4],
                                FolderName     = @"https://galaxis.axis.com/" + foundDirectories[i].ToString(),
                                NewFileName    = $"{viewer.PartNo}_{names[1]}_{names[2]}{viewer.Extension}"
                            });
                        }
                    }
                }
                //If item is not in any list
                if (!haselements)
                {
                    if (viewer.Status == "None" && viewer.Extension != ".STL")
                    {
                        _source.Add(new ViewFile
                        {
                            FileDescription = (names[0].Length > 7) ? "Deco Variant" : "Deco Spec",
                            Extension       = infoFile.Extension.ToUpper(),
                            FileSize        = (infoFile.Length / 1024).ToString() + " kB",
                            PartNo          = infoFile.Name.Substring(0, 7),
                            SourceLocation  = filepath,
                            FileName        = infoFile.Name,
                            CopySite        = "",
                            SiteFound       = false,
                            Version         = "None",
                            Status          = "None",
                            Supplier        = "",
                            FolderName      = "",
                            NewFileName     = $"{names[0]}_deco.pdf"
                        });
                    }

                    else if (viewer.Extension != ".STL")
                    {
                        _source.Add(new ViewFile
                        {
                            Extension      = infoFile.Extension.ToUpper(),
                            FileSize       = (infoFile.Length / 1024).ToString() + " kB",
                            PartNo         = infoFile.Name.Substring(0, 7),
                            SourceLocation = filepath,
                            FileName       = infoFile.Name,
                            CopySite       = "",
                            SiteFound      = false,
                            Version        = names[1] + "." + names[2],
                            Status         = "",
                            Supplier       = "",
                            FolderName     = "",
                            NewFileName    = $"{viewer.PartNo}_{names[1]}_{names[2]}{viewer.Extension}"
                        });
                    }
                }

                if (viewer.Status == "Error")
                {
                    viewer.SiteFound = false;
                }
                foundDirectories.Clear();
            }
        }
예제 #13
0
 public async Task DeleteFile(ViewFile file)
 {
     await DeleteFile(file.JsonFileId);
     await DeleteFile(file.Id);
 }
        public async Task DeleteFile(ViewFile file)
        {
            await _driveService.Files.Delete(file.Id).ExecuteAsync();

            await _driveService.Files.Delete(file.JsonFileId).ExecuteAsync();
        }