public List <ProcessResultModel> procUpdStatWIse(string parameterBody)
        {
            var connectionString = context.Database.GetDbConnection().ConnectionString;
            List <ProcessResultModel> procUpdStatWIse = new List <ProcessResultModel>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                //Declare COnnection
                var        querySstring = "spMKT_POLO_APIUPDATEDATA_FROM_MSSWISE";
                SqlCommand command      = new SqlCommand(querySstring, connection);
                command.CommandType = System.Data.CommandType.StoredProcedure;

                //Define Query Parameter
                command.Parameters.AddWithValue("@parameterBody", parameterBody);

                //open Connection
                command.Connection.Open();

                //PRoses Sp
                SqlDataReader rd = command.ExecuteReader();
                while (rd.Read())
                {
                    ProcessResultModel data = new ProcessResultModel();
                    data.responseCode    = rd[0].ToString();
                    data.responseMessage = rd[1].ToString();
                    data.errorMessage    = rd[2].ToString();
                    procUpdStatWIse.Add(data);
                }

                //Connection Close
                command.Connection.Close();
            }

            return(procUpdStatWIse);
        }
        public async Task <IActionResult> GetMPoloQuestionLabel()
        {
            var    processResult = new ProcessResultModel();
            string parameterBody = "";

            using (StreamReader stream = new StreamReader(Request.Body))
            {
                parameterBody = await stream.ReadToEndAsync();
            }
            MMktPoloQuestionLabelProvider mMktPoloQuestionLabelProvider = new MMktPoloQuestionLabelProvider();
            var data = mMktPoloQuestionLabelProvider.getQuestionLabel(parameterBody);

            if (data.Count == 0)
            {
                return(NotFound(data));
            }
            return(Ok(data));
        }
示例#3
0
        public List <ProcessResultModel> getQuestionLabel(string parameterBody)
        {
            var connectionString = context.Database.GetDbConnection().ConnectionString;
            List <ProcessResultModel> mMktPoloQuestionLabels = new List <ProcessResultModel>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                //Declare COnnection
                var        querySstring = "spMKT_POLO_APIPROCESS";
                SqlCommand command      = new SqlCommand(querySstring, connection);
                command.CommandType = System.Data.CommandType.StoredProcedure;

                //Define Query Parameter
                command.Parameters.AddWithValue("@parameterBody", parameterBody);

                //open Connection
                command.Connection.Open();

                //PRoses Sp
                SqlDataReader rd = command.ExecuteReader();
                while (rd.Read())
                {
                    ProcessResultModel data = new ProcessResultModel();
                    data.responseMessage = rd[0].ToString();
                    data.responseCode    = rd[1].ToString();
                    data.errorMessage    = rd[2].ToString();
                    mMktPoloQuestionLabels.Add(data);
                }

                //Connection Close
                command.Connection.Close();
                Console.WriteLine("test");
            }

            return(mMktPoloQuestionLabels);
        }
示例#4
0
        /// <inheritdoc/>
        public async Task <ProcessResultModel> ProcessAsync(ProcessPathCommand command, CancellationToken ct)
        {
            Ensure.ArgumentNotNull(command, nameof(command));
            Ensure.ArgumentNotNull(ct, nameof(ct));

            ImageFormat imageFormat    = GetImageFormat(command.ImageFormat);
            string      imageExtension = imageFormat.FileExtensionFromEncoder();

            if (string.IsNullOrWhiteSpace(imageExtension))
            {
                throw new UnexpectedNullException("Image file extension could not be determined.");
            }

            var fs = fileSystemStrategy.Create(command.DestinationPath);

            if (fs == null)
            {
                throw new UnexpectedNullException("Filesystem could not be created based on the destination path.");
            }

            var reader = readerFactory.Create();

            if (reader == null)
            {
                throw new UnexpectedNullException("Image reader could not be created.");
            }

            await reader.InitAsync(command.SourcePath, ct);

            reader.Mapper = new AxisPositionMapper(command.AmountPerAxis, reader.Width, reader.Height, reader.Depth);

            PreProcess(reader, imageFormat, command.AmountPerAxis, command.OutputSize);

            var result = new ProcessResultModel
            {
                LabelCount = Convert.ToInt32(reader.GetLabelCount()),
                Size       = new int[] { reader.Width, reader.Height, reader.Depth }
            };

            ISet <AxisType> axisTypes = new HashSet <AxisType>(command.AxisTypes);

            if (axisTypes.Count == 0)
            {
                axisTypes = new HashSet <AxisType> {
                    AxisType.Z
                };
            }

            BitmapWrapper watermark = null;

            if (!string.IsNullOrWhiteSpace(command.WatermarkSourcePath))
            {
                BitmapReader bitmapReader    = new BitmapReader();
                var          watermarkBitmap = await bitmapReader.ReadAsync(command.WatermarkSourcePath, command.OutputSize, ct);

                if (watermarkBitmap == null)
                {
                    throw new UnexpectedNullException("Watermark could not be read.");
                }

                watermark = new BitmapWrapper(watermarkBitmap);
            }

            var images = new List <PositionAxisContainerModel <string> >();

            foreach (AxisType axisType in axisTypes)
            {
                for (int i = 0; i < reader.Mapper.GetLength(axisType); i++)
                {
                    ct.ThrowIfCancellationRequested();

                    string filename = $"{axisType}_{i}{imageExtension}";

                    var image = WriteImage(i, fs, command, reader, axisType, imageFormat, filename, watermark);
                    if (image != null)
                    {
                        images.Add(image);
                    }
                }
            }

            reader.Dispose();

            result.Images = images.OrderBy(e => e.Position).ToList();

            return(result);
        }
        /// <summary>
        /// Processes the images asynchronous.
        /// </summary>
        /// <param name="command">The command information.</param>
        /// <param name="ct">The cancellation token.</param>
        /// <returns>
        /// The result of the image processing.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// command
        /// or
        /// ct
        /// </exception>
        /// <exception cref="UnexpectedNullException">
        /// Image file extension could not be determined.
        /// or
        /// Filesystem could not be created based on the destination path.
        /// or
        /// Image reader could not be created.
        /// or
        /// Watermark could not be read.
        /// or
        /// Bitmap could not be centered.
        /// </exception>
        public async Task <ProcessResultModel> ProcessAsync(ProcessPathCommand command, CancellationToken ct)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            if (ct == null)
            {
                throw new ArgumentNullException(nameof(ct));
            }

            var result         = new ProcessResultModel();
            var imageFormat    = GetImageFormat(command.ImageFormat);
            var imageExtension = imageFormat.FileExtensionFromEncoder();

            if (string.IsNullOrWhiteSpace(imageExtension))
            {
                throw new UnexpectedNullException("Image file extension could not be determined.");
            }

            var fs = fileSystemStrategy.Create(command.DestinationPath);

            if (fs == null)
            {
                throw new UnexpectedNullException("Filesystem could not be created based on the destination path.");
            }

            var reader = readerFactory.Create();

            if (reader == null)
            {
                throw new UnexpectedNullException("Image reader could not be created.");
            }

            await reader.InitAsync(command.SourcePath, ct);

            reader.Mapper = new AxisPositionMapper(Convert.ToUInt32(command.AmountPerAxis), reader.Width, reader.Height, reader.Depth);

            PreProcess(reader, imageFormat, Convert.ToUInt32(command.AmountPerAxis), Convert.ToUInt32(command.DesiredSize));

            result.LabelCount = Convert.ToInt32(reader.GetLabelCount());

            ISet <AxisType> axisTypes = new HashSet <AxisType>(command.AxisTypes);

            if (axisTypes.Count == 0)
            {
                axisTypes = reader.GetRecommendedAxisTypes();
            }

            BitmapWrapper watermark = null;

            if (!string.IsNullOrWhiteSpace(command.WatermarkSourcePath))
            {
                BitmapReader bitmapReader    = new BitmapReader();
                var          watermarkBitmap = await bitmapReader.ReadAsync(command.WatermarkSourcePath, Convert.ToUInt32(command.DesiredSize), ct);

                if (watermarkBitmap == null)
                {
                    throw new UnexpectedNullException("Watermark could not be read.");
                }

                watermark = new BitmapWrapper(watermarkBitmap);
            }

            var images = new List <PositionAxisContainerModel <string> >();

            foreach (AxisType axisType in axisTypes)
            {
                for (int i = 0; i < command.AmountPerAxis; i++)
                {
                    ct.ThrowIfCancellationRequested();
                    string filename = $"{axisType}_{i}{imageExtension}";
                    var    bitmap   = reader.ExtractPosition(axisType, Convert.ToUInt32(i), Convert.ToUInt32(command.DesiredSize));
                    if (bitmap != null)
                    {
                        if (command.Grayscale)
                        {
                            bitmap = bitmap.To8bppIndexedGrayscale();
                        }

                        bitmap = bitmap.ToCenter(Convert.ToUInt32(command.DesiredSize), Color.Black);
                        if (bitmap == null)
                        {
                            throw new UnexpectedNullException("Bitmap could not be centered.");
                        }

                        if (watermark != null)
                        {
                            bitmap = bitmap.AppendWatermark(watermark);
                        }

                        fs.File.WriteAllBytes(fs.Path.Combine(command.DestinationPath, filename), bitmap.ToByteArray(imageFormat));
                        images.Add(new PositionAxisContainerModel <string>(Convert.ToUInt32(i), axisType, filename));
                    }
                }
            }

            result.Images = images.OrderBy(e => e.Position).ToList();

            return(result);
        }