public void UpdateTranslation(TranslationModel translation) { using (AppTourEntities data = new AppTourEntities()) { try { TRANSLATIONS edited = data.TRANSLATIONS.Single(x => translation.Id == x.ID); if (edited != null) { edited.TABLE_NAME = translation.TableName; edited.FIELD_NAME = translation.FieldName; edited.VALUE = translation.Value; edited.LANGUAGE = data.LANGUAGE.Single(x => x.ID.Equals(translation.Language.Id)); edited.FOREIGN_ID = translation.ForeignId; data.SaveChanges(); } } catch (Exception e) { if (e.InnerException != null) { throw new Exception(e.InnerException.Message); } throw; } } }
public WebService() { var xmlSerializer = new XmlSerializer(typeof(TRANSLATIONS)); using (Stream reader = new FileStream(Server.MapPath("~/App_Data/Intelligent_translator.xml"), FileMode.Open)) { _translations = (TRANSLATIONS)xmlSerializer.Deserialize(reader); } }
public Guid InsertTranslation(TranslationModel translation) { if (translation == null) { throw new ArgumentNullException("translation"); } using (AppTourEntities data = new AppTourEntities()) { try { TRANSLATIONS novo = new TRANSLATIONS { ID = translation.Id == null || translation.Id == Guid.Empty ? Guid.NewGuid() : translation.Id, LANGUAGE = data.LANGUAGE.Single(x => x.ID.Equals(translation.Language.Id)), TABLE_NAME = translation.TableName, FIELD_NAME = translation.FieldName, FOREIGN_ID = translation.ForeignId, VALUE = translation.Value }; data.TRANSLATIONS.AddObject(novo); data.SaveChanges(); return(novo.ID); } catch (UpdateException upd) { throw new UpdateException(upd.InnerException.Message); } catch (Exception e) { if (e.InnerException != null) { throw new ApplicationException(e.InnerException.Message); } throw; } } }
protected override void OnCreate(Bundle savedInstanceState) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(savedInstanceState); TRANSLATIONS translations = null; XmlSerializer serializer = new XmlSerializer(typeof(TRANSLATIONS)); using (StreamReader streamReader = new StreamReader(Assets.Open("Intelligent_translator.xml"))) { translations = (TRANSLATIONS)serializer.Deserialize(streamReader); } Bootstrapper.InitWordsProviderService(translations); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); LoadApplication(new App()); }
public static void InitWordsProviderService(TRANSLATIONS translations) { Dictionary <string, Word> dict = new Dictionary <string, Word>(); var records = translations.RECORD; foreach (var r in records) { var item = new Word { Language = r.culture, Text = r.word }; item.Links = new List <Word>(); foreach (var l in r.LINK) { item.Links.Add(new Word { Text = l.word, Language = l.culture }); } dict.Add(item.Text.ToLowerInvariant(), item); } SimpleIoc.Default.Register <WordsProviderService>(() => new WordsProviderService(dict)); }
public bool DeleteTranslation(TranslationModel translation) { if (translation == null) { throw new ArgumentNullException("translation"); } using (AppTourEntities data = new AppTourEntities()) { try { TRANSLATIONS actual = data.TRANSLATIONS.Single(x => x.ID == translation.Id); if (actual != null) { data.TRANSLATIONS.DeleteObject(actual); data.SaveChanges(); return(true); } return(false); } catch (UpdateException upd) { throw new UpdateException(upd.InnerException.Message); } catch (Exception e) { if (e.InnerException != null) { throw new ApplicationException(e.InnerException.Message); } throw; } } }