예제 #1
0
void
Database::writeNotification(bool single_line)
{
    StoragePtr homepage = m_Storages[IDX_HOMEPAGE];

    std::string filename = ConfigurationFindscholarships::instance()->pathDatabase() + currentDateTime();
    if (single_line)
    {
        filename = filename + ".single";
    }
    else
    {
        filename = filename + ".multiple";
    }

    std::ofstream file_notification(filename.c_str());
    if (file_notification.is_open())
    {
        Storage::const_iterator beg = homepage->begin();
        Storage::const_iterator end = homepage->end();
        end--;
        for (Storage::const_iterator it = end; it != beg; it--)
        {
            DatePtr deadline = it->first;
            const DataEntry& data = it->second;
            if (data.isNew())
            {
                if (single_line)
                {
                    file_notification << data.getTitle().getSingleLineNotification(deadline) << std::endl << std::endl;
                }
                else
                {
                    file_notification << data.getTitle().getMultipleLineNotification(deadline) << std::endl << std::endl;
                }
            }
        }

        DatePtr deadline = beg->first;
        const DataEntry& data = beg->second;
        if (data.isNew())
        {
            if (single_line)
            {
                file_notification << data.getTitle().getSingleLineNotification(deadline) << std::endl << std::endl;
            }
            else
            {
                file_notification << data.getTitle().getMultipleLineNotification(deadline) << std::endl << std::endl;
            }
        }
    }
    else
    {
        DBGERR(__FUNCTION__ << ": Cannot open file \"" << filename << "\" for writing!")
    }
}
예제 #2
0
 inline void directory_changes::async_get_one(ptr_observer<observer<element_type>> receiver)
 {
     assert(!receiver_);
     receiver_ = receiver.get();
     assert(immovable);
     immovable->read_dispatcher.post(
         [this]
         {
             DWORD received = 0;
             std::array<char, 0x10000> buffer;
             DWORD const actions = FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE |
                                   FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_CREATION |
                                   FILE_NOTIFY_CHANGE_ATTRIBUTES;
             if (!ReadDirectoryChangesW(watch_file.get(), buffer.data(), static_cast<DWORD>(buffer.size()),
                                        is_recursive, actions, &received, nullptr, nullptr))
             {
                 // TODO: handle ERROR_NOTIFY_ENUM_DIR (overflow of event queue)
                 return;
             }
             std::vector<file_notification> notifications;
             for (char *next_event = buffer.data();;)
             {
                 FILE_NOTIFY_INFORMATION const &notification =
                     reinterpret_cast<FILE_NOTIFY_INFORMATION const &>(*next_event);
                 relative_path name(notification.FileName + 0,
                                    notification.FileName + (notification.FileNameLength / sizeof(WCHAR)));
                 notifications.emplace_back(file_notification(notification.Action, std::move(name)));
                 if (0 == notification.NextEntryOffset)
                 {
                     break;
                 }
                 next_event += notification.NextEntryOffset;
             }
             Si::exchange(this->receiver_, nullptr)->got_element(std::move(notifications));
         });
 }