コード例 #1
0
 static public string Convert(double bytes, ConversionType conversionType, string format)
 {
     if (conversionType.ToString().Contains("i"))
     {
         return((bytes / Math.Pow(2, (int)conversionType)).ToString(format) +
                " " +
                conversionType.ToString());
     }
     else
     {
         return((bytes / Math.Pow(1000, (int)conversionType)).ToString(format) +
                " " +
                conversionType.ToString());
     }
 }
コード例 #2
0
 static public string Convert(double bytes, ConversionType conversionType, string format)
 {
     if (conversionType.ToString().Contains("i"))
     {
         return (bytes / Math.Pow(2, (int)conversionType)).ToString(format) +
             " " +
             conversionType.ToString();
     }
     else
     {
         return (bytes / Math.Pow(1000, (int)conversionType)).ToString(format) +
             " " +
             conversionType.ToString();
     }
 }
コード例 #3
0
        static private ConversionType MoveDirection(ConversionType conversion, DirectionType direction)
        {
            int mult = 1;

            if (direction == DirectionType.Down)
            {
                mult = -1;
            }

            try
            {
                ConversionType newConversion = conversion;
                if (conversion.ToString().Contains("i"))
                {
                    newConversion = (ConversionType)((int)conversion + (mult * 10));
                }
                else
                {
                    newConversion = (ConversionType)((int)conversion + mult);
                }

                return(newConversion);
            }
            catch
            {
                return(conversion);
            }
        }
コード例 #4
0
        internal RecipeDTO ConvertRecipeMeasurements(RecipeDTO recipe, ConversionType conversionType,
                                                     bool reverseConversion)
        {
            var returnRecipe = recipe.Clone();

            foreach (var ingredientList in returnRecipe.IngredientsByComponent.Values)
            {
                foreach (var ingredient in ingredientList)
                {
                    var conversionTypeString      = conversionType.ToString();
                    var conversionTypeStringSplit = conversionTypeString.Split('_');
                    var leftMeasurement           =
                        (Measurement)Enum.Parse(typeof(Measurement), conversionTypeStringSplit.First());
                    var rightMeasurement =
                        (Measurement)Enum.Parse(typeof(Measurement), conversionTypeStringSplit.Last());
                    if ((reverseConversion && ingredient.Measurement != rightMeasurement) ||
                        (!reverseConversion && ingredient.Measurement != leftMeasurement))
                    {
                        continue;
                    }
                    if (!reverseConversion)
                    {
                        ingredient.Quantity   *= _conversionTable[conversionType];
                        ingredient.Measurement = rightMeasurement;
                    }
                    else
                    {
                        ingredient.Quantity   *= 1 / _conversionTable[conversionType];
                        ingredient.Measurement = leftMeasurement;
                    }
                }
            }

            return(returnRecipe);
        }
コード例 #5
0
        // [DispId(28)]
        public override string ToString()
        {
            // give something useful, for example, for a tooltip.
            string str = "Converter Details:";

            // indicate whether it's temporary or not
            if (!this.IsInRepository)
            {
                str = "Temporary " + str;
            }

            str += FormatTabbedTip("Name: '{0}'", Name);
            str += FormatTabbedTip("Identifier: '{0}'", ConverterIdentifier);
            str += FormatTabbedTip("Implementation Type: '{0}'", ImplementType);
            str += FormatTabbedTip("Conversion Type: '{0}'", ConversionType.ToString());
            if ((ProcessTypeFlags)ProcessType != ProcessTypeFlags.DontKnow)
            {
                str += FormatTabbedTip("Process Type: '{0}'", strProcessType(ProcessType));
            }
            if (!String.IsNullOrEmpty(LeftEncodingID))
            {
                str += FormatTabbedTip("Left side Encoding ID: '{0}'", LeftEncodingID);
            }
            if (!String.IsNullOrEmpty(RightEncodingID))
            {
                str += FormatTabbedTip("Right side Encoding ID: '{0}'", RightEncodingID);
            }

            // also include the current conversion option values
            str += String.Format("{0}{0}Current Conversion Options:", Environment.NewLine);
            str += FormatTabbedTip("Direction: '{0}'", (this.DirectionForward) ? "Forward" : "Reverse");
            str += FormatTabbedTip("Normalize Output: '{0}'", this.NormalizeOutput.ToString());
            str += FormatTabbedTip("Debug: '{0}'", this.Debug.ToString());

            DirectableEncConverter aDEC = new DirectableEncConverter(this);

            if (aDEC.IsLhsLegacy)
            {
                str += FormatTabbedTip("Input Code Page: '{0}'", aDEC.CodePageInput.ToString());
            }
            if (aDEC.IsRhsLegacy)
            {
                str += FormatTabbedTip("Output Code Page: '{0}'", aDEC.CodePageOutput.ToString());
            }
            return(str);
        }
コード例 #6
0
        private async Task ConvertToType(ConversionType conversionType)
        {
            var inputFile  = Path.GetTempFileName() + ".pptx";
            var outputFile = Path.GetTempFileName() + "." + conversionType.ToString().ToLower();

            try
            {
                "Download PPTX From Request stream".Info();
                using (var requestStream = HttpContext.OpenRequestStream())
                    using (var responseStream = HttpContext.OpenResponseStream())
                    {
                        using (var pptxStream = File.Create(inputFile))
                        {
                            await requestStream.CopyToAsync(pptxStream);
                        }

                        var completion = ConversionWorker.Instance.Enqueue(new ConversionTask
                        {
                            Type       = conversionType,
                            InputFile  = inputFile,
                            OutputFile = outputFile,
                        });
                        await Task.WhenAny(completion.Task, Task.Delay(5 * 60 * 1000));


                        "Send PDF into Response stream".Info();
                        using (var pdfStream = File.OpenRead(outputFile))
                        {
                            await pdfStream.CopyToAsync(responseStream);
                        }
                        "All done".Info();
                    }
            }
            catch (Exception e)
            {
                e.Error("Convert", "Cannot convert due to");
            }
            finally
            {
                FileUtils.CleanupFile(inputFile);
                FileUtils.CleanupFile(outputFile);
            }
        }
コード例 #7
0
        static private ConversionType MoveDirection(ConversionType conversion, DirectionType direction)
        {            
            int mult = 1;

            if (direction == DirectionType.Down)
                mult = -1;

            try
            {
                ConversionType newConversion = conversion;
                if (conversion.ToString().Contains("i"))
                    newConversion = (ConversionType)((int)conversion + (mult * 10));
                else
                    newConversion = (ConversionType)((int)conversion + mult);

                return newConversion;
            }
            catch
            {
                return conversion;
            }
        }