Esempio n. 1
0
        private static void Process(TcpClient client)
        {
            using (var context = new Context(connectionString))
            {
                var dictionaryService = new DictionaryService(context);
                using (var stream = client.GetStream())
                {
                    byte[] data = new byte[64];

                    while (true)
                    {
                        StringBuilder commandBuilder = new StringBuilder();
                        do
                        {
                            var bytes = stream.Read(data, 0, data.Length);
                            commandBuilder.Append(Encoding.Unicode.GetString(data, 0, bytes));
                        }while (stream.DataAvailable);

                        var command = commandBuilder.ToString();

                        if (command.StartsWith("get "))
                        {
                            var prefix = command.Replace("get ", "");

                            var words = dictionaryService.Read(prefix);
                            data = Encoding.Unicode.GetBytes(words.Join("\n") + "\n");
                            stream.Write(data, 0, data.Length);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
    public static int Main(string[] args)
    {
        // Validate arguments
        if (args.Length < 1)
        {
            Console.WriteLine("Usage: dotnet server.dll {PORT}");
            return(-1);
        }
        int port;

        if (!int.TryParse(args[0], out port))
        {
            Console.WriteLine("invalid format for port, use a number");
            return(-1);
        }

        // Build the gRPC server
        Console.WriteLine("Firing off GRPC server");
        var server = new Server {
            Services = { DictionaryService.BindService(new DictionaryServiceImpl()) },
            Ports    = { new ServerPort("*", port, ServerCredentials.Insecure) }
        };

        // Launch the gRPC server
        ThreadPool.QueueUserWorkItem(_ => {
            server.Start();
            Console.WriteLine($"GRPC server listening on port {port}");
        }
                                     );
        autoEvent.WaitOne();
        server.ShutdownAsync().Wait();
        Console.WriteLine("Shutting down ...");
        return(0);
    }
Esempio n. 3
0
        /// <summary>
        /// Expand Search is used for A-Z Lists on dictionaries
        /// </summary>
        /// <param name="searchText">search text</param>
        /// <param name="includeTypes">types to include</param>
        /// <param name="offset">how many results to offset</param>
        /// <param name="numResults"># of results to return</param>
        /// <param name="dictionary">The dictionary</param>
        /// <param name="language">which language</param>
        /// <param name="version">version of dictionary service</param>
        /// <returns>Collection of Dictionary Search Results</returns>
        public DictionarySearchResultCollection Expand(String searchText, String includeTypes, int offset, int maxResults, DictionaryType dictionary, String language, String version)
        {
            // Translate from types the AppManager exposes to types the Dictionary Service exposes.
            svcDictionaryType svcDictionary = TypeTranslator.Translate(dictionary);
            svcLanguage       svcLanguage   = TypeTranslator.TranslateLocaleString(language);

            DictionaryService service = new DictionaryService();

            NCI.Services.Dictionary.BusinessObjects.SearchReturn expandRet = null;
            try
            {
                expandRet = service.Expand(searchText, includeTypes, offset, maxResults, svcDictionary, svcLanguage);
            }
            catch (Exception ex)
            {
                log.Error("Error in Expand Method in Dictionary Web Service.", ex);
            }

            List <DictionarySearchResult>    expansionList = DeserializeList(expandRet.Result, svcDictionary);
            DictionarySearchResultCollection collection    = new DictionarySearchResultCollection(expansionList.AsEnumerable());

            collection.ResultsCount = expandRet.Meta.ResultCount;


            return(collection);
        }
Esempio n. 4
0
        /// <param name="args">arg 1 - connection string (in quotes), arg 2 - port</param>
        static void Main(string[] args)
        {
            connectionString = args[0];
            using (var context = new Context(connectionString))
            {
                var tcpListener = new TcpListener(IPAddress.Any, int.Parse(args[1]));
                tcpListener.Start();
                Listen(tcpListener);

                var dictionaryService = new DictionaryService(context);
                while (true)
                {
                    var command = Console.ReadLine();
                    if (command == "create")
                    {
                        Console.WriteLine("Enter file path");
                        dictionaryService.Create(Console.ReadLine());
                    }
                    else if (command == "update")
                    {
                        Console.WriteLine("Enter file path");
                        dictionaryService.Update(Console.ReadLine());
                    }
                    else if (command == "delete")
                    {
                        dictionaryService.Delete();
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Dictionary search that will return a list of dictionary terms based on the dictionary type passed in
        /// and what kind of search is desired
        /// </summary>
        /// <param name="searchText">the text that has been typed into the search box</param>
        /// <param name="searchType">the type of search being executed</param>
        /// <param name="offset">how many to offset the first return result</param>
        /// <param name="maxResults">the max results to return<remarks>int.maxvalue should be used for retrieving all unless we have more</remarks></param>
        /// <param name="dictionary">the dictionary type (cancert term, drug, genetic)</param>
        /// <param name="language">English/Spanish</param>
        /// <returns>returns a list of dictioanry terms and related metadata</returns>
        public DictionarySearchResultCollection Search(String searchText, SearchType searchType, int offset, int maxResults, DictionaryType dictionary, String language)
        {
            // Translate from types the AppManager exposes to types the Dictionary Service exposes.
            svcDictionaryType svcDictionary = TypeTranslator.Translate(dictionary);
            svcSearchType     svcSearchType = TypeTranslator.Translate(searchType);
            svcLanguage       svcLanguage   = TypeTranslator.TranslateLocaleString(language);

            DictionaryService service = new DictionaryService();

            //sets up SearchReturn from Web Service
            NCI.Services.Dictionary.BusinessObjects.SearchReturn searchRet = null;

            //tries the dictionary service to get the strings back
            try
            {
                searchRet = service.Search(searchText, svcSearchType, offset, maxResults, svcDictionary, svcLanguage);
            }
            catch (Exception ex)
            {
                log.Error("There is an error in the Search Method of the Dictionary Service.", ex);
            }

            List <DictionarySearchResult>    resultList = DeserializeList(searchRet.Result, svcDictionary);
            DictionarySearchResultCollection collection = new DictionarySearchResultCollection(resultList.AsEnumerable());

            collection.ResultsCount = searchRet.Meta.ResultCount;
            return(collection);
        }
Esempio n. 6
0
 public ExamService(UsersPairsService usersPairsService, ExamsAndMetricService examsAndMetricService,
                    DictionaryService dictionaryService)
 {
     _usersPairsService     = usersPairsService;
     _examsAndMetricService = examsAndMetricService;
     _dictionaryService     = dictionaryService;
 }
        public async void getTranslation()
        {
            string source_lang = getLanguageId(SelectedInput);
            string target_lang = getLanguageId(SelectedOutput);
            var    service     = new DictionaryService();
            var    uri         = "/api/v1/entries/" + source_lang + "/" + Word + "/translations=" + target_lang;

            if (SelectedInput == null || SelectedOutput == null)
            {
                DependencyService.Get <IMessage>().LongAlert("Please select language!");
            }
            else
            {
                TransResult = await service.GetTranslationsAsync(uri);

                if (TransResult != null)
                {
                    setTranslationValues();
                }
                else
                {
                    TranslationEntry.Clear();
                }
            }
        }
Esempio n. 8
0
        public ActionResult listkey()
        {
            DictionaryService        divserv  = new DictionaryService();
            IEnumerable <dictionary> listedic = divserv.GetMany();

            return(View(listedic));
        }
        public ActionResult Save(int?id)
        {
            var obj = new CompanyAuthorize()
            {
                Source = 1, Way = 1, MemberShared = "Y", EffectiveDT = System.DateTime.Now.ToString("yyyy-MM-dd")
            };

            if (id.HasValue)
            {
                obj = CompAuthorService.GetOne(id.Value);
            }
            ViewBag.BusinessModes = ListToSelect(DictionaryService.GetChildList(221, false).Select(o => new SelectListItem()
            {
                Text = o.Title, Value = o.DicSN.ToString()
            }));
            ViewBag.OpenScopeIds = ListToSelect(BusinessService.GetList(false).Select(o => new SelectListItem()
            {
                Text = o.Title, Value = o.ById
            }));
            ViewBag.users = ListToSelect(UserService.GetList(false).Select(o => new SelectListItem()
            {
                Text = o.FullName, Value = o.UserId
            }), emptyTitle: "请选择");
            ViewBag.states = EnumToSelect(typeof(CompanyAuthorizeState));
            return(View(obj.IsNullThrow()));
        }
Esempio n. 10
0
        public void Should_Create_with_DictionaryTable()
        {
            Dictionary dictionary = new Dictionary
            {
                Code             = 100,
                CompanyId        = 1,
                CreatedBy        = 1,
                DateAdded        = DateTime.Now,
                DateUpdated      = DateTime.Now,
                DepartmentId     = 1,
                Description      = "",
                DictionaryType   = "INSERTED",
                FullDescription  = "INSERTED",
                Hierarchy        = 1,
                Id2              = 1,
                Id3              = 1,
                UpdatedBy        = 1,
                IsDeleted        = false,
                DictionaryTypeId = 20
            };

            var ctx = new WorkBenchContext();
            var dictionaryService = new DictionaryService(
                new UnitOfWork(ctx),
                new GenericDataRepository <Dictionary>(new WorkBenchContext())
                );

            Assert.DoesNotThrow(() =>
            {
                dictionaryService.Create(dictionary);
                dictionaryService.Update(dictionary);
                dictionaryService.GetAll();
                dictionaryService.Delete(dictionary);
            });
        }
Esempio n. 11
0
        public ActionResult DeleteDictionary(DictionaryType type, int dictionaryId)
        {
            if (!CurrentCustomer.IsSuperAdmin())
            {
                return(NoAuthorityJson());
            }

            Dictionary dictionary;

            if (type != DictionaryType.FirstCommentType)
            {
                var list = DictionaryService.GetDictionaryList(type.GetDescription());
                dictionary = list.Find(e => e.Id == dictionaryId);

                new DictionaryService().DeleteDictionary(dictionary);
            }
            else
            {
                dictionary = DictionaryService.DesignCommentTypeDictionary.FirstOrDefault(e => e.Id == dictionaryId);
                if (dictionary == null)
                {
                    dictionary = DictionaryService.IntegralityCommentTypeDictionary.Find(e => e.Id == dictionaryId);
                }

                new DictionaryService().DeleteDictionary(dictionary);
            }

            return(Json(new { result = true, dictionaryId = dictionaryId, type = type, level = dictionary.DisplayName }));
        }
Esempio n. 12
0
        public ActionResult Hanzi(Word word)
        {
            Models.CharacterViewModel charViewModel = new Models.CharacterViewModel();

            CharService       charService       = new CharService();
            PhrasesService    phrasesService    = new PhrasesService();
            DictionaryService dictionaryService = new DictionaryService();

            charViewModel.word = word;

            if (word.Character.Length == 1)
            {
                string NumberPinyin = word.NumberPinyin;

                charViewModel.AudioSource = "../Audio/" + NumberPinyin + ".mp3";
            }


            //TODO
            ArrayList   getPhrasesArrayList = phrasesService.GetPhrasesContainingCharacter(word.Character);
            List <Word> getPhraseslist      = ToList(getPhrasesArrayList);

            ArrayList   getIdiomsArrayList = dictionaryService.GetIdiomsContainingCharacter(word.Character);
            List <Word> getIdiomslist      = ToList(getIdiomsArrayList);

            ArrayList   getImagePhrasesArrayList = phrasesService.GetImagePhrasesContainingCharacter(word.Character);
            List <Word> getImagePhraseslist      = ToList(getImagePhrasesArrayList);


            charViewModel.PhrasesContainingCharacter      = getPhraseslist;
            charViewModel.ImagePhrasesContainingCharacter = getImagePhraseslist;
            charViewModel.IdiomsContainingCharacter       = getIdiomslist;

            return(View(charViewModel));
        }
 public HomeController(DncZeusDbContext dbContext, IMapper mapper,
                       DictionaryService dictionaryService)
 {
     _dbContext         = dbContext;
     _mapper            = mapper;
     _dictionaryService = dictionaryService;
 }
Esempio n. 14
0
 public ResultStatus GetWIPMsgs(
     DictionaryService dictionaryService,
     DictionaryService_Request request,
     out DictionaryService_Result result)
 {
     return(this.GetWIPMsgs(dictionaryService, (DictionaryService_Parameters)null, request, out result));
 }
        public IDictionary <string, string> GetDictionary(string locale, string key)
        {
            //Get all dictionary from root key by specific language.
            IDictionaryService dictionaryService = new DictionaryService();

            return(dictionaryService.GetDictionary(new DefaultCultureDictionary(CultureInfo.GetCultureInfo(locale)), key));
        }
Esempio n. 16
0
            public bool AddResult()
            {
                DictionaryService deServ = new DictionaryService();
                bool f = deServ.Add(id, name, depart);

                return(f);
            }
        public IDictionary <string, string> GetDictionary(string key)
        {
            //Get all dictionary from root key with no specific language.
            IDictionaryService dictionaryService = new DictionaryService();

            return(dictionaryService.GetDictionary(new DefaultCultureDictionary(), key));
        }
Esempio n. 18
0
 public ExamService(ExamsAndMetricService examsAndMetricService,
                    DictionaryService dictionaryService, UsersWordsService usersWordsService)
 {
     _examsAndMetricService = examsAndMetricService;
     _dictionaryService     = dictionaryService;
     _usersWordsService     = usersWordsService;
 }
Esempio n. 19
0
 /// <summary>
 /// 获取查询列表
 /// </summary>
 /// <param name="keyWord"></param>
 /// <returns></returns>
 public List <MyProduct> GetList(string userID)
 {
     using (DbContext db = new CRDatabase())
     {
         var query = db.Set <CTMS_MYPRODUCT>().AsNoTracking().Where(o => !o.ISDELETED);
         if (!string.IsNullOrEmpty(userID))
         {
             query = query.Where(o => o.USERID.Equals(userID));
         }
         List <MyProduct> list = new List <MyProduct>();
         query.ToList().ForEach((o) => {
             MyProduct pro = list.Find(p => p.UserID.Equals(o.USERID) && p.ProductID.Equals(o.PRODUCTID) && p.StartDate == o.STARTDATE && p.EndDate == o.ENDDATE);
             if (pro != null)
             {
                 pro.ProductNum += o.PRODUCTNUM;
             }
             else
             {
                 List <Dictionary> ProductTypes = new DictionaryService().GetDictionaryByCategory("ProductType").FirstOrDefault().nodes;
                 List <Dictionary> ProductUnits = new DictionaryService().GetDictionaryByCategory("ProductUnit").FirstOrDefault().nodes;
                 MyProduct myProduct            = EntityToModel(o);
                 var type = ProductTypes.Find(d => d.value.Trim().Equals(myProduct.Product.ProductType.ToString()));
                 var unit = ProductUnits.Find(d => d.value.Trim().Equals(myProduct.Product.ProductUnit.ToString()));
                 myProduct.Product.ProductTypeText = (type == null ? "" : type.text);
                 myProduct.Product.ProductUnitText = (unit == null ? "" : unit.text);
                 list.Add(myProduct);
             }
         });
         return(list.OrderByDescending(q => q.StartDate).ToList());
     }
 }
Esempio n. 20
0
            public bool DeleteResult()
            {
                DictionaryService deServ = new DictionaryService();
                bool f = deServ.Delete(Id);

                return(f);
            }
Esempio n. 21
0
        public ActionResult SavePlan(string id)
        {
            string LeaderFullName = "";

            ViewBag.types = ListToSelect(DictionaryService.GetChildList(369, false).Select(o => new SelectListItem()
            {
                Value = o.DicSN.ToString(), Text = o.Title
            }));
            ViewBag.users = ListToSelect(UserService.GetList(false).Select(o => new SelectListItem()
            {
                Value = o.UserId, Text = o.FullName
            }));
            var obj = new Pharos.Logic.OMS.Entity.Plans()
            {
                Type = 372, AssignerUID = CurrentUser.UID
            };

            if (!string.IsNullOrWhiteSpace(id))
            {
                obj            = PlanService.GetOne(id);
                LeaderFullName = tradersService.getLeaderFullName(obj.LeaderUID);
            }
            Attachments            = null;
            ViewBag.LeaderFullName = LeaderFullName;
            return(View(obj));
        }
Esempio n. 22
0
 /// <summary>
 /// 创建dic数据
 /// </summary>
 /// <param name="groupName"></param>
 /// <param name="value"></param>
 public void CreateDictionary(string groupName, string value)
 {
     DAL.DictionaryService dicSvc = new DictionaryService();
     dicSvc.Create(new Dictionary()
     {
         GroupName = groupName, Value = value
     });
 }
        public void HasBeenDictionaryInstantiated_GivenNull_ReturnsFalse()
        {
            var dictionaryService            = new DictionaryService();
            Dictionary <int, int> dictionary = null;
            bool result = dictionaryService.HasBeenDictionaryInstantiated(dictionary);

            Assert.False(result);
        }
Esempio n. 24
0
        public void QueryDatas()
        {
            var vote = new DictionaryService();

            var list = vote.QueryList(x => x.Id > 0);

            Assert.AreEqual(list.Count, 9);
        }
Esempio n. 25
0
 public void Init()
 {
     _efContext             = EFContextFactory.CreateInMemoryEFContext();
     _efContextMock         = new Mock <EFContext>();
     _mapperMock            = new Mock <IMapper>();
     _dictionaryService     = new DictionaryService(_efContext, _eventServiceMock.Object, _mapperMock.Object);
     _dictionaryServiceMock = new DictionaryService(_efContextMock.Object, _eventServiceMock.Object, _mapperMock.Object);
 }
Esempio n. 26
0
 public ReceiverController(DncZeusDbContext dbContext, IMapper mapper,
                           DictionaryService dictionaryService, TelegramService telegramService)
 {
     _dbContext         = dbContext;
     _mapper            = mapper;
     _dictionaryService = dictionaryService;
     _telegramService   = telegramService;
 }
        public void HasBeenDictionaryInstantiated_GivenEmptyDictionary_ReturnsTrue()
        {
            var dictionaryService            = new DictionaryService();
            Dictionary <int, int> dictionary = new Dictionary <int, int>();
            bool result = dictionaryService.HasBeenDictionaryInstantiated(dictionary);

            Assert.True(result);
        }
        public string GetDictionaryItem(string locale, string key)
        {
            //Get single dictionary by specific language.
            ILocalizationService localizationService = Services.LocalizationService;
            IDictionaryService   dictionaryService   = new DictionaryService();

            return(dictionaryService.GetDictionaryItem(localizationService, CultureInfo.GetCultureInfo(locale), key));
        }
Esempio n. 29
0
 public ActionResult Index()
 {
     ViewBag.types = ListToSelect(DictionaryService.GetChildList(5).Select(o => new SelectListItem()
     {
         Value = o.DicSN.ToString(), Text = o.Title
     }), emptyTitle: "全部");
     return(View());
 }
Esempio n. 30
0
 public AddWordService(UsersWordsService usersWordsService, YandexDictionaryApiClient yapiDicClient,
                       YandexTranslateApiClient yapiTransClient, DictionaryService dictionaryService)
 {
     _usersWordsService = usersWordsService;
     _yapiDicClient     = yapiDicClient;
     _yapiTransClient   = yapiTransClient;
     _dictionaryService = dictionaryService;
 }