コード例 #1
0
        private void CheckStatus(TransportClass1 oTransportClass1, TaskResultData oTaskResultData)
        {
            switch (oTaskResultData.eStatus)
            {
            case FileStatus.Ok:
                string sFilename   = HttpUtility.UrlEncode("output." + FileFormats.ToString(oTransportClass1.m_oInputParams.m_nOutputtype));
                string sPath       = HttpUtility.UrlEncode(Path.GetFileNameWithoutExtension(oTransportClass1.m_oInputParams.m_sKey) + "/output." + FileFormats.ToString(oTransportClass1.m_oInputParams.m_nOutputtype));
                string sDeletePath = HttpUtility.UrlEncode(Path.GetFileNameWithoutExtension(oTransportClass1.m_oInputParams.m_sKey));

                string sSiteUrl = UrlBuilder.UrlWithoutPath(oTransportClass1.m_oHttpContext.Request);

                string strFileUrl = sSiteUrl + Constants.mc_sResourceServiceUrlRel + sPath + "&nocache=true" + "&deletepath=" + sDeletePath + "&filename=" + sFilename;
                WriteOutputCommand(oTransportClass1, new OutputCommand(strFileUrl, "100", true, ErrorTypes.NoError));
                break;

            case FileStatus.WaitQueue:
                if (oTransportClass1.m_oInputParams.m_bAsyncConvert)
                {
                    WriteOutputCommand(oTransportClass1, new OutputCommand("", "0", false, ErrorTypes.NoError));
                }
                else
                {
                    WaitEnd(oTransportClass1);
                }
                break;

            case FileStatus.Convert:
                if (oTransportClass1.m_oInputParams.m_bAsyncConvert)
                {
                    WriteOutputCommand(oTransportClass1, new OutputCommand("", oTaskResultData.nStatusInfo.ToString(), false, ErrorTypes.NoError));
                }
                else
                {
                    WaitEnd(oTransportClass1);
                }
                break;

            case FileStatus.Err:
            case FileStatus.ErrToReload:
                AsyncClearCacheOperation oAsyncClearCacheOperation = new AsyncClearCacheOperation();
                TransportClass2          oTransportClass2          = new TransportClass2(oTransportClass1, oAsyncClearCacheOperation, (ErrorTypes)oTaskResultData.nStatusInfo);
                oAsyncClearCacheOperation.ClearCacheBegin(oTransportClass1.m_oInputParams.m_sKey, ClearCacheCallback, oTransportClass2);
                break;

            default:
                WriteOutputCommand(oTransportClass1, new OutputCommand(null, null, null, ErrorTypes.Unknown));
                break;
            }
        }
コード例 #2
0
        private void GetOrCreateCallback(IAsyncResult ar)
        {
            TransportClass1 oTransportClass1 = ar.AsyncState as TransportClass1;

            try
            {
                TaskResultData oTaskResultData;
                bool           bCreate;
                ErrorTypes     eError = oTransportClass1.m_oTaskResult.GetOrCreateEnd(ar, out oTaskResultData, out bCreate);
                if (ErrorTypes.NoError == eError)
                {
                    if (bCreate)
                    {
                        InputParams   oInputParams   = oTransportClass1.m_oInputParams;
                        TaskQueueData oTaskQueueData = new TaskQueueData(oInputParams.m_sKey, oInputParams.m_nOutputtype, "output." + FileFormats.ToString(oInputParams.m_nOutputtype));
                        oTaskQueueData.m_sFromUrl    = oInputParams.m_sUrl;
                        oTaskQueueData.m_sFromFormat = oInputParams.m_sFiletype;
                        if (null != oInputParams.m_sDelimiter && string.Empty != oInputParams.m_sDelimiter)
                        {
                            oTaskQueueData.m_nCsvDelimiter = int.Parse(oInputParams.m_sDelimiter);
                        }
                        else
                        {
                            oTaskQueueData.m_nCsvDelimiter = (int)CsvDelimiter.Comma;
                        }
                        if (null != oInputParams.m_sCodepage && string.Empty != oInputParams.m_sCodepage)
                        {
                            oTaskQueueData.m_nCsvTxtEncoding = int.Parse(oInputParams.m_sCodepage);
                        }
                        else
                        {
                            oTaskQueueData.m_nCsvTxtEncoding = Encoding.UTF8.CodePage;
                        }
                        if ("true" == oInputParams.m_sEmbeddedfonts)
                        {
                            oTaskQueueData.m_bEmbeddedFonts = true;
                        }
                        oTransportClass1.m_oTaskQueue.AddTaskBegin(oTaskQueueData, Priority.Low, AddTaskCallback, oTransportClass1);
                    }
                    else
                    {
                        CheckStatus(oTransportClass1, oTaskResultData);
                    }
                }
                else
                {
                    WriteOutputCommand(oTransportClass1, new OutputCommand(null, null, null, eError));
                }
            }
            catch
            {
                WriteOutputCommand(oTransportClass1, new OutputCommand(null, null, null, ErrorTypes.Unknown));
            }
        }
コード例 #3
0
        private void ReadContextCallback(IAsyncResult ar)
        {
            TransportClass2 oTransportClass2 = ar.AsyncState as TransportClass2;

            try
            {
                ErrorTypes eError = oTransportClass2.m_oAsyncContextReadOperation.ReadContextEnd(ar);
                if (ErrorTypes.NoError == eError)
                {
                    HttpPostedFile oCurrentFile = ((HttpPostedFile)oTransportClass2.m_oFiles[(string)oTransportClass2.m_oFilesEnumerator.Current]);
                    oCurrentFile.InputStream.Position = 0;
                    Stream oImageStream      = oCurrentFile.InputStream;
                    byte[] aBuffer           = oTransportClass2.m_oAsyncContextReadOperation.m_aOutput.ToArray();
                    int    nImageFormat      = FormatChecker.GetFileFormat(aBuffer);
                    string sSupportedFormats = ConfigurationSettings.AppSettings["limits.image.types.upload"] ?? "jpg";
                    if (0 != (FileFormats.AVS_OFFICESTUDIO_FILE_IMAGE & nImageFormat) && -1 != sSupportedFormats.IndexOf(FileFormats.ToString(nImageFormat)))
                    {
                        if (FileFormats.AVS_OFFICESTUDIO_FILE_IMAGE_GIF == nImageFormat || FileFormats.AVS_OFFICESTUDIO_FILE_IMAGE_ICO == nImageFormat)
                        {
                            byte[] aNewBuffer;
                            if (Utils.ConvertGifIcoToPng(aBuffer, nImageFormat, out aNewBuffer))
                            {
                                nImageFormat = FileFormats.AVS_OFFICESTUDIO_FILE_IMAGE_PNG;
                                aBuffer      = aNewBuffer;
                                oImageStream = new MemoryStream(aBuffer);
                            }
                        }
                        string sImageHash = null;
                        using (MemoryStream ms = new MemoryStream(aBuffer))
                            sImageHash = Utils.getMD5HexString(ms);

                        string sFileName;
                        if (oTransportClass2.m_oMediaXmlMapHash.TryGetValue(sImageHash, out sFileName))
                        {
                            ImageUrlProcess(oTransportClass2, Constants.mc_sResourceServiceUrlRel + Path.Combine(oTransportClass2.m_sKey, @"media\" + sFileName).Replace('\\', '/'));
                        }
                        else
                        {
                            string     sSearchName = "image";
                            List <int> aIndexes    = new List <int>();
                            foreach (KeyValuePair <string, string> kvp in oTransportClass2.m_oMediaXmlMapFilename)
                            {
                                string sFilename = Path.GetFileNameWithoutExtension(kvp.Key);
                                if (0 == sFilename.IndexOf(sSearchName))
                                {
                                    int nCurIndex;
                                    if (int.TryParse(sFilename.Substring(sSearchName.Length), out nCurIndex))
                                    {
                                        aIndexes.Add(nCurIndex);
                                    }
                                }
                            }
                            int nMaxIndex = -1;
                            for (int i = 0, length = aIndexes.Count; i < length; ++i)
                            {
                                int nCurIndex = aIndexes[i];
                                if (nMaxIndex < nCurIndex)
                                {
                                    nMaxIndex = nCurIndex;
                                }
                            }
                            int nNewIndex = 1;
                            if (nMaxIndex >= nNewIndex)
                            {
                                nNewIndex = nMaxIndex + 1;
                            }
                            string sNewName = sSearchName + nNewIndex + "." + FileFormats.ToString(nImageFormat);

                            string          sNewPath         = Path.Combine(oTransportClass2.m_sKey, @"media\" + sNewName).Replace('\\', '/');
                            Storage         oStorage         = new Storage();
                            TransportClass3 oTransportClass3 = new TransportClass3(oTransportClass2, sNewName, sImageHash, sNewPath, oStorage);
                            oTransportClass3.m_oStorage.WriteFileBegin(sNewPath, oImageStream, WriteUploadedFileCallback, oTransportClass3);
                        }
                    }
                    else
                    {
                        WriteToResponse(oTransportClass2, ErrorTypes.UploadExtension, null, oTransportClass2.m_aInputParams);
                    }
                }
                else
                {
                    WriteToResponse(oTransportClass2, eError, null, oTransportClass2.m_aInputParams);
                }
            }
            catch (Exception e)
            {
                _log.Error("Exeption: ", e);
                WriteToResponse(oTransportClass2, ErrorTypes.Upload, null, oTransportClass2.m_aInputParams);
            }
        }