Beispiel #1
0
        private static void ParseArguments(string[] args)
        {
            if (args.Length > 0)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    string currentParameter = args[i];
                    if (currentParameter == LaunchParameters.Mode && (i + 1) < args.Length)
                    {
                        if (Enum.TryParse <OperationModeEnum>(args[i + 1], out OperationModeEnum mode))
                        {
                            operationMode = mode;
                        }
                    }

                    if (currentParameter == LaunchParameters.AddToBootManager)
                    {
                        addToBootManager = true;
                    }

                    if (currentParameter == LaunchParameters.Quiet)
                    {
                        quiet = true;
                    }

                    if (currentParameter == LaunchParameters.ImageTemporaryFolderPath && (i + 1) < args.Length)
                    {
                        vhdTemporaryFolderPath = args[i + 1];
                    }
                }
            }
        }
        public TMessageValidatorProtocol(TProtocol protocol, ValidationModeEnum validation_mode, OperationModeEnum operation_mode)
            : base(protocol)
        {
            ValidationMode = validation_mode;
            OperationMode  = operation_mode;
            var rand = new Random();

            _random_seq_id = rand.Next();
        }
Beispiel #3
0
        /// <summary>
        /// Switch the operation mode.
        /// </summary>
        /// <param name="modes">Mode: wilma/stub/proxy</param>
        /// <returns>True if the request is successful, otherwise returns false.</returns>
        public async Task <bool> SetOperationModeAsync(OperationModeEnum modes)
        {
            _logger.Debug("WilmaService SetOperationMode enter with value: " + modes);

            var resp = await _httpClient.GetAsync(GetUrl(OPERATION_SETTER_URL_POSTFIX_FORMAT, modes.ToString().ToLower()));

            if (resp.IsSuccessStatusCode)
            {
                _logger.Debug("WilmaService SetOperationMode success.");
                return(true);
            }

            _logger.Debug("WilmaService SetOperationMode failed: {0}", resp.StatusCode);
            return(false);
        }
Beispiel #4
0
        private static MigrationFlowData BuildMigrationData(OperationModeEnum operationMode, IFileSystemHelper fileSystemHelper, bool addToBootManager)
        {
            MigrationFlowData migrationData   = new MigrationFlowData();
            IDriveInfo        systemDriveInfo = fileSystemHelper.GetSystemDriveInfo();

            migrationData.OperatingSystemDriveLetter = systemDriveInfo.Name.First();
            migrationData.TemporaryVhdFileMaxSize    = systemDriveInfo.TotalSize + (200 << 20) /*200MB*/;
            migrationData.VhdFileName            = "VHDNBOM_System_Image.vhdx";
            migrationData.VhdFileType            = Logic.Models.Enums.VhdType.VhdxDynamic;
            migrationData.VhdFileTemporaryFolder = vhdTemporaryFolderPath ?? fileSystemHelper.FindBestLocationForVhdTemporaryFolder();
            migrationData.AddVhdToBootManager    = addToBootManager;

            if (operationMode == OperationModeEnum.MigrateCurrentOsToVhd)
            {
                migrationData.DeleteTemporaryVhdFile    = true;
                migrationData.DestinationVhdMaxFileSize = (systemDriveInfo.AvailableFreeSpace - Constants.FiveGigs + Constants.OneGig) + (200 << 20);
                migrationData.DesiredTempVhdShrinkSize  = (systemDriveInfo.TotalSize - (systemDriveInfo.AvailableFreeSpace - Constants.FiveGigs));
                migrationData.VhdFileDestinationFolder  = $"{migrationData.OperatingSystemDriveLetter}:\\VHD_Boot";
            }

            return(migrationData);
        }
        /// <summary>
        /// Sets up all the in memory column information cache and objects that are reused in ProcessInput
        /// ToDo:
        /// Cache input column information
        /// Cache output column information
        /// Setup NAudio objects
        /// Setup SpeechClient objects
        /// </summary>
        public override void PreExecute()
        {
            bool   fireAgain     = true;
            string DefaultLocale = string.Empty;

            this.ComponentMetaData.FireInformation(0, this.ComponentMetaData.Name, "Pre-Execute phase is beginning.", string.Empty, 0, ref fireAgain);
            // Load up the custom properties.
            SubscriptionKey   = (string)ComponentMetaData.CustomPropertyCollection[Utility.SubscriptionKeyPropName].Value;
            OperationMode     = (OperationModeEnum)ComponentMetaData.CustomPropertyCollection[Utility.OperationModePropName].Value;
            Language          = (SpeechLanguageEnum)ComponentMetaData.CustomPropertyCollection[Utility.LanguagePropName].Value;
            ChannelSeparation = (ChannelSeparationEnum)ComponentMetaData.CustomPropertyCollection[Utility.ChannelSeparationPropName].Value;
            // ToDo: Implement this!
            string ShortPhaseUrl = (string)ComponentMetaData.CustomPropertyCollection[Utility.ShortPhraseUrlPropName].Value;
            string LongPhaseUrl  = (string)ComponentMetaData.CustomPropertyCollection[Utility.LongPhraseUrlPropName].Value;

            switch (OperationMode)
            {
            case OperationModeEnum.ShortDictation:
                SpeechServiceUri = new Uri(ShortPhaseUrl);
                break;

            case OperationModeEnum.LongDictation:
                SpeechServiceUri = new Uri(LongPhaseUrl);
                break;

            default:
                SpeechServiceUri = new Uri(LongPhaseUrl);
                break;
            }

            switch (Language)
            {
            case SpeechLanguageEnum.AmericanEnglish:
                DefaultLocale = "en-us";
                break;

            case SpeechLanguageEnum.BritishEnglish:
                DefaultLocale = "en-gb";
                break;

            case SpeechLanguageEnum.German:
                DefaultLocale = "de-de";
                break;

            case SpeechLanguageEnum.Spanish:
                DefaultLocale = "es-es";
                break;

            case SpeechLanguageEnum.French:
                DefaultLocale = "fr-fr";
                break;

            case SpeechLanguageEnum.Italian:
                DefaultLocale = "it-it";
                break;

            case SpeechLanguageEnum.Mandarin:
                DefaultLocale = "zh-cn";
                break;

            default:
                DefaultLocale = "en-us";
                break;
            }

            //RM             this.dataClient = SpeechRecognitionServiceFactory.CreateDataClient(
            //RM             this.speechRecognitionMode,
            //RM             DefaultLocale,
            //RM             this.SubscriptionKey);
            //RM             this.dataClient.ShortPhraseUrl = this.ShortPhraseUrl;

            // Event handlers for speech recognition results
            //RM             if (this.speechRecognitionMode == SpeechRecognitionMode.ShortPhrase)
            //RM             {
            //RM             this.dataClient.OnResponseReceived += this.OnDataShortPhraseResponseReceivedHandler;
            //RM         }
            //RM             else
            //RM             {
            //RM             this.dataClient.OnResponseReceived += this.OnDataDictationResponseReceivedHandler;
            //RM         }

            //this.dataClient.OnPartialResponseReceived += this.OnPartialResponseReceivedHandler;
            //RM             this.dataClient.OnConversationError += this.OnConversationErrorHandler;
            base.PreExecute();
        }
        /// <summary>
        /// 生成缩略图
        /// </summary>
        /// <param name="originalImagePath">源图路径(物理路径)</param>
        /// <param name="width">缩略图宽度</param>
        /// <param name="height">缩略图高度</param>
        /// <param name="mode">生成缩略图的方式</param>    
        public static byte[] MakeThumbnail(string originalImagePath, int width, int height, OperationModeEnum mode)
        {
            byte[] imgData;

            #region

            using (Image originalImage = Image.FromFile(originalImagePath))
            {

                int towidth = width;
                int toheight = height;

                int x = 0;
                int y = 0;
                int ow = originalImage.Width;
                int oh = originalImage.Height;

                switch (mode)
                {
                    case OperationModeEnum.HW://指定高宽缩放(可能变形)
                        break;
                    case OperationModeEnum.W://指定宽,高按比例
                        toheight = originalImage.Height * width / originalImage.Width;
                        break;
                    case OperationModeEnum.H://指定高,宽按比例
                        towidth = originalImage.Width * height / originalImage.Height;
                        break;
                    case OperationModeEnum.Cut://指定高宽裁减(不变形)
                        if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
                        {
                            oh = originalImage.Height;
                            ow = originalImage.Height * towidth / toheight;
                            y = 0;
                            x = (originalImage.Width - ow) / 2;
                        }
                        else
                        {
                            ow = originalImage.Width;
                            oh = originalImage.Width * height / towidth;
                            x = 0;
                            y = (originalImage.Height - oh) / 2;
                        }
                        break;
                    default:
                        break;
                }

                //新建一个bmp图片
                using (Image bitmap = new System.Drawing.Bitmap(towidth, toheight))
                {

                    //新建一个画板
                    Graphics g = System.Drawing.Graphics.FromImage(bitmap);

                    //设置高质量插值法
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

                    //设置高质量,低速度呈现平滑程度
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                    //清空画布并以透明背景色填充
                    g.Clear(Color.Transparent);

                    //在指定位置并且按指定大小绘制原图片的指定部分
                    g.DrawImage(originalImage, new Rectangle(0, 0, towidth, toheight),
                        new Rectangle(x, y, ow, oh),
                        GraphicsUnit.Pixel);

                    try
                    {
                        //以jpg格式保存缩略图
                        /*
                        Bitmap a = new Bitmap(bitmap);
                        a.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg);
                        a.Dispose();
                         * */

                        Bitmap a = new Bitmap(bitmap);
                        MemoryStream ms = new MemoryStream();
                        a.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                        /*
                        Bitmap a2 = new Bitmap(ms);
                        a2.Save(HttpContext.Current.Server.MapPath("/upload/s/a2.jpg"));

                         * */
                        imgData = ms.GetBuffer();
                        //new WebService1().SaveThumnail(imgData);
                        ms.Close();

                        /*
                        using (Stream stream = new MemoryStream())
                        {
                            //克隆Bitmap对象
                    Bitmap bmp = new Bitmap(bitmap);
                    bmp.Save(stream, bitmap.RawFormat);
                     bmp.Dispose();

                         * */
                    }
                    catch (System.Exception e)
                    {
                        throw e;
                        //imgData = null;
                    }
                    finally
                    {
                        g.Dispose();
                        bitmap.Dispose();
                        originalImage.Dispose();
                    }
                    return imgData;
                }
            }

            #endregion

            #region

            /*
            System.Drawing.Image img = System.Drawing.Image.FromFile(originalImagePath);//源图像的信息
            System.Drawing.Imaging.ImageFormat thisformat = img.RawFormat; //源图像的格式

            Size newSize = NewSize(width, height, img.Width, img.Height); //返回调整后的图像Width与Height
            Bitmap outBmp = new Bitmap(newSize.Width, newSize.Height);
            Graphics g = Graphics.FromImage(outBmp);
            //设置画布的描绘质量(高)
            g.CompositingQuality = CompositingQuality.HighQuality;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.DrawImage(img, new Rectangle(0, 0, newSize.Width, newSize.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel);
            g.Dispose();
            //以下代码为保存图片时,设置压缩质量
            EncoderParameters encoderParams = new EncoderParameters();
            long[] quality = new long[1];
            quality[0] = 100;
            EncoderParameter encoderParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
            encoderParams.Param[0] = encoderParam;
            //获取包含有关内置图像编码解码器的信息的ImageCodecInfo对象。
            ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
            ImageCodecInfo jpegICI = null;
            for (int x = 0; x < arrayICI.Length; x++)
            {
                if (arrayICI[x].FormatDescription.Equals("JPEG"))
                {
                    jpegICI = arrayICI[x];//设置jpeg编码
                    break;
                }
            }
            try
            {
                if (jpegICI != null)
                {
                    outBmp.Save(thumbnailPath, jpegICI, encoderParams);
                }
                else
                {
                    outBmp.Save(thumbnailPath, thisformat);
                }
            }
            catch (Exception ex)
            { }
            finally {
            img.Dispose();
            outBmp.Dispose();
            }

             * */
            #endregion
        }
Beispiel #7
0
        /// <summary>
        /// Switch the operation mode.
        /// </summary>
        /// <param name="modes">Mode: wilma/stub/proxy</param>
        /// <returns>True if the request is successful, otherwise returns false.</returns>
        public async Task<bool> SetOperationModeAsync(OperationModeEnum modes)
        {
            _logger.Debug("WilmaService SetOperationMode enter with value: " + modes);

            var resp = await _httpClient.GetAsync(GetUrl(OPERATION_SETTER_URL_POSTFIX_FORMAT, modes.ToString().ToLower()));
            if (resp.IsSuccessStatusCode)
            {
                _logger.Debug("WilmaService SetOperationMode success.");
                return true;
            }

            _logger.Debug("WilmaService SetOperationMode failed: {0}", resp.StatusCode);
            return false;
        }
        /// <summary>
        /// 生成缩略图
        /// </summary>
        /// <param name="originalImagePath">源图路径(物理路径)</param>
        /// <param name="width">缩略图宽度</param>
        /// <param name="height">缩略图高度</param>
        /// <param name="mode">生成缩略图的方式</param>    
        public static byte[] MakeThumbnailLow(string originalImagePath, int width, int height, OperationModeEnum mode)
        {
            byte[] imgData;

            #region

            using (Image originalImage = Image.FromFile(originalImagePath))
            {

                int towidth = width;
                int toheight = height;

                int x = 0;
                int y = 0;
                int ow = originalImage.Width;
                int oh = originalImage.Height;

                switch (mode)
                {
                    case OperationModeEnum.HW://指定高宽缩放(可能变形)
                        break;
                    case OperationModeEnum.W://指定宽,高按比例
                        toheight = originalImage.Height * width / originalImage.Width;
                        break;
                    case OperationModeEnum.H://指定高,宽按比例
                        towidth = originalImage.Width * height / originalImage.Height;
                        break;
                    case OperationModeEnum.Cut://指定高宽裁减(不变形)
                        if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
                        {
                            oh = originalImage.Height;
                            ow = originalImage.Height * towidth / toheight;
                            y = 0;
                            x = (originalImage.Width - ow) / 2;
                        }
                        else
                        {
                            ow = originalImage.Width;
                            oh = originalImage.Width * height / towidth;
                            x = 0;
                            y = (originalImage.Height - oh) / 2;
                        }
                        break;
                    case OperationModeEnum.Auto:
                        AutoSize(ow, oh, ref towidth, ref toheight);
                        break;
                    case OperationModeEnum.AutoRefMinSize:
                        AutoRefMinSize(ow, oh, ref towidth, ref toheight);
                        break;
                    default:
                        towidth = originalImage.Width;
                        toheight = originalImage.Height;
                        break;
                }

                //新建一个bmp图片
                using (Image bitmap = new System.Drawing.Bitmap(towidth, toheight))
                {

                    //新建一个画板
                    Graphics g = System.Drawing.Graphics.FromImage(bitmap);

                    //设置高质量插值法
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;

                    //设置高质量,低速度呈现平滑程度
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;

                    //清空画布并以透明背景色填充
                    g.Clear(Color.Transparent);

                    //在指定位置并且按指定大小绘制原图片的指定部分
                    g.DrawImage(originalImage, new Rectangle(0, 0, towidth, toheight),
                        new Rectangle(x, y, ow, oh),
                        GraphicsUnit.Pixel);

                    try
                    {
                        //以jpg格式保存缩略图
                        /*
                        Bitmap a = new Bitmap(bitmap);
                        a.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg);
                        a.Dispose();
                         * */

                        Bitmap a = new Bitmap(bitmap);
                        MemoryStream ms = new MemoryStream();
                        a.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                        /*
                        Bitmap a2 = new Bitmap(ms);
                        a2.Save(HttpContext.Current.Server.MapPath("/upload/s/a2.jpg"));

                         * */
                        imgData = ms.GetBuffer();
                        //new WebService1().SaveThumnail(imgData);
                        ms.Close();

                        /*
                        using (Stream stream = new MemoryStream())
                        {
                            //克隆Bitmap对象
                    Bitmap bmp = new Bitmap(bitmap);
                    bmp.Save(stream, bitmap.RawFormat);
                     bmp.Dispose();

                         * */
                    }
                    catch (System.Exception e)
                    {
                        throw e;
                        //imgData = null;
                    }
                    finally
                    {
                        g.Dispose();
                        bitmap.Dispose();
                        originalImage.Dispose();
                    }
                    return imgData;
                }
            }
            #endregion
        }