private void RemoveMessage(DatumId datumId)
        {
            var callbackId = _idIndex.GetCallbackIdFromDatumId(datumId);
            var messageId  = _idIndex.GetMessageIdFromCallbackId(callbackId);

            Methods.deleteMessage(_chatId, messageId);
            _idIndex.RemoveMessageByCallbackId(callbackId);
        }
        private void MarkDatumDone(DatumId datumId)
        {
            var matchingData = IncompleteData().Where(d => d.DatumId.Equals(datumId)).ToList();

            foreach (var datum in matchingData)
            {
                _dataOutput.HandleDatumDone(datum);
            }
            RemoveMessage(datumId);
            PostMessages();
        }
        public void AddDatumId(DatumId datumId)
        {
            var datumStr = datumId.ToString();

            if (_datumIdToCallbackId.ContainsKey(datumStr) || _callbackIdToDatumId.ContainsValue(datumStr))
            {
                return;
            }
            var callbackId = _nextCallbackId++;

            _callbackIdToDatumId.Add(callbackId, datumStr);
            _datumIdToCallbackId.Add(datumStr, callbackId);
        }
        private void MarkDatum(DatumId datumId, string option)
        {
            var matchingData = IncompleteData().Where(d => d.DatumId.Equals(datumId)).ToList();

            foreach (var datum in matchingData)
            {
                _dataOutput.HandleDatum(datum, option);
                if (_canSelectMultipleOptions)
                {
                    UpdateKeyboard(_idIndex.GetCallbackIdFromDatumId(datumId));
                }
                else
                {
                    _dataOutput.HandleDatumDone(datum);
                    RemoveMessage(datumId);
                }
            }
            PostMessages();
        }
Пример #5
0
        public static FileDatum FromFile(string fileName)
        {
            var ext     = Path.GetExtension(fileName).ToLower();
            var datumId = new DatumId(Path.GetFileName(fileName));

            switch (ext)
            {
            case ".txt":
                return(new TextFileDatum(datumId, fileName));

            case ".png":
            case ".jpg":
            case ".jpeg":
                return(new ImageDatum(datumId, fileName));

            case ".mp4":
            case ".gif":
                return(new AnimationDatum(datumId, fileName));

            default:
                return(new DocumentDatum(datumId, fileName));
            }
        }
Пример #6
0
 public JsonDatum(DatumId datumId, JObject jsonData) : base(datumId)
 {
     _jsonData = jsonData;
 }
        public bool DatumIdHasMessage(DatumId datumId)
        {
            var callbackId = _datumIdToCallbackId[datumId.ToString()];

            return(_callbackIdToMessageId.ContainsKey(callbackId));
        }
 public int GetCallbackIdFromDatumId(DatumId datumId)
 {
     return(_datumIdToCallbackId[datumId.ToString()]);
 }
Пример #9
0
 public static Datum FromJson(DatumId datumId, JObject jsonData, string textKey)
 {
     return(new JsonTextDatum(datumId, jsonData, textKey));
 }
Пример #10
0
 public static JsonDatum FromJson(DatumId datumId, JObject jsonData)
 {
     return(new JsonDatum(datumId, jsonData));
 }
Пример #11
0
 internal JArray GetOptionsList(JObject dataFile, DatumId datumId)
 {
     return((JArray)dataFile[datumId.ToString()]?[_tagsKey]);
 }
Пример #12
0
 protected FileDatum(DatumId datumId, string fileName) : base(datumId)
 {
     FileName = fileName;
 }
Пример #13
0
 public JsonDataOutputException(DatumId datumId, string message)
     : base($"Fault in JSON data output with Datum ID: \"{datumId}\". Fault: {message}")
 {
 }
Пример #14
0
 public DocumentDatum(DatumId datumId, string documentPath)
     : base(datumId, documentPath)
 {
 }
Пример #15
0
 public AnimationDatum(DatumId datumId, string documentPath) : base(datumId, documentPath)
 {
 }
Пример #16
0
 public ImageDatum(DatumId datumId, string imagePath) : base(datumId, imagePath)
 {
 }
Пример #17
0
 public TextFileDatum(DatumId datumId, string fileName) : base(datumId, fileName)
 {
     _text = File.ReadAllText(fileName);
 }
Пример #18
0
            internal JObject SetupDatumEntry(DatumId datumId)
            {
                var     dataFile = ParseJsonFile();
                JObject datumEntry;

                try
                {
                    datumEntry = (JObject)dataFile[datumId.ToString()];
                }
                catch (InvalidCastException)
                {
                    throw new JsonDataOutputException(
                              datumId,
                              "Failure to parse data entry, datum ID already points to a non-object value in the output file."
                              );
                }

                if (datumEntry == null)
                {
                    datumEntry = new JObject();
                    dataFile[datumId.ToString()] = datumEntry;
                }

                JArray sessionsDoneList;

                try
                {
                    sessionsDoneList = (JArray)datumEntry[SessionsDoneKey];
                }
                catch (InvalidCastException)
                {
                    throw new JsonDataOutputException(
                              datumId,
                              $"Failure to parse data entry, datum ID already has a \"{SessionsDoneKey}\" key " +
                              "(the key the bot intends to use to store which enrichment sessions are completed) " +
                              "pointing to a non-array value in the output file."
                              );
                }

                if (sessionsDoneList == null)
                {
                    sessionsDoneList            = new JArray();
                    datumEntry[SessionsDoneKey] = sessionsDoneList;
                }

                JArray tagList;

                try
                {
                    tagList = (JArray)datumEntry[_tagsKey];
                }
                catch (InvalidCastException)
                {
                    throw new JsonDataOutputException(
                              datumId,
                              $"Failure to parse data entry, datum ID already has a \"{_tagsKey}\" key " +
                              "(the key the bot intends to use to store the output of this enrichment session) " +
                              "pointing to a non-array value in the output file."
                              );
                }

                if (tagList == null)
                {
                    tagList = new JArray();
                    datumEntry[_tagsKey] = tagList;
                }

                return(dataFile);
            }
Пример #19
0
 public JsonTextDatum(DatumId datumId, JObject jsonData, string textPath) : base(datumId, jsonData)
 {
     _text = jsonData.SelectToken(textPath)?.ToString();
 }
Пример #20
0
 internal JArray GetSessionsCompletedList(JObject dataFile, DatumId datumId)
 {
     return((JArray)dataFile[datumId.ToString()]?[SessionsDoneKey]);
 }
Пример #21
0
        public readonly DatumId DatumId;  // This wants to be an external unique ID

        protected Datum(DatumId datumId)
        {
            DatumId = datumId;
        }