Beispiel #1
0
            public int Compare(object x, object y)
            {
                ServiceItemSetting xss = ((ServiceSettingsContainer)(((ListViewItem)x).Tag)).Setting;
                ServiceItemSetting yss = ((ServiceSettingsContainer)(((ListViewItem)y).Tag)).Setting;

                return(owner.CompareServiceSettings(xss, yss));
            }
Beispiel #2
0
        public void MoveAfter(ServiceItemSetting serviceSettingAfter, ServiceItemSetting serviceSetting)
        {
            ServiceItemsSortDataCollection itemsSortData;

            if (sortData.TryGetValue(languagePair, out itemsSortData))
            {
                itemsSortData.MoveAfter(serviceSettingAfter, serviceSetting);
            }
        }
        public ReadOnlyServiceSettingCollection GetServiceSettings()
        {
            ServiceSettingCollection result = new ServiceSettingCollection();

            foreach (ListViewItem lvi in lvServicesEnabled.Items)
            {
                ServiceSettingsContainer sc       = lvi.Tag as ServiceSettingsContainer;
                ServiceItemSetting       tsetting = new ServiceItemSetting(sc.Setting.LanguagePair, sc.Setting.Subject, sc.Setting.ServiceItem, TranslateOptions.Instance.GetNetworkSetting(sc.Setting.ServiceItem.Service));
                result.Add(tsetting);
            }
            return(new ReadOnlyServiceSettingCollection(result));
        }
Beispiel #4
0
        public int IndexOf(ServiceItemSetting a)
        {
            ServiceItemSortData data = new ServiceItemSortData(a.ServiceItem.FullName, a.Subject);
            int result = items.IndexOf(data);

            if (result < 0)
            {
                items.Add(data);
                result = items.Count - 1;
            }
            return(result);
        }
Beispiel #5
0
        public void MoveAfter(ServiceItemSetting serviceSettingAfter, ServiceItemSetting serviceSetting)
        {
            int idx = IndexOf(serviceSetting);
            ServiceItemSortData data = items[idx];

            if (idx < items.Count - 1)
            {
                items.RemoveAt(idx);
                int idx_after = IndexOf(serviceSettingAfter);
                items.Insert(idx_after + 1, data);
                modified = true;
            }
        }
Beispiel #6
0
        public void MoveBefore(ServiceItemSetting serviceSettingBefore, ServiceItemSetting serviceSetting)
        {
            int idx = IndexOf(serviceSetting);
            ServiceItemSortData data = items[idx];

            if (idx > 0)
            {
                items.RemoveAt(idx);
                int idx_before = IndexOf(serviceSettingBefore);
                items.Insert(idx_before, data);
                modified = true;
            }
        }
Beispiel #7
0
        public int CompareServiceSettings(ServiceItemSetting x, ServiceItemSetting y)
        {
            ServiceItemsSortDataCollection itemsSortData;

            if (!sortData.TryGetValue(languagePair, out itemsSortData))
            {
                itemsSortData = new ServiceItemsSortDataCollection();
                sortData.Add(languagePair, itemsSortData);
            }

            int idxx   = itemsSortData.IndexOf(x);
            int idxy   = itemsSortData.IndexOf(y);
            int result = idxx - idxy;

            if (result == 0)
            {
                result = string.Compare(x.ServiceItem.FullName, y.ServiceItem.FullName);
            }
            return(result);
        }
        internal static void TranslateWorker(
            ServiceItemSetting translatorSetting,
            AsyncTranslateState translateState)
        {
            if (translateState.IsTerminated)
            {
                return;
            }

            Result tr = translatorSetting.ServiceItem.Translate(translateState.Phrase, translatorSetting.LanguagePair, translatorSetting.Subject, translatorSetting.NetworkSetting, translateState);

            ReportProgressState repState = new ReportProgressState(tr, translateState);

            try
            {              //lock errors when
                translateState.AsyncOperation.Post(ReportProgress, repState);
            }
            catch (InvalidOperationException)
            {
            }
        }
Beispiel #9
0
        public override ReadOnlyServiceSettingCollection GetServiceSettings(string phrase, LanguagePair languagePair)
        {
            ServiceSettingCollection result = new ServiceSettingCollection();

            PrepareProcessing();
            foreach (KeyValuePair <LanguagePair, ServiceItemsCollection> kvp in Manager.LanguagePairServiceItems)
            {
                if (disabledSourceLanguages.BinarySearch(kvp.Key.From) >= 0)
                {
                    continue;
                }

                if (disabledTargetLanguages.BinarySearch(kvp.Key.To) >= 0)
                {
                    continue;
                }

                foreach (ServiceItem si in kvp.Value)
                {
                    if (
                        (kvp.Key.From == languagePair.From || languagePair.From == Language.Any) &&
                        (kvp.Key.To == languagePair.To || languagePair.To == Language.Any ||
                         (IncludeMonolingualDictionaryInTranslation && si is MonolingualDictionary)
                        )
                        )
                    {
                        foreach (string subject in si.SupportedSubjects)
                        {
                            if (Subjects.BinarySearch(subject) >= 0)
                            {
                                ServiceItemSetting tsetting = new ServiceItemSetting(kvp.Key, subject, si, TranslateOptions.Instance.GetNetworkSetting(si.Service));
                                result.Add(tsetting);
                            }
                        }
                    }
                }
            }
            return(new ReadOnlyServiceSettingCollection(result));
        }
        int GetDelayBeforeRun(ServiceItemSetting ts)
        {
            int cnt = 1;

            if (useCount.TryGetValue(ts.ServiceItem, out cnt))
            {
                cnt++;
            }

            useCount[ts.ServiceItem] = cnt;

            int result = ((cnt - 1) * 1000);

            int koeff = cnt < 10 ? cnt : 10;

            if (cnt < 4)
            {
                koeff = 0;
            }

            result *= koeff;
            return(result);
        }
Beispiel #11
0
        public override ReadOnlyServiceSettingCollection GetServiceSettings(string phrase, LanguagePair languagePair)
        {
            PrepareProcessing();
            ServiceSettingCollection result = new ServiceSettingCollection();

            int index;

            foreach (ServiceItemData sid in services)
            {
                if (
                    (sid.LanguagePair.From == languagePair.From || languagePair.From == Language.Any) &&
                    (sid.LanguagePair.To == languagePair.To || languagePair.To == Language.Any)
                    )
                {
                    index = Subjects.BinarySearch(sid.Subject);
                    if (index >= 0)
                    {
                        ServiceItemSetting tsetting = new ServiceItemSetting(sid.LanguagePair, sid.Subject, sid.ServiceItem, TranslateOptions.Instance.GetNetworkSetting(sid.ServiceItem.Service));
                        result.Add(tsetting);
                    }
                }
            }
            return(new ReadOnlyServiceSettingCollection(result));
        }
        void DelayedProcess(object state)
        {
            ServiceItemSetting ts = (ServiceItemSetting)state;

            TranslateManager.TranslateWorker(ts, this);
        }
 public ServiceSettingsContainer(ServiceItemSetting setting, bool showLanguage)
 {
     this.setting      = setting;
     this.showLanguage = showLanguage;
     GenerateName();
 }