def get_all_cameras_for_server(server):
    try:
        cameras_array = []

        camera_link_query = Query()
        camera_link_query.TransactionType = eTransactionType.Query
        camera_link_query.Sql ="SELECT cs.CameraID FROM tCameraServer cs WHERE cs.ServerID = %s"
        camera_link_query.Args = [str(server.ServerID)]

        camera_ids_array = DBConn.single_query(camera_link_query)
        if len(camera_ids_array) > 0:
            camera_ids_string = ""
            for camera_id in camera_ids_array:
                value = camera_id.get("CameraID")
                camera_ids_string += str(value) + ","

            camera_ids_string = camera_ids_string[:-1]
            camera_query = Query()
            camera_query.TransactionType = eTransactionType.MultiSelectQuery
            camera_query.Sql = sql_select + sql_from + " WHERE c.CameraID IN (?)"
            camera_query.Args = [str(camera_ids_string)]
            camera_dict_list = DBConn.single_query(camera_query)

            for camera_dict in camera_dict_list:
                camera_obj = Camera()
                camera_obj.mapper(camera_dict)
                cameras_array.append(camera_obj)

        return cameras_array

    except Exception as err:
        print(err)
        ServerBL.update_server_status(server.ServerID, ServerStatus.Error.value)
        return []
Exemple #2
0
def __insert_camera_log(camera_id, status_id, message):
    insert_query = Query()
    insert_query.TransactionType = eTransactionType.Insert
    insert_query.Sql = "INSERT INTO tCameraLog(CameraID, CameraStatusID, CameraMessage, LogDateTime) VALUES (%s, %s, %s, %s)"
    insert_query.Args = [
        str(camera_id),
        str(status_id), message,
        datetime.now()
    ]
    DBConn.single_query(insert_query)
Exemple #3
0
def __insert_server_log(server_id, status_id, message):
    insert_query = Query()
    insert_query.TransactionType = eTransactionType.Insert
    insert_query.Sql = "INSERT INTO tServerLog(ServerID, ServerStatusID, ServerMessage, LogDateTime) VALUES (%s, %s, %s, %s)"
    insert_query.Args = [
        str(server_id),
        str(status_id),
        str(message),
        datetime.now()
    ]
    DBConn.single_query(insert_query)
Exemple #4
0
def insert_default_values_into_db(mac_address):
    camera = Camera()
    camera.Name = "Camera"
    camera.MacAddress = mac_address
    camera.InternalAddress = get_local_ip()
    camera.ExternalAddress = get_external_ip()
    camera.PortNumber = 8089
    camera.CameraStatusID = CameraStatus.CameraBootStart.value
    camera.DirectoryPath = ""

    insert_query = Query()
    insert_query.TransactionType = eTransactionType.Insert
    insert_query.Sql = "INSERT INTO tCameras (Name, MacAddress, InternalAddress, ExternalAddress, PortNumber, CameraStatusID, DirectoryPath) VALUES (%s, %s, %s, %s, %s, %s, %s)"
    insert_query.Args = [
        str(camera.Name),
        str(camera.MacAddress),
        str(camera.InternalAddress),
        str(camera.ExternalAddress),
        str(camera.PortNumber),
        str(camera.CameraStatusID),
        str(camera.DirectoryPath)
    ]
    camera.CameraID = DBConn.single_query(insert_query)
    __insert_camera_log(camera.CameraID, CameraStatus.CameraBootStart.value,
                        "Camera is starting.")
Exemple #5
0
def insert_default_values_into_db(mac_address):
    server = Server()
    server.Name = "Server"
    server.MacAddress = mac_address
    server.InternalAddress = get_local_ip()
    server.ExternalAddress = get_external_ip()
    server.PortNumber = 8089
    server.ServerStatusID = ServerStatus.ServerBootStart.value
    server.DirectoryPath = "/VideoSecurityServer"

    insert_query = Query()
    insert_query.TransactionType = eTransactionType.Insert
    insert_query.Sql = "INSERT INTO tServers (Name, MacAddress, InternalAddress, ExternalAddress, PortNumber, ServerStatusID, DirectoryPath) VALUES (%s,%s,%s,%s,%s,%s,%s)"
    insert_query.Args = [
        str(server.Name),
        str(server.MacAddress),
        str(server.InternalAddress),
        str(server.ExternalAddress),
        str(server.PortNumber),
        str(server.ServerStatusID),
        str(server.DirectoryPath)
    ]
    server.ServerID = DBConn.single_query(insert_query)
    __insert_server_log(server.ServerID, ServerStatus.ServerBootStart.value,
                        "Server is starting.")
Exemple #6
0
def update_startup_values_into_db(camera):
    camera.InternalAddress = get_local_ip()
    camera.ExternalAddress = get_external_ip()
    camera.CameraStatusID = CameraStatus.CameraBootStart.value

    update_query = Query()
    update_query.TransactionType = eTransactionType.Update
    update_query.Sql = "UPDATE tCameras SET InternalAddress = %s, ExternalAddress = %s, CameraStatusID = %s WHERE CameraID = %s"
    update_query.Args = [
        str(camera.InternalAddress),
        str(camera.ExternalAddress),
        str(camera.CameraStatusID),
        str(camera.CameraID)
    ]
    DBConn.single_query(update_query)
    __insert_camera_log(camera.CameraID, CameraStatus.CameraBootStart.value,
                        "Camera is starting.")
Exemple #7
0
def update_startup_values_into_db(server):
    server.InternalAddress = get_local_ip()
    server.ExternalAddress = get_external_ip()
    server.ServerStatusID = ServerStatus.ServerBootStart.value

    update_query = Query()
    update_query.TransactionType = eTransactionType.Update
    update_query.Sql = "UPDATE tServers SET InternalAddress = %s, ExternalAddress = %s, ServerStatusID = %s WHERE ServerID = %s"
    update_query.Args = [
        str(server.InternalAddress),
        str(server.ExternalAddress),
        str(server.ServerStatusID),
        str(server.ServerID)
    ]
    DBConn.single_query(update_query)
    __insert_server_log(server.ServerID, ServerStatus.ServerBootStart.value,
                        "Server is starting.")
Exemple #8
0
def get_camera_from_mac_address(mac_address):
    camera = Camera()

    query = Query()
    query.TransactionType = eTransactionType.Query
    query.Sql = sql_select + sql_from + " WHERE c.MacAddress = %s"
    query.Args = [str(mac_address)]
    result = DBConn.single_query(query)
    if len(result) > 0:
        camera.mapper(result[0])
        return camera
    else:
        return None
Exemple #9
0
def get_server_from_mac_address(mac_address):
    server = Server()

    query = Query()
    query.TransactionType = eTransactionType.Query
    query.Sql = sql_select + sql_from + " WHERE s.MacAddress = %s"
    query.Args = [str(mac_address)]
    result = DBConn.single_query(query)
    if len(result) > 0:
        server.mapper(result[0])
        return server
    else:
        return None
Exemple #10
0
def __update_current_camera_status(camera_id, status_id):
    update_query = Query()
    update_query.TransactionType = eTransactionType.Update
    update_query.Sql = "Update tCameras SET CameraStatusID = %s WHERE CameraID = %s"
    update_query.Args = [str(status_id), str(camera_id)]
    DBConn.single_query(update_query)
Exemple #11
0
def __update_current_server_status(server_id, status_id):
    update_query = Query()
    update_query.TransactionType = eTransactionType.Update
    update_query.Sql = "UPDATE tServers SET ServerStatusID = %s WHERE ServerID = %s"
    update_query.Args = [str(status_id), str(server_id)]
    DBConn.single_query(update_query)