private void Import(string fullFilename)
 {
     if (UnitConversionService.CanImportFrom(fullFilename))
     {
         UnitConversionService.ImportFrom(fullFilename);
     }
 }
        private void Export(string filename)
        {
            var fullFilename = GetImportExportFullFilename(filename);

            UnitConversionService.ExportTo(fullFilename);
            SystemService.OpenUrl(SystemService.ApplicationDataPath);
        }
        public IEnumerable <WoxResult> CreateNewPrefix(string search)
        {
            var result = UnitConversionService.PrepareNewPrefixCreation(search);

            if (result != null)
            {
                yield return(GetActionResult(result.Item1, result.Item2, result.Item3));
            }
        }
        public IEnumerable <WoxResult> ConvertUnit(string search)
        {
            var result = UnitConversionService.Convert(search);

            if (result != null)
            {
                yield return(GetActionResult(result.Item1, result.Item2, () => { }));
            }
        }
        private IEnumerable <WoxResult> SearchUnitCommand(WoxQuery query, int position)
        {
            var unitBaseNames = UnitConversionService.GetUnitBaseNames();
            var patterns      = query.SearchTerms.Skip(position);
            var patternFull   = query.GetAllSearchTermsStarting(position);
            var hasResult     = false;

            foreach (var unitBaseName in unitBaseNames)
            {
                var  searchField = "{0} {1} {2}".FormatWith(unitBaseName.Name, unitBaseName.Symbol, unitBaseName.Namespace);
                bool match       = true;
                foreach (var pattern in patterns)
                {
                    match = match && searchField.MatchPattern(pattern);
                }
                if (match && unitBaseName.Symbol.Length > 0)
                {
                    var convertSI = UnitConversionService.Convert(unitBaseName.Symbol);
                    var title     = "{0} ({1})".FormatWith(unitBaseName.Name, unitBaseName.Symbol);
                    var subtitle  = "{0} (namespace: {1})".FormatWith(convertSI.Item2, unitBaseName.Namespace);
                    if (patternFull == unitBaseName.Name)
                    {
                        subtitle  = subtitle + " - convert";
                        hasResult = true;
                        yield return(GetCompletionResultFinal(title, subtitle, () => "convert {0}".FormatWith(unitBaseName.Symbol)));
                    }
                    else
                    {
                        hasResult = true;
                        yield return(GetCompletionResultFinal(title, subtitle, () => "search unit {0}".FormatWith(unitBaseName.Name)));
                    }
                }
            }
            if (!hasResult)
            {
                yield return(GetEmptyCommandResult("unit", GetCommandInfos("search")));
            }
        }
        private IEnumerable <WoxResult> ImportCommand(WoxQuery query, int position)
        {
            var filename = query.GetAllSearchTermsStarting(position);

            if (string.IsNullOrEmpty(filename))
            {
                yield return(GetEmptyCommandResult("import", CommandInfos));
            }
            else
            {
                var fullFilename = GetImportExportFullFilename(filename);
                if (UnitConversionService.CanImportFrom(fullFilename))
                {
                    yield return(GetActionResult("import {0}".FormatWith(filename), "Import unit and prefix definitions from filename [{0}]".FormatWith(filename), () => Import(fullFilename)));
                }
                else
                {
                    yield return(new WoxResult {
                        Title = "import {0}".FormatWith(filename), SubTitle = "Import unit and prefix definitions from filename [{0}] (No file found!)".FormatWith(filename)
                    });
                }
            }
        }
 public override void Init()
 {
     UnitConversionService.Init();
     InitCommands();
 }