Ejemplo n.º 1
0
        internal static int GetLastEntryID(string tbID, out List <string> tbLanguages, out int tbSize)
        {
            CheckLogin();
            string response;
            string postData;

            tbLanguages = new List <string>();
            tbSize      = 0;

            response = JsonComm.SendRequest(null, false, "/tbs/" + tbID + "?authToken=" + AccessToken);
            TBListResponse tblr = new JavaScriptSerializer().Deserialize <TBListResponse>(response);

            if (tblr.Languages.Count < 2)
            {
                return(0);
            }

            tbLanguages.AddRange(tblr.Languages);
            tbSize = tblr.NumEntries;
            string lang = tblr.Languages[0];

            ResourcesAPI_TBEntry.TermItem tbeTerm = new ResourcesAPI_TBEntry.TermItem();
            tbeTerm.Text = "Naezttaláldkitenagyokos";
            ResourcesAPI_TBEntry.Language tbeLang = new ResourcesAPI_TBEntry.Language();
            tbeLang.language  = lang;
            tbeLang.TermItems = new List <ResourcesAPI_TBEntry.TermItem>();
            tbeLang.TermItems.Add(tbeTerm);

            TBEntry te = new TBEntry();

            te.Created   = DateTime.Now.ToString();
            te.Creator   = ConfigurationManager.AppSettings["userLogin"].ToString();
            te.Languages = new List <ResourcesAPI_TBEntry.Language>();
            te.Languages.Add(tbeLang);

            postData = new JavaScriptSerializer().Serialize(te);
            int entryID = 0;

            try
            {
                response = JsonComm.SendRequest(Encoding.UTF8.GetBytes(postData), true, "/tbs/" + tbID + "/entries/create?authToken=" + AccessToken);
                string lastLocation = JsonComm.lastLocation;
                entryID  = Convert.ToInt32(lastLocation.Substring(lastLocation.LastIndexOf('/') + 1));
                response = JsonComm.SendRequest(null, true, "/tbs/" + tbID + "/entries/" + entryID.ToString() + "/delete?authToken=" + AccessToken);
                lastTest = DateTime.Now;
            }
            catch (Exception ex)
            {
                if (ex.Message == "The remote server returned an error: (404) Not Found.")
                {
                    Log.AddLog("The term base is probably open for editing in memoQ. Close it first.", true);
                }
                throw new Exception(ex.Message);
            }

            return(entryID - 1);

            //TBLookupRequest tbLookupRequest = new TBLookupRequest();
            //tbLookupRequest.SourceLanguage = lang;
            //tbLookupRequest.TargetLanguage = tblr.Languages[1];
            //string segment = "<seg>Naezttaláldkitenagyokos</seg>";
            //tbLookupRequest.Segments.Add(segment);
            //postData = new JavaScriptSerializer().Serialize(tbLookupRequest);
            //response = JsonComm.SendRequest(Encoding.UTF8.GetBytes(postData), true, "/tbs/" + tbID + "/lookupterms?authToken=" + AccessToken);

            //TBLookupResponse tblur = new JavaScriptSerializer().Deserialize<TBLookupResponse>(response);

            //var hits = tblur.Result[0].TBHits[0];


            //foreach (var hit in hits)
            //{
            //    entryID = hit.Entry.Id;
            //    try
            //    {

            //        lastTest = DateTime.Now;
            //    }
            //    catch (Exception ex)
            //    {
            //        Log.AddLog("The last term checker expression could not be deleted. " + ex.Message, true);
            //    }
            //}
        }
Ejemplo n.º 2
0
        private bool CheckEntry(ref TBEntry tbEntry)
        {
            bool result = false;

            foreach (string tbLang in tbLanguages)
            {
                bool isLangInEntry = false;
                ResourcesAPI_TBEntry.Language entryLangMatching = new ResourcesAPI_TBEntry.Language();

                foreach (ResourcesAPI_TBEntry.Language entryLang in tbEntry.Languages)
                {
                    if (entryLang.language == tbLang)
                    {
                        isLangInEntry     = true;
                        entryLangMatching = entryLang;
                        break;
                    }
                }

                if (isLangInEntry)
                {
                    if (entryLangMatching.TermItems == null)
                    {
                        entryLangMatching.TermItems = new List <TermItem>();
                    }

                    if (entryLangMatching.TermItems.Count == 0)
                    {
                        TermItem tbeTerm = getSubstTermItem();
                        entryLangMatching.TermItems.Add(tbeTerm);
                        missingTerms[tbLang]++;
                        RAPI_Session.UpdateTBEntry(tbID.ToString(), tbEntry.Id, tbEntry);  // This line is to work around the bug that we cannot add multiple terms
                        RAPI_Session.getTBEntry(tbID.ToString(), tbEntry.Id, out tbEntry); // This line is to work around the bug that we cannot add multiple terms
                        result = true;
                    }
                    else if (entryLangMatching.TermItems.Count == 1)
                    {
                        if (entryLangMatching.TermItems[0].Text == searchText)
                        {
                            entryLangMatching.TermItems[0].Text = substText;
                            missingTerms[tbLang]++;
                            result = true;
                        }
                    }
                }
                else
                {
                    ResourcesAPI_TBEntry.Language tbeLang = new ResourcesAPI_TBEntry.Language();
                    tbeLang.language  = tbLang;
                    tbeLang.Id        = -1;
                    tbeLang.TermItems = new List <TermItem>();
                    TermItem tbeTerm = getSubstTermItem();
                    tbeLang.TermItems.Add(tbeTerm);
                    tbEntry.Languages.Add(tbeLang);
                    missingTerms[tbLang]++;
                    RAPI_Session.UpdateTBEntry(tbID.ToString(), tbEntry.Id, tbEntry);  // This line is to work around the bug that we cannot add multiple terms
                    RAPI_Session.getTBEntry(tbID.ToString(), tbEntry.Id, out tbEntry); // This line is to work around the bug that we cannot add multiple terms

                    result = true;
                }
            }

            return(result);
        }