示例#1
0
        public static void Init()
        {
            Imposter.ImpersonateRobot();
            IFormatter formatter = new BinaryFormatter();

            if (File.Exists(Paths.TEST_USERS))
            {
                var stream = new FileStream(Paths.TEST_USERS, FileMode.Open, FileAccess.Read);
                Testbrukere = (List <Bundles.AnsattInfo>)formatter.Deserialize(stream);
                stream.Close();
            }

            if (File.Exists(Paths.SUPER_USERS))
            {
                var stream = new FileStream(Paths.SUPER_USERS, FileMode.Open, FileAccess.Read);
                Superbrukere = (List <Bundles.LederInfo>)formatter.Deserialize(stream);
                stream.Close();
            }

            if (File.Exists(Paths.RAADMENN_USERS))
            {
                var stream = new FileStream(Paths.RAADMENN_USERS, FileMode.Open, FileAccess.Read);
                Raadmenn = (List <Bundles.LederInfo>)formatter.Deserialize(stream);
                stream.Close();
            }

            Imposter.UndoImpersonation();
        }
示例#2
0
        public static Response <List <Bundles.ESignInfo> > HentFullforteSigneringsoppdragForBruker(string ADbruker)
        {
            Imposter.ImpersonateRobot();

            List <Bundles.ESignInfo> fullforteOppdrag = new List <Bundles.ESignInfo>();

            var file = Paths.ESIGN_LOG + ADbruker + ".txt";

            if (File.Exists(file))
            {
                var content = File.ReadAllLines(file);

                foreach (var line in content)
                {
                    var row           = line.Split(';');
                    var dokDato       = row[0];
                    var mottakernavn  = row[1];
                    var signDato      = row[2];
                    var journalpostID = row[3];

                    fullforteOppdrag.Add(new Bundles.ESignInfo
                    {
                        Dato          = dokDato,
                        Mottaker      = mottakernavn,
                        SignDato      = signDato,
                        JournalpostID = journalpostID
                    });
                }
            }

            Imposter.UndoImpersonation();

            return(new Response <List <Bundles.ESignInfo> >(fullforteOppdrag, "ok", Codes.Code.OK));
        }
        public static Response <List <LogEntry> > GetOppfølginger()
        {
            var filbane = $@"{Paths.UNC_ADDRESS}{Paths.PORTAL_LOG}Sykefravær";

            Imposter.ImpersonateRobot();
            if (Directory.Exists(filbane))
            {
                var logFiles = Directory.GetFiles(filbane);
                var result   = new List <LogEntry>();

                foreach (var file in logFiles)
                {
                    var content = File.ReadAllLines(file);

                    foreach (var line in content)
                    {
                        if (line.StartsWith("Sykefraværsoppfølging")) // Kun sykefraværsoppfølginger skal telles
                        {
                            result.Add(new LogEntry()
                            {
                                Date = file.Split('\\').Last().Replace(".txt", ""), Name = line, Type = Mappetype.Sykefravær
                            });
                        }
                    }
                }
                Imposter.UndoImpersonation();
                return(new Response <List <LogEntry> >(result, "OK", Codes.Code.OK));
            }
            else
            {
                Imposter.UndoImpersonation();
                return(new Response <List <LogEntry> >(null, $"Mappen {filbane} ble ikke funnet", Codes.Code.ERROR));
            }
        }
        public static Response <List <VarselWeb> > GetVarselLogg()
        {
            Imposter.ImpersonateRobot();

            if (File.Exists(Paths.VARSEL_WEB_FILE))
            {
                var list    = new List <VarselWeb>();
                var content = File.ReadAllLines(Paths.VARSEL_WEB_FILE, System.Text.Encoding.Default);
                foreach (var line in content)
                {
                    var lineContent = line.Split(';');
                    if (!"".Equals(lineContent[5]) && !"".Equals(lineContent[7]) && !lineContent[5].Equals("Behandles av"))
                    {
                        list.Add(new VarselWeb(lineContent[1], lineContent[3], lineContent[5], lineContent[6]));
                    }
                }

                var dateMod = File.GetLastWriteTime(Paths.VARSEL_WEB_FILE).ToString("dd/MM/yyyy 'kl.'hh/mm/ss");

                Imposter.UndoImpersonation();
                return(new Response <List <VarselWeb> >(list, $"Sist oppdatert {dateMod}", Codes.Code.OK));
            }
            else
            {
                Imposter.UndoImpersonation();
                return(new Response <List <VarselWeb> >(null, $"Filen {Paths.VARSEL_WEB_FILE} ble ikke funnet", Codes.Code.ERROR));
            }
        }
 public static void Init()
 {
     _logEntries = new List <LogEntry>();
     Imposter.ImpersonateRobot();
     ReadLogFiles("Sykefravær", Mappetype.Sykefravær);
     ReadLogFiles("Ansattforhold", Mappetype.Ansattforhold);
     ReadJsonLogFile();
     Imposter.UndoImpersonation();
     var k = 42;
 }
示例#6
0
 private static Response <int> WriteObject(string filename, object obj)
 {
     try
     {
         Imposter.ImpersonateRobot();
         IFormatter formatter = new BinaryFormatter();
         Stream     stream    = new FileStream(filename, FileMode.Create, FileAccess.Write);
         formatter.Serialize(stream, obj);
         stream.Close();
         Imposter.UndoImpersonation();
         return(new Response <int>(0, "Great success", Codes.Code.OK));
     }
     catch (IOException e)
     {
         return(new Response <int>(1, e.Message, Codes.Code.ERROR));
     }
 }
        public static void Log(string filename, string arg)
        {
            try
            {
#if DEBUG
                Debug.WriteLine(arg);
#else
                System.IO.File.AppendAllText($"{Paths.LOG_DEFAULT}/{filename}", StringConstants.GetLogHeader() + Environment.NewLine + arg + Environment.NewLine);
#endif
            }
            catch (UnauthorizedAccessException)
            {
                // hvis vi havner her betyr det at prosessen kjører med robot-rettigheter der loggingen ble kalt
                Imposter.UndoImpersonation();
                Log(filename, arg);
                Imposter.ImpersonateRobot();
            }
        }
示例#8
0
        public static Response <List <Bundles.ESignInfo> > HentAktiveSigneringsoppdragForBruker(string ADbruker)
        {
            Imposter.ImpersonateRobot();

            List <Bundles.ESignInfo> aktiveOppdrag = new List <Bundles.ESignInfo>();

            var mapper = Directory.GetDirectories(Paths.GetUploadFolder());

            foreach (var mappe in mapper)
            {
                var lederAD = File.ReadAllText($"{mappe}\\{HelperFile.MANAGER_AD}");
                if (ADbruker.ToUpper().Equals(lederAD.ToUpper()))
                {
                    if (File.Exists($"{mappe}\\{HelperFile.SIGNATURE_STATUS}"))
                    {
                        var dokDato       = File.ReadAllText($"{mappe}\\{HelperFile.DATE}");
                        var signDatoFil   = $"{mappe}\\{HelperFile.SIGNATURE_DATE}";
                        var signDato      = File.Exists(signDatoFil) ? File.ReadAllText(signDatoFil) : "Ikke signert";
                        var ansattnavnfil = $"{mappe}\\{HelperFile.EMPLOYEE_NAME}";
                        var mottakernavn  = File.Exists(ansattnavnfil) ? File.ReadAllText(ansattnavnfil) : "Ikke tilgjengelig";
                        var statusfil     = $"{mappe}\\{HelperFile.SIGNATURE_ERROR}";
                        var status        = File.Exists(statusfil) ? File.ReadAllText(statusfil) : "Ingen feil";

                        var mottakerEpost = ADHelper.GetAnsattEpost(File.ReadAllText($"{mappe}\\{HelperFile.EMPLOYEE_ID}")).Get();

                        aktiveOppdrag.Add(new Bundles.ESignInfo
                        {
                            Dato          = dokDato,
                            Mottaker      = mottakernavn,
                            SignDato      = signDato,
                            JournalpostID = "Kommer snart?",
                            Signert       = !signDato.Equals("Ikke signert"),
                            MottakerEpost = mottakerEpost,
                            Status        = status.Split(':').First()
                        });
                    }
                }
            }

            Imposter.UndoImpersonation();

            return(new Response <List <Bundles.ESignInfo> >(aktiveOppdrag, "hello there", Codes.Code.OK));
        }
示例#9
0
        // les tidligere jobber fra fil, i tilfelle kræsj
        public static Response <int> Init()
        {
            Debug.WriteLine("starting static init()...");
            portal_clients.Clear();

            /*
             * if (File.Exists(queue_file_path))
             * {
             *  var clientConfigStrings = File.ReadAllLines(queue_file_path);
             *  Debug.WriteLine("loading " + clientConfigStrings.Length + " items...");
             *
             *  foreach (var config in clientConfigStrings)
             *  {
             *      if (config != string.Empty)
             *      {
             *          var client = CustomPortalClient.Deserialize(config);
             *          if (!portal_clients.ContainsKey(client.QueueID))
             *              portal_clients.Add(client.QueueID, client);
             *      }
             *  }
             */
            // ny kode 6.6.2019

            Imposter.ImpersonateRobot();
            if (Directory.Exists(Paths.GetUploadFolder()))
            {
                var uploadFolders = Directory.GetDirectories(Paths.GetUploadFolder());

                foreach (var folder in uploadFolders)
                {
                    if (File.Exists($"{folder}\\{HelperFile.REFERENCE}"))
                    {
                        // bare oppdrag som ikke har en signaturdato skal leses inn i polle-køen
                        if (!File.Exists($"{folder}\\{HelperFile.SIGNATURE_DATE}"))
                        {
                            // bare oppdrag som ikke har en feilmelding skal leses inn i polle-køen
                            if (!File.Exists($"{folder}\\{HelperFile.SIGNATURE_ERROR}"))
                            {
                                var config = File.ReadAllText($"{folder}\\{HelperFile.REFERENCE}");
                                if (config != string.Empty)
                                {
                                    var client = CustomPortalClient.FromReference(config);
                                    //client.FileFolder = folder;
                                    if (!portal_clients.ContainsKey(client.QueueID))
                                    {
                                        portal_clients.Add(client.QueueID, client);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            Imposter.UndoImpersonation();

            if (portal_clients.Count > 0)
            {
                return(new Response <int>(portal_clients.Count, "Lastet " + portal_clients.Count + " aktive signeringsoppdrag", Codes.Code.OK));
            }
            else
            {
                return(new Response <int>(0, "Oppdatert uten endring", Codes.Code.WARNING));
            }
        }
示例#10
0
        public static void PollForChange()
        {
            Init();

            //var clientsToRemove = new List<string>();

            foreach (var queueID in portal_clients.Keys)
            {
                try
                {
                    var client = portal_clients[queueID];
                    Debug.WriteLine("polling " + client.QueueID);

                    var jobStatusChanged = client.GetStatusChange().Result;

                    if (jobStatusChanged.Status != JobStatus.NoChanges)
                    {
                        var  signatureJobStatus     = jobStatusChanged.Status;
                        var  signatures             = jobStatusChanged.Signatures;
                        bool hasAllRecipientsSigned = true;

                        // Sjekk om alle mottakere har signert
                        foreach (var signature in signatures)
                        {
                            var signert = signature.SignatureStatus.Equals(SignatureStatus.Signed);
                            if (!signert)
                            {
                                hasAllRecipientsSigned = false;
                                break;
                            }
                            else if (signature.SignatureStatus == SignatureStatus.Rejected)
                            {
                                // TODO: send en e-post til oppdragsigver om at signeringen ble avvist
                                //File.AppendAllText($"{client.FileFolder}\\{HelperFile.SIGNATURE_ERROR}", signature.ToString());
                                break;
                            }
                            else if (signature.SignatureStatus == SignatureStatus.ContactInformationMissing)
                            {
                                // TODO: send en e-post til oppdragsgiver om at kontaktinformasjon ikke ble funnet
                                //File.AppendAllText($"{client.FileFolder}\\{HelperFile.SIGNATURE_ERROR}", signature.ToString());
                                break;
                            }
                        }

                        if (hasAllRecipientsSigned)
                        {
                            // hent signert dokument og skriv til fil
                            var pades = client.GetPades(jobStatusChanged.PadesReference).Result;

                            Imposter.ImpersonateRobot();
                            //var fileStream2 = File.Create($"{client.FileFolder}\\{client.DocumentFileName}.pdf");
                            //pades.Seek(0, SeekOrigin.Begin);
                            //pades.CopyTo(fileStream2);
                            //fileStream2.Close();

                            // marker mappen klar for WebSak-import av roboten
                            //File.WriteAllText($"{client.FileFolder}\\{HelperFile.SIGNATURE_STATUS}", "true");
                            //File.WriteAllText($"{client.FileFolder}\\{HelperFile.SIGNATURE_DATE}", DateTime.Now.ToString("dd/MM/yyyy"));

                            Imposter.UndoImpersonation();
                            // marker oppdraget som fullført
                            //clientsToRemove.Add(queueID);
                        }
                    }
                    if (jobStatusChanged.Status == JobStatus.Failed)
                    {
                        Imposter.ImpersonateRobot();
                        //File.AppendAllText($"{client.FileFolder}\\{HelperFile.SIGNATURE_ERROR}", jobStatusChanged.ToString());
                        Imposter.UndoImpersonation();
                    }
                }
                catch (TooEagerPollingException tep)
                {
                    File.WriteAllText(@"C:\inetpub\logs\crash.txt", tep.Message);
                }
                catch (Exception e)
                {
#if DEBUG
                    File.WriteAllText(@"C:\Users\anddyr\Documents\crash.txt", e.Message + "\n" + queueID);
#else
                    File.WriteAllText(@"C:\inetpub\logs\crash.txt", e.Message + "\n" + queueID);
#endif
                }
            }

            // fjern klienten fra listen i polle-filen når signeringen er utført

            /*
             * foreach (var id in clientsToRemove)
             * {
             *  portal_clients.Remove(id);
             *
             *  if (File.Exists(queue_file_path))
             *  {
             *      var oldQueue = File.ReadAllLines(queue_file_path);
             *      var newQueue = new List<string>();
             *      foreach (var q in oldQueue)
             *      {
             *          if (!q.Contains(id))
             *              newQueue.Add(q);
             *      }
             *
             *      File.WriteAllLines(queue_file_path, newQueue.ToArray());
             *  }
             * }
             */
        }
        public static void PollForChange()
        {
#if !DEBUG
            Logger.Log(LogFile.POLL_LOG, "polling...");
#endif
            Imposter.ImpersonateRobot();
            if (Directory.Exists(Paths.GetUploadFolder()))
            {
                var uploadFolders = Directory.GetDirectories(Paths.GetUploadFolder());

                foreach (var folder in uploadFolders)
                {
                    if (File.Exists($"{folder}\\{HelperFile.REFERENCE}"))
                    {
                        // bare oppdrag som ikke har en signaturdato skal leses inn i polle-køen
                        if (!File.Exists($"{folder}\\{HelperFile.SIGNATURE_DATE}"))
                        {
                            // bare oppdrag som ikke har en feilmelding skal leses inn i polle-køen
                            if (!File.Exists($"{folder}\\{HelperFile.SIGNATURE_ERROR}"))
                            {
                                var config    = File.ReadAllText($"{folder}\\{HelperFile.REFERENCE}");
                                var lederMail = File.ReadAllText($"{folder}\\{HelperFile.MANAGER_EMAIL}");
                                if (config != string.Empty)
                                {
                                    var client = CustomPortalClient.FromReference(config);
                                    try
                                    {
                                        Debug.WriteLine("polling " + client.QueueID);

                                        var jobStatusChanged = client.GetStatusChange().Result;

                                        if (jobStatusChanged.Status != JobStatus.NoChanges)
                                        {
                                            var             signatureJobStatus = jobStatusChanged.Status;
                                            var             signatures         = jobStatusChanged.Signatures;
                                            List <DateTime> signedDates        = new List <DateTime>();

                                            // Sjekk status på hver signatur
                                            foreach (var signature in signatures)
                                            {
                                                var ssn = signature.Identifier.ToPersonalIdentificationNumber().ToString().Split(' ').Last();
                                                if (signature.SignatureStatus.Equals(SignatureStatus.Rejected))
                                                {
                                                    // mottaker har avvist signeringsoppdraget
                                                    MailHelper.SendEsignatureError(lederMail, string.Format(string.Format(StringConstants.ESIGNATURE_REJECTED, ssn)));
                                                    File.AppendAllText($"{folder}\\{HelperFile.SIGNATURE_ERROR}", "Avvist: " + signature.ToString());
                                                    break;
                                                }
                                                else if (signature.SignatureStatus.Equals(SignatureStatus.ContactInformationMissing))
                                                {
                                                    // mottaker har ikke lagt inn informasjon i kontaktregisteret
                                                    MailHelper.SendEsignatureError(lederMail, string.Format(string.Format(StringConstants.ESIGNATURE_MISSING_INFO, ssn)));
                                                    File.AppendAllText($"{folder}\\{HelperFile.SIGNATURE_ERROR}", "Mangler kontaktinformasjon: " + signature.ToString());
                                                    break;
                                                }

                                                signedDates.Add(signature.DateTimeForStatus);
                                            }

                                            // skal ha dato for siste signatur
                                            signedDates.Sort();

                                            if (signatureJobStatus == JobStatus.CompletedSuccessfully)
                                            {
                                                // hent signert dokument og skriv til fil
                                                var pades = client.GetPades(jobStatusChanged.PadesReference).Result;

                                                Imposter.ImpersonateRobot();
                                                var fileStream = File.Create($"{folder}\\{client.DocumentFileName}.pdf");
                                                pades.Seek(0, SeekOrigin.Begin);
                                                pades.CopyTo(fileStream);
                                                fileStream.Close();

                                                // marker mappen klar for WebSak-import av roboten
                                                File.WriteAllText($"{folder}\\{HelperFile.SIGNATURE_STATUS}", "true");
                                                File.WriteAllText($"{folder}\\{HelperFile.SIGNATURE_DATE}", signedDates.Last().ToString("dd/MM/yyyy"));

                                                client.Confirm(jobStatusChanged.ConfirmationReference);

                                                Imposter.UndoImpersonation();
                                            }
                                        }
                                        if (jobStatusChanged.Status == JobStatus.Failed)
                                        {
                                            Imposter.ImpersonateRobot();
                                            string tt = "";
                                            foreach (var s in jobStatusChanged.Signatures)
                                            {
                                                tt += s.Identifier + ": " + s.SignatureStatus + ", ";
                                                var ssn = s.Identifier.ToPersonalIdentificationNumber().ToString().Split(' ').Last();
                                                if (s.SignatureStatus.Equals(SignatureStatus.Reserved))
                                                {
                                                    // mottaker har reservert seg mot digital kommunikasjon fra det offentlige
                                                    MailHelper.SendEsignatureError(lederMail, string.Format(string.Format(StringConstants.ESIGNATURE_RESERVED, ssn)));
                                                    File.AppendAllText($"{folder}\\{HelperFile.SIGNATURE_ERROR}", "Reservert mot digital kommunikasjon: " + s.ToString());
                                                }
                                                else if (s.SignatureStatus.Equals(SignatureStatus.Expired))
                                                {
                                                    // dokumentet har ikke blitt signert av alle mottakere innen fristen
                                                    MailHelper.SendEsignatureError(lederMail, string.Format(string.Format(StringConstants.ESIGNATURE_EXPIRED, ssn)));
                                                    File.AppendAllText($"{folder}\\{HelperFile.SIGNATURE_ERROR}", "Utløpt: " + s.ToString());
                                                }
                                            }
                                            File.AppendAllText($"{folder}\\{HelperFile.SIGNATURE_ERROR}", tt + Environment.NewLine + jobStatusChanged.ToString());
                                            Imposter.UndoImpersonation();
                                        }
                                    }
                                    catch (TooEagerPollingException tep)
                                    {
                                        Imposter.UndoImpersonation();
                                        Logger.Log(LogFile.CRASH, "Too eager polling: " + tep.Message);
                                    }
                                    catch (Exception e)
                                    {
#if DEBUG
                                        File.AppendAllText(@"C:\Users\anddyr\Documents\crash.txt", e.InnerException.Message + ": " + client.QueueID + Environment.NewLine);
#else
                                        Imposter.UndoImpersonation();
                                        Logger.Log(LogFile.CRASH, e.InnerException.Message + ": " + client.QueueID);
#endif
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }