public static ITranslationEngine GetTranslationEngine(
            Project project)
        {
            if (_translationEngine == null)
            {
                if (project != null)
                {
                    var uid = project.TranslationEngineUniqueInternalName;
                    if (!StringExtensionMethods.IsNullOrWhiteSpace(uid))
                    {
                        foreach (var engine in Engines)
                        {
                            if (uid.EqualsNoCase(engine.UniqueInternalName))
                            {
                                _translationEngine = engine;
                                return(engine);
                            }
                        }
                    }
                }

                foreach (var engine in Engines)
                {
                    if (engine.IsDefault)
                    {
                        _translationEngine = engine;
                        return(engine);
                    }
                }

                throw new Exception();
            }

            return(_translationEngine);
        }
        public static ITranslationEngine GetTranslationEngine(
            Project project)
        {
            if (_translationEngine == null)
            {
                if (project != null)
                {
                    var uid = project.TranslationEngineUniqueInternalName;
                    if (!StringExtensionMethods.IsNullOrWhiteSpace(uid))
                    {
                        foreach (var engine in Engines)
                        {
                            if (string.Compare(uid, engine.UniqueInternalName, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                _translationEngine = engine;
                                return(engine);
                            }
                        }
                    }
                }

                foreach (var engine in Engines)
                {
                    if (engine.IsDefault)
                    {
                        _translationEngine = engine;
                        return(engine);
                    }
                }

                throw new Exception();
            }

            return(_translationEngine);
        }
Exemple #3
0
        public static HttpHeaderDictionary FromString(string value)
        {
            if (null == value)
            {
                throw new ArgumentNullException("value");
            }

            var result = new HttpHeaderDictionary();

#if NET20
            var lines = IEnumerableExtensionMethods.ToQueue(StringExtensionMethods.Split(value, Environment.NewLine, StringSplitOptions.None));
#else
            var lines = value.Split(Environment.NewLine, StringSplitOptions.None).ToQueue();
#endif
            if (0 == lines.Count)
            {
                return(result);
            }

            while (0 != lines.Count)
            {
                var line = lines.Dequeue();
                if (0 == line.Length)
                {
                    break;
                }

                result.Add(HttpHeader.FromString(line));
            }

            return(result);
        }
Exemple #4
0
        public static HttpParameter FromString(string value)
        {
            if (null == value)
            {
                throw new ArgumentNullException("value");
            }

            value = value.Trim();
            if (0 == value.Length)
            {
                throw new ArgumentOutOfRangeException("value");
            }

#if NET20
            if (StringExtensionMethods.ContainsAny(value, ';'))
#else
            if (value.ContainsAny(';'))
#endif
            {
                throw new FormatException(Resources.HttpParameter_FormatException_MessageSemicolon);
            }

#if NET20
            var parts = StringExtensionMethods.Split(value, '=', StringSplitOptions.None);
#else
            var parts = value.Split('=', StringSplitOptions.None);
#endif
            if (2 != parts.Length)
            {
                throw new FormatException(Resources.HttpParameter_FormatException_Message);
            }

            return(new HttpParameter(parts[0], parts[1]));
        }
        internal static string MakeFileName(DataTypeDescriptor dataTypeDescriptor, DataScopeIdentifier dataScopeIdentifier, string cultureName)
        {
            string typeFullName = StringExtensionMethods.CreateNamespace(dataTypeDescriptor.Namespace, dataTypeDescriptor.Name, '.');

            string publicationScopePart = "";

            switch (dataScopeIdentifier.Name)
            {
            case DataScopeIdentifier.PublicName:
                break;

            case DataScopeIdentifier.AdministratedName:
                publicationScopePart = "_" + PublicationScope.Unpublished;
                break;

            default:
                throw new InvalidOperationException($"Unsupported data scope identifier: '{dataScopeIdentifier.Name}'");
            }

            string cultureNamePart = "";

            if (cultureName != "")
            {
                cultureNamePart = "_" + cultureName;
            }

            return(typeFullName + publicationScopePart + cultureNamePart + ".xml");
        }
        private static string Cell(Range range,
                                   int row,
                                   int column)
        {
            var cell = (Range)range.Cells[row, column];

            if (cell.Value is bool)
            {
                return(XmlConvert.ToString((bool)cell.Value));
            }

            if (cell.Value is DateTime)
            {
                var value = XmlConvert.ToString((DateTime)cell.Value, XmlDateTimeSerializationMode.Utc);
                if (value.EndsWith("T00:00:00Z", StringComparison.Ordinal))
                {
#if NET20
                    value = StringExtensionMethods.RemoveFromEnd(value, "T00:00:00Z", StringComparison.Ordinal);
#else
                    value = value.RemoveFromEnd("T00:00:00Z", StringComparison.Ordinal);
#endif
                }

                return(value);
            }

            return((string)cell.Text);
        }
        public static void GetTranslationAppID(
            Project project,
            out string appID)
        {
            if (!_translationAppIDSet)
            {
                if (project != null)
                {
                    var uid = project.TranslationEngineUniqueInternalName;
                    if (!StringExtensionMethods.IsNullOrWhiteSpace(uid))
                    {
                        var ids = project.TranslationAppIDs;
                        if (ids != null)
                        {
                            foreach (var key in project.TranslationAppIDs.Keys)
                            {
                                if (key != null && key == uid)
                                {
                                    _translationAppIDSet = true;
                                    _translationAppID    = safeGetValue(project.TranslationAppIDs, key);

                                    appID = _translationAppID;
                                    return;
                                }
                            }
                        }
                    }
                }
            }

            appID = _translationAppID;
        }
        public string GetSettingValue(
            string key)
        {
            if (StringExtensionMethods.IsNullOrWhiteSpace(key))
            {
                return(null);
            }
            else
            {
                using (var connection = new SQLiteConnection(connectionString))
                {
                    connection.Open();
                    var cmd =
                        new SQLiteCommand(connection)
                    {
                        CommandText = @"SELECT Value2 FROM ZreSettings WHERE Value1=@Value1"
                    };
                    cmd.Parameters.Add(new SQLiteParameter(@"@Value1")
                    {
                        Value = key
                    });

                    return(cmd.ExecuteScalar() as string);
                }
            }
        }
        public override bool Equals(string x,
                                    string y)
        {
            if (null == (x ?? y))
            {
                return(true);
            }

            if (null == y)
            {
                return(false);
            }

            var threshold = Math.Abs(Threshold < y.Length ? (y.Length / Threshold) : 0);

            if (0 == threshold)
            {
                return(base.Equals(x, y));
            }

            y = Normalize(y);
            if (string.Equals(x, y, Comparison))
            {
                return(true);
            }

#if NET20
            return((threshold + 1) > StringExtensionMethods.LevenshteinDistance(x, y));
#else
            return((threshold + 1) > x.LevenshteinDistance(y));
#endif
        }
        private void progressBackgroundWorker_ProgressChanged(
            object sender,
            ProgressChangedEventArgs e)
        {
            var s = e.UserState as ExcelProgressInformation;

            if (s == null)
            {
                var t = e.UserState as string;

                if (t == null)
                {
                    progressLabel.Visible = false;
                    progressLabel.Text    = string.Empty;
                }
                else
                {
                    progressLabel.Visible = !StringExtensionMethods.IsNullOrWhiteSpace(t);
                    progressLabel.Text    = t;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(s.TemporaryProgressMessage))
                {
                    progressLabel.Visible = false;
                    progressLabel.Text    = string.Empty;
                }
                else
                {
                    progressLabel.Visible = true;
                    progressLabel.Text    = s.TemporaryProgressMessage;
                }
            }
        }
Exemple #11
0
        private static string ToString(decimal value,
                                       char positive,
                                       char negative)
        {
            if (0m == value)
            {
                return("0° 0' 0\"");
            }

            var indicator = 0m < value ? positive : negative;

            value = Math.Abs(value);
            var degrees  = Math.Truncate(value);
            var fraction = value - degrees;

            value = fraction * 60;
            var minutes = Math.Truncate(value);

            fraction = value - minutes;
            var seconds = fraction * 60;

#if NET20
            return(StringExtensionMethods.FormatWith("{0}° {1}' {2:0.#####}\" {3}", degrees, minutes, seconds, indicator));
#else
            return("{0}° {1}' {2:0.#####}\" {3}".FormatWith(degrees, minutes, seconds, indicator));
#endif
        }
Exemple #12
0
        public static HttpVersion FromString(string value)
        {
            if (null == value)
            {
                throw new ArgumentNullException("value");
            }

            if (0 == value.Length)
            {
                throw new ArgumentOutOfRangeException("value");
            }

            if (!value.StartsWith("HTTP/", StringComparison.Ordinal))
            {
                throw new FormatException();
            }

            if ("HTTP/1.1".Equals(value, StringComparison.Ordinal))
            {
                return(Latest);
            }

#if NET20
            var parts = StringExtensionMethods.Split(value.Substring("HTTP/".Length), '.', StringSplitOptions.RemoveEmptyEntries);
#else
            var parts = value.Substring("HTTP/".Length).Split('.', StringSplitOptions.RemoveEmptyEntries);
#endif
            if (2 != parts.Length)
            {
                throw new FormatException();
            }

            return(new HttpVersion(XmlConvert.ToInt32(parts[0]), XmlConvert.ToInt32(parts[1])));
        }
Exemple #13
0
        public static string FormatCommaSeparatedValue(this string value)
#endif
        {
            if (null == value)
            {
                return(null);
            }

            if (0 == value.Length)
            {
                return(string.Empty);
            }

#if NET20
            value = StringExtensionMethods.Replace(value, "\"", "\"\"", StringComparison.Ordinal);
#else
            value = value.Replace("\"", "\"\"", StringComparison.Ordinal);
#endif

            return(' ' == value[0] ||
                   ' ' == value[value.Length - 1]
#if NET20
                   || StringExtensionMethods.ContainsAny(value, ',', '\n', '"')
#else
                   || value.ContainsAny(',', '\n', '"')
#endif
                   || value.Contains(Environment.NewLine)
                       ? string.Concat("\"", value, "\"")
                       : value);
        }
        public static TsvDataSheet Download(AbsoluteUri location)
        {
            if (null == location)
            {
                throw new ArgumentNullException("location");
            }

            TsvDataSheet tsv = null;

            var request = WebRequest.Create((Uri)location);

            using (var response = request.GetResponse())
            {
                using (var stream = response.GetResponseStream())
                {
                    if (null != stream)
                    {
                        using (var reader = new StreamReader(stream))
                        {
#if NET20
                            var file = new FileInfo(StringExtensionMethods.FormatWith("{0}.tsv", AlphaDecimal.Random()));
                            FileInfoExtensionMethods.Create(file, reader.ReadToEnd());
#else
                            var file = new FileInfo("{0}.tsv".FormatWith(AlphaDecimal.Random()));
                            file.Create(reader.ReadToEnd());
#endif

                            tsv = new TsvDataSheet(file);
                        }
                    }
                }
            }

            return(tsv);
        }
Exemple #15
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            _project.ReadOnlyFileOverwriteBehaviour =
                ((ReadOnlyHelper)readOnlySaveBehaviourComboBox.SelectedItem).Behaviour;

            _project.CreateBackupFiles        = createBackupsCheckBox.Checked;
            _project.OmitEmptyItems           = omitEmptyItemsCheckBox.Checked;
            _project.NeutralLanguageCode      = neutralLanguageCodeTextEdit.Text.Trim();
            _project.UseSpellChecker          = useSpellCheckingCheckEdit.Checked;
            _project.ResXIndentChar           = StringExtensionMethods.UnreplaceEscapes(ResXIndentCharTextEdit.Text); // KEIN TRIM.
            _project.HideEmptyRows            = hideEmptyRowsCheck.Checked;
            _project.HideTranslatedRows       = hideTranslatedRowsCheck.Checked;
            _project.ShowCommentsColumnInGrid = showCommentsColumnInGridCheckEdit.Checked;
            _project.IgnoreWindowsFormsResourcesWithDesignerFiles =
                ignoreWindowsFormsDesignerFiles.Checked;
            _project.HideInternalDesignerRows =
                hideInternalDesignerRowsCheckEdit.Checked;
            _project.UseShallowGridDataCumulation = shallowCumulationCheckEdit.Checked;
            _project.HideFileGroupFilesInTree     = hideFileGroupFilesInTreeCheckEdit.Checked;

            _project.NeutralLanguageFileNamePattern    = neutralLanguageFileNamePatternTextEdit.Text.Trim();
            _project.NonNeutralLanguageFileNamePattern = nonNeutralLanguageFileNamePatternTextEdit.Text.Trim();
            _project.BaseNameDotCount           = (int)baseNameDotCountSpinEdit.Value;
            _project.DefaultFileTypesToIgnore   = defaultTypesTextEdit.Text.Trim();
            _project.PersistGridSettings        = persistGridSettingsCheckEdit.Checked;
            _project.ColorifyNullCells          = colorifyNullCellsCheckEdit.Checked;
            _project.EnableExcelExportSnapshots = enableExcelExportSnapshotsCheckEdit.Checked;

            _project.MarkAsModified();
        }
Exemple #16
0
        public static HttpRequestLine FromString(string value)
        {
            if (null == value)
            {
                throw new ArgumentNullException("value");
            }

            if (0 == value.Length)
            {
                throw new ArgumentOutOfRangeException("value");
            }

#if NET20
            var parts = StringExtensionMethods.Split(value, ' ', StringSplitOptions.RemoveEmptyEntries);
#else
            var parts = value.Split(' ', StringSplitOptions.RemoveEmptyEntries);
#endif
            if (2 == parts.Length)
            {
                return(new HttpRequestLine(parts[0], parts[1], HttpVersion.Latest));
            }

            if (3 == parts.Length)
            {
                return(new HttpRequestLine(parts[0], parts[1], parts[2]));
            }

            throw new FormatException();
        }
        public virtual bool Undo()
        {
#if NET20
            Trace.WriteIf(Tracing.Is.TraceVerbose, StringExtensionMethods.FormatWith("Count={0}", Count));
#else
            Trace.WriteIf(Tracing.Is.TraceVerbose, "Count={0}".FormatWith(Count));
#endif
            if (0 == Count)
            {
                return(true);
            }

#if NET20
            for (var i = 0; i < Count; i++)
            {
                var command = this[Count - 1 - i];
                CommandCounter.Increment();
                if (!command.Revert())
                {
                    return(false);
                }
            }
#else
            foreach (var command in this.Reverse())
            {
                CommandCounter.Increment();
                if (!command.Revert())
                {
                    return(false);
                }
            }
#endif

            return(true);
        }
        public void PutSettingValue(
            string key,
            string value)
        {
            if (!StringExtensionMethods.IsNullOrWhiteSpace(key))
            {
                DeleteSettingValue(key);

                if (!string.IsNullOrEmpty(value))
                {
                    using var connection = new SQLiteConnection(connectionString);
                    connection.Open();
                    var cmd =
                        new SQLiteCommand(connection)
                    {
                        CommandText = @"INSERT INTO ZreSettings (Value1, Value2) VALUES (@Value1, @Value2)"
                    };
                    cmd.Parameters.Add(new SQLiteParameter(@"@Value1")
                    {
                        Value = key
                    });
                    cmd.Parameters.Add(new SQLiteParameter(@"@Value2")
                    {
                        Value = value
                    });

                    cmd.ExecuteNonQuery();
                }
            }
        }
        public virtual void Save(Lexicon lexicon)
        {
            Trace.WriteIf(Tracing.Is.TraceVerbose, string.Empty);
            if (null == lexicon)
            {
                throw new ArgumentNullException("lexicon");
            }

            using (var writers = new StreamWriterDictionary("CANONICAL,SYNONYMS")
            {
                Access = FileAccess.Write,
                Mode = FileMode.Create,
                Share = FileShare.None
            })
            {
#if NET20
                if (0 == IEnumerableExtensionMethods.Count(lexicon))
#else
                if (!lexicon.Any())
#endif
                {
                    writers.Item(Location.FullName).WriteLine(string.Empty);
                    return;
                }

#if NET20
                var items = new SortedList <string, LexicalItem>();
                foreach (var item in lexicon)
                {
                    items.Add(item.CanonicalForm, item);
                }

                foreach (var item in items)
                {
                    var synonyms = new SortedList <string, string>();
                    foreach (var synonym in item.Value.Synonyms)
                    {
                        synonyms.Add(synonym, synonym);
                    }

                    writers
                    .Item(Location.FullName)
                    .WriteLine(StringExtensionMethods.FormatWith(
                                   "{0},{1}",
                                   CsvStringExtensionMethods.FormatCommaSeparatedValue(item.Value.CanonicalForm),
                                   CsvStringExtensionMethods.FormatCommaSeparatedValue(IEnumerableExtensionMethods.Concat(synonyms.Values, ';'))));
                }
#else
                foreach (var item in lexicon.OrderBy(x => x.CanonicalForm))
                {
                    writers
                    .Item(Location.FullName)
                    .WriteLine("{0},{1}".FormatWith(
                                   item.CanonicalForm.FormatCommaSeparatedValue(),
                                   item.Synonyms.OrderBy(x => x).Concat(';').FormatCommaSeparatedValue()));
                }
#endif
            }
        }
Exemple #20
0
        public override string ToString()
        {
#if NET20
            return(StringExtensionMethods.FormatWith("{0} {1} {2}", Method, RequestUri, Version));
#else
            return("{0} {1} {2}".FormatWith(Method, RequestUri, Version));
#endif
        }
Exemple #21
0
        /// <exclude />
        public static bool FunctionExists(string namespaceName, string name)
        {
            IFunction fun;

            bool exists = FunctionFacade.TryGetFunction(out fun, StringExtensionMethods.CreateNamespace(namespaceName, name));

            return(exists);
        }
        public virtual T Value <T>(int index)
        {
#if NET20
            return(StringExtensionMethods.To <T>(this[index]));
#else
            return(this[index].To <T>());
#endif
        }
        public virtual T Value <T>(string key)
        {
#if NET20
            return(StringExtensionMethods.To <T>(this[key]));
#else
            return(this[key].To <T>());
#endif
        }
Exemple #24
0
        public override string ToString()
        {
#if NET20
            return(StringExtensionMethods.FormatWith("{0} {1} {2}", Prefix, Item, Suffix).Trim());
#else
            return("{0} {1} {2}".FormatWith(Prefix, Item, Suffix).Trim());
#endif
        }
        public override string ToString()
        {
#if NET20
            return(StringExtensionMethods.FormatWith("{0}: {1}", Name, Value));
#else
            return("{0}: {1}".FormatWith(Name, Value));
#endif
        }
Exemple #26
0
        public override string ToString()
        {
#if NET20
            return(StringExtensionMethods.FormatWith("HTTP/{0}.{1}", Major, Minor));
#else
            return("HTTP/{0}.{1}".FormatWith(Major, Minor));
#endif
        }
Exemple #27
0
        public virtual string Normalize(string value)
        {
#if NET20
            return(StringExtensionMethods.Metaphone(value));
#else
            return(value.Metaphone());
#endif
        }
        public override string ToString()
        {
#if NET20
            return(StringExtensionMethods.FormatWith("{0} {1} {2}", Version, Code, Reason));
#else
            return("{0} {1} {2}".FormatWith(Version, Code, Reason));
#endif
        }
Exemple #29
0
        public override string ToString()
        {
#if NET20
            return(StringExtensionMethods.FormatWith("{0}, {1}", ToString(Latitude, 'N', 'S'), ToString(Longitude, 'E', 'W')));
#else
            return("{0}, {1}".FormatWith(ToString(Latitude, 'N', 'S'), ToString(Longitude, 'E', 'W')));
#endif
        }
        public virtual string Normalize(string value)
        {
#if NET20
            return(StringExtensionMethods.Soundex(value));
#else
            return(value.Soundex());
#endif
        }