コード例 #1
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);
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            string input  = @"D:\logs\doc.onlyoffice.com\sync\files";
            string output = @"D:\logs\doc.onlyoffice.com\6.0.0\errorsorted";

            DateTime start = DateTime.Now;
            Dictionary <long, long> hash = new Dictionary <long, long>();

            if (Directory.Exists(output))
            {
                initCache(hash, output);
            }


            Directory.CreateDirectory(output);
            string[] dirs = Directory.GetDirectories(input);
            for (int i = 0; i < dirs.Length; ++i)
            {
                string[] dirs2 = Directory.GetDirectories(dirs[i]);
                for (int j = 0; j < dirs2.Length; ++j)
                {
                    string curDir = dirs2[j];
                    if (!curDir.EndsWith("browser"))
                    {
                        string source = Path.Combine(curDir, "source");
                        bool   bError = true;
                        if (Directory.Exists(source))
                        {
                            string[] files = Directory.GetFiles(source);
                            if (files.Length > 0)
                            {
                                bError = false;
                                string file = files[0];
                                long   size = new System.IO.FileInfo(file).Length;
                                long   outVal;
                                if (!hash.TryGetValue(size, out outVal))
                                {
                                    hash[size] = 1;

                                    int    format    = FormatChecker.GetFileFormat(file);
                                    string formatStr = FormatChecker.FileFormats.ToString(format);
                                    if (string.IsNullOrEmpty(formatStr))
                                    {
                                        formatStr = "unknown";
                                    }
                                    string formatDir = Path.Combine(output, formatStr);
                                    Directory.CreateDirectory(formatDir);
                                    Copy(curDir, Path.Combine(formatDir, Path.GetFileName(curDir)));
                                }
                            }
                        }
                        if (bError)
                        {
                            string error = Path.Combine(output, "error");
                            Directory.CreateDirectory(error);
                            Copy(curDir, Path.Combine(error, Path.GetFileName(curDir)));
                        }
                    }
                }
            }

            TimeSpan time = DateTime.Now - start;
        }