示例#1
0
        private static bool LogErrorReport(Logging.DiagnosticData dump)
        {
            // note: normally 404s are not emailed to us, but if we have any processes that we need to ensure will send us an email on a 404 we can specify emailonfail=1 in the querystring
            if (!CheckIfErrorShouldBeLogged(dump))
            {
                return(false);
            }

            bool wasLogged = false;

            try {
                //Logging.dlog("LogErrorReport try logging");
                double secondsSinceLastReported = dump.SecondsSinceLastReport;
                var    isNewError = secondsSinceLastReported == 0 || secondsSinceLastReported > Util.GetSetting("ThrottleSameError", "60").ToInt(60);

                if (!isNewError)
                {
                    // assume already logged previously, so we want to display to the user that we have logged this error
                    wasLogged = true;
                }
                else
                {
                    wasLogged      = PostErrorReport(dump);
                    dump.WasLogged = wasLogged;
                }
                //Logging.dlog("LogErrorReport result: "+ wasLogged);
            } catch (Exception e) {
                //Logging.dlog("LogErrorReport problem [" + e.Message + "]");
                SendEMail.SimpleSendEmail("*****@*****.**", "LogErrorReport problem", e.Message);
            }
            return(wasLogged);
        }
示例#2
0
        /// <summary>
        /// Run the import. To tailor the import to handle a specific data format, create a derived class and override the various methods.
        /// </summary>
        public void ImportFilesInDropbox()
        {
            if (IsDropboxNotEmpty())
            {
                string dropboxFullPath          = Web.MapPath(IncomingPath);
                string dropboxProcessedFullPath = null;
                string dropboxRejectsFullPath   = null;
                if (!NoFilePermissionsMode)
                {
                    dropboxProcessedFullPath = Web.MapPath(ProcessedPath);
                    dropboxRejectsFullPath   = Web.MapPath(RejectsPath);
                }

                try {
                    Init(dropboxFullPath, dropboxProcessedFullPath, dropboxRejectsFullPath);

                    string[] files;
                    if (DirectoryFilter.IsNotBlank())
                    {
                        files = Directory.GetFiles(dropboxFullPath, DirectoryFilter);
                    }
                    else
                    {
                        files = Directory.GetFiles(dropboxFullPath);
                    }

                    foreach (var pathname in files)
                    {
                        string filename = pathname.RightFrom("\\");

                        this.fileName = filename;

                        if (!NoFilePermissionsMode || new Sql("select count(*) from DataImport where filename=", filename.SqlizeText()).FetchIntOrZero() == 0)
                        {
                            // process new file
                            var ok = ProcessFile(dropboxFullPath, filename);

                            bool useUniqueFiles = Util.GetSettingBool("ImporterUniqueFiles", true);
                            if (ok)
                            {
                                if (NoFilePermissionsMode)
                                {
                                    var log = new ActiveRecord("DataImport", "DataImportID");
                                    log["FileName"].ValueObject     = filename;
                                    log["DateImported"].ValueObject = DateTime.Now;
                                    log["ImportedBy"].ValueObject   = "Importer";
                                    log.Save();
                                }
                                else
                                {
                                    //bool useUniqueFiles = Util.GetSettingBool("ImporterUniqueFiles", true);
                                    string destfilename = filename;
                                    if (useUniqueFiles)
                                    {
                                        destfilename = FileSystem.GetUniqueFilename(dropboxFullPath + "\\", filename, 50, true);
                                    }

                                    if (Util.GetSettingBool("ImporterMoveFiles", true) && MoveImportedFiles)
                                    {
                                        bool allowOverwrite = !useUniqueFiles;
                                        FileSystem.Move(dropboxFullPath + "\\" + filename, dropboxProcessedFullPath + "\\" + destfilename, allowOverwrite);
                                    }
                                }

                                //Web.Response.Write("Imported file: " + filename + "<br>");
                                ImportSuccess(pathname);
                            }
                            else
                            {
                                if (ErrorAction == ErrorActions.ThrowError)
                                {
                                    throw new ProgrammingErrorException("Data Import Error: could not import file [" + filename + "]");
                                }
                                else if (ErrorAction == ErrorActions.EmailDeveloper)
                                {
                                    SendEMail.SimpleSendEmail(SendEMail.EmailAboutError, Util.GetSiteName() + " Import error", "Data Import Error: could not import file [" + filename + "]. Moved to Rejects folder.");
                                }
                                if (!NoFilePermissionsMode)
                                {
                                    if (!IsIgnoredIfError)
                                    {
                                        if (useUniqueFiles)
                                        {
                                            filename = FileSystem.GetUniqueFilename(dropboxRejectsFullPath + "\\", filename, 50, true);
                                        }
                                        bool allowOverwrite = !useUniqueFiles;

                                        try {
                                            FileSystem.Move(dropboxFullPath + "\\" + filename, dropboxRejectsFullPath + "\\" + filename, allowOverwrite);
                                        } catch (Exception e) {
                                            Web.Response.Write("NOK:file did not process ok. Also failed to move file: " + filename + " exception[" + e.Message + "]<br>");
                                        }
                                    }
                                }
                                Web.Response.Write("Could not import file: " + filename + "<br>");
                                //return; // just go on to the next file

                                ImportFailure(pathname);
                            }
                        }
                    }
                } catch (System.UnauthorizedAccessException accessException) {
                    throw new System.UnauthorizedAccessException("Drop folder problem: you need to grant the user ASPNET read/write/delete permissions over the folder '" + dropboxFullPath + "'.\n" + accessException.Message);
                }
            }
        }