Ejemplo n.º 1
0
    private bool ReadJson()
    {
        try
        {
            // Read the text from the sidecar file
            using StreamReader streamReader = SidecarFileInfo.OpenText();
            string json = streamReader.ReadToEnd();
            streamReader.Close();

            // Create object from text
            SidecarJson = SidecarFileJsonSchema.FromJson(json);
        }
        catch (Exception e) when(Log.Logger.LogAndHandle(e, MethodBase.GetCurrentMethod()?.Name))
        {
            return(false);
        }

        // Compare the schema version
        if (SidecarJson.SchemaVersion != SidecarFileJsonSchema.CurrentSchemaVersion)
        {
            Log.Logger.Warning("Sidecar JSON schema mismatch : {JsonSchemaVersion} != {CurrentSchemaVersion}, {FileName}",
                               SidecarJson.SchemaVersion,
                               SidecarFileJsonSchema.CurrentSchemaVersion,
                               SidecarFileInfo.Name);

            // Upgrade schema
            if (!SidecarFileJsonSchema.Upgrade(SidecarJson))
            {
                return(false);
            }
        }

        return(true);
    }
Ejemplo n.º 2
0
    public bool Delete()
    {
        try
        {
            if (SidecarFileInfo.Exists)
            {
                SidecarFileInfo.Delete();
            }
        }
        catch (Exception e) when(Log.Logger.LogAndHandle(e, MethodBase.GetCurrentMethod()?.Name))
        {
            return(false);
        }

        // Reset
        SidecarJson   = null;
        State         = States.None;
        FfProbeInfo   = null;
        MkvMergeInfo  = null;
        MediaInfoInfo = null;

        Log.Logger.Information("Sidecar deleted : {FileName}", SidecarFileInfo.Name);

        return(true);
    }
Ejemplo n.º 3
0
    private bool WriteJson()
    {
        try
        {
            // Get json text from object
            string json = SidecarFileJsonSchema.ToJson(SidecarJson);

            // Write the text to the sidecar file
            using StreamWriter streamWriter = SidecarFileInfo.CreateText();
            streamWriter.Write(json);
            streamWriter.Flush();
            streamWriter.Close();
        }
        catch (Exception e) when(Log.Logger.LogAndHandle(e, MethodBase.GetCurrentMethod()?.Name))
        {
            return(false);
        }
        return(true);
    }