Ejemplo n.º 1
0
        public ActionResult SeeChanges(String Project, String Filename, int Projectid)
        {
            string root = $@"{Server.MapPath("~/")}\UserContent\ProjectFiles\{Project}\";

            if (!Directory.Exists(root))
            {
                Directory.CreateDirectory(root);
            }

            // REDUNDANCY
            List <VerComparativeItem> changeList = new List <VerComparativeItem>();

            try
            {
                var versionner = new BinaryVersionner(Filename, Filename, root, @"\backup\");
                changeList.AddRange(versionner.CheckDifferences()
                                    .Select(change => new VerComparativeItem()
                {
                    BeginLine   = change.StartingLine,
                    EndLine     = change.EndLine,
                    Code        = (int)change.changeType,
                    Differences = change.ChangeSet.ToArray()
                }));
                versionner.Dispose();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            TempData["Project"]   = Project;
            TempData["Filename"]  = Filename;
            TempData["Projectid"] = Projectid;

            ViewData["Root"] = root;
            return(View("SeeChanges", changeList));
        }
Ejemplo n.º 2
0
        public void UploadFiles(IEnumerable <HttpPostedFileBase> files, String directoryPath, int projectid)
        {
            if (files != null)
            {
                foreach (var file in files)
                {
                    // Verify that the user selected a file
                    if (file != null && file.ContentLength > 0)
                    {
                        // extract only the fielname
                        var fileName = Path.GetFileName(file.FileName);
                        // TODO: need to define destination
                        var path = Path.Combine(directoryPath, fileName);

                        // REDUNDANCY
                        if (System.IO.File.Exists(path))
                        {
                            if (!System.IO.Directory.Exists(directoryPath + @"backup\"))
                            {
                                Directory.CreateDirectory(directoryPath + @"backup\");
                            }

                            if (System.IO.File.Exists(directoryPath + @"backup\" + file))
                            {
                                System.IO.File.Delete(directoryPath + @"backup\" + file);
                            }

                            System.IO.File.Copy(path, directoryPath + @"backup\" + file);
                        }

                        file.SaveAs(path);

                        // REDUNDANCY
                        String ProjectName = _Session.GetProject((long)projectid).name;
                        String nameToSave  = path.Substring(path.IndexOf(ProjectName));
                        String recordNam   = $"{nameToSave}/{file}";
                        if (!_Session.GetFiles(projectid).Any(record => record.name.Equals(recordNam)))
                        {
                            _Session.CreateFile(new FileModel()
                            {
                                name          = recordNam,
                                change_count  = 0,
                                creation_date = DateTime.Now,
                                owner_id      = (int)_Session.CurrentUser.id,
                                project_id    = projectid,
                                last_update   = DateTime.Now,
                                last_updater  = (int)_Session.CurrentUser.id
                            });
                        }
                        else
                        {
                            var oldModel = _Session.GetFiles(projectid).Single(rec => rec.name.Equals(recordNam));

                            oldModel.last_update  = DateTime.Now;
                            oldModel.last_updater = (int)_Session.CurrentUser.id;
                            oldModel.change_count++;

                            _Session.UpdateFile(oldModel);

                            // REDUNDANCY
                            List <VerComparativeItem> changeList = new List <VerComparativeItem>();

                            int addition = 0, edition = 0, removal = 0;
                            try
                            {
                                var versionner = new BinaryVersionner(fileName, fileName, directoryPath, @"\backup\");
                                var values     = versionner.CheckDifferences();
                                versionner.Dispose();

                                if (values.Any(rec => rec.changeType == WorkstationUtilities.Analytic.ChangeType.LineChange))
                                {
                                    foreach (var editedLine in values.Where(
                                                 rec => rec.changeType == WorkstationUtilities.Analytic.ChangeType.LineChange))
                                    {
                                        edition += Math.Abs(editedLine.EndLine - editedLine.StartingLine) + 1;
                                    }
                                }

                                if (values.Any(rec => rec.changeType == WorkstationUtilities.Analytic.ChangeType.NewContent))
                                {
                                    foreach (var editedLine in values.Where(
                                                 rec => rec.changeType == WorkstationUtilities.Analytic.ChangeType.NewContent))
                                    {
                                        addition += Math.Abs(editedLine.EndLine - editedLine.StartingLine) + 1;
                                    }
                                }

                                if (values.Any(rec => rec.changeType == WorkstationUtilities.Analytic.ChangeType.RemovedContent))
                                {
                                    foreach (var editedLine in values.Where(
                                                 rec => rec.changeType == WorkstationUtilities.Analytic.ChangeType.RemovedContent))
                                    {
                                        removal += Math.Abs(editedLine.EndLine - editedLine.StartingLine) + 1;
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e);
                            }

                            _Session.CreateChangeSet(new ChangeSetModel()
                            {
                                trackerId   = oldModel.tracker_id,
                                description = "",
                                shortName   = $"{recordNam} Update",
                                addition    = addition,
                                deletion    = removal,
                                edition     = edition,
                                origin      = (int)_Session.CurrentUser.id,
                                stamp       = DateTime.Now
                            });
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        [ValidateInput(false)] // Ugly way, should be replaced by a built-in engine sending XML and or JSON
        public ActionResult _DocumentCreator(String title, String extension, String content, String project, int projectid)
        {
            /*
             * if (!TitleVerifier.IsMatch(title)){
             *  TempData["Project"] = project;
             *  TempData["Projectid"] = projectid;
             *
             *  return View();
             * }*/
            //String projectPath = $@"C:\inetpub\ftproot\{(String) TempData["Project"]}\";
            var root = $@"{Server.MapPath("~/")}\UserContent\ProjectFiles\{project}\";
            var file = $"{title}.{extension}";

            // REDUNDANCY
            if (System.IO.File.Exists(root + file))
            {
                if (!System.IO.Directory.Exists(root + @"backup\"))
                {
                    Directory.CreateDirectory(root + @"backup\");
                }

                if (System.IO.File.Exists(root + @"backup\" + file))
                {
                    System.IO.File.Delete(root + @"backup\" + file);
                }

                System.IO.File.Copy(root + file, root + @"backup\" + file);
            }

            System.IO.File.WriteAllText(root + file, content);
            string recName = $"{project}/{file}";

            // REDUNDANCY
            if (!_Session.GetFiles(projectid).Any(record => record.name.Equals(recName)))
            {
                _Session.CreateFile(new FileModel()
                {
                    name          = recName,
                    change_count  = 0,
                    creation_date = DateTime.Now,
                    owner_id      = (int)_Session.CurrentUser.id,
                    project_id    = projectid,
                    last_update   = DateTime.Now,
                    last_updater  = (int)_Session.CurrentUser.id
                });
            }

            var myFile = _Session.GetFiles(projectid).First(record => record.name.Equals(recName));

            // REDUNDANCY
            List <VerComparativeItem> changeList = new List <VerComparativeItem>();

            int addition = 0, edition = 0, removal = 0;

            // Values are inverted here
            try
            {
                var versionner = new BinaryVersionner(file, file, root, @"\backup\");
                var values     = versionner.CheckDifferences();
                versionner.Dispose();

                if (values.Any(rec => rec.changeType == WorkstationUtilities.Analytic.ChangeType.LineChange))
                {
                    foreach (var editedLine in values.Where(
                                 rec => rec.changeType == WorkstationUtilities.Analytic.ChangeType.LineChange))
                    {
                        edition += Math.Abs(editedLine.EndLine - editedLine.StartingLine) + 1;
                    }
                }

                if (values.Any(rec => rec.changeType == WorkstationUtilities.Analytic.ChangeType.NewContent))
                {
                    foreach (var editedLine in values.Where(
                                 rec => rec.changeType == WorkstationUtilities.Analytic.ChangeType.NewContent))
                    {
                        addition += Math.Abs(editedLine.EndLine - editedLine.StartingLine) + 1;
                    }
                }

                if (values.Any(rec => rec.changeType == WorkstationUtilities.Analytic.ChangeType.RemovedContent))
                {
                    foreach (var editedLine in values.Where(
                                 rec => rec.changeType == WorkstationUtilities.Analytic.ChangeType.RemovedContent))
                    {
                        removal += Math.Abs(editedLine.EndLine - editedLine.StartingLine) + 1;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            myFile.change_count += 1;
            myFile.last_updater  = (int)_Session.CurrentUser.id;
            myFile.last_update   = DateTime.Now;

            _Session.UpdateFile(myFile);

            _Session.CreateChangeSet(new ChangeSetModel()
            {
                trackerId   = myFile.tracker_id,
                description = "",
                shortName   = $"{recName} Update",
                addition    = removal,
                deletion    = addition,
                edition     = edition,
                origin      = (int)_Session.CurrentUser.id,
                stamp       = DateTime.Now
            });

            return(RedirectToAction("ProjectDocuments", new{ project = project, projectid = projectid }));
        }