Пример #1
0
        public void Convert(ConvertParams args, BinaryWriter bw)
        {
            var toDsc = new DataSubChunk();
            toDsc.Setup(mDsc.subChunk2Size, mDsc.data);

            switch (args.ditherType) {
            case ConvertParams.DitherType.NoiseShaping:
                args.order = 1;
                args.filter = new double[] {1, -1};
                ReduceBitsPerSample24Ns2(args, toDsc);
                break;
            case ConvertParams.DitherType.NoiseShaping2:
                args.order = 2;
                args.filter = new double[] {1, -2, 1};
                ReduceBitsPerSample24Ns2(args, toDsc);
                break;
            case ConvertParams.DitherType.NoiseShapingMash2:
                ReduceBitsPerSample24Mash2(args, toDsc);
                break;
            default:
                ReduceBitsPerSample24Other(args, toDsc);
                break;
            }

            mRcd.Write(bw);
            mFsc.Write(bw);
            toDsc.Write(bw);
        }
        protected void start_thread()
        {
            while (true)
            {
                try
                {
                    ConvertParams data = WxHelper.GetAccessToken(SiteConfig.Instance.AppID, SiteConfig.Instance.AppSecret);

                    if (data != null)
                    {
                        var    model    = db1.wx_settings.Where(c => c.ID == 1).FirstOrDefault();
                        string ticketzj = WxHelper.Getjsapi_ticket(data.access_token);
                        model.access_token = data.access_token;
                        model.jsapi_ticket = ticketzj;
                        model.updateTime   = DateTime.Now;
                        db1.SaveChanges();
                        // 休眠7000秒
                        Thread.Sleep((data.expires_in - 200) * 1000);
                    }
                    else
                    {
                        // 如果access_token为null,60秒后再获取
                        Thread.Sleep(60 * 1000);
                    }
                }
                catch (Exception)
                {
                    Thread.Sleep(60 * 1000);
                }
            }
        }
Пример #3
0
        public void Convert(ConvertParams args, BinaryWriter bw)
        {
            var toDsc = new DataSubChunk();

            toDsc.Setup(mDsc.subChunk2Size, mDsc.data);

            switch (args.ditherType)
            {
            case ConvertParams.DitherType.NoiseShaping:
                args.order  = 1;
                args.filter = new double[] { 1, -1 };
                ReduceBitsPerSample24Ns2(args, toDsc);
                break;

            case ConvertParams.DitherType.NoiseShaping2:
                args.order  = 2;
                args.filter = new double[] { 1, -2, 1 };
                ReduceBitsPerSample24Ns2(args, toDsc);
                break;

            case ConvertParams.DitherType.NoiseShapingMash2:
                ReduceBitsPerSample24Mash2(args, toDsc);
                break;

            default:
                ReduceBitsPerSample24Other(args, toDsc);
                break;
            }

            mRcd.Write(bw);
            mFsc.Write(bw);
            toDsc.Write(bw);
        }
Пример #4
0
        private void ReduceBitsPerSample24Ns2(ConvertParams args, DataSubChunk toDsc)
        {
            var ns = new NoiseShaper2[mFsc.numChannels];

            for (int ch = 0; ch < mFsc.numChannels; ++ch)
            {
                ns[ch] = new NoiseShaper2(args.order, args.filter, args.newQuantizationBitrate);
            }

            int bytesPerFrame = mFsc.numChannels * mFsc.bitsPerSample / 8;
            int numFrames     = toDsc.data.Length / bytesPerFrame;

            int readPos  = 0;
            int writePos = 0;

            for (int i = 0; i < numFrames; ++i)
            {
                for (int ch = 0; ch < mFsc.numChannels; ++ch)
                {
                    int sample = 0;

                    sample   = ns[ch].Filter24(ReadSampleValue24(toDsc, readPos));
                    readPos += mFsc.bitsPerSample / 8;

                    WriteSampleValue24(toDsc, writePos, sample);
                    writePos += mFsc.bitsPerSample / 8;
                }
            }
        }
Пример #5
0
        static void _ConvertAll(ConvertType eConvertType)
        {
            if (ms_locked)
            {
                return;
            }
            ms_locked = true;

            ms_beginTime = System.DateTime.Now.Ticks;

            var dir = Path.GetFullPath(Application.dataPath + ExcelConfig.XLSX_PATH);

            string[] strList = Directory.GetFiles(dir, "Z-资源配置表.xls", SearchOption.AllDirectories);
            Debug.LogFormat("[npoi] start convert sum = {0}", strList.Length);
            ms_num = 0;
            contents.Clear();
            for (int i = 0; i < strList.Length; ++i)
            {
                string name = Path.GetFileName(strList[i]);

                ConvertParams param = new ConvertParams
                {
                    name            = name,
                    index           = i,
                    sum             = strList.Length,
                    applicationPath = Application.dataPath,
                    eConvertType    = eConvertType,
                };

                contents.Add(param);
            }

            int iThreadMax = 1;

            if (iThreadMax == 0)
            {
                _ConvertTable(contents);
            }
            else
            {
                int      iMaxThread = iThreadMax <= contents.Count ? iThreadMax : contents.Count;
                Thread[] threads    = new Thread[iMaxThread];
                for (int i = 0; i < threads.Length; ++i)
                {
                    threads[i]          = new Thread(_ConvertTable);
                    threads[i].Priority = System.Threading.ThreadPriority.Highest;
                    threads[i].Start(contents);
                }
            }
        }
Пример #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["usermodel"] == null)
            {
                string action      = Request["state"];
                string code        = Request["code"];
                string redirecturl = HttpUtility.UrlDecode(Request["redirecturl"]);
                if (!string.IsNullOrEmpty(code))
                {
                    if (action == "userinfo")
                    {
                        string str = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + SiteConfig.Instance.AppID + "&secret=" + SiteConfig.Instance.AppSecret + "&code=" + code + "&grant_type=authorization_code";

                        string param = RequestType.HttpPost(str, "");

                        ConvertParams returnparam = JsonConvert.DeserializeObject <ConvertParams>(param);

                        string str1 = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=" + SiteConfig.Instance.AppID + "&grant_type=refresh_token&refresh_token=" + returnparam.refresh_token;

                        string param1 = RequestType.HttpPost(str1, "");

                        ConvertParams returnparam1 = JsonConvert.DeserializeObject <ConvertParams>(param1);

                        string str2 = "https://api.weixin.qq.com/sns/userinfo?access_token=" + returnparam1.access_token + "&openid=" + returnparam1.openid + "&lang=zh_CN";

                        string param2 = RequestType.HttpPost(str2, "");

                        UserInfo userinfo = JsonConvert.DeserializeObject <UserInfo>(param2);

                        user = userinfo;

                        Session["usermodel"] = userinfo;

                        if (!string.IsNullOrEmpty(redirecturl))
                        {
                            Response.Redirect(redirecturl);
                        }
                    }
                }
                else
                {
                    Response.Redirect("https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + SiteConfig.Instance.AppID + "&redirect_uri=" + HttpUtility.UrlEncode(Request.Url.ToString()) + "&response_type=code&scope=snsapi_userinfo&state=userinfo&redirecturl=" + redirecturl + "#wechat_redirect");
                }
            }
            else
            {
                user = Session["usermodel"] as UserInfo;
            }
        }
Пример #7
0
        public static void _ConvertTable(object param)
        {
            while (true)
            {
                ConvertParams curParam = null;
                int           iNum     = 0;
                lock (param)
                {
                    var contents = param as List <ConvertParams>;
                    if (null != contents && contents.Count > 0)
                    {
                        curParam = contents [0];
                        contents.RemoveAt(0);
                    }
                }

                if (null == curParam)
                {
                    break;
                }

                if (ExcelManager.Instance().Convert(curParam.applicationPath, curParam.name, curParam.eConvertType))
                {
                    lock (param)
                    {
                        iNum = ++ms_num;
                    }
                    Debug.LogFormat("[npoi] convert [{0}/{1}] <color=#00ff00>{2}</color> ok !!!", iNum, curParam.sum, curParam.name);
                }
                else
                {
                    lock (param)
                    {
                        iNum = ++ms_num;
                    }
                    Debug.LogErrorFormat("[npoi] convert [{0}/{1}] <color=#ffff00>{2}</color> failed !!!", iNum, curParam.sum, curParam.name);
                }

                if (iNum == curParam.sum)
                {
                    _OnConvertDone();
                }
            }
        }
        public IActionResult Post([FromBody] ConvertParams convertParams)
        {
            int count = 0;

            foreach (string ext in convertParams.extentions)
            {
                foreach (string fileName in Directory.EnumerateFiles(convertParams.folderFrom, "*." + ext))
                {
                    using (MagickImage image = new MagickImage(fileName))
                    {
                        // Save frame as jpg
                        image.Write(Path.Combine(convertParams.folderTo, Path.GetFileNameWithoutExtension(fileName) + ".jpg"));
                        count++;
                    }
                }
            }

            return(Ok(new { count }));
        }
Пример #9
0
        private void ReduceBitsPerSample24Mash2(ConvertParams args, DataSubChunk toDsc)
        {
            var mash = new NoiseShaperMash[mFsc.numChannels];

            for (int ch = 0; ch < mFsc.numChannels; ++ch)
            {
                mash[ch] = new NoiseShaperMash(args.newQuantizationBitrate);
            }

            int bytesPerFrame = mFsc.numChannels * mFsc.bitsPerSample / 8;
            int numFrames     = toDsc.data.Length / bytesPerFrame;

            int readPos  = 0;
            int writePos = 0;

            // 1サンプル遅延するので…。
            for (int i = 0; i < numFrames + 1; ++i)
            {
                for (int ch = 0; ch < mFsc.numChannels; ++ch)
                {
                    int sample = 0;

                    if (i < numFrames)
                    {
                        sample   = mash[ch].Filter24(ReadSampleValue24(toDsc, readPos));
                        readPos += mFsc.bitsPerSample / 8;
                    }
                    else
                    {
                        sample = mash[ch].Filter24(0);
                    }

                    if (1 <= i)
                    {
                        WriteSampleValue24(toDsc, writePos, sample);
                        writePos += mFsc.bitsPerSample / 8;
                    }
                }
            }
        }
Пример #10
0
 private static Func <Func <string, (Error error, Edmx edmx)>, Result <Edmx> > MapEdmx(ConvertParams @params) =>
 mapper =>
 {
     var edmxOrError = mapper(@params.Edmx);
     return(edmxOrError.error != Error.Empty
             ? Result.Fail <Edmx>(edmxOrError.error.Message)
             : Result.Ok(edmxOrError.edmx));
 };
Пример #11
0
 private static Func <Edmx, ConvertEdmxArgs> Convert(ConvertParams @params) =>
 edmx => new ConvertEdmxArgs(edmx, @params.Source, @params.Target);
Пример #12
0
 public static Result <ConvertEdmxArgs> CreateArguments(ConvertParams convParams) =>
 FlowHelpers.With(convParams)
 .OnSuccess(GetEdmxMapper())
 .OnSuccess(MapEdmx(convParams))
 .OnSuccess(Convert(convParams));
Пример #13
0
 public static bool RunCommand(ConvertParams paramObj)
 {
     return(RunCommand(paramObj.ToString()));
 }
Пример #14
0
        private void ReduceBitsPerSample24Ns2(ConvertParams args, DataSubChunk toDsc)
        {
            var ns = new NoiseShaper2[mFsc.numChannels];
            for (int ch=0; ch < mFsc.numChannels; ++ch) {
                ns[ch] = new NoiseShaper2(args.order, args.filter, args.newQuantizationBitrate);
            }

            int bytesPerFrame = mFsc.numChannels * mFsc.bitsPerSample / 8;
            int numFrames = toDsc.data.Length / bytesPerFrame;

            int readPos = 0;
            int writePos = 0;
            for (int i=0; i < numFrames; ++i) {
                for (int ch=0; ch < mFsc.numChannels; ++ch) {
                    int sample = 0;

                    sample = ns[ch].Filter24(ReadSampleValue24(toDsc, readPos));
                    readPos += mFsc.bitsPerSample / 8;

                    WriteSampleValue24(toDsc, writePos, sample);
                    writePos += mFsc.bitsPerSample / 8;
                }
            }
        }
Пример #15
0
        private void ReduceBitsPerSample24Other(ConvertParams args, DataSubChunk toDsc)
        {
            uint mask = 0xffffffff << (24 - args.newQuantizationBitrate);
            uint maskError = ~mask;
            var gen = new RNGCryptoServiceProvider();
            var gng = new GaussianNoiseGenerator();
            var randomNumber = new byte[3];
            int noiseMagnitude = (int)Math.Pow(2, (24 - args.newQuantizationBitrate))/2;

            Console.WriteLine("D: maskErr={0:X}", maskError);

            int bytesPerFrame = mFsc.numChannels * mFsc.bitsPerSample / 8;
            int numFrames = toDsc.data.Length / bytesPerFrame;

            int pos = 0;
            for (int i=0; i < numFrames; ++i) {
                for (int ch=0; ch < mFsc.numChannels; ++ch) {
                    double sample = ReadSampleValue24(toDsc, pos);
                    uint error = (uint)sample & maskError;
                    sample -= error;

                    switch (args.ditherType) {
                    case ConvertParams.DitherType.Truncate:
                        break;
                    case ConvertParams.DitherType.RpdfDither:
                        gen.GetBytes(randomNumber);
                        int randDither = (int)((randomNumber[0]) + (randomNumber[1] << 8) + (randomNumber[2]<<16) & ~mask);
                        sample += randDither;
                        break;
                    case ConvertParams.DitherType.GaussianDither:
                        float noise = gng.NextFloat();
                        noise *= noiseMagnitude;
                        sample += (int)noise;
                        break;
                    default:
                        System.Diagnostics.Debug.Assert(false);
                        break;
                    }

                    if (0x7fffff < sample) {
                        sample = 0x7fffff;
                    }
                    if (sample < -0x800000) {
                        sample = -0x800000;
                    }

                    WriteSampleValue24(toDsc, pos, (int)sample);

                    pos += mFsc.bitsPerSample / 8;
                }
            }
        }
Пример #16
0
        string ConvertToPDF(CallType callType, string fileName = "file", int count = 1, int threads = 1)
        {
            InitConsole();

            string name;
            string ext;

            if (callType == CallType.Console)
            {
                name = ConfigurationManager.AppSettings["SourcePath"] + Path.GetFileNameWithoutExtension(fileName);;
                ext  = !string.IsNullOrEmpty(Path.GetExtension(fileName)) ? Path.GetExtension(fileName) : "docx";
            }
            else
            {
                name = fileName;
                ext  = "";
            }

            var parametersDocx = new ConvertParams
            {
                Count          = count,
                Config         = _config,
                ResultFileName = name,
                FileType       = ext
            };

            var total      = count;
            var offset     = total / threads;
            var parameters = new DownloadParams
            {
                Offset   = 0,
                Count    = offset,
                Config   = _config,
                FileName = name,
                FileType = ext
            };

            for (int i = 0; i < threads; i++)
            {
                parameters.Offset = i * offset;
                var uploadDocx1 = new WordConvertThread("Convert DOCX", parametersDocx);
            }
            return("Convert success!");

            //var parametersXlsx = new ConvertParams
            //{
            //    Count = 500,
            //    Config = _config,
            //    ResultFileName = "New",
            //    FileType = "xlsx"
            //};
            //var parametersPptx = new ConvertParams
            //{
            //    Count = 500,
            //    Config = _config,
            //    ResultFileName = "New",
            //    FileType = "pptx"
            //};

            //var uploadDocx1 = new WordConvertThread("Convert first 500 DOCX", parametersDocx);
            //parametersDocx.ResultFileName = "New1";
            //var uploadDocx2 = new WordConvertThread("Convert second 500 DOCX", parametersDocx);
            //parametersDocx.ResultFileName = "New2";
            //var uploadDocx3 = new WordConvertThread("Convert third 500 DOCX", parametersDocx);

            //var uploadXlsx1 = new WordConvertThread("Convert first 500 XLSX", parametersXlsx);
            //parametersXlsx.ResultFileName = "New1";
            //var uploadXlsx2 = new WordConvertThread("Convert second 500 XLSX", parametersXlsx);
            //parametersXlsx.ResultFileName = "New2";
            //var uploadXlsx3 = new WordConvertThread("Convert third 500 XLSX", parametersXlsx);

            //var uploadPptx1 = new WordConvertThread("Convert first 500 PPTX", parametersPptx);
            //parametersPptx.ResultFileName = "New1";
            //var uploadPptx2 = new WordConvertThread("Convert second 500 PPTX", parametersPptx);
            //parametersPptx.ResultFileName = "New2";
            //var uploadPptx3 = new WordConvertThread("Convert third 500 PPTX", parametersPptx);
        }
Пример #17
0
 public static Result <ConvertParams> Validate(ConvertParams payload) =>
 FlowHelpers.With(payload)
 .Ensure(x => !string.IsNullOrWhiteSpace(x.Edmx), "Source EDMX should not be empty.")
 .Ensure(x => x.Source != payload.Target, "Source and target types are the same.");
Пример #18
0
        private void ReduceBitsPerSample24Other(ConvertParams args, DataSubChunk toDsc)
        {
            uint mask           = 0xffffffff << (24 - args.newQuantizationBitrate);
            uint maskError      = ~mask;
            var  gen            = new RNGCryptoServiceProvider();
            var  gng            = new GaussianNoiseGenerator();
            var  randomNumber   = new byte[3];
            int  noiseMagnitude = (int)Math.Pow(2, (24 - args.newQuantizationBitrate)) / 2;

            Console.WriteLine("D: maskErr={0:X}", maskError);

            int bytesPerFrame = mFsc.numChannels * mFsc.bitsPerSample / 8;
            int numFrames     = toDsc.data.Length / bytesPerFrame;

            int pos = 0;

            for (int i = 0; i < numFrames; ++i)
            {
                for (int ch = 0; ch < mFsc.numChannels; ++ch)
                {
                    double sample = ReadSampleValue24(toDsc, pos);
                    uint   error  = (uint)sample & maskError;
                    sample -= error;

                    switch (args.ditherType)
                    {
                    case ConvertParams.DitherType.Truncate:
                        break;

                    case ConvertParams.DitherType.RpdfDither:
                        gen.GetBytes(randomNumber);
                        int randDither = (int)((randomNumber[0]) + (randomNumber[1] << 8) + (randomNumber[2] << 16) & ~mask);
                        sample += randDither;
                        break;

                    case ConvertParams.DitherType.GaussianDither:
                        float noise = gng.NextFloat();
                        noise  *= noiseMagnitude;
                        sample += (int)noise;
                        break;

                    default:
                        System.Diagnostics.Debug.Assert(false);
                        break;
                    }

                    if (0x7fffff < sample)
                    {
                        sample = 0x7fffff;
                    }
                    if (sample < -0x800000)
                    {
                        sample = -0x800000;
                    }

                    WriteSampleValue24(toDsc, pos, (int)sample);

                    pos += mFsc.bitsPerSample / 8;
                }
            }
        }
Пример #19
0
        private void ReduceBitsPerSample24Mash2(ConvertParams args, DataSubChunk toDsc)
        {
            var mash = new NoiseShaperMash[mFsc.numChannels];
            for (int ch=0; ch < mFsc.numChannels; ++ch) {
                mash[ch] = new NoiseShaperMash(args.newQuantizationBitrate);
            }

            int bytesPerFrame = mFsc.numChannels * mFsc.bitsPerSample / 8;
            int numFrames = toDsc.data.Length / bytesPerFrame;

            int readPos = 0;
            int writePos = 0;

            // 1サンプル遅延するので…。
            for (int i=0; i < numFrames + 1; ++i) {
                for (int ch=0; ch < mFsc.numChannels; ++ch) {
                    int sample = 0;

                    if (i < numFrames) {
                        sample = mash[ch].Filter24(ReadSampleValue24(toDsc, readPos));
                        readPos += mFsc.bitsPerSample / 8;
                    } else {
                        sample = mash[ch].Filter24(0);
                    }

                    if (1 <= i) {
                        WriteSampleValue24(toDsc, writePos, sample);
                        writePos += mFsc.bitsPerSample / 8;
                    }
                }
            }
        }