Exemplo n.º 1
0
        /// <summary>
        /// Return the query results of all the queries
        /// </summary>
        /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
        public async Task <IList> ListAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            using (session.BeginProcess())
            {
                bool cacheable = session.Factory.Settings.IsQueryCacheEnabled && isCacheable;
                combinedParameters = CreateCombinedQueryParameters();

                if (log.IsDebugEnabled())
                {
                    log.Debug("Multi query with {0} queries.", queries.Count);
                    for (int i = 0; i < queries.Count; i++)
                    {
                        log.Debug("Query #{0}: {1}", i, queries[i]);
                    }
                }

                try
                {
                    Before();

                    var querySpaces = new HashSet <string>(Translators.SelectMany(t => t.QuerySpaces));
                    if (resultSetsCommand.HasQueries)
                    {
                        await(session.AutoFlushIfRequiredAsync(querySpaces, cancellationToken)).ConfigureAwait(false);
                    }

                    return(cacheable ? await(ListUsingQueryCacheAsync(querySpaces, cancellationToken)).ConfigureAwait(false) : await(ListIgnoreQueryCacheAsync(cancellationToken)).ConfigureAwait(false));
                }
                finally
                {
                    After();
                }
            }
        }
Exemplo n.º 2
0
        private void CheckMissingTranslation(string textId, string defaultText)
        {
            if (LogOutMissingTranslations)
            {
                bool needLogUpdate = false;

                AvailableLanguages.ToList().ForEach(languageId =>
                {
                    if (!Translators.Any(tr => tr.CanTranslate(textId, languageId)))
                    {
                        if (!MissingTranslations.ContainsKey(textId))
                        {
                            MissingTranslations.Add(textId, new SortedDictionary <string, string>());
                        }

                        MissingTranslations[textId][languageId] = $"default text : {defaultText}";

                        needLogUpdate = true;
                    }
                });

                if (needLogUpdate)
                {
                    MissingTranslationFound?.Invoke(this, new LocalizationMissingTranslationEventArgs(this, MissingTranslations, textId));
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Return the query results of all the queries
        /// </summary>
        public IList List()
        {
            using (session.BeginProcess())
            {
                bool cacheable = session.Factory.Settings.IsQueryCacheEnabled && isCacheable;
                combinedParameters = CreateCombinedQueryParameters();

                if (log.IsDebugEnabled())
                {
                    log.Debug("Multi query with {0} queries.", queries.Count);
                    for (int i = 0; i < queries.Count; i++)
                    {
                        log.Debug("Query #{0}: {1}", i, queries[i]);
                    }
                }

                try
                {
                    Before();

                    var querySpaces = new HashSet <string>(Translators.SelectMany(t => t.QuerySpaces));
                    if (resultSetsCommand.HasQueries)
                    {
                        session.AutoFlushIfRequired(querySpaces);
                    }

                    return(cacheable ? ListUsingQueryCache(querySpaces) : ListIgnoreQueryCache());
                }
                finally
                {
                    After();
                }
            }
        }
 public TranslationEngine(Subtitle subtitle, Translators api, string fromLanguage, string toLanguage, string toEmail)
 {
     _subtitle = subtitle;
     _api = api;
     _fromLanguage = fromLanguage;
     _toLanguage = toLanguage;
     _toEmail = toEmail;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Unity Update method.
        /// </summary>
        public void Update()
        {
            // Get the current Pose.
            ApiPose apiPose = AnchorApi.GetAnchorPose(
                ARCoreExtensions.Instance.CurrentARCoreSessionHandle,
                m_AnchorHandle);

            m_Pose = Translators.ToUnityPose(apiPose);

            // Update the cloud reference point transform to match.
            transform.localPosition = m_Pose.position;
            transform.localRotation = m_Pose.rotation;
        }
        /// <summary>
        /// Unity Update method.
        /// </summary>
        public void Update()
        {
            // Get the current Pose.
            ApiPose apiPose = AnchorApi.GetAnchorPose(
                ARCoreExtensions._instance.currentARCoreSessionHandle,
                _anchorHandle);

            _pose = Translators.ToUnityPose(apiPose);

            // Update the Cloud Anchor transform to match.
            transform.localPosition = _pose.position;
            transform.localRotation = _pose.rotation;
        }
Exemplo n.º 7
0
 /// <summary>
 /// Constructor
 /// </summary>
 public AssetManager()
 {
     Filters        = AppDomain.CurrentDomain.GetAssemblies().Objects <IFilter>();
     ContentFilters = AppDomain.CurrentDomain.GetAssemblies().Objects <IContentFilter>();
     Translators    = AppDomain.CurrentDomain.GetAssemblies().Objects <ITranslator>();
     FileTypes      = new ListMapping <AssetType, string>();
     RunOrder       = new System.Collections.Generic.List <RunTime>();
     Translators.ForEach(x => FileTypes.Add(x.TranslatesTo, x.FileTypeAccepts));
     FileTypes.Add(AssetType.CSS, "css");
     FileTypes.Add(AssetType.Javascript, "js");
     RunOrder.Add(RunTime.PostTranslate);
     RunOrder.Add(RunTime.PreMinified);
     RunOrder.Add(RunTime.Minify);
     RunOrder.Add(RunTime.PostMinified);
     RunOrder.Add(RunTime.PreCombine);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Translate the given textId in current language.
        /// </summary>
        /// <param name="textId">The text to translate identifier</param>
        /// <param name="defaultText">The text to return if no text correspond to textId in the current language</param>
        /// <param name="languageId">The language id in which to get the translation. To Specify if not CurrentLanguage</param>
        /// <returns>The translated text</returns>
        public string Translate(string textId, string defaultText = null, string languageId = null)
        {
            if (string.IsNullOrEmpty(defaultText))
            {
                defaultText = textId;
            }

            if (string.IsNullOrEmpty(languageId))
            {
                languageId = CurrentLanguage;
            }

            CheckMissingTranslation(textId ?? string.Empty, defaultText);

            return(Translators
                   .Find(tr => tr.CanTranslate(textId, languageId))?
                   .Translate(textId ?? string.Empty, languageId)
                   ?? defaultText ?? string.Empty);
        }
Exemplo n.º 9
0
        public async ValueTask Create(MangasContext context)
        {
            var type = await context.Types
                       .FirstAsync(t => t.Id == Type.Id);

            var tagsIds = Tags.Select(t => t.Id).ToList();

            var tags = await context.Tags
                       .Where(tag => tagsIds.Contains(tag.Id))
                       .ToListAsync();

            var translatorsIds = Translators.Select(t => t.Id).ToList();

            var translators = await context.Translators
                              .Where(translator => translatorsIds.Contains(translator.Id))
                              .ToListAsync();

            var authorsIds = Authors.Select(a => a.Id).ToList();

            var authors = await context.Authors
                          .Where(author => authorsIds.Contains(author.Id))
                          .ToListAsync();

            var manga = new Manga
            {
                Title       = Title,
                Description = Description,
                Image       = Image,
                Type        = type
            };

            await context.MangaTags
            .AddRangeAsync(tags.Select(tag => new MangaTag(tag, manga)));

            await context.MangaTranslators
            .AddRangeAsync(translators.Select(translator => new MangaTranslator(translator, manga)));

            await context.MangaAuthors
            .AddRangeAsync(authors.Select(author => new MangaAuthor(author, manga)));

            await context.Mangas.AddAsync(manga);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Translate the given textId in current language.
        /// </summary>
        /// <param name="textId">The text to translate identifier</param>
        /// <param name="defaultText">The text to return if no text correspond to textId in the current language</param>
        /// <param name="languageId">The language id in which to get the translation. To Specify if not CurrentLanguage</param>
        /// <returns>The translated text</returns>
        public string Translate(string textId, string defaultText = null, string languageId = null)
        {
            if (string.IsNullOrEmpty(textId))
            {
                throw new InvalidOperationException("The textId argument cannot be null or empty");
            }

            if (string.IsNullOrEmpty(defaultText))
            {
                defaultText = textId;
            }

            if (string.IsNullOrEmpty(languageId))
            {
                languageId = CurrentLanguage;
            }

            CheckMissingTranslation(textId, defaultText);

            return(Translators
                   .Find(tr => tr.CanTranslate(textId, languageId))?
                   .Translate(textId, languageId)
                   ?? defaultText);
        }
Exemplo n.º 11
0
        public static ITranslator GetTranslator(Translators translator)
        {
            ITranslator requestedTranslator = null;

            switch (translator)
            {
            case Translators.Google:
                if (google == null)
                {
                    google = new GoogleTranslator();
                }
                requestedTranslator = google;
                break;

            case Translators.Bing:
                if (bing == null)
                {
                    bing = new BingTranslator();
                }
                requestedTranslator = bing;
                break;

            case Translators.Yahoo:
                if (yahoo == null)
                {
                    yahoo = new YahooTranslator();
                }
                requestedTranslator = yahoo;
                break;
            }
            if (requestedTranslator == null)
            {
                throw new NotSupportedException(translator + " is not supported");
            }
            return(requestedTranslator);
        }
Exemplo n.º 12
0
 public string GetVideoRegion(ref byte[] smcconfigdata)
 {
     return(Translators.TranslateVideoRegion(string.Format("0x{0:X}{1:X2}", smcconfigdata[0x22A], smcconfigdata[0x22B])));
 }
 public void Activate(TranslatorType translatorType)
 {
     Translators.FirstOrDefault(t => t.Type == translatorType)?.Activate();
 }
Exemplo n.º 14
0
        public void Initialize()
        {
            bool started = false;

            KanColleClient.Current.Proxy.SessionSource.Where(x => !started).Subscribe(x =>
            {
                started = true;
                HttpProxy.UpstreamProxyConfig = new ProxyConfig(ProxyConfigType.SpecificProxy, "localhost", ProxyPort);
            });

            ModifyProxy.BeforeResponse = (session, data) =>
            {
                #region swf patch
                foreach (var patcher in BinaryPatchers)
                {
                    if (patcher.Patch(session, ref data))
                    {
                        return(data);
                    }
                }
                #endregion

                #region Patch HTTP requests
                try
                {
                    Func <string, string, string> getTranslation = (x, y) =>
                    {
                        if (y.Length == 0)
                        {
                            return(y);
                        }
                        var output = Translators.ContainsKey(x) ? (Translators[x]?.GetTranslation(y) ?? y) : y;
                        if (output == y)
                        {
                            System.Diagnostics.Debug.WriteLine("{0} => {1}", x, y);
                        }
                        return(output);
                    };

                    var serializeOption = new JsonSerializerSettings {
                        StringEscapeHandling = StringEscapeHandling.EscapeNonAscii
                    };
                    string  raw_content = null;
                    dynamic svdata;

                    switch (session.Request.PathAndQuery)
                    {
                        #region api_start2
                    case "/kcsapi/api_start2":
                        raw_content = Encoding.UTF8.GetString(data).Substring("svdata=".Length);
                        svdata      = JObject.Parse(raw_content);
                        {
                            // Ship names
                            foreach (var x in svdata.api_data.api_mst_ship)
                            {
                                if (x.api_name != null)
                                {
                                    x.api_name = getTranslation("ShipName", x.api_name.ToString());
                                }
                                if (x.api_getmes != null)
                                {
                                    x.api_getmes = getTranslation("ShipGetMessage", x.api_getmes.ToString());
                                }
                            }

                            // Slotitem names
                            foreach (var x in svdata.api_data.api_mst_slotitem)
                            {
                                if (x.api_name != null)
                                {
                                    x.api_name = getTranslation("EquipmentName", x.api_name.ToString());
                                }
                                if (x.api_info != null)
                                {
                                    x.api_info = getTranslation("EquipmentInfo", x.api_info.ToString());
                                }
                            }

                            // Slotitem Type names
                            foreach (var x in svdata.api_data.api_mst_slotitem_equiptype)
                            {
                                if (x.api_name != null)
                                {
                                    x.api_name = getTranslation("EquipmentType", x.api_name.ToString());
                                }
                            }
                            // Ship Type names
                            foreach (var x in svdata.api_data.api_mst_stype)
                            {
                                if (x.api_name != null)
                                {
                                    x.api_name = getTranslation("ShipType", x.api_id.ToString());
                                }
                            }

                            // Furniture names
                            foreach (var x in svdata.api_data.api_mst_furniture)
                            {
                                if (x.api_title != null)
                                {
                                    x.api_title = getTranslation("Furniture", x.api_title.ToString());
                                }
                                if (x.api_description != null)
                                {
                                    x.api_description = getTranslation("Furniture", x.api_description.ToString());
                                }
                            }

                            // Useitem names
                            foreach (var x in svdata.api_data.api_mst_useitem)
                            {
                                if (x.api_name != null)
                                {
                                    x.api_name = getTranslation("UseItem", x.api_name.ToString());
                                }
                                if (x.api_description != null)
                                {
                                    x.api_description[0] = getTranslation("UseItem", x.api_description[0].ToString());
                                }
                            }
                            // Payitem names
                            foreach (var x in svdata.api_data.api_mst_payitem)
                            {
                                if (x.api_name != null)
                                {
                                    x.api_name = getTranslation("PayItem", x.api_name.ToString());
                                }
                                if (x.api_description != null)
                                {
                                    x.api_description = getTranslation("PayItem", x.api_description.ToString());
                                }
                            }

                            // MapArea
                            foreach (var x in svdata.api_data.api_mst_maparea)
                            {
                                if (x.api_name != null)
                                {
                                    x.api_name = getTranslation("MapArea", x.api_name.ToString());
                                }
                            }

                            foreach (var x in svdata.api_data.api_mst_mapinfo)
                            {
                                if (x.api_name != null)
                                {
                                    x.api_name = getTranslation("MapArea", x.api_name.ToString());
                                }
                                if (x.api_opetext != null)
                                {
                                    x.api_opetext = getTranslation("MapArea", x.api_opetext.ToString());
                                }
                                if (x.api_infotext != null)
                                {
                                    x.api_infotext = getTranslation("MapArea", x.api_infotext.ToString());
                                }
                            }

                            // Expedition
                            foreach (var x in svdata.api_data.api_mst_mission)
                            {
                                if (x.api_name != null)
                                {
                                    x.api_name = getTranslation("Expedition", x.api_name.ToString());
                                }
                                if (x.api_details != null)
                                {
                                    x.api_details = getTranslation("Expedition", x.api_details.ToString());
                                }
                            }

                            // BGM
                            foreach (var x in svdata.api_data.api_mst_bgm)
                            {
                                if (x.api_name != null)
                                {
                                    x.api_name = getTranslation("BGM", x.api_name.ToString());
                                }
                            }
                        }
                        raw_content = JsonConvert.SerializeObject(svdata, serializeOption);
                        data        = Encoding.UTF8.GetBytes("svdata=" + raw_content);
                        break;
                        #endregion

                        #region Jukebox list request
                    case "/kcsapi/api_req_furniture/music_list":
                        raw_content = Encoding.UTF8.GetString(data).Substring("svdata=".Length);
                        svdata      = JObject.Parse(raw_content);
                        {
                            foreach (var x in svdata.api_data)
                            {
                                if (x.api_name != null)
                                {
                                    x.api_name = getTranslation("BGM", x.api_name.ToString());
                                }
                                if (x.api_description != null)
                                {
                                    x.api_description = getTranslation("BGM", x.api_description.ToString());
                                }
                            }
                        }
                        raw_content = JsonConvert.SerializeObject(svdata, serializeOption);
                        data        = Encoding.UTF8.GetBytes("svdata=" + raw_content);
                        break;
                        #endregion

                        #region Dictionary screen
                    case "/kcsapi/api_get_member/picture_book":
                        var s_type = HttpUtility.ParseQueryString(session.Request.BodyAsString)["api_type"];
                        int n_type = 1;
                        int.TryParse(s_type, out n_type);

                        raw_content = Encoding.UTF8.GetString(data).Substring("svdata=".Length);
                        svdata      = JObject.Parse(raw_content);
                        {
                            foreach (var x in svdata.api_data.api_list)
                            {
                                if (n_type == 1)                                         // Ship
                                {
                                    if (x.api_name != null)
                                    {
                                        x.api_name = getTranslation("ShipName", x.api_name.ToString());
                                    }
                                    if (x.api_sinfo != null)
                                    {
                                        x.api_sinfo = getTranslation("ShipLibraryText", x.api_index_no.ToString());
                                    }
                                }
                                else if (n_type == 2)                                         // Equipment
                                {
                                    if (x.api_name != null)
                                    {
                                        x.api_name = getTranslation("EquipmentName", x.api_name.ToString());
                                    }
                                    if (x.api_info != null)
                                    {
                                        x.api_info = getTranslation("EquipmentInfo", x.api_info.ToString());
                                    }
                                }
                            }
                        }
                        raw_content = JsonConvert.SerializeObject(svdata, serializeOption);
                        data        = Encoding.UTF8.GetBytes("svdata=" + raw_content);
                        break;
                        #endregion

                        #region Quest page
                    case "/kcsapi/api_get_member/questlist":
                        raw_content = Encoding.UTF8.GetString(data).Substring("svdata=".Length);
                        svdata      = JObject.Parse(raw_content);
                        {
                            foreach (var x in svdata.api_data.api_list)
                            {
                                if (x.GetType() == typeof(JValue))
                                {
                                    continue;
                                }

                                var id     = x.api_no.ToString();
                                var output = QuestTranslator.Instance.GetTranslation("Name" + id);
                                if (output != null)
                                {
                                    x.api_title  = QuestTranslator.Instance.GetTranslation("Name" + id);
                                    x.api_detail = QuestTranslator.Instance.GetTranslation("Detail" + id);
                                }
                            }
                        }
                        raw_content = JsonConvert.SerializeObject(svdata, serializeOption);
                        data        = Encoding.UTF8.GetBytes("svdata=" + raw_content);
                        break;
                        #endregion
                    }
                }
                catch { }
                #endregion

                return(data);                // Encoding.UTF8.GetBytes(sv_data);
            };

            string ver = Common.CheckUpdate();
            if (ver != null && ver.Length > 0)
            {
                var message = string.Format("-= Z-Translation =-\n\nNew version {0} has released.\n\nOK: Open Update Webpage\nCancel: Dismiss", ver);
                var output  = System.Windows.MessageBox.Show(message, "Z-Translation", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Information);

                if (output == System.Windows.MessageBoxResult.OK)
                {
                    System.Diagnostics.Process.Start(Common.UpdateWebpage);
                }
            }

            // Disable auto-translations
            KanColleSettings.EnableTranslations.Value = false;
            KanColleClient.Current.Translations.EnableTranslations = false;

            // Prepare Translator, Binary Patcher
            PrepareTranslators();
            PrepareBinaryPatchers();

            // Start LocalProxy
            var Server = new SafeTcpServer(ProxyPort, false);
            Server.Start(ModifyProxy.CreateProxy);

            Server.InitListenFinished.WaitOne();
            if (Server.InitListenException != null)
            {
                throw Server.InitListenException;
            }

            Grabacr07.KanColleViewer.Application.Current.Exit += (s, e) =>
            {
                Server.Shutdown();
                new Thread(() =>
                {
                    try
                    {
                        Thread.Sleep(3000);
                        Environment.Exit(0);
                    }
                    catch { }
                }).Start();
            };
        }
Exemplo n.º 15
0
 public JsExpression TryTranslateCall(HalfTranslatedExpression context, HalfTranslatedExpression[] arguments, MethodInfo method) =>
 Translators.Select(t => t.TryTranslateCall(context, arguments, method)).FirstOrDefault(d => d != null);
Exemplo n.º 16
0
 public JavascriptTranslatorConfiguration()
 {
     Translators.Add(MethodCollection = new JavascriptTranslatableMethodCollection());
 }
 public void AddTranslator(TranslatorType translatorType)
 {
     Translators.Add(new Translator(translatorType.ToString(), translatorType));
 }
 public void PassivateAll()
 {
     Translators.ForEach(t => t.Passivate());
 }
Exemplo n.º 19
0
 public string GetGameRegion(ref byte[] keyvaultdata, bool includebytes = false)
 {
     return(Translators.TranslateGameRegion(string.Format("0x{0:X2}{1:X2}", keyvaultdata[0xC8], keyvaultdata[0xC9]), includebytes));
 }
Exemplo n.º 20
0
 public string GetDVDRegion(ref byte[] smcconfigdata)
 {
     return(Translators.TranslateDVDRegion(smcconfigdata[0x237].ToString(CultureInfo.InvariantCulture)));
 }
        private static void TranslateLine(List <string> xxxx, string lineNumber)
        {
            string translated = null;
            bool   isGekko18  = false;

            if (G.equal(Program.options.interface_mode, "sim"))
            {
                translated = Translators.Translate1(false, xxxx);
                isGekko18  = true;
            }
            else
            {
                translated = Translator2.Translate2(false, xxxx);
            }

            List <string> translatedLines = G.RemoveEmptyLines(G.ExtractLinesFromText(translated));

            string before = G.ExtractTextFromLines(xxxx).ToString();
            string after  = G.ExtractTextFromLines(translatedLines).ToString();

            after  = after.Replace(Globals.restartSnippet, "");
            before = before.Replace(" ", "");
            after  = after.Replace(" ", "");
            before = before.Replace("\r\n", "");
            after  = after.Replace("\r\n", "");
            if (before.EndsWith(";"))
            {
                before = before.Substring(0, before.Length - 1);
            }
            if (after.EndsWith(";"))
            {
                after = after.Substring(0, after.Length - 1);
            }
            before = before.ToLower().Trim();
            after  = after.ToLower().Trim();

            if (before == "" || after == "")
            {
                //do nothing
            }
            else
            {
                if (before == after)
                {
                    //do nothing
                }
                else
                {
                    if (isGekko18)
                    {
                        G.Writeln2("    Suggestion (translating from Gekko 1.8 syntax):");
                    }
                    else
                    {
                        G.Writeln2("    Suggestion (translating from AREMOS syntax):");
                    }
                    foreach (string s12 in translatedLines)
                    {
                        if (s12.Trim() == Globals.restartSnippet)
                        {
                            continue;                                       //skip that here, only good for files
                        }
                        G.Writeln("    --> " + lineNumber + " " + s12, Color.Blue);
                    }
                    G.Writeln();
                }
            }
        }
Exemplo n.º 22
0
        public void Run()
        {
            string        log            = String.Empty;
            ReplaceString replaceString  = new ReplaceString();
            DirectoryInfo dir            = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent;
            string        dirPath        = dir.FullName;
            string        templateReport = System.IO.Path.Combine(dirPath, @"Json\Province.json");

            using (StreamReader r = new StreamReader(templateReport))
            {
                string          json  = r.ReadToEnd();
                List <Province> items = JsonConvert.DeserializeObject <List <Province> >(json);
                foreach (var item in items)
                {
                    using (var context = new quickbeedev1Context())
                    {
                        var provine = (from p in context.Provinces
                                       select new
                        {
                            Id = p.Id,
                            Name = replaceString.Replace(p.Name, "PROVINCE")
                        }).ToList();

                        var provinceObj = provine.Where(x => x.Name == replaceString.Replace(item.PROVINCE_NAME, "PROVINCE")).FirstOrDefault();

                        if (provinceObj != null)
                        {
                            var translators = new Translators()
                            {
                                DataKey         = "VTP.PROVINCE",
                                OriginalValue   = Convert.ToString(provinceObj.Id),
                                TranslatedValue = Convert.ToString(item.PROVINCE_ID)
                            };
                            var provineExists = context.Translators.Where(x => x.DataKey == translators.DataKey &&
                                                                          x.OriginalValue == translators.OriginalValue && x.TranslatedValue == translators.TranslatedValue);
                            if (provineExists.Count() == 0)
                            {
                                context.Translators.Add(translators);
                                context.SaveChanges();
                                log += provinceObj.Name + "-" + item.PROVINCE_NAME + "\n";
                            }
                        }
                        else
                        {
                            string a        = replaceString.Replace(item.PROVINCE_NAME, "PROVINCE");
                            var    province = new Provinces()
                            {
                                Name         = item.PROVINCE_NAME,
                                ProvinceType = "Tỉnh",
                                CountryId    = 256
                            };
                            context.Provinces.Add(province);
                            context.SaveChanges();
                            var translators = new Translators()
                            {
                                DataKey         = "VTP.PROVINCE",
                                OriginalValue   = Convert.ToString(province.Id),
                                TranslatedValue = Convert.ToString(item.PROVINCE_ID)
                            };
                            context.Translators.Add(translators);
                            context.SaveChanges();
                            log += provinceObj.Name + "-" + item.PROVINCE_NAME + "\n";
                        }
                    }
                }
                Console.WriteLine(log);
            }
        }
Exemplo n.º 23
0
        public void Run()
        {
            string        log            = String.Empty;
            ReplaceString replaceString  = new ReplaceString();
            DirectoryInfo dir            = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent;
            string        dirPath        = dir.FullName;
            string        templateReport = System.IO.Path.Combine(dirPath, @"Json\District.json");

            using (StreamReader r = new StreamReader(templateReport))
            {
                string          json  = r.ReadToEnd();
                List <District> items = JsonConvert.DeserializeObject <List <District> >(json);
                using (var context = new quickbeedev1Context())
                {
                    var translator = context.Translators.Where(x => x.DataKey == "VTP.PROVINCE").ToList();
                    foreach (var i in translator)
                    {
                        int?   provinceOriginalId = Convert.ToInt32(i.OriginalValue);
                        string provinceJsId       = i.TranslatedValue;
                        //List DistrictJS
                        var districtJsList       = items.Where(x => x.PROVINCE_ID == provinceJsId);
                        var districtOriginalList = (from d in context.Districts.Where(x => x.ProvinceId == provinceOriginalId)
                                                    select new
                        {
                            Id = d.Id,
                            Name = replaceString.Replace(d.Name, "DISTRICT")
                        }).ToList();

                        foreach (var itemD in districtJsList)
                        {
                            var districtOriginalObj = districtOriginalList.Where(x => x.Name == replaceString.Replace(itemD.DISTRICT_NAME, "DISTRICT")).FirstOrDefault();
                            if (districtOriginalObj != null)
                            {
                                var translators = new Translators()
                                {
                                    DataKey         = "VTP.DISTRICT",
                                    OriginalValue   = Convert.ToString(districtOriginalObj.Id),
                                    TranslatedValue = Convert.ToString(itemD.DISTRICT_ID)
                                };
                                var districtExists = context.Translators.Where(x => x.DataKey == translators.DataKey &&
                                                                               x.TranslatedValue == translators.TranslatedValue);
                                if (districtExists.Count() == 0)
                                {
                                    context.Translators.Add(translators);
                                    context.SaveChanges();
                                    log += districtOriginalObj.Name + "-" + itemD.DISTRICT_NAME + "\n";
                                }
                            }
                            else
                            {
                                var districtNew = new Districts()
                                {
                                    Name       = replaceString.ConverToUpper(itemD.DISTRICT_NAME),
                                    ProvinceId = provinceOriginalId ?? 0
                                };

                                context.Districts.Add(districtNew);
                                context.SaveChanges();
                                var translators = new Translators()
                                {
                                    DataKey         = "VTP.DISTRICT",
                                    OriginalValue   = Convert.ToString(districtNew.Id),
                                    TranslatedValue = provinceJsId
                                };
                                context.Translators.Add(translators);
                                context.SaveChanges();
                                log += itemD.DISTRICT_NAME + "\n";
                            }
                        }
                    }
                    Console.WriteLine(log);
                }
            }
        }
        public async ValueTask Update(MangasContext context, int mangaId)
        {
            var manga = await context.Mangas
                        .Include(m => m.Tags)
                        .Include(m => m.Translators)
                        .Include(m => m.Authors)
                        .FirstAsync(m => m.Id == mangaId);

            if (Title != null)
            {
                manga.Title = Title;
            }

            if (Description != null)
            {
                manga.Description = Description;
            }

            if (Type != null)
            {
                var type = await context.Types.FirstAsync(t => t.Id == Type.Id);

                manga.Type = type;
            }

            if (Tags != null)
            {
                var modelTagIds = Tags.Select(t => t.Id).ToList();
                var mangaTagIds = manga.Tags.Select(t => t.Tag.Id).ToList();

                var mangaTagsToRemove = mangaTagIds.Except(modelTagIds)
                                        .Select(tagId => manga.Tags.First(t => t.Tag.Id == tagId))
                                        .ToList();

                var mangaTagsToAdd = modelTagIds.Except(mangaTagIds)
                                     .Select(tagId => context.Tags.First(t => t.Id == tagId))
                                     .Select(tag => new MangaTag(tag, manga))
                                     .ToList();

                context.MangaTags.RemoveRange(mangaTagsToRemove);
                await context.MangaTags.AddRangeAsync(mangaTagsToAdd);
            }

            if (Translators != null)
            {
                var modelTranslatorIds = Translators.Select(t => t.Id).ToList();
                var mangaTranslatorIds = manga.Translators.Select(t => t.Translator.Id).ToList();

                var mangaTranslatorsToRemove = mangaTranslatorIds.Except(modelTranslatorIds)
                                               .Select(translatorId => manga.Translators.First(t => t.Translator.Id == translatorId))
                                               .ToList();

                var mangaTranslatorsToAdd = modelTranslatorIds.Except(mangaTranslatorIds)
                                            .Select(translatorId => context.Translators.First(t => t.Id == translatorId))
                                            .Select(translator => new MangaTranslator(translator, manga))
                                            .ToList();

                context.MangaTranslators.RemoveRange(mangaTranslatorsToRemove);
                await context.MangaTranslators.AddRangeAsync(mangaTranslatorsToAdd);
            }

            if (Authors != null)
            {
                var modelAuthorIds = Authors.Select(t => t.Id).ToList();
                var mangaAuthorIds = manga.Authors.Select(t => t.Author.Id).ToList();

                var mangaAuthorsToRemove = mangaAuthorIds.Except(modelAuthorIds)
                                           .Select(authorId => manga.Authors.First(t => t.Author.Id == authorId))
                                           .ToList();

                var mangaAuthorsToAdd = modelAuthorIds.Except(mangaAuthorIds)
                                        .Select(authorId => context.Authors.First(t => t.Id == authorId))
                                        .Select(author => new MangaAuthor(author, manga))
                                        .ToList();

                context.MangaAuthors.RemoveRange(mangaAuthorsToRemove);
                await context.MangaAuthors.AddRangeAsync(mangaAuthorsToAdd);
            }
        }
Exemplo n.º 25
0
 public string GetGameRegion(ref byte[] smcconfigdata, bool includebytes = false)
 {
     return(Translators.TranslateGameRegion(string.Format("0x{0:X2}{1:X2}", smcconfigdata[0x22C], smcconfigdata[0x22D]), includebytes));
 }