public List <StatementReferenceMaster> PrepareStatementReferenceMasterStart(FileMaster fileMaster, int pClassStartIndicator) { var fileName = Path.GetFileNameWithoutExtension(fileMaster.FilePath); var pNameNew = fileMaster.ProjectMaster.ProjectName; var pPathNew = fileMaster.ProjectMaster.PhysicalPath; var classNameProgram = fileMaster.FilePath.Replace(pPathNew + "\\", "") .Replace(fileMaster.FileName, "").Replace("\\", "."); var fileNameProgram = Path.GetFileNameWithoutExtension(fileMaster.FilePath); var classNameDeclaredProgram = pNameNew + "." + classNameProgram + fileNameProgram; var lstStatementReferenceMaster = new List <StatementReferenceMaster> { new StatementReferenceMaster { FileId = fileMaster.FileId, ResolvedStatement = fileName, OriginalStatement = fileName, ClassCalled = null, MethodName = null, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, ClassNameDeclared = classNameDeclaredProgram, PrimaryCommandId = pClassStartIndicator, BaseCommandId = 19, ProjectId = fileMaster.ProjectId, SolutionId = fileMaster.SolutionId ?? 0 } }; return(lstStatementReferenceMaster); }
public List <StatementReferenceMaster> PrepareStatementReferenceMasterStart(FileMaster fileMaster, int pClassStartIndicator) { string fileName = Path.GetFileNameWithoutExtension(fileMaster.FilePath); var lstStatementReferenceMaster = new List <StatementReferenceMaster> { new StatementReferenceMaster { FileId = fileMaster.FileId, ResolvedStatement = fileName, OriginalStatement = fileName, ClassCalled = null, MethodName = null, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, ClassNameDeclared = null, PrimaryCommandId = pClassStartIndicator, BaseCommandId = 19, ProjectId = fileMaster.ProjectId } }; return(lstStatementReferenceMaster); }
public Boolean UpdateDocumentsDataForUser(Int64 fileId, String fileName, String userName, String metaTags, String companyInfo , String categoryType, String comment, Byte[] overwriteStream) { try { ICPresentationEntities entity = new ICPresentationEntities(); if (overwriteStream == null) { entity.UpdateDocumentsData(fileId, userName, metaTags, companyInfo, categoryType, comment); } else { FileMaster fileMaster = entity.FileMasters.Where(record => record.FileID == fileId).FirstOrDefault(); if (fileMaster != null) { String uploadUrl = UploadDocument(fileName, overwriteStream, fileMaster.Location); Int32? result = entity.SetUploadFileInfo(userName, fileName, uploadUrl, companyInfo, null, null , categoryType, metaTags, comment).FirstOrDefault(); if (result == 0) { entity.DeleteFileMaster(fileMaster.FileID); } } } return(true); } catch (Exception ex) { ExceptionTrace.LogException(ex); string networkFaultMessage = ServiceFaultResourceManager.GetString("NetworkFault").ToString(); throw new FaultException <ServiceFault>(new ServiceFault(networkFaultMessage), new FaultReason(ex.Message)); } }
public void ExampleTest() { FileMaster FM = new FileMaster("/Users/person1/Pictures/house.png"); Assert.AreEqual("png", FM.extension()); Assert.AreEqual("house", FM.filename()); Assert.AreEqual("/Users/person1/Pictures/", FM.dirpath()); }
public async Task <IHttpActionResult> GetFileMaster(int id) { FileMaster fileMaster = await db.FileMaster.FindAsync(id); if (fileMaster == null) { return(NotFound()); } return(Ok(fileMaster)); }
private static void Execute() { int contactId; do { Console.Clear(); ConsoleLogging.WhichActionText(); var userChoice = Console.ReadKey(); Console.WriteLine(); switch (userChoice.Key) { case ConsoleKey.D1: case ConsoleKey.NumPad1: Console.Clear(); PhoneBook.CreateContact(PhoneBook.ContactList.Count); ConsoleLogging.PressEnter(); break; case ConsoleKey.D2: case ConsoleKey.NumPad2: Console.Clear(); PhoneBook.GetAllContacts(); ConsoleLogging.PressEnter(); break; case ConsoleKey.D3: case ConsoleKey.NumPad3: Console.Clear(); contactId = ConsoleLogging.GetContactToUpdate(); PhoneBook.UpdateContact(contactId); ConsoleLogging.PressEnter(); break; case ConsoleKey.D4: case ConsoleKey.NumPad4: Console.Clear(); contactId = ConsoleLogging.GetContactToDelete(); PhoneBook.DeleteContact(contactId); ConsoleLogging.PressEnter(); break; case ConsoleKey.D5: case ConsoleKey.NumPad5: Console.Clear(); FileMaster.WriteFile(PhoneBook.ContactList); Console.WriteLine("Thank You!"); Environment.Exit(0); break; } } while (true); }
public async Task <IHttpActionResult> CopyFile(int folderID, FileMaster fileMaster) { try { FolderMaster folderMaster = await db.FolderMaster.FindAsync(folderID); if (!(bool)folderMaster.UseFlag) { return(NotFound()); } // save original file path string dirFilePath = Path.Combine(ROOT_PATH + FORLDER); if (!Directory.Exists(dirFilePath)) { Directory.CreateDirectory(dirFilePath); } //save thumbnail file path string dirThumbnailFilePath = Path.Combine(ROOT_PATH + THUMBNAILFORLDER); if (!Directory.Exists(dirThumbnailFilePath)) { Directory.CreateDirectory(dirThumbnailFilePath); } string fileNameKey = DateTime.Now.ToString("yyyyMMddHHmmssffff"); string filePathName = fileNameKey + fileMaster.FileExtension; string thumbnailFilePathName = filePathName.ToLower().Replace(".mp4", ".gif"); File.Copy(Path.Combine(ROOT_PATH + fileMaster.FileUrl), Path.Combine(dirFilePath, filePathName), true); File.Copy(Path.Combine(ROOT_PATH + fileMaster.FileThumbnailUrl), Path.Combine(dirThumbnailFilePath, thumbnailFilePathName), true); FileMaster newFile = new FileMaster(); newFile.GroupID = fileMaster.GroupID; newFile.FolderID = folderID; newFile.UserID = fileMaster.UserID; newFile.FileExtension = fileMaster.FileExtension; newFile.FileType = fileMaster.FileType; newFile.FileName = fileMaster.FileName; newFile.FileUrl = FORLDER + filePathName; newFile.FileThumbnailUrl = THUMBNAILFORLDER + thumbnailFilePathName; newFile.UseFlag = fileMaster.UseFlag; newFile.UpdateDate = DateTime.Now; newFile.InsertDate = DateTime.Now; db.FileMaster.Add(newFile); await db.SaveChangesAsync(); return(Ok(newFile)); } catch { throw; } }
public async Task <ActionResult> ProcessForFileMasterData(string projectId) { var projectMaster = _floKaptureService.ProjectMasterRepository.GetById(projectId); if (projectMaster == null) { return(BadRequest($@"Project with id {projectId} not found!")); } var generalService = new GeneralService().BaseRepository <FileTypeReference>(); var extensionReferences = generalService.GetAllListItems(d => d.LanguageId == projectMaster.LanguageId); var csFiles = Directory.GetFiles(projectMaster.PhysicalPath, "*.cs", SearchOption.AllDirectories).ToList(); foreach (var csFile in csFiles) { if (Regex.IsMatch(csFile, @"\b\\bin\\\b|\b\\obj\\\b|\b\.Test\b", RegexOptions.IgnoreCase)) { continue; } string fileName = Path.GetFileName(csFile); if (string.IsNullOrEmpty(fileName)) { continue; } if (fileName.Contains(".dll.config")) { continue; } if (new[] { "Reference", "AssemblyInfo" }.Any(fileName.StartsWith)) { continue; } var extension = csFile.GetFileNameAndExtension(); // .UpTo("."); var extRef = extensionReferences.Find(e => Regex.IsMatch(extension.Value, e.FileExtension, RegexOptions.IgnoreCase)); if (extRef == null) { break; } var fileMaster = new FileMaster { FileName = Path.GetFileName(csFile), DoneParsing = false, FilePath = csFile, Processed = 0, ProjectId = projectMaster._id, FileTypeReferenceId = extRef._id, LinesCount = 0, WorkflowStatus = string.Empty }; await _floKaptureService.FileMasterRepository.AddDocument(fileMaster).ConfigureAwait(false); } return(Ok(new { Message = "Project processed successfully", Status = "OK", ProjectId = projectId })); }
public List <StatementReferenceMaster> PrepareStatementReferenceMasterStart(FileMaster fileMaster, int pClassStartIndicator) { var lstStatementReference = new List <StatementReferenceMaster>(); var fileName = Path.GetFileNameWithoutExtension(fileMaster.FilePath); var projectName = fileMaster.ProjectMaster.ProjectName; var physicalPath = fileMaster.ProjectMaster.PhysicalPath; var classNameFile = fileMaster.FilePath.Replace(physicalPath + "\\", "") .Replace(fileMaster.FileName, "") .Replace("\\", "."); var classNameDeclared = projectName + "." + classNameFile + fileName; lstStatementReference.Add(new StatementReferenceMaster { FileId = fileMaster.FileId, ResolvedStatement = fileName, OriginalStatement = fileName, ClassCalled = null, MethodName = null, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, ClassNameDeclared = classNameDeclared, PrimaryCommandId = pClassStartIndicator, BaseCommandId = 19, ProjectId = fileMaster.ProjectId, SolutionId = fileMaster.SolutionId ?? 0 }); /* * lstStatementReference.Add(new StatementReferenceMaster * { * FileId = fileMaster.FileId, * ResolvedStatement = fileName, * OriginalStatement = fileName, * ClassCalled = fileName + "()", * MethodName = fileName + "()", * DataOrObjectType = null, * MethodCalled = null, * VariableNameDeclared = null, * ClassNameDeclared = null, * PrimaryCommandId = 23, * BaseCommandId = 8, * ProjectId = fileMaster.ProjectId, * SolutionId = fileMaster.SolutionId ?? 0 * }); */ return(lstStatementReference); }
static void Main(string[] args) { ConsoleLogging.IntroText(); PhoneBook.ContactList = FileMaster.ReadFile(); if (PhoneBook.ContactList.Count == 0) { ConsoleLogging.FirstTimeText(); PhoneBook.CreateContact(0); } Execute(); }
/// <summary> /// UploadCommand execution method /// </summary> /// <param name="param"></param> private void UploadCommandMethod(object param) { if (dbInteractivity != null) { BusyIndicatorNotification(true, "Uploading document"); String deleteUrl = String.Empty; FileMaster overwriteFileMaster = SelectedMeetingDocumentationInfo .Where(record => record.Category == SelectedUploadDocumentInfo).FirstOrDefault(); if (overwriteFileMaster != null) { deleteUrl = overwriteFileMaster.Location; } dbInteractivity.UploadDocument(UploadFileData.Name, UploadFileStreamData, deleteUrl, UploadDocumentCallbackMethod); } }
public async Task <IHttpActionResult> PostFileMaster(FileMaster fileMaster) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } fileMaster.UpdateDate = DateTime.Now; fileMaster.InsertDate = DateTime.Now; fileMaster.UseFlag = true; db.FileMaster.Add(fileMaster); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = fileMaster.FileID }, fileMaster)); }
public async Task <IHttpActionResult> DeleteFileMaster(int id) { FileMaster fileMaster = await db.FileMaster.FindAsync(id); if (fileMaster == null) { return(NotFound()); } File.Delete(ROOT_PATH + fileMaster.FileUrl); File.Delete(ROOT_PATH + fileMaster.FileThumbnailUrl); db.FileMaster.Remove(fileMaster); await db.SaveChangesAsync(); return(Ok(fileMaster)); }
public async Task <IActionResult> Uploading(IFormFile file) { string fullPath = ""; int folderCount = Track.level; //store the file FileMaster duplicateFiles = await _context.Files.Include(p => p.FileIterations).FirstOrDefaultAsync(p => p.FileName == file.FileName); //Folder getLastFolder = await _context.Folders.LastOrDefaultAsync(); //Folder parentFolder = await _context.Folders.FirstOrDefaultAsync(p => p.Id == getLastFolder.Id); if (duplicateFiles != null) { string dupliPath = root + duplicateFiles.Location + "/" + duplicateFiles.FileName; fullPath = FormatthePath(dupliPath); } if (file.Length > 0) { if (duplicateFiles == null) { return(new ObjectResult(await upNewFile(file))); } else { Stream stream = file.OpenReadStream(); CheckSum checkSum = new CheckSum(); if (duplicateFiles.FileIterations.Any(f => f.IterationCheckSum == checkSum.CalcCRC32(stream))) { return(new ObjectResult("Same file already exists!")); } else { FileMaster fi = await updateFile(stream, checkSum, file, duplicateFiles, fullPath); return(Ok()); } } } else { return(new ObjectResult("Empty file Choosen!")); } }
public List <StatementReferenceMaster> PrepareStatementReferenceMasterEnd(FileMaster fileMaster, int pClassEndIndicator) { var fileName = Path.GetFileNameWithoutExtension(fileMaster.FilePath); var lstStatementReference = new List <StatementReferenceMaster> { new StatementReferenceMaster { FileId = fileMaster.FileId, ResolvedStatement = fileName, OriginalStatement = fileName, ClassCalled = null, MethodName = null, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, ClassNameDeclared = null, PrimaryCommandId = pClassEndIndicator, BaseCommandId = 20, ProjectId = fileMaster.ProjectId, SolutionId = fileMaster.SolutionId ?? 0 } }; /* * lstStatementReference.Add(new StatementReferenceMaster * { * FileId = fileMaster.FileId, * ResolvedStatement = "END", * OriginalStatement = "END", * ClassCalled = null, * MethodName = null, * DataOrObjectType = null, * MethodCalled = null, * VariableNameDeclared = null, * ClassNameDeclared = null, * PrimaryCommandId = 30, * BaseCommandId = 9, * ProjectId = fileMaster.ProjectId, * SolutionId = fileMaster.SolutionId ?? 0 * }); */ return(lstStatementReference); }
private static void createLog() { try { if (MyAPIGateway.Utilities.FileExistsInLocalStorage(s_logMaster, typeof(Logger))) { for (int i = 0; i < 10; i++) { deleteIfExists("log-" + i + ".txt"); } FileMaster master = new FileMaster(s_logMaster, "log-", 10); Static.logWriter = master.GetTextWriter(DateTime.UtcNow.Ticks + ".txt"); } else { for (int i = 0; i < 10; i++) { if (Static.logWriter == null) { try { Static.logWriter = MyAPIGateway.Utilities.WriteFileInLocalStorage("log-" + i + ".txt", typeof(Logger)); } catch { AlwaysLog("failed to start writer for file: log-" + i + ".txt", severity.INFO); } } else { deleteIfExists("log-" + i + ".txt"); } } } if (Static.logWriter == null) { MyLog.Default.WriteLine("ARMS Logger ERROR: failed to create a log file"); throw new Exception("Failed to create log file"); } } catch (Exception ex) { MyLog.Default.WriteLine("ARMS Logger ERROR: failed to create a log file"); MyLog.Default.WriteLine(ex); throw; } }
private Builder_ArmsData GetData() { m_fileMaster = new FileMaster("SaveDataMaster.txt", "SaveData - ", int.MaxValue); Builder_ArmsData data = null; string serialized; if (MyAPIGateway.Utilities.GetVariable(SaveXml, out serialized)) { data = MyAPIGateway.Utilities.SerializeFromXML <Builder_ArmsData>(serialized); if (data != null) { Logger.DebugLog("ARMS data was imbeded in the save file proper", Rynchodon.Logger.severity.DEBUG); return(data); } } string identifier = LegacyIdentifier(true); if (identifier == null) { Logger.DebugLog("no identifier"); return(data); } var reader = m_fileMaster.GetTextReader(identifier); if (reader != null) { Logger.DebugLog("loading from file: " + identifier); data = MyAPIGateway.Utilities.SerializeFromXML <Builder_ArmsData>(reader.ReadToEnd()); reader.Close(); } else { Logger.AlwaysLog("Failed to open file reader for " + identifier); } return(data); }
public async Task <IHttpActionResult> PutFileMaster(FileMaster fileMaster) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } fileMaster.UpdateDate = DateTime.Now; db.Entry(fileMaster).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(Ok(fileMaster)); }
public StatementReferenceMaster PrepareStatementReferenceMasterMethodEnd(FileMaster fileMaster) { var lstStatementReference = new StatementReferenceMaster { FileId = fileMaster.FileId, ResolvedStatement = "END", OriginalStatement = "END", ClassCalled = null, MethodName = null, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, ClassNameDeclared = null, PrimaryCommandId = 30, BaseCommandId = 9, ProjectId = fileMaster.ProjectId, SolutionId = fileMaster.SolutionId ?? 0 }; return(lstStatementReference); }
public StatementReferenceMaster PrepareStatementReferenceMasterMethodStart(FileMaster fileMaster, string methodStatement) { var fileName = Path.GetFileNameWithoutExtension(fileMaster.FilePath); var lstStatementReference = new StatementReferenceMaster { FileId = fileMaster.FileId, ResolvedStatement = methodStatement, OriginalStatement = methodStatement, ClassCalled = fileName + "()", MethodName = methodStatement + "()", DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, ClassNameDeclared = null, PrimaryCommandId = 23, BaseCommandId = 8, ProjectId = fileMaster.ProjectId, SolutionId = fileMaster.SolutionId ?? 0 }; return(lstStatementReference); }
public async Task <IHttpActionResult> CutFile(int folderID, FileMaster fileMaster) { try { FolderMaster folderMaster = await db.FolderMaster.FindAsync(folderID); if (!(bool)folderMaster.UseFlag) { return(NotFound()); } fileMaster.FolderID = folderID; fileMaster.UpdateDate = DateTime.Now; db.Entry(fileMaster).State = EntityState.Modified; await db.SaveChangesAsync(); return(Ok(fileMaster)); } catch (DbUpdateConcurrencyException) { throw; } }
public List <StatementReferenceMaster> PrepareStatementReferenceMasterEnd(FileMaster fileMaster, int pClassEndIndicator) { var lstStatementReferenceMaster = new List <StatementReferenceMaster> { new StatementReferenceMaster { FileId = fileMaster.FileId, ResolvedStatement = "End", OriginalStatement = "End", ClassCalled = null, MethodName = null, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, ClassNameDeclared = null, PrimaryCommandId = pClassEndIndicator, BaseCommandId = 20, ProjectId = fileMaster.ProjectId } }; return(lstStatementReferenceMaster); }
public async Task <IHttpActionResult> ParseCallAndIncludesFilesUniverse(FileMaster icdFile, int languageId, List <FileMaster> copyOfFileMaster) { var stringBuilder = new StringBuilder(); int commanClassProjId = 9; using (_codeVortoService = new CodeVortoService()) { #region Load Project and Base Command Reference Details... var baseCommandReferenceRepository = new BaseCommandReferenceRepository(new AppDbContext()); var baseCommandReference = await baseCommandReferenceRepository.GetAllItems() .ContinueWith(t => { var result = t.Result; return(result.ToList()); }); var lineCommentedIndicators = baseCommandReference.Find(s => s.BaseCommand == "Line Comment") .PrimaryLanguageReference.ToList().FindAll(p => p.LanguageId == languageId); var ifConditionStart = baseCommandReference.Find(s => s.BaseCommand == "IF Start") .PrimaryLanguageReference.ToList().FindAll(p => p.LanguageId == languageId); var ifConditionEnd = baseCommandReference.Find(s => s.BaseCommand == "IF End") .PrimaryLanguageReference.ToList().FindAll(p => p.LanguageId == languageId); var callExternalIndicationStart = baseCommandReference.Find(s => s.BaseCommand == "Call External") .PrimaryLanguageReference.ToList().FindAll(p => p.LanguageId == languageId); var methodIndicationEnd = baseCommandReference.Find(s => s.BaseCommand == "Method End") .PrimaryLanguageReference.ToList().FindAll(p => p.LanguageId == languageId); var callInternalIndicationStart = baseCommandReference.Find(s => s.BaseCommand == "Call Internal") .PrimaryLanguageReference.ToList().FindAll(p => p.LanguageId == languageId); var loopIndicatorStart = baseCommandReference.Find(s => s.BaseCommand == "Loop Start") .PrimaryLanguageReference.ToList().FindAll(p => p.LanguageId == languageId); var loopIndicatorEnd = baseCommandReference.Find(s => s.BaseCommand == "Loop End") .PrimaryLanguageReference.ToList().FindAll(p => p.LanguageId == languageId); var universeBasicV1 = new UniverseBasicVersion1(); var callClassIndicatorStart = baseCommandReference.Find(s => s.BaseCommand == "Class Start") .PrimaryLanguageReference.ToList().FindAll(p => p.LanguageId == languageId); var callClassIndicatorEnd = baseCommandReference.Find(s => s.BaseCommand == "Class End") .PrimaryLanguageReference.ToList().FindAll(p => p.LanguageId == languageId); var methodIndicationStart = baseCommandReference.Find(s => s.BaseCommand == "Method Start") .PrimaryLanguageReference.ToList().FindAll(p => p.LanguageId == languageId); var methodEnd = methodIndicationEnd.Find(x => true); var classStart = callClassIndicatorStart.Find(x => true); var classEnd = callClassIndicatorEnd.Find(x => true); var methodStart = methodIndicationStart.Find(x => true); #endregion var programFileLines = File.ReadAllLines(icdFile.FilePath).ToList(); int projectId = icdFile.ProjectId; programFileLines.RemoveAll(s => s.Length <= 0); programFileLines = programFileLines.Select(s => s.Trim()).ToList(); programFileLines = programFileLines.AdjustMatReadLockedLikeStatements(); // var copyOfFileLines = programFileLines.ToList(); programFileLines = programFileLines.Where(s => !s.StartsWith("*") && !s.StartsWith("!!") && !s.StartsWith(";*") && !s.StartsWith("; *")).ToList(); #region Correct all method blocks and statements... // Program file processing started... var programLineList = new List <string>(); stringBuilder.AppendLine("========================================================================================"); stringBuilder.AppendLine("Started collecting all GOSUB: GetAllGoSub for project:" + projectId); var lstAllGoSubs = programFileLines.GetAllGoSub("GOSUB"); Dictionary <string, List <string> > methodBlockDictionary; stringBuilder.AppendLine("========================================================================================"); stringBuilder.AppendLine("Started collecting all certainpointInclude: GetListFromCertainPointInclude for project: " + projectId); methodBlockDictionary = universeBasicV1.GetListFromCertainPointInclude(copyOfFileLines, lstAllGoSubs); var startedBlock = false; for (var length = 0; length < programFileLines.Count; length++) { var currentLine = programFileLines[length]; if (lstAllGoSubs.Any(l => currentLine.StartsWith(l))) { startedBlock = true; var firstOrDefault = currentLine.Split('*').FirstOrDefault(); if (firstOrDefault != null) { currentLine = firstOrDefault.Trim(); } stringBuilder.AppendLine("========================================================================================"); stringBuilder.AppendLine("Started collecting all methodblocks: PickUpAllMethodBlocks for project:" + projectId); var methodBlockOriginal = universeBasicV1.PickUpAllMethodBlocks(copyOfFileLines, programFileLines[length], lstAllGoSubs, "RETURN", "STOP"); var methodBlock = methodBlockDictionary.FirstOrDefault(s => s.Key == currentLine); programLineList.AddRange(methodBlock.Value); length = length + methodBlockOriginal.Count - 1; continue; } if (startedBlock) { continue; } programLineList.Add(currentLine); } #endregion var statmentRefStart = universeBasicV1.PrepareStatementReferenceMasterStart(icdFile, 42); await _codeVortoService.StatementReferenceMasterRepository.BulkInsert(statmentRefStart); #region Insert into StatementReferenceMaster... var ifStart = ifConditionStart.Find(s => true); var ifEnd = ifConditionEnd.FindAll(s => true); var loopStart = loopIndicatorStart.FindAll(l => true); var loopEnd = loopIndicatorEnd.FindAll(l => true); var callInternal = callInternalIndicationStart.Find(c => true); var callExternal = callExternalIndicationStart.Find(c => true); var indexPosition = -1; var methodBusinessName = string.Empty; string businessName = null; var linesWithCommentedPart = programLineList.ToList(); programLineList = programLineList.Select(s => s.CheckCommentInStatement()).ToList(); stringBuilder.AppendLine("Started dump statement into database of file: " + icdFile.FilePath); foreach (var line in programLineList) { indexPosition = indexPosition + 1; if (string.IsNullOrEmpty(line)) { continue; } if (indexPosition + 1 < programLineList.Count) { var nextLine = programLineList[indexPosition + 1]; if (!string.IsNullOrEmpty(nextLine) && lstAllGoSubs.Any(a => a.StartsWith(nextLine))) { methodBusinessName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(line.ToLower()); continue; } if (linesWithCommentedPart[indexPosition].Contains("; *") || linesWithCommentedPart[indexPosition].Contains(";*")) { var lastOrDefault = linesWithCommentedPart[indexPosition].Split(';').LastOrDefault(); if (lastOrDefault != null) { businessName = lastOrDefault.Replace("*", ""); } if (businessName != null) { businessName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(businessName.ToLower()); businessName = businessName.Replace("&", "AND").Replace("&&", "AND").Replace("||", "OR"); } } } if (line.StartsWith(lineCommentedIndicators.Find(x => x.StartIndicator != null).StartIndicator)) { continue; } if (line.StartsWith("RETURN")) { var stmtReferenceMaster = new StatementReferenceMaster { FileId = icdFile.FileId, ResolvedStatement = line, OriginalStatement = line, ClassCalled = null, MethodName = null, BusinessName = businessName, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, BaseCommandId = methodEnd.BaseCommandId, PrimaryCommandId = methodEnd.PrimaryReferenceId, ParsedOrNot = "Y", ProjectId = projectId }; await _codeVortoService.StatementReferenceMasterRepository.AddNewItem(stmtReferenceMaster); businessName = string.Empty; continue; } if (lstAllGoSubs.Any(a => line.StartsWith(a))) { var stmtReferenceMaster = new StatementReferenceMaster { FileId = icdFile.FileId, ResolvedStatement = line, OriginalStatement = line, ClassCalled = null, MethodName = line.Split(':').FirstOrDefault() + "()", DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, BaseCommandId = 8, PrimaryCommandId = 36, ParsedOrNot = "Y", ProjectId = projectId, BusinessName = methodBusinessName }; await _codeVortoService.StatementReferenceMasterRepository.AddNewItem(stmtReferenceMaster); businessName = string.Empty; methodBusinessName = string.Empty; continue; } if (line.StartsWith(ifStart.StartIndicator)) { var stmtReferenceMaster = new StatementReferenceMaster { FileId = icdFile.FileId, ResolvedStatement = line, OriginalStatement = line, ClassCalled = null, MethodName = null, BusinessName = businessName, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, BaseCommandId = ifStart.BaseCommandId, PrimaryCommandId = ifStart.PrimaryReferenceId, ParsedOrNot = "Y", ProjectId = projectId }; await _codeVortoService.StatementReferenceMasterRepository.AddNewItem(stmtReferenceMaster); businessName = string.Empty; continue; } if ((line == "END ELSE") || (line == "ELSE")) { var stmtReferenceMaster = new StatementReferenceMaster { FileId = icdFile.FileId, ResolvedStatement = line, OriginalStatement = line, ClassCalled = null, MethodName = null, BusinessName = businessName, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, BaseCommandId = 10, PrimaryCommandId = 0, ParsedOrNot = "Y", ProjectId = projectId }; await _codeVortoService.StatementReferenceMasterRepository.AddNewItem(stmtReferenceMaster); businessName = string.Empty; continue; } if (ifEnd.Any(l => line == l.StartIndicator)) { var stmtReferenceMaster = new StatementReferenceMaster { FileId = icdFile.FileId, ResolvedStatement = line, OriginalStatement = line, ClassCalled = null, MethodName = null, BusinessName = businessName, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, BaseCommandId = 2, PrimaryCommandId = ifEnd.Find(s => line.StartsWith(s.StartIndicator)).PrimaryReferenceId, ParsedOrNot = "Y", ProjectId = projectId }; await _codeVortoService.StatementReferenceMasterRepository.AddNewItem(stmtReferenceMaster); businessName = string.Empty; continue; } if (loopStart.Any(l => line.StartsWith(l.StartIndicator)) || line == "LOOP") { var stmtReferenceMaster = new StatementReferenceMaster { FileId = icdFile.FileId, ResolvedStatement = line, OriginalStatement = line, ClassCalled = null, MethodName = null, BusinessName = businessName, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, BaseCommandId = line == "LOOP" ? 3 : loopStart.Find(s => line.StartsWith(s.StartIndicator)).BaseCommandId, PrimaryCommandId = line == "LOOP" ? 62 : loopStart.Find(s => line.StartsWith(s.StartIndicator)).PrimaryReferenceId, ParsedOrNot = "Y", ProjectId = projectId }; await _codeVortoService.StatementReferenceMasterRepository.AddNewItem(stmtReferenceMaster); businessName = string.Empty; continue; } if (loopEnd.Any(l => line.StartsWith(l.StartIndicator))) { var stmtReferenceMaster = new StatementReferenceMaster { FileId = icdFile.FileId, ResolvedStatement = line, OriginalStatement = line, ClassCalled = null, MethodName = null, BusinessName = businessName, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, BaseCommandId = loopEnd.Find(s => line.StartsWith(s.StartIndicator)).BaseCommandId, PrimaryCommandId = loopEnd.Find(s => line.StartsWith(s.StartIndicator)).PrimaryReferenceId, ParsedOrNot = "Y", ProjectId = projectId }; await _codeVortoService.StatementReferenceMasterRepository.AddNewItem(stmtReferenceMaster); businessName = string.Empty; continue; } if (line.StartsWith(callInternal.StartIndicator)) { var methodName = line.CheckCommentInStatement(); var stmtReferenceMaster = new StatementReferenceMaster { FileId = icdFile.FileId, ResolvedStatement = methodName, OriginalStatement = methodName, ClassCalled = null, MethodName = null, BusinessName = businessName, DataOrObjectType = null, MethodCalled = methodName.Split(' ').LastOrDefault() + "()", VariableNameDeclared = null, BaseCommandId = callInternal.BaseCommandId, PrimaryCommandId = callInternal.PrimaryReferenceId, ParsedOrNot = "Y", ProjectId = projectId }; await _codeVortoService.StatementReferenceMasterRepository.AddNewItem(stmtReferenceMaster); businessName = string.Empty; continue; } if (line.StartsWith(callExternal.StartIndicator + " ")) { var stmtReferenceMaster = new StatementReferenceMaster { FileId = icdFile.FileId, ResolvedStatement = line, OriginalStatement = line, ClassCalled = null, MethodName = null, BusinessName = businessName, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, BaseCommandId = callExternal.BaseCommandId, PrimaryCommandId = callExternal.PrimaryReferenceId, ParsedOrNot = "Y", ProjectId = projectId }; await _codeVortoService.StatementReferenceMasterRepository.AddNewItem(stmtReferenceMaster); businessName = string.Empty; } else { var stmtReferenceMaster = new StatementReferenceMaster { FileId = icdFile.FileId, ResolvedStatement = line, OriginalStatement = line, ClassCalled = null, MethodName = null, BusinessName = businessName, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, BaseCommandId = 0, PrimaryCommandId = 0, ParsedOrNot = "Y", ProjectId = projectId }; await _codeVortoService.StatementReferenceMasterRepository.AddNewItem(stmtReferenceMaster); businessName = string.Empty; } } #endregion var statmentRefEnd = universeBasicV1.PrepareStatementReferenceMasterEnd(icdFile, 43); await _codeVortoService.StatementReferenceMasterRepository.BulkInsert(statmentRefEnd); #region Update ClassCalled field for StatementReferenceMaster... stringBuilder.AppendLine("========================================================================================"); stringBuilder.AppendLine("Started update classcalled and methodcalled for basecommandId = 6 & 19 for project: " + projectId); /* Added shubhangi */ var execOrCallSql = " Select sm.* from StatementReferenceMaster as sm " + " Inner Join FileMaster as fm ON sm.FileId = fm.FileId Where sm.ProjectId IN (" + projectId + "," + commanClassProjId + " ) AND fm.Processed = 0 AND sm.BaseCommandId IN (6, 19); "; var callExternals = await baseCommandReferenceRepository .GetDataFromSqlQuery <StatementReferenceMaster>(execOrCallSql).ConfigureAwait(false); foreach (var cExternal in callExternals) { if (cExternal.BaseCommandId == 6) { string pgName; if (cExternal.OriginalStatement.ContainsAll("@", "(", ")")) { pgName = cExternal.OriginalStatement.Split('@').LastOrDefault(); if (pgName != null) { pgName = pgName.Split('(').FirstOrDefault(); } } else { pgName = cExternal.OriginalStatement.Split('@').LastOrDefault(); } var pName = copyOfFileMaster.ToList().Where(f => !string.IsNullOrEmpty(pgName) && f.FileName.StartsWith(pgName) && (f.FileTypeExtensionId == 9)).ToList(); if (!pName.Any()) { continue; } var projectDetatils = _codeVortoService.ProjectMasterRepository.GetItem(pName[0].ProjectId); var pNameNew = projectDetatils.ProjectName; var pPathNew = projectDetatils.PhysicalPath; var className = pName[0].FilePath.Replace(pPathNew + "\\", "") .Replace(pName[0].FileName, "").Replace("\\", "."); var fileName = Path.GetFileNameWithoutExtension(pName[0].FilePath); // Use it later... var classNameDeclared = pNameNew + "." + className + fileName; cExternal.ClassCalled = classNameDeclared; await _codeVortoService.StatementReferenceMasterRepository .UpdateItem(cExternal).ConfigureAwait(false); continue; } if (cExternal.BaseCommandId == 19) { var fileId = cExternal.FileId; var pName = copyOfFileMaster.ToList().Where(f => f.FileId == fileId).ToList(); if (pName.Count == 0) // Added shubhangi { var fileMasterNew = await _codeVortoService.FileMasterRepository .GetAllItems(p => p.ProjectId == projectId || p.ProjectId == commanClassProjId); copyOfFileMaster = new List <FileMaster>(fileMasterNew as FileMaster[] ?? fileMasterNew.ToArray()); pName = copyOfFileMaster.ToList().Where(f => f.FileId == fileId).ToList(); } var projectDetatils = _codeVortoService.ProjectMasterRepository.GetItem(pName[0].ProjectId); var pNameNew = projectDetatils.ProjectName; var pPathNew = projectDetatils.PhysicalPath; var classNameProgram = pName[0].FilePath.Replace(pPathNew + "\\", "") .Replace(pName[0].FileName, "").Replace("\\", "."); var fileNameProgram = Path.GetFileNameWithoutExtension(pName[0].FilePath); // Use it later... var classNameDeclaredProgram = pNameNew + "." + classNameProgram + fileNameProgram; cExternal.ClassNameDeclared = classNameDeclaredProgram; await _codeVortoService.StatementReferenceMasterRepository.UpdateItem(cExternal); } } #endregion #region Update Method called for base command id = 6 in Jcl and program... stringBuilder.AppendLine("========================================================================================"); stringBuilder.AppendLine("Started update methodcalled for Jcl and program basecommandId = 6 for project: " + projectId); var execSql = " Select sm.* from StatementReferenceMaster as sm " + " Inner Join FileMaster as fm ON fm.FileId = sm.FileId Where sm.ProjectId = " + projectId + " AND sm.BaseCommandId = 6 " + " AND fm.Processed = 0 AND sm.ClassCalled is not null;"; var execName = await baseCommandReferenceRepository .GetDataFromSqlQuery <StatementReferenceMaster>(execSql).ConfigureAwait(false); foreach (var constructor in execName) { // ReSharper disable once RedundantAssignment var fName = constructor.ClassCalled.Split('.').LastOrDefault().Trim() + ".pgm"; var allCheckFiles = await _codeVortoService.FileMasterRepository .GetAllItems(f => (f.ProjectId == projectId) && (f.FileName == fName)).ConfigureAwait(false); foreach (var files in allCheckFiles) { var methodSql = " SELECT DISTINCT sm.* from statementreferencemaster as sm " + " INNER JOIN FileMaster as fm where sm.FileId = " + files.FileId + " AND fm.SolutionId = " + files.SolutionId + " AND sm.BaseCommandId = 8;"; var methodName = await baseCommandReferenceRepository .GetDataFromSqlQuery <StatementReferenceMaster>(methodSql).ConfigureAwait(false); foreach (var statementReference in methodName) { if (string.IsNullOrEmpty(statementReference.MethodName)) { continue; } var pName = copyOfFileMaster.ToList().Where(f => f.FileId == statementReference.FileId).ToList(); var projectDetails1 = _codeVortoService.ProjectMasterRepository.GetItem(pName[0].ProjectId); var pNameNew = projectDetails1.ProjectName; var pPathNew = projectDetails1.PhysicalPath; var classNameProgram = pName[0].FilePath.Replace(pPathNew + "\\", "") .Replace(pName[0].FileName, "").Replace("\\", "."); var fileNameProgram = Path.GetFileNameWithoutExtension(pName[0].FilePath); // Use it later... var classCalled = pNameNew + "." + classNameProgram + fileNameProgram; constructor.ClassCalled = classCalled; constructor.MethodCalled = statementReference.MethodName; await _codeVortoService.StatementReferenceMasterRepository.UpdateItem(constructor).ConfigureAwait(false); break; } } } #endregion #region Update field for basecommandId = 30 stringBuilder.AppendLine("========================================================================================"); stringBuilder.AppendLine("Started update field for basecommandId = 30 for project: " + projectId); if (!string.IsNullOrEmpty(icdFile.FilePath)) { var fileId = icdFile.FileId; var execSqlPrgm = " Select * from StatementReferenceMaster where ProjectId =" + projectId + " AND FileId = " + fileId + " AND BaseCommandId IN (0, 1);"; var execNamePrgm = await baseCommandReferenceRepository.GetDataFromSqlQuery <StatementReferenceMaster>(execSqlPrgm); var indexPositionPrgm = -1; foreach (var exNmPg in execNamePrgm) { indexPositionPrgm = indexPositionPrgm + 1; if (exNmPg.BaseCommandId != 1) { continue; } if ((exNmPg.OriginalStatement != "IF FOUND THEN") && (exNmPg.OriginalStatement != "IF FOUND") && (exNmPg.OriginalStatement != "IF NOT SUCCESS THEN") && (exNmPg.OriginalStatement != "IF NOT-SUCCESS THEN") && (exNmPg.OriginalStatement != "IF SUCCESS THEN") && (exNmPg.OriginalStatement != "IF NOT FOUND THEN") && (exNmPg.OriginalStatement != "IF NOT-FOUND THEN") && (exNmPg.OriginalStatement != "IF NOT FOUND") && (exNmPg.OriginalStatement != "IF NOT-FOUND")) { continue; } var aboveLine = execNamePrgm[indexPositionPrgm - 1]; aboveLine.BaseCommandId = 30; await _codeVortoService.StatementReferenceMasterRepository.UpdateItem(aboveLine); } } #endregion #region Update Include program File Processed stringBuilder.AppendLine("========================================================================================"); stringBuilder.AppendLine("Started update Include program File Processed for project: " + projectId + ", and file is:" + icdFile.FileName + ""); icdFile.DoneParsing = 1; icdFile.ProjectMaster = null; await _codeVortoService.FileMasterRepository.UpdateItem(icdFile).ConfigureAwait(false); if (icdFile.FileTypeExtensionId != 12) { return(Ok("Done")); } icdFile.Processed = 1; icdFile.ProjectMaster = null; await _codeVortoService.FileMasterRepository.UpdateItem(icdFile).ConfigureAwait(false); #endregion LogMessage.WriteLogMessage(stringBuilder); return(Ok("Done")); } }
public async Task <IHttpActionResult> UploadFile() { try { int userID = int.Parse(HttpContext.Current.Request["UserID"]); int groupID = int.Parse(HttpContext.Current.Request["GroupID"]); int folderID = int.Parse(HttpContext.Current.Request["FolderID"]); FolderMaster folderMaster = await db.FolderMaster.FindAsync(folderID); GroupMaster groupMaster = await db.GroupMaster.FindAsync(groupID); if (!(bool)folderMaster.UseFlag || !(bool)groupMaster.UseFlag) { return(NotFound()); } // save original file path string dirFilePath = Path.Combine(ROOT_PATH + FORLDER); if (!Directory.Exists(dirFilePath)) { Directory.CreateDirectory(dirFilePath); } //save thumbnail file path string dirThumbnailFilePath = Path.Combine(ROOT_PATH + THUMBNAILFORLDER); if (!Directory.Exists(dirThumbnailFilePath)) { Directory.CreateDirectory(dirThumbnailFilePath); } HttpFileCollection fileUploadData = HttpContext.Current.Request.Files; HttpPostedFile file = fileUploadData[0]; string fileName = file.FileName.Trim('"'); FileInfo fileInfo = new FileInfo(fileName); string fileExtension = fileInfo.Extension.ToLower(); string fileType = ""; string fileNameKey = DateTime.Now.ToString("yyyyMMddHHmmssffff"); string filePathName = fileNameKey + fileExtension; string thumbnailFilePathName = filePathName; string filePath = Path.Combine(dirFilePath, filePathName); string thumbnailFilePath = Path.Combine(dirThumbnailFilePath, thumbnailFilePathName); if (fileExtension == ".mp4" || fileExtension == ".wmv" || fileExtension == ".mpg" || fileExtension == ".avi" || fileExtension == ".mpeg" || fileExtension == ".flv" || fileExtension == ".mkv" || fileExtension == ".mov") { // save video file fileType = "video"; file.SaveAs(filePath); // save gif from mp4 string ffmpeg = Path.Combine(ROOT_PATH, "bin/ffmpeg.exe"); if (!System.IO.File.Exists(ffmpeg)) { return(BadRequest()); } thumbnailFilePathName = thumbnailFilePathName.ToLower().Replace(fileExtension, ".gif"); Process pcs = new Process(); pcs.StartInfo.FileName = ffmpeg; pcs.StartInfo.Arguments = " -i " + filePath + " -ss 00:00:00.000 -pix_fmt rgb24 -r 10 -s 320x240 -t 00:00:10.000 " + thumbnailFilePath.Replace(fileExtension, ".gif"); pcs.StartInfo.UseShellExecute = false; pcs.StartInfo.RedirectStandardError = true; pcs.StartInfo.CreateNoWindow = false; try { pcs.Start(); pcs.BeginErrorReadLine(); pcs.WaitForExit(); } catch { return(BadRequest()); } finally { pcs.Close(); pcs.Dispose(); } } else { // save image file fileType = "image"; Image originalImg = Image.FromStream(file.InputStream); int thumbnailMaxWidth = 200; int thumbnailMaxHeight = 150; Image thumbnailImg; if (originalImg.Width > thumbnailMaxWidth && originalImg.Height <= thumbnailMaxHeight)//宽度比目的图片宽度大,长度比目的图片长度小 { thumbnailImg = ImageHelper.GetThumbnailImage(originalImg, thumbnailMaxWidth, (thumbnailMaxWidth * originalImg.Height) / originalImg.Width); } else if (originalImg.Width <= thumbnailMaxWidth && originalImg.Height > thumbnailMaxHeight)//宽度比目的图片宽度小,长度比目的图片长度大 { thumbnailImg = ImageHelper.GetThumbnailImage(originalImg, (thumbnailMaxHeight * originalImg.Width) / originalImg.Height, thumbnailMaxHeight); } else if (originalImg.Width <= thumbnailMaxWidth && originalImg.Height <= thumbnailMaxHeight) //长宽比目的图片长宽都小 { thumbnailImg = ImageHelper.GetThumbnailImage(originalImg, originalImg.Width, originalImg.Height); } else { if ((thumbnailMaxWidth * originalImg.Height) / originalImg.Width > thumbnailMaxHeight) { thumbnailImg = ImageHelper.GetThumbnailImage(originalImg, (thumbnailMaxHeight * originalImg.Width) / originalImg.Height, thumbnailMaxHeight); } else { thumbnailImg = ImageHelper.GetThumbnailImage(originalImg, thumbnailMaxWidth, (thumbnailMaxWidth * originalImg.Height) / originalImg.Width); } } originalImg.Save(filePath); thumbnailImg.Save(thumbnailFilePath); } FileMaster fileMaster = new FileMaster(); fileMaster.GroupID = groupID; fileMaster.FolderID = folderID; fileMaster.UserID = userID; fileMaster.FileExtension = fileExtension; fileMaster.FileType = fileType; fileMaster.FileName = fileName; fileMaster.FileUrl = FORLDER + filePathName; fileMaster.FileThumbnailUrl = THUMBNAILFORLDER + thumbnailFilePathName; fileMaster.UseFlag = true; fileMaster.UpdateDate = DateTime.Now; fileMaster.InsertDate = DateTime.Now; db.FileMaster.Add(fileMaster); await db.SaveChangesAsync(); return(Ok(fileMaster)); } catch { throw; } }
private async Task <bool> ProcessFileMasterDetails(ProjectMaster projectMaster) { var entitiesToExcludeService = new GeneralService().BaseRepository <EntitiesToExclude>(); var fileTypeReferences = _floKaptureService.FileTypeReferenceRepository .GetAllListItems(p => p.LanguageId == projectMaster.LanguageId).ToList(); var directoryList = new List <string> { projectMaster.PhysicalPath }; var regExCommented = new Regex(@"^\/\/\*|^\/\*|^\*|^\'", RegexOptions.CultureInvariant); foreach (var directory in directoryList) { try { var fileExtensions = fileTypeReferences.Select(extension => extension.FileExtension); var allFiles = Directory.GetFiles(directory, "*.*", SearchOption.AllDirectories) .Where(s => fileExtensions.Any(e => s.EndsWith(e) || s.ToUpper().EndsWith(e.ToUpper()))).ToList(); foreach (var currentFile in allFiles) { var fileLines = System.IO.File.ReadAllLines(currentFile).ToList(); int lineCount = fileLines.Count(line => !regExCommented.IsMatch(line) || !string.IsNullOrWhiteSpace(line)); // TODO: Look for this in old code // if (ignoredFile.Any(f => f.FileName == Path.GetFileName(currentFile))) continue; var fileName = Path.GetFileName(currentFile); if (string.IsNullOrEmpty(fileName)) { continue; } if (fileName.Contains(".dll.config")) { continue; } var extension = Path.GetExtension(currentFile); var extensionId = fileTypeReferences.First(e => e.FileExtension == extension || string.Equals(e.FileExtension, extension, StringComparison.CurrentCultureIgnoreCase))._id; var fileMaster = new FileMaster { FileName = fileName, FilePath = currentFile, FileTypeReferenceId = extensionId, ProjectId = projectMaster._id, DoneParsing = false, LinesCount = lineCount, Processed = 0 }; var addedDocument = await _floKaptureService.FileMasterRepository.AddDocument(fileMaster) .ConfigureAwait(false); if (projectMaster.IsCtCode && extension == ".icd" && fileMaster.FileName.StartsWith("I_", StringComparison.CurrentCultureIgnoreCase)) { await entitiesToExcludeService.AddDocument(new EntitiesToExclude { FileId = addedDocument._id, FileName = Path.GetFileNameWithoutExtension(currentFile), ProjectId = addedDocument.ProjectId }).ConfigureAwait(false); } } } catch (Exception exception) { Console.WriteLine(exception); } } return(true); }
private async Task <FileMaster> updateFile(Stream stream, CheckSum checkSum, IFormFile file, FileMaster duplicateFiles, string path) { FileIteration iteration = new FileIteration { Id = 0, FileMasterId = duplicateFiles.Id, IterationCheckSum = checkSum.CalcCRC32(stream), }; EntityEntry <FileIteration> entity = await _context.FileIterations.AddAsync(iteration); _context.SaveChanges(); duplicateFiles.DateUpdated = DateTime.UtcNow; duplicateFiles.Size = stream.Length; duplicateFiles.VersionNumber = duplicateFiles.VersionNumber + 1; duplicateFiles.FileIterations.Add(entity.Entity); EntityEntry <FileMaster> entry2 = _context.Files.Update(duplicateFiles); _context.SaveChanges(); duplicateFiles = entry2.Entity; string newFileName = duplicateFiles.Id + "_" + duplicateFiles.VersionNumber + Path.GetExtension(path); string thenPath = root + "/" + duplicateFiles.Location + "/" + newFileName; string newFilePath = FormatthePath(thenPath); entity.Entity.IterationName = newFileName; entity.Entity.IterationPath = newFilePath; EntityEntry <FileIteration> entry3 = _context.FileIterations.Update(entity.Entity); _context.SaveChanges(); //iteration = entry3.Entity; using (FileStream fileStream = System.IO.File.Create(newFilePath)) { await stream.CopyToAsync(fileStream); } await _context.SaveChangesAsync(); return(entry2.Entity); }
private async Task <IActionResult> upNewFile(IFormFile file) { string fname = ""; Stream stream1 = file.OpenReadStream(); CheckSum objCheckSum = new CheckSum(); //string hafPath = Track.FolderLevels; Counter count = await _context.Counter.LastOrDefaultAsync(); for (int i = 0; i < 6; i++) { if (count.CounterNumber == 5) { await FormatFolders(count); } if (count.CounterNumber < 5) { fname = count.CounterNumber + ""; if (fname.Length < 2) { fname = "00" + i; } else if (fname.Length < 3) { fname = "0" + i; } else if (fname.Length < 4) { fname = i + ""; } if (!Directory.Exists(Track.FolderLevels + fname)) { break; } } } string nroot = Track.FolderLevels + fname; if (!Directory.Exists(nroot)) { Folder pholder = new Folder() { Id = 0, FolderName = fname, DateCreated = DateTime.UtcNow, Location = Path.GetRelativePath(Track.FolderLevels, nroot), ParentFolderId = null, }; EntityEntry <Folder> entry1 = await _context.Folders.AddAsync(pholder); _context.SaveChanges(); Directory.CreateDirectory(nroot); Counter lcount = await _context.Counter.LastOrDefaultAsync(); int lastCount = lcount.CounterNumber++; EntityEntry <Counter> entr = _context.Counter.Update(lcount); _context.SaveChanges(); } Folder uploadingfolder = _context.Folders.LastOrDefault(); int folId = uploadingfolder.Id; FileMaster theFile = new FileMaster { Id = 0, FileName = Path.GetFileName(file.FileName), //Name = Path.GetFileNameWithoutExtension(file.FileName), ClientFilePath = Path.GetFullPath(file.FileName), DateUploaded = DateTime.UtcNow, DateUpdated = DateTime.UtcNow, Location = ((await _context.Folders.FirstOrDefaultAsync(p => p.Id == folId)).Location), Type = Path.GetExtension(file.FileName), Size = file.Length, VersionNumber = 0, Folder = await _context.Folders.FirstOrDefaultAsync(p => p.Id == folId), FileIterations = new List <FileIteration>() }; EntityEntry <FileMaster> entry = await _context.Files.AddAsync(theFile); _context.SaveChanges(); string stName = entry.Entity.Id + "_" + entry.Entity.VersionNumber + Path.GetExtension(file.FileName); string stPath = Track.FolderLevels + uploadingfolder.FolderName + "/" + stName; FileIteration iter = new FileIteration { Id = 0, FileMasterId = entry.Entity.Id, IterationCheckSum = objCheckSum.CalcCRC32(stream1), IterationName = stName, IterationPath = stPath }; EntityEntry <FileIteration> entry2 = await _context.FileIterations.AddAsync(iter); _context.SaveChanges(); theFile.FileIterations.Add(entry2.Entity); //when the version of file is updated EntityEntry <FileMaster> entry3 = _context.Files.Update(theFile); _context.SaveChanges(); theFile = entry3.Entity; using (var stream = new FileStream(stPath, FileMode.Create)) { await file.CopyToAsync(stream); } return(Ok()); }
/// <summary> /// btnBrowse Click event handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnBrowse_Click(object sender, RoutedEventArgs e) { String filter = "All Files (*.*)|*.*"; if (DataContextViewModelCreateUpdatePresentations.SelectedUploadDocumentInfo == UploadDocumentType.PRESENTATION) { filter = "PDF (*.pdf)|*.pdf"; } else if (DataContextViewModelCreateUpdatePresentations.SelectedUploadDocumentInfo == UploadDocumentType.ADDITIONAL_ATTACHMENT) { filter = "PDF (*.pdf)|*.pdf|JPEG Picture (*.jpeg, *.jpg)|*.jpeg;*.jpg"; } else { filter = "PDF (*.pdf)|*.pdf"; } OpenFileDialog dialog = new OpenFileDialog() { Multiselect = false, Filter = filter }; if (dialog.ShowDialog() == true) { if (DataContextViewModelCreateUpdatePresentations.SelectedUploadDocumentInfo == UploadDocumentType.PRESENTATION) { if (dialog.File.Extension != null && dialog.File.Extension.ToLower() != ".pdf") { return; } } else if (DataContextViewModelCreateUpdatePresentations.SelectedUploadDocumentInfo == UploadDocumentType.ADDITIONAL_ATTACHMENT) { if (dialog.File.Extension != null && dialog.File.Extension.ToLower() != ".pdf" && dialog.File.Extension.ToLower() != ".jpeg" && dialog.File.Extension.ToLower() != ".jpg") { return; } } else { if (dialog.File.Extension != null && dialog.File.Extension.ToLower() != ".pdf") { return; } } DataContextViewModelCreateUpdatePresentations.BusyIndicatorNotification(true, "Reading file..."); Boolean uploadFileExists = DataContextViewModelCreateUpdatePresentations.SelectedUploadDocumentInfo != UploadDocumentType.ADDITIONAL_ATTACHMENT && DataContextViewModelCreateUpdatePresentations.SelectedUploadDocumentInfo != UploadDocumentType.DCF_MODEL && DataContextViewModelCreateUpdatePresentations.SelectedPresentationDocumentationInfo .Any(record => record.Category.ToUpper() == DataContextViewModelCreateUpdatePresentations.SelectedUploadDocumentInfo.ToUpper()); if (uploadFileExists) { FileMaster uploadDocumentInfo = DataContextViewModelCreateUpdatePresentations.SelectedPresentationDocumentationInfo .Where(record => record.Category == DataContextViewModelCreateUpdatePresentations.SelectedUploadDocumentInfo).FirstOrDefault(); if (uploadDocumentInfo != null) { DataContextViewModelCreateUpdatePresentations.UploadFileData = uploadDocumentInfo; } } else { FileMaster presentationAttachedFileData = new FileMaster() { Name = dialog.File.Name, SecurityName = DataContextViewModelCreateUpdatePresentations.SelectedPresentationOverviewInfo.SecurityName, SecurityTicker = DataContextViewModelCreateUpdatePresentations.SelectedPresentationOverviewInfo.SecurityTicker, Type = EnumUtils.GetDescriptionFromEnumValue <DocumentCategoryType>(DocumentCategoryType.IC_PRESENTATIONS), Category = DataContextViewModelCreateUpdatePresentations.SelectedUploadDocumentInfo }; DataContextViewModelCreateUpdatePresentations.UploadFileData = presentationAttachedFileData; } FileStream fileStream = dialog.File.OpenRead(); DataContextViewModelCreateUpdatePresentations.UploadFileStreamData = ReadFully(fileStream); DataContextViewModelCreateUpdatePresentations.SelectedUploadFileName = dialog.File.Name; fileStream.Dispose(); DataContextViewModelCreateUpdatePresentations.BusyIndicatorNotification(); } }
public List <StatementReferenceMaster> PrepareParseJclFile(int fileId, int languageId, List <FileMaster> fileMaster, List <BaseCommandReference> baseCommandReference, List <string> inputList, int callExtRefId, params string[] lineStartString) { if (baseCommandReference == null) { using (var appDbContext = new AppDbContext()) { var lstItems = appDbContext.Set <BaseCommandReference>().Include("PrimaryLanguageReference").ToList(); var settings = new JsonSerializerSettings { ContractResolver = new ReferenceLoopResolver <BaseCommandReference>(), PreserveReferencesHandling = PreserveReferencesHandling.None, ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.Indented }; var json = JsonConvert.SerializeObject(lstItems, settings); var listData = JsonConvert.DeserializeObject <List <BaseCommandReference> >(json); baseCommandReference = listData; } } if (fileMaster == null) { using (var appDbContext = new AppDbContext()) { var lstItems = appDbContext.Set <FileMaster>().AsQueryable().Include("ProjectMaster"). Include("FileTypeExtensionReference").ToList(); var settings = new JsonSerializerSettings { ContractResolver = new ReferenceLoopResolver <FileMaster>(), PreserveReferencesHandling = PreserveReferencesHandling.None, ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.Indented }; var json = JsonConvert.SerializeObject(lstItems, settings); var listData = JsonConvert.DeserializeObject <List <FileMaster> >(json); fileMaster = listData; } } var lstStatementReferenceMaster = new List <StatementReferenceMaster>(); var lineCommentedIndicators = baseCommandReference.Find(s => s.BaseCommand == "Line Comment") .PrimaryLanguageReference.ToList().FindAll(p => p.LanguageId == languageId); var ifConditionStart = baseCommandReference.Find(s => s.BaseCommand == "IF Start") .PrimaryLanguageReference.ToList().FindAll(p => p.LanguageId == languageId); var ifConditionEnd = baseCommandReference.Find(s => s.BaseCommand == "IF End") .PrimaryLanguageReference.ToList().FindAll(p => p.LanguageId == languageId); var loopIndicatorStart = baseCommandReference.Find(s => s.BaseCommand == "Loop Start") .PrimaryLanguageReference.ToList().FindAll(p => p.LanguageId == languageId); var loopIndicatorEnd = baseCommandReference.Find(s => s.BaseCommand == "Loop End") .PrimaryLanguageReference.ToList().FindAll(p => p.LanguageId == languageId); var ifStart = ifConditionStart.Find(s => true); var ifEnd = ifConditionEnd.FindAll(s => true); var loopStart = loopIndicatorStart.FindAll(l => true); var loopEnd = loopIndicatorEnd.FindAll(l => true); var regEx = new Regex(@"^EXECUTE\s|^PH\s|^PHANTOM\s", RegexOptions.IgnoreCase); var programLineListMainList = inputList.SplitIfElseThenStatement(true); foreach (var input in programLineListMainList) { var classNameDeclared = ""; FileMaster referenceFileMaster = null; if (input.StartsWith("*")) { continue; } if (lineStartString.Any(l => input.StartsWith(l + " "))) { var oStatement = input.Trim(); if (regEx.IsMatch(oStatement)) { oStatement = Regex.Replace(oStatement, @"\s+", " ").Trim(); int splitLength = oStatement.Split(' ').Length; if (splitLength <= 1) { goto ContinueFurther; } string programName = regEx.IsMatch(oStatement) ? oStatement.Split(' ')[1] : oStatement.Split(' ')[2]; var anyFile = fileMaster.ToList() .Any(f => programName != null && Path.GetFileNameWithoutExtension(f.FilePath) == programName && f.FileTypeExtensionId == 10); if (!anyFile) { goto ContinueFurther; } var pName = fileMaster.ToList() .Find(f => programName != null && Path.GetFileNameWithoutExtension(f.FilePath) == programName && f.FileTypeExtensionId == 10); if (pName == null) { goto ContinueFurther; } var projectMaster = _appDbContext.ProjectMaster.Find(pName.ProjectId); if (pName.ProjectMaster == null) { pName.ProjectMaster = projectMaster; } if (pName.ProjectMaster != null) { var pNameNew = pName.ProjectMaster.ProjectName; var pPathNew = pName.ProjectMaster.PhysicalPath; var className = pName.FilePath.Replace(pPathNew + "\\", "") .Replace(pName.FileName, "").Replace("\\", "."); var fileName = Path.GetFileNameWithoutExtension(pName.FilePath); classNameDeclared = pNameNew + "." + className + fileName; } referenceFileMaster = pName; } else { string programName = regEx.IsMatch(oStatement) ? oStatement.Split(' ')[1] : oStatement.Split(' ')[2]; var anyFile = fileMaster.ToList() .Any(f => programName != null && Path.GetFileNameWithoutExtension(f.FilePath) == programName && (f.FileTypeExtensionId == 9 || f.FileTypeExtensionId == 17)); if (!anyFile) { goto ContinueFurther; } var pName = fileMaster.ToList() .Find(f => programName != null && Path.GetFileNameWithoutExtension(f.FilePath) == programName && (f.FileTypeExtensionId == 9 || f.FileTypeExtensionId == 17)); if (pName == null) { goto ContinueFurther; } var pNameNew = pName.ProjectMaster.ProjectName; var pPathNew = pName.ProjectMaster.PhysicalPath; var className = pName.FilePath.Replace(pPathNew + "\\", "") .Replace(pName.FileName, "").Replace("\\", "."); var fileName = Path.GetFileNameWithoutExtension(pName.FilePath); classNameDeclared = pNameNew + "." + className + fileName; referenceFileMaster = pName; } } ContinueFurther: if (input.StartsWith(lineCommentedIndicators.Find(x => x.StartIndicator != null).StartIndicator)) { continue; } if (lineStartString.Any(l => input.StartsWith(l + " ")) || regEx.IsMatch(input)) { lstStatementReferenceMaster.Add(new StatementReferenceMaster { FileId = fileId, ResolvedStatement = input, OriginalStatement = input, ClassCalled = classNameDeclared, MethodName = null, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, ClassNameDeclared = null, PrimaryCommandId = callExtRefId, BaseCommandId = 6, ReferenceFileId = referenceFileMaster?.FileId ?? 0, StatementComment = "" }); continue; } if (input.StartsWith(ifStart.StartIndicator)) { lstStatementReferenceMaster.Add(new StatementReferenceMaster { FileId = fileId, ResolvedStatement = input, OriginalStatement = input, ClassCalled = null, MethodName = null, BusinessName = null, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, BaseCommandId = ifStart.BaseCommandId, PrimaryCommandId = ifStart.PrimaryReferenceId }); continue; } if (ifEnd.Any(l => input == l.StartIndicator)) { lstStatementReferenceMaster.Add(new StatementReferenceMaster { FileId = fileId, ResolvedStatement = input, OriginalStatement = input, ClassCalled = null, MethodName = null, BusinessName = null, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, BaseCommandId = 2, PrimaryCommandId = ifEnd.Find(s => input.StartsWith(s.StartIndicator)).PrimaryReferenceId }); continue; } if (loopStart.Any(l => input.StartsWith(l.StartIndicator)) || input == "LOOP") { lstStatementReferenceMaster.Add(new StatementReferenceMaster { FileId = fileId, ResolvedStatement = input, OriginalStatement = input, ClassCalled = null, MethodName = null, BusinessName = null, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, BaseCommandId = input == "LOOP" ? 3 : loopStart.Find(s => input.StartsWith(s.StartIndicator)).BaseCommandId, PrimaryCommandId = input == "LOOP" ? 62 : loopStart.Find(s => input.StartsWith(s.StartIndicator)).PrimaryReferenceId }); continue; } if (loopEnd.Any(l => input.StartsWith(l.StartIndicator))) { lstStatementReferenceMaster.Add(new StatementReferenceMaster { FileId = fileId, ResolvedStatement = input, OriginalStatement = input, ClassCalled = null, MethodName = null, BusinessName = null, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, BaseCommandId = loopEnd.Find(s => input.StartsWith(s.StartIndicator)).BaseCommandId, PrimaryCommandId = loopEnd.Find(s => input.StartsWith(s.StartIndicator)).PrimaryReferenceId }); continue; } if ((input == "END ELSE") || (input == "ELSE")) { lstStatementReferenceMaster.Add(new StatementReferenceMaster { FileId = fileId, ResolvedStatement = input, OriginalStatement = input, ClassCalled = null, MethodName = null, BusinessName = null, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, BaseCommandId = 10, PrimaryCommandId = 0 }); continue; } lstStatementReferenceMaster.Add(new StatementReferenceMaster { FileId = fileId, ResolvedStatement = input, OriginalStatement = input, ClassCalled = null, MethodName = null, BusinessName = null, DataOrObjectType = null, MethodCalled = null, VariableNameDeclared = null, BaseCommandId = 0, PrimaryCommandId = 0 }); } return(lstStatementReferenceMaster); }
/// <summary> /// btnBrowse Click EventHandler /// </summary> /// <param name="sender"></param> /// <param name="e">RoutedEventArgs</param> private void btnBrowse_Click(object sender, RoutedEventArgs e) { String filter = "All Files (*.*)|*.*"; OpenFileDialog dialog = new OpenFileDialog() { Multiselect = false, Filter = filter }; if (dialog.ShowDialog() == true) { DataContextViewPresentationMeetingMinutes.BusyIndicatorNotification(true, "Reading file..."); Boolean uploadFileExists = DataContextViewPresentationMeetingMinutes.SelectedUploadDocumentInfo != UploadDocumentType.OTHER_DOCUMENT && DataContextViewPresentationMeetingMinutes.SelectedMeetingDocumentationInfo .Any(record => record.Category.ToUpper() == DataContextViewPresentationMeetingMinutes.SelectedUploadDocumentInfo.ToUpper()); if (uploadFileExists) { FileMaster uploadDocumentInfo = DataContextViewPresentationMeetingMinutes.SelectedMeetingDocumentationInfo .Where(record => record.Category == DataContextViewPresentationMeetingMinutes.SelectedUploadDocumentInfo).FirstOrDefault(); if (uploadDocumentInfo != null) { DataContextViewPresentationMeetingMinutes.UploadFileData = uploadDocumentInfo; } } else { String securityNames = String.Empty; String securityTickers = String.Empty; String presenters = String.Empty; foreach (MeetingMinuteData item in DataContextViewPresentationMeetingMinutes.ClosedForVotingMeetingMinuteDistinctPresentationInfo) { securityNames += item.SecurityName + ";"; securityTickers += item.SecurityTicker + ";"; presenters += item.Presenter + ";"; } securityNames = securityNames != String.Empty ? securityNames.Substring(0, securityNames.Length - 1) : securityNames; securityTickers = securityTickers != String.Empty ? securityTickers.Substring(0, securityTickers.Length - 1) : securityTickers; presenters = presenters != String.Empty ? presenters.Substring(0, presenters.Length - 1) : presenters; FileMaster presentationAttachedFileData = new FileMaster() { Name = dialog.File.Name, SecurityName = securityNames, SecurityTicker = securityTickers, MetaTags = DataContextViewPresentationMeetingMinutes.SelectedClosedForVotingMeetingInfo .MeetingDateTime.ToString("yyyy-MM-dd") + ";" + presenters, Type = EnumUtils.GetDescriptionFromEnumValue <DocumentCategoryType>(DocumentCategoryType.IC_PRESENTATIONS), Category = DataContextViewPresentationMeetingMinutes.SelectedUploadDocumentInfo }; DataContextViewPresentationMeetingMinutes.UploadFileData = presentationAttachedFileData; } FileStream fileStream = dialog.File.OpenRead(); DataContextViewPresentationMeetingMinutes.UploadFileStreamData = ReadFully(fileStream); DataContextViewPresentationMeetingMinutes.SelectedUploadFileName = dialog.File.Name; fileStream.Dispose(); DataContextViewPresentationMeetingMinutes.BusyIndicatorNotification(); } }