Exemplo n.º 1
0
        internal WorkflowDetailsCache(UserDefinedSettings settings, Workflow.Workflow workflow)
        {
            Workflow = workflow;
            Operator = new UpdateOperator(settings);

            Workflow.PostSwitchProject += async(_, mergeRequests) =>
            {
                Trace.TraceInformation("[WorkflowDetailsCache] Processing project switch");

                List <Project> enabledProjects = Workflow.GetProjectsToUpdate();
                Debug.Assert(enabledProjects.Any((x) => x.Id == Workflow.State.Project.Id));

                cacheMergeRequests(Workflow.State.HostName, Workflow.State.Project, mergeRequests);
                await cacheVersionsAsync(Workflow.State.HostName,
                                         InternalDetails.GetMergeRequests(getProjectKey(Workflow.State)));
            };

            Workflow.PostSwitchMergeRequest += async(_) =>
            {
                Trace.TraceInformation("[WorkflowDetailsCache] Processing merge request switch");

                List <Project> enabledProjects = Workflow.GetProjectsToUpdate();
                Debug.Assert(enabledProjects.Any((x) => x.Id == Workflow.State.MergeRequest.Project_Id));

                await cacheVersionsAsync(Workflow.State.HostName, Workflow.State.MergeRequest);
            };
        }
Exemplo n.º 2
0
        public static string ReplaceWordsBasedOnGender(InternalDetails internDetails, string doctText)
        {
            Regex  replaceTag = new Regex(@"(<<[a-zA-Z]*\/.*?>>)");
            Regex  reg_male   = new Regex(@"(<<.*?\/)");
            Regex  reg_female = new Regex(@"(\/.*?>>)");
            string word       = "DUMMY/FEHLER";

            MatchCollection mc      = replaceTag.Matches(doctText);
            var             matches = new string[mc.Count];

            for (int i = 0; i < matches.Length; i++)
            {
                matches[i] = mc[i].ToString();

                if (internDetails.Sex == Sex.Male)
                {
                    string tempMale = reg_male.Match(matches[i]).ToString();
                    word     = tempMale.Substring(2, tempMale.Length - 3);
                    doctText = doctText.Replace(mc[i].ToString(), word);
                }
                else
                {
                    string tempFemale = reg_female.Match(matches[i]).ToString();
                    word     = tempFemale.Substring(1, tempFemale.Length - 3);
                    doctText = doctText.Replace(mc[i].ToString(), word);
                }
            }
            return(doctText);
        }
Exemplo n.º 3
0
        public static void ReplaceDatesAndNames(DocX document, InternalDetails internDetails, string path)
        {
            string text = document.Text;

            ReplaceDatesAndNames(document, internDetails);
            document.SaveAs(path);
        }
        private static string CreateDocumentWithSexDependendwords(Sex s, InternalDetails internDetails)
        {
            string tempTemplatePath = @"Files\temp.docx";
            DocX   document         = null;

            if (SavepathSerializer.Instance.SavePath != "")
            {
                File.Copy(SavepathSerializer.Instance.SavePath, tempTemplatePath, true);
                try
                {
                    document = DocX.Load(tempTemplatePath);
                }
                catch (FileFormatException)
                {
                    MessageDialog Dialog = new MessageDialog(WORDPROCESS_ERR_TITLE, WORDPROCESS_ERR_EMPTY_FILE);
                    Dialog.ShowDialog();
                    throw new FileFormatException();
                }
            }
            else
            {
                File.Copy(@"Files/Vorlage.docx", tempTemplatePath, true);
                document = DocX.Load(tempTemplatePath);
            }

            StringEditor.ReplaceWordsBasedOnGender(document, internDetails, tempTemplatePath);
            StringEditor.ReplaceDatesAndNames(document, internDetails, tempTemplatePath);
            return(tempTemplatePath);
        }
Exemplo n.º 5
0
        public static void ReplaceWordsBasedOnGender(DocX document, InternalDetails internDetails, string path)
        {
            string text = document.Text;

            ReplaceWordsBasedOnGender(document, internDetails);
            document.SaveAs(path);
        }
Exemplo n.º 6
0
        public void LoadInternDetails(string loadPath)
        {
            CurShowedInternDetails = InternalDetails.Deserialize(loadPath);
            //List<Criteria> CriteriaList = CurShowedInternDetails.Criterias;

            view.RefreshView();
            emptyFile    = false;
            savedChanges = true;
        }
Exemplo n.º 7
0
        internal async Task UpdateAsync()
        {
            Trace.TraceInformation("[WorkflowDetailsCache] Processing external Update request");

            await cacheMergeRequestsAsync(Workflow.State.HostName, Workflow.State.Project);
            await cacheVersionsAsync(Workflow.State.HostName,
                                     InternalDetails.GetMergeRequests(getProjectKey(Workflow.State)));

            Trace.TraceInformation("[WorkflowDetailsCache] External Update request processed");
        }
Exemplo n.º 8
0
 private void cleanupOldRecords(List <MergeRequest> oldRecords, List <MergeRequest> newRecords)
 {
     foreach (MergeRequest mergeRequest in oldRecords)
     {
         if (!newRecords.Any((x) => x.Id == mergeRequest.Id))
         {
             InternalDetails.CleanupTimestamps(mergeRequest.Id);
         }
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Adds the specified detail.
        /// </summary>
        /// <param name="detail">The detail.</param>
        public void Add(
            ValidationFaultElement detail)
        {
            if (detail == null)
            {
                throw new ArgumentNullException(nameof(detail));
            }

            InternalDetails.Add(detail);
        }
        public void RefreshView()
        {
            InternDetails = IdInternDetails.presenter.CurShowedInternDetails;
            ViewState     = ViewState.IsRefreshing;
            if (textPartSelectionList != null)
            {
                foreach (CriteriaTextSelectionView ctV in textPartSelectionList)
                {
                    ctV.RefreshView();
                }
            }
            RefreshToolStripMenu();

            ViewState = ViewState.WaitingForInput;
        }
        public MainWindowView(List <Criteria> criteriaList)
        {
            InitializeComponent();
            CurrentlyShownCriterias = new List <Criteria>();
            CriteriaList            = criteriaList;
            Presenter             = new MainWindowPresenter(this);
            textPartSelectionList = new List <CriteriaTextSelectionView>();
            IdInternDetails.SetBasis(this);
            InternDetails = IdInternDetails.presenter.CurShowedInternDetails;
            FlpCriteriaContainer.HorizontalScroll.Enabled = false;
            FlpCriteriaContainer.VerticalScroll.Enabled   = true;

            RefreshToolStripMenu();
            ViewState = ViewState.WaitingForInput;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Cache passed merge requests
        /// </summary>
        private void cacheMergeRequests(string hostname, Project project, List <MergeRequest> mergeRequests)
        {
            ProjectKey key = getProjectKey(hostname, project.Id);

            InternalDetails.SetProjectName(key, project.Path_With_Namespace);

            List <MergeRequest> previouslyCachedMergeRequests = InternalDetails.GetMergeRequests(key);

            InternalDetails.SetMergeRequests(key, mergeRequests);

            Trace.TraceInformation(String.Format(
                                       "[WorkflowDetailsCache] Number of cached merge requests for project {0} at {1} is {2} (was {3} before update)",
                                       project.Path_With_Namespace, hostname, mergeRequests.Count, previouslyCachedMergeRequests.Count));

            cleanupOldRecords(previouslyCachedMergeRequests, mergeRequests);
        }
Exemplo n.º 13
0
        public static void ReplaceDatesAndNames(DocX document, InternalDetails internDetails)
        {
            Regex regExTag = new Regex(@"(<<.*?>>)");

            Regex regExNachname      = new Regex(@"(<<NACHNAME>>)", RegexOptions.IgnoreCase);
            Regex regExVorname       = new Regex(@"(<<VORNAME>>)", RegexOptions.IgnoreCase);
            Regex regExGeburtsdatum  = new Regex(@"(<<GEBURTSDATUM>>)", RegexOptions.IgnoreCase);
            Regex regExAnfangsdatum  = new Regex(@"(<<ANFANGSDATUM>>)", RegexOptions.IgnoreCase);
            Regex regExEnddatum      = new Regex(@"(<<ENDDATUM>>)", RegexOptions.IgnoreCase);
            Regex regExHeutigesDatum = new Regex(@"(<<HEUTIGESDATUM>>)", RegexOptions.IgnoreCase);

            string text = document.Text.ToString();

            MatchCollection mc = regExTag.Matches(text);

            for (int i = 0; i < mc.Count; i++)
            {
                if (regExNachname.IsMatch(mc[i].ToString()))
                {
                    document.ReplaceText(mc[i].ToString(), internDetails.LastName != null ? internDetails.LastName : "");
                }

                if (regExVorname.IsMatch(mc[i].ToString()))
                {
                    document.ReplaceText(mc[i].ToString(), internDetails.FirstName != null ? internDetails.FirstName : "");
                }

                if (regExGeburtsdatum.IsMatch(mc[i].ToString()))
                {
                    document.ReplaceText(mc[i].ToString(), internDetails.DateOfBirth.ToString("dd.MM.yyyy"));
                }

                if (regExAnfangsdatum.IsMatch(mc[i].ToString()))
                {
                    document.ReplaceText(mc[i].ToString(), internDetails.FromDate.ToString("dd.MM.yyyy"));
                }

                if (regExEnddatum.IsMatch(mc[i].ToString()))
                {
                    document.ReplaceText(mc[i].ToString(), internDetails.UntilDate.ToString("dd.MM.yyyy"));
                }
                if (regExHeutigesDatum.IsMatch(mc[i].ToString()))
                {
                    document.ReplaceText(mc[i].ToString(), DateTime.Now.ToString("dd.MM.yyyy"));
                }
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Load merge requests from GitLab and cache them
        /// </summary>
        async private Task cacheMergeRequestsAsync(string hostname, Project project)
        {
            ProjectKey key = getProjectKey(hostname, project.Id);

            InternalDetails.SetProjectName(key, project.Path_With_Namespace);

            List <MergeRequest> mergeRequests;

            try
            {
                mergeRequests = await Operator.GetMergeRequestsAsync(hostname, InternalDetails.GetProjectName(key));
            }
            catch (OperatorException ex)
            {
                ExceptionHandlers.Handle(ex, String.Format("Cannot load merge requests for project Id {0}", project.Id));
                return; // silent return
            }

            cacheMergeRequests(hostname, project, mergeRequests);
        }
 public void GenerateWordDocument(
     InternalDetails internDetails,
     Dictionary <string, string> textParts,
     bool PractExpBulletpoints, bool ExcercisesBulletPoints)
 {
     //Anfangsdautm muss kleiner als jetztigesdatum sein
     if (internDetails.DateNow < internDetails.FromDate)
     {
         MessageDialog messagedialog = new MessageDialog(UNGÜLTIGES_DATUM_TITLE, UNGÜLTIGES_ANFANGSDATUM_ZUKUNFT_TEXT);
         messagedialog.ShowDialog();
         return;
     }
     // Geburtsdatum darf nicht Größer oder gleich Anfang sein
     if (internDetails.DateOfBirth >= internDetails.FromDate)
     {
         MessageDialog messagedialog = new MessageDialog(UNGÜLTIGES_DATUM_TITLE, UNGÜLTIGES_GEBURTSDATUM_TEXT);
         messagedialog.ShowDialog();
         return;
     }
     //Startdatum darf nicht größer Enddatum sein
     if (internDetails.FromDate > internDetails.UntilDate)
     {
         MessageDialog messagedialog = new MessageDialog(UNGÜLTIGES_DATUM_TITLE, UNGÜLTIGES_ANFANGSDATUM_TEXT);
         messagedialog.ShowDialog();
         return;
     }
     try
     {
         WordDocumentManipulater.WordReplacerInterop(internDetails, textParts, PractExpBulletpoints, ExcercisesBulletPoints);
     }
     catch (FileNotFoundException)
     {
         SavepathSerializer.Instance.SaveSavepath(string.Empty);
         MessageDialog message = new MessageDialog(VORLAGE_NICHT_GEFUNDEN_TITLE, VORLAGE_NICHT_GEFUNDEN_TEXT);
         message.ShowDialog();
         SavepathSerializer.Instance.SavePath = string.Empty;
         WordDocumentManipulater.WordReplacerInterop(internDetails, textParts, PractExpBulletpoints, ExcercisesBulletPoints);
     }
 }
Exemplo n.º 16
0
        /// <summary>
        /// Load Versions from GitLab and cache them
        /// </summary>
        async private Task cacheVersionsAsync(string hostname, MergeRequest mergeRequest)
        {
            Debug.Assert(InternalDetails.GetProjectKey(mergeRequest.Id).ProjectId != 0);

            MergeRequestDescriptor mrd = new MergeRequestDescriptor
            {
                HostName    = hostname,
                ProjectName = InternalDetails.GetProjectName(getProjectKey(hostname, mergeRequest.Project_Id)),
                IId         = mergeRequest.IId
            };

            Version latestVersion;

            try
            {
                latestVersion = await Operator.GetLatestVersionAsync(mrd);
            }
            catch (OperatorException ex)
            {
                ExceptionHandlers.Handle(ex, String.Format("Cannot load latest version for MR Id {0}", mergeRequest.Id));
                return; // silent return
            }

            DateTime previouslyCachedTimestamp = InternalDetails.GetLatestChangeTimestamp(mergeRequest.Id);

            InternalDetails.SetLatestChangeTimestamp(mergeRequest.Id, latestVersion.Created_At);

            if (previouslyCachedTimestamp > latestVersion.Created_At)
            {
                Debug.Assert(false);
                Trace.TraceWarning("[WorkflowDetailsCache] Latest version is older than a previous one");
            }

            Trace.TraceInformation(String.Format(
                                       "[WorkflowDetailsCache] Latest version of merge request with Id {0} has timestamp {1} (was {2} before update)",
                                       mergeRequest.Id,
                                       latestVersion.Created_At.ToLocalTime().ToString(),
                                       previouslyCachedTimestamp.ToLocalTime().ToString()));
        }
        public static void WordReplacerInterop(InternalDetails internDetails, Dictionary <string, string> textParts, bool PractExpBulletpoints, bool ExcercisesBulletPoints)
        {
            //Erstelle nötige Pfade
            string csvFileName      = "csvTempFile.csv";
            string fullCsvFilePath  = Path.GetFullPath(csvFileName);
            string tempTemplatePath = "";

            try
            {
                tempTemplatePath = CreateDocumentWithSexDependendwords(internDetails.Sex, internDetails);
            }
            catch (FileFormatException)
            {
                return;
            }
            string fullTemplatePath = Path.GetFullPath(tempTemplatePath);

            //Erstelle nötige Strings
            string lastname           = internDetails.LastName != null ? internDetails.LastName : "";
            string firstname          = internDetails.FirstName != null ? internDetails.FirstName : "";
            string dateOfBirth        = internDetails.DateOfBirth.Date.ToString().Replace(" 00:00:00", "");
            string department         = internDetails.Department != null ? internDetails.Department : "";
            string fromDate           = internDetails.FromDate.Date.ToString().Replace(" 00:00:00", "");
            string untilDate          = internDetails.UntilDate.Date.ToString().Replace(" 00:00:00", "");
            string exercises          = internDetails.Exercises != null ? internDetails.Exercises : "";
            string praticalExp        = internDetails.PracitcalExperience != null ? internDetails.PracitcalExperience : "";
            string today              = DateTime.Now.Date.ToString().Replace(" 00:00:00", "");
            string criteriaEvaluation = "";

            foreach (KeyValuePair <string, string> text in textParts)
            {
                criteriaEvaluation += text.Value + " ";
            }
            criteriaEvaluation = StringEditor.ReplaceDatesAndNames(internDetails, criteriaEvaluation);
            criteriaEvaluation = StringEditor.ReplaceWordsBasedOnGender(internDetails, criteriaEvaluation);
            Regex backSlashN = new Regex(@"\n");

            criteriaEvaluation = backSlashN.Replace(criteriaEvaluation, " ");

            //Überschreibe MailMergeField "PraktischeErfahrung" und "Aufgaben" damit diese Mehrzeilig sind
            try
            {
                using (WordprocessingDocument wrdProssesDoc = WordprocessingDocument.Open(tempTemplatePath, true))
                {
                    Document document = wrdProssesDoc.MainDocumentPart.Document;
                    IEnumerable <FieldCode> allMailMergeFields = document.Body.Descendants <FieldCode>();

                    foreach (FieldCode mm in allMailMergeFields)
                    {
                        if (mm.InnerText == " MERGEFIELD PraktischeErfahrung ")
                        {
                            OpenXmlElement refParagraph;
                            for (refParagraph = mm; !(refParagraph is DocumentFormat.OpenXml.Wordprocessing.Paragraph) && !(refParagraph is Body); refParagraph = refParagraph.Parent)
                            {
                                ;
                            }
                            if (refParagraph is Body)
                            {
                                continue;
                            }
                            if (PractExpBulletpoints)
                            {
                                ParagraphProperties prp = (ParagraphProperties)refParagraph.GetFirstChild <ParagraphProperties>().CloneNode(true);
                                OverrideMailmergefield(refParagraph, praticalExp, prp);
                            }
                            else
                            {
                                ParagraphProperties prp = new ParagraphProperties();
                                OverrideMailmergefield(refParagraph, praticalExp, prp);
                            }

                            wrdProssesDoc.MainDocumentPart.Document.Save();
                        }
                        if (mm.InnerText == " MERGEFIELD Aufgaben ")
                        {
                            OpenXmlElement refParagraph;
                            for (refParagraph = mm; !(refParagraph is DocumentFormat.OpenXml.Wordprocessing.Paragraph) && !(refParagraph is Body); refParagraph = refParagraph.Parent)
                            {
                                ;
                            }
                            if (refParagraph is Body)
                            {
                                continue;
                            }
                            if (ExcercisesBulletPoints)
                            {
                                ParagraphProperties prp = (ParagraphProperties)refParagraph.GetFirstChild <ParagraphProperties>();
                                OverrideMailmergefield(refParagraph, exercises, prp);
                            }
                            else
                            {
                                ParagraphProperties prp = new ParagraphProperties();
                                OverrideMailmergefield(refParagraph, exercises, prp);
                            }
                            wrdProssesDoc.MainDocumentPart.Document.Save();
                        }
                    }
                }
            }
            catch (Exception)
            {
                MessageDialog msg = new MessageDialog(WORDPROCESS_ERR_TITLE, WORDPROCESS_ERR_TEXT);
            }



            //Erstelle .csv Datei für Serienbrief
            using (FileStream csvFileStream = new FileStream(csvFileName, FileMode.Create))
            {
                using (StreamWriter streamWriter = new StreamWriter(csvFileStream))
                {
                    streamWriter.WriteLine("Name; Vorname; Geburtsdatum; Abteilung; Anfangsdatum; Enddatum; Aufgaben; PraktischeErfahrung; HeutigesDatum; Benotung");
                    streamWriter.WriteLine(lastname + ";" + firstname + ";" + dateOfBirth + ";" + department + ";" + fromDate + ";" + untilDate + ";" + " " + ";" + " " + ";" + today + ";" + criteriaEvaluation);
                }
            }

            //Mailmerge ausführen
            Word.Application wrdApp = new Word.Application();
            Word._Document   wrdDoc = null;
            wrdApp.Visible = true;
            try
            {
                wrdDoc = wrdApp.Documents.Open(fullTemplatePath);
                wrdDoc.MailMerge.OpenDataSource(fullCsvFilePath);

                wrdDoc.MailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument;
                wrdDoc.MailMerge.Execute();
            }

            finally
            {
                if (wrdDoc != null)
                {
                    wrdDoc.Close(false);
                }
                wrdApp = null;
            }
            DeleteUsedFiles(csvFileName, tempTemplatePath);
        }
Exemplo n.º 18
0
 public InternDetailsPresenter(InternDetailsV view)
 {
     this.view = view;
     CurShowedInternDetails = new InternalDetails();
 }