public TaxonRepository(CactusGuruEntities context, TranslatorBase <Taxon, tblTaxon> translator)
 {
     ArgumentChecker.CheckNull(context);
     ArgumentChecker.CheckNull(translator);
     _context    = context;
     _translator = translator;
 }
 public SupplierRepository(CactusGuruEntities context, TranslatorBase <Supplier, tblSupplier> translator)
 {
     ArgumentChecker.CheckNull(context);
     ArgumentChecker.CheckNull(translator);
     _context    = context;
     _translator = translator;
 }
Beispiel #3
0
        private static bool PrintAvailableTranslation(string[] plugins)
        {
            bool is_translator = false;

            foreach (string s in plugins)
            {
                Assembly asm = null;
                try
                {
                    asm = Assembly.LoadFrom($"../../../Plugins/{s}.dll");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }

                var pluginTypes = from t in asm.GetTypes()
                                  where t.IsClass && (t.BaseType == typeof(TranslatorBase))
                                  select t;

                foreach (Type t in pluginTypes)
                {
                    is_translator = true;
                    TranslatorBase obj = (TranslatorBase)Activator.CreateInstance(t);
                    Console.Write(obj?.Translate());

                    var lang_attr = t.GetCustomAttribute(typeof(LanguageAttribute)) as LanguageAttribute;
                    Console.WriteLine(lang_attr == null ? $" (n/a)" : $" ({lang_attr.Language})");
                }
            }
            return(is_translator);
        }
Beispiel #4
0
        public IPhpValue TranslateToPhp(IExternalTranslationContext ctx, ClassFieldAccessExpression src)
        {
            var s = TranslatorBase.GetCompareName(src.Member);

            if (cache == null)
            {
                cache = new Dictionary <string, IPhpValue>()
                {
                    { "System.String::Empty", new PhpConstValue("") },
                    { "System.Math::PI", new PhpDefinedConstExpression("M_PI", null) },
                    { "System.Math::E", new PhpDefinedConstExpression("M_E", null) },
                    { "System.Int32::MaxValue", new PhpConstValue(int.MaxValue) },
                }
            }
            ;

            // Math.E
            IPhpValue o;

            if (cache.TryGetValue(s, out o))
            {
                return(o);
            }
            return(null);
        }

                #endregion Methods 

                #region Fields 

        Dictionary <string, IPhpValue> cache;

                #endregion Fields 
    }
 public GenusRepository(CactusGuruEntities context, TranslatorBase <Genus, tblGenus> translator)
 {
     ArgumentChecker.CheckNull(context);
     ArgumentChecker.CheckNull(translator);
     _context    = context;
     _translator = translator;
 }
Beispiel #6
0
        public static Expression Build(Expression expression, Expression provider, TranslatorBase translator)
        {
            var executor = Expression.Constant(translator.InternalContext.Database);
            var builder  = new ExecutionBuilder()
            {
                executor = executor, translator = translator
            };

            return(builder.Bind(expression));
        }
 public CollectionItemTranslator(
     TranslatorBase <Collector, tblCollector> collectorTranslator,
     TranslatorBase <Supplier, tblSupplier> supplierTranslator,
     TranslatorBase <Taxon, tblTaxon> taxonTranslator)
 {
     ArgumentChecker.CheckNull(collectorTranslator);
     ArgumentChecker.CheckNull(supplierTranslator);
     ArgumentChecker.CheckNull(taxonTranslator);
     _collectorTranslator = collectorTranslator;
     _supplierTranslator  = supplierTranslator;
     _taxonTranslator     = taxonTranslator;
 }
Beispiel #8
0
        public IPhpValue TranslateToPhp(IExternalTranslationContext ctx, CsharpInstancePropertyAccessExpression src)
        {
            this.ctx = ctx;
            this.src = src;
            var t = TranslatorBase.GetGenericTypeDefinition(src.Member.DeclaringType);

            if (t == typeof(KeyValuePair <,>))
            {
                return(_KeyValuePair());
            }
            if (t == typeof(Nullable <>))
            {
                return(_Nullable());
            }
            if (t == typeof(Array))
            {
                return(_Array());
            }
            return(null);
        }
Beispiel #9
0
        internal void TranslateStrings(TranslatorBase translator)
        {
            try
            {
                var sourceString = string.Format(_messageLabelFormat, _requestedCulture.EnglishName, "{0}");
                var s            = translator.TranslateText(sourceString);
                if (s == sourceString)
                {
                    return;
                }
                if (s.Contains("{0}") && s.Length > 5)                 // If we just get back "{0} or "({0})", we won't consider that useful.
                {
                    // Bing will presumably have translated the English string into the native language, so now we want
                    // to display the English name in parentheses. (As a sanity check, we could look to see whether the
                    // native name is in the string, but there could be situations where it may not be an exact match.)
                    s = string.Format(s, _requestedCulture.EnglishName);
                }
                else if (_messageLabelFormat.Contains("{1}"))
                {
                    // If we already weeded out the param (because the language names are the same), there's no need to re-try (in case it's slow).
                    // This is just a fall-back in case there is some rare situation where the translator chokes on the presence of a formatting param in the string.
                    s = translator.TranslateText(string.Format(_messageLabelFormat, _requestedCulture.EnglishName, _requestedCulture.NativeName));
                }

                if (!string.IsNullOrEmpty(s))
                {
                    Message = s;
                    // In general, we will be able to translate OK and the title bar text iff we were able to translate
                    // the message.  This assumption saves a few processor cycles and prevents disappearing text when
                    // a language has not been localized (as is likely the case when we display this dialog).
                    AcceptButtonText = translator.TranslateText(_acceptButtonText);
                    WindowTitle      = translator.TranslateText(_windowTitle);
                }
            }
            catch (Exception)
            {
                //swallow
            }
        }
Beispiel #10
0
 public CollectorRepository(CactusGuruEntities context, TranslatorBase <Collector, tblCollector> translator)
 {
     _context    = context;
     _translator = translator;
 }
Beispiel #11
0
 public CollectionItemImageReader(CactusGuruEntities context, TranslatorBase <CollectionItemImage, tblCollectionItemImage> translator)
 {
     _context    = context;
     _translator = translator;
 }
Beispiel #12
0
        protected void ProcessLines(List <List <string> > listLines,
                                    List <List <string> > listDefineLines,
                                    string sReferencePath)
        {
#warning this method is horribly long

            const string ALLOWED_LAYOUT = "allowed_layout";
            const string OVERRIDE       = "override:";

            var nDefaultCount              = CardLayout.defaultCount;
            var listColumnNames            = new List <string>();
            var dictionaryColumnNames      = new Dictionary <string, int>();
            var dictionaryElementOverrides = new Dictionary <string, Dictionary <string, int> >();
            var dictionaryDefines          = new Dictionary <string, string>();

            // Line Processing
            if (0 < listLines.Count)
            {
                // Read the column names
                var listAllColumnNames = listLines[0];
                for (int nIdx = 0; nIdx < listAllColumnNames.Count; nIdx++)
                {
                    string sKey = listAllColumnNames[nIdx].ToLower().Trim();
                    listColumnNames.Add(sKey);
                    if (!dictionaryColumnNames.ContainsKey(sKey))
                    {
                        dictionaryColumnNames.Add(sKey, nIdx);
                    }
                    else
                    {
                        IssueManager.Instance.FireAddIssueEvent("Duplicate column found in: " + sReferencePath + "::" + "Column [" + nIdx + "]: " + sKey);
                        Logger.AddLogLine("Duplicate column found in: " + sReferencePath + "::" + "Column [" + nIdx + "]: " + sKey);
                    }
                }

                // determine the allowed layout column index
                int nAllowedLayoutColumn;
                if (!dictionaryColumnNames.TryGetValue(ALLOWED_LAYOUT, out nAllowedLayoutColumn))
                {
                    nAllowedLayoutColumn = -1;
                }

                // construct the override dictionary
                foreach (string sKey in listColumnNames)
                {
                    if (sKey.StartsWith(OVERRIDE))
                    {
                        string[] arraySplit = sKey.Split(new char[] { ':' });
                        if (3 == arraySplit.Length)
                        {
                            string sElementName         = arraySplit[1].Trim();
                            string sElementItemOverride = arraySplit[2].Trim();
                            if (!dictionaryElementOverrides.ContainsKey(sElementName))
                            {
                                dictionaryElementOverrides.Add(sElementName, new Dictionary <string, int>());
                            }
                            Dictionary <string, int> dictionaryOverrides = dictionaryElementOverrides[sElementName];
                            if (dictionaryOverrides.ContainsKey(sElementItemOverride))
                            {
                                Logger.AddLogLine("Duplicate override found: {0}".FormatString(sElementItemOverride));
                            }
                            dictionaryOverrides[sElementItemOverride] = dictionaryColumnNames[sKey];
                        }
                    }
                }

                // remove the columns
                listLines.RemoveAt(0);

                // remove any lines that do not contain any values
                int nRow = 0;
                while (nRow < listLines.Count)
                {
                    var listRow   = listLines[nRow];
                    var bEmptyRow = true;
                    foreach (string sCol in listRow)
                    {
                        if (0 < sCol.Trim().Length)
                        {
                            bEmptyRow = false;
                            break;
                        }
                    }
                    if (bEmptyRow)
                    {
                        listLines.RemoveAt(nRow);
                    }
                    else
                    {
                        nRow++;
                    }
                }

                // remove any layout elements that do not match the card layout
                if (-1 != nAllowedLayoutColumn)
                {
                    int nLine = 0;

                    while (nLine < listLines.Count)
                    {
                        if (!CardLayout.Name.Equals(listLines[nLine][nAllowedLayoutColumn], StringComparison.CurrentCultureIgnoreCase))
                        {
                            listLines.RemoveAt(nLine);
                        }
                        else
                        {
                            nLine++;
                        }
                    }
                }

                // indicate if no lines remain!
                if (0 == listLines.Count)
                {
                    IssueManager.Instance.FireAddIssueEvent("No lines found?! allowed_layout may be cutting them!");
                }
            }

            ValidLines.Clear();

            // create the duplicated lines (with count > 0)
            foreach (List <string> listItems in listLines)
            {
                if (0 < listItems.Count)
                {
                    int nNumber;
                    if (!int.TryParse(listItems[0].Trim(), out nNumber))
                    {
                        IssueManager.Instance.FireAddIssueEvent("Invalid card count found: [" + listItems[0] + "] The first column should always have a number value.");
                        nNumber = 1;
                    }
                    for (var nCount = 0; nCount < nNumber; nCount++)
                    {
                        ValidLines.Add(new DeckLine(listItems, nCount));
                    }
                }
            }
            // always create a line
            if (0 == ValidLines.Count && 0 < nDefaultCount)
            {
                // create the default number of lines.
                for (int nIdx = 0; nIdx < nDefaultCount; nIdx++)
                {
                    if (0 < listColumnNames.Count)// create each line and the correct number of columns
                    {
                        var arrayDefaultLine = new List <string>();
                        for (int nCol = 0; nCol < arrayDefaultLine.Count; nCol++)
                        {
                            arrayDefaultLine.Add(string.Empty);
                        }
                        ValidLines.Add(new DeckLine(arrayDefaultLine));
                    }
                    else // no columns just create an empty row
                    {
                        ValidLines.Add(new DeckLine(new List <string>()));
                    }
                }
                if (!string.IsNullOrEmpty(sReferencePath))
                {
                    IssueManager.Instance.FireAddIssueEvent("No lines found for this layout! Generated " + nDefaultCount);
                }
            }

            // Define Processing
            // remove the column names
            if (listDefineLines.Count > 0)
            {
                // the removal of the first row happens in the reader(s) for defines
//                listDefineLines.RemoveAt(0);
                foreach (var row in listDefineLines)
                {
                    if (row.Count > 1)
                    {
                        string sKey = row[0];
                        int    nIdx;
                        string sVal;
                        if (dictionaryDefines.TryGetValue(sKey.ToLower(), out sVal))
                        {
                            string sMsg = "Duplicate define found: " + sKey;
                            IssueManager.Instance.FireAddIssueEvent(sMsg);
                            Logger.AddLogLine(sMsg);
                        }
                        else if (dictionaryColumnNames.TryGetValue(sKey.ToLower(), out nIdx))
                        {
                            string sMsg = "Overlapping column name and define found in: " + sReferencePath + "::" + "Column [" + nIdx + "]: " + sKey;
                            IssueManager.Instance.FireAddIssueEvent(sMsg);
                            Logger.AddLogLine(sMsg);
                        }
                        else
                        {
                            dictionaryDefines.Add(sKey.ToLower(), row[1]);
                        }
                    }
                }
            }

            m_zTranslator = TranslatorFactory.GetTranslator(dictionaryColumnNames, dictionaryDefines, dictionaryElementOverrides, listColumnNames);

#if MONO_BUILD
            Thread.Sleep(100);
#endif
            WaitDialog.Instance.ThreadSuccess = true;
            WaitDialog.Instance.CloseWaitDialog();
        }
 public TaxonTranslator(TranslatorBase <Genus, tblGenus> genusTranslator)
 {
     ArgumentChecker.CheckNull(genusTranslator);
     _genusTranslator = genusTranslator;
 }