Search in sources :

Example 1 with AsciiFileDataSourceVO

use of com.infiniteautomation.asciifile.vo.AsciiFileDataSourceVO in project ma-modules-public by infiniteautomation.

the class AsciiFileEditDwr method saveFileDataSource.

@DwrPermission(user = true)
public ProcessResult saveFileDataSource(BasicDataSourceVO basic, int updatePeriods, int updatePeriodType, String filePath) {
    AsciiFileDataSourceVO ds = (AsciiFileDataSourceVO) Common.getHttpUser().getEditDataSource();
    setBasicProps(ds, basic);
    ds.setUpdatePeriods(updatePeriods);
    ds.setUpdatePeriodType(updatePeriodType);
    try {
        ds.setFilePath(new File(filePath).getCanonicalPath());
    } catch (IOException e) {
        ProcessResult pr = new ProcessResult();
        pr.addContextualMessage("filePath", "dsEdit.file.ioexceptionCanonical", filePath);
        return pr;
    }
    return tryDataSourceSave(ds);
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) AsciiFileDataSourceVO(com.infiniteautomation.asciifile.vo.AsciiFileDataSourceVO) IOException(java.io.IOException) File(java.io.File) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 2 with AsciiFileDataSourceVO

use of com.infiniteautomation.asciifile.vo.AsciiFileDataSourceVO in project ma-modules-public by infiniteautomation.

the class AsciiFileDataSourceRT method connect.

/**
 * Load a file path
 *
 * @throws Exception
 */
public boolean connect() throws Exception {
    AsciiFileDataSourceVO vo = (AsciiFileDataSourceVO) this.getVo();
    this.file = new File(vo.getFilePath());
    if (!file.exists()) {
        raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("file.event.fileNotFound", vo.getFilePath()));
        return false;
    } else if (!file.canRead()) {
        raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("file.event.readFailed", vo.getFilePath()));
        return false;
    } else {
        this.fobs = new FileAlterationObserver(this.file);
        this.fobs.initialize();
        this.fobs.addListener(this);
        return true;
    }
}
Also used : FileAlterationObserver(org.apache.commons.io.monitor.FileAlterationObserver) AsciiFileDataSourceVO(com.infiniteautomation.asciifile.vo.AsciiFileDataSourceVO) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) File(java.io.File)

Aggregations

AsciiFileDataSourceVO (com.infiniteautomation.asciifile.vo.AsciiFileDataSourceVO)2 File (java.io.File)2 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)1 IOException (java.io.IOException)1 FileAlterationObserver (org.apache.commons.io.monitor.FileAlterationObserver)1