Added server components.
This commit is contained in:
parent
7b3b2248e5
commit
dbbc76d37d
7
ServerComponents/Bin/ConnectionStrings.config
Normal file
7
ServerComponents/Bin/ConnectionStrings.config
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<connectionStrings>
|
||||||
|
<clear />
|
||||||
|
<!-- Line to connect to the main base -->
|
||||||
|
<add name="ConnectionString2" connectionString="Server=localhost;database=onlyoffice;user id=root;password=onlyoffice;pooling=True;Character Set=utf8" providerName="MySql.Data.MySqlClient" />
|
||||||
|
<add name="FileStatisticConnectionString" connectionString="Server=localhost;database=onlyoffice;user id=root;password=onlyoffice;pooling=True;Character Set=utf8" providerName="MySql.Data.MySqlClient" />
|
||||||
|
</connectionStrings>
|
9
ServerComponents/Bin/DoctRenderer.config
Normal file
9
ServerComponents/Bin/DoctRenderer.config
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<Settings>
|
||||||
|
<file>/var/www/onlyoffice/documentserver/DocService/OfficeWeb/sdk/Common/Native/native.js</file>
|
||||||
|
<file>/var/www/onlyoffice/documentserver/DocService/OfficeWeb/sdk/Common/Native/jquery_native.js</file>
|
||||||
|
<file>/var/www/onlyoffice/documentserver/DocService/OfficeWeb/vendor/xregexp/xregexp-all-min.js</file>
|
||||||
|
<file>/var/www/onlyoffice/documentserver/DocService/OfficeWeb/sdk/Common/AllFonts.js</file>
|
||||||
|
<DoctSdk>/var/www/onlyoffice/documentserver/DocService/OfficeWeb/sdk/Word/sdk-all.js</DoctSdk>
|
||||||
|
<PpttSdk>/var/www/onlyoffice/documentserver/DocService/OfficeWeb/sdk/PowerPoint/sdk-all.js</PpttSdk>
|
||||||
|
<XlstSdk>/var/www/onlyoffice/documentserver/DocService/OfficeWeb/sdk/Excel/sdk-all.js</XlstSdk>
|
||||||
|
</Settings>
|
453
ServerComponents/Bin/FileConverter.py
Normal file
453
ServerComponents/Bin/FileConverter.py
Normal file
|
@ -0,0 +1,453 @@
|
||||||
|
#
|
||||||
|
# (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
#
|
||||||
|
# This program is a free software product. You can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
# version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
# Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
# that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
# of any third-party rights.
|
||||||
|
#
|
||||||
|
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
# details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
#
|
||||||
|
# You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
# EU, LV-1021.
|
||||||
|
#
|
||||||
|
# The interactive user interfaces in modified source and object code versions
|
||||||
|
# of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
# Section 5 of the GNU AGPL version 3.
|
||||||
|
#
|
||||||
|
# Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
# logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
# grant you any rights under trademark law for use of our trademarks.
|
||||||
|
#
|
||||||
|
# All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
# well as technical writing content are licensed under the terms of the
|
||||||
|
# Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
# terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
#
|
||||||
|
|
||||||
|
#----Import---
|
||||||
|
import datetime
|
||||||
|
import logging
|
||||||
|
import os #makedirs
|
||||||
|
import os.path # check file exists
|
||||||
|
import xml.etree.ElementTree as ET # read xml
|
||||||
|
import subprocess
|
||||||
|
import shutil # copy file
|
||||||
|
import uno
|
||||||
|
from os.path import abspath, isfile, splitext, split, join
|
||||||
|
from com.sun.star.beans import PropertyValue
|
||||||
|
from com.sun.star.task import ErrorCodeIOException
|
||||||
|
from com.sun.star.connection import NoConnectException
|
||||||
|
|
||||||
|
#----Const----
|
||||||
|
|
||||||
|
converterToXport = "2002"
|
||||||
|
converterToXarg = "socket,host=localhost,port=" + converterToXport + ";urp;StarOffice"
|
||||||
|
converterToX = 'sudo soffice --headless "--accept=' + converterToXarg + '.ServiceManager"'
|
||||||
|
|
||||||
|
converterToT = "./x2t"
|
||||||
|
AVS_OFFICESTUDIO_FILE_UNKNOWN = "0"
|
||||||
|
AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX = "65"
|
||||||
|
AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX = "129"
|
||||||
|
AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSX = "132"
|
||||||
|
AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX = "257"
|
||||||
|
AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_PDF = "513"
|
||||||
|
AVS_OFFICESTUDIO_FILE_TEAMLAB_DOCY = "4097"
|
||||||
|
AVS_OFFICESTUDIO_FILE_TEAMLAB_XLSY = "4098"
|
||||||
|
AVS_OFFICESTUDIO_FILE_TEAMLAB_PPTY = "4099"
|
||||||
|
AVS_OFFICESTUDIO_FILE_CANVAS_WORD = "8193"
|
||||||
|
AVS_OFFICESTUDIO_FILE_CANVAS_SPREADSHEET = "8194"
|
||||||
|
AVS_OFFICESTUDIO_FILE_CANVAS_PRESENTATION = "8195"
|
||||||
|
AVS_OFFICESTUDIO_FILE_OTHER_HTMLZIP = "2051"
|
||||||
|
AVS_OFFICESTUDIO_FILE_OTHER_ZIP = "2057"
|
||||||
|
|
||||||
|
InternalFormatsCode = {
|
||||||
|
AVS_OFFICESTUDIO_FILE_TEAMLAB_DOCY: ("docx", AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX),
|
||||||
|
AVS_OFFICESTUDIO_FILE_TEAMLAB_XLSY: ("xlsx", AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX),
|
||||||
|
AVS_OFFICESTUDIO_FILE_TEAMLAB_PPTY: ("pptx", AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX),
|
||||||
|
AVS_OFFICESTUDIO_FILE_CANVAS_WORD: ("docx", AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX),
|
||||||
|
AVS_OFFICESTUDIO_FILE_CANVAS_SPREADSHEET: ("xlsx", AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX),
|
||||||
|
AVS_OFFICESTUDIO_FILE_CANVAS_PRESENTATION: ("pptx", AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX)
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorTypes = {
|
||||||
|
"ConvertLibreOffice" : 87,
|
||||||
|
"ConvertReadFile" : 84,
|
||||||
|
"Convert" : 80,
|
||||||
|
"Unknown" : 1,
|
||||||
|
"NoError" : 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
importFilterMap = {
|
||||||
|
"csv": {
|
||||||
|
"FilterName": "Text - txt - csv (StarCalc)",
|
||||||
|
"FilterOptions": "44,34,0"
|
||||||
|
},
|
||||||
|
"html": {
|
||||||
|
"FilterName": "HTML Document"
|
||||||
|
},
|
||||||
|
"odp": {
|
||||||
|
"FilterName": "OpenDocument Presentation (Flat XML)"
|
||||||
|
},
|
||||||
|
"rtf": {
|
||||||
|
"FilterName": "Rich Text Format"
|
||||||
|
},
|
||||||
|
"txt": {
|
||||||
|
"FilterName": "Text (encoded)",
|
||||||
|
"FilterOptions": "utf8"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exportFilterMap = {
|
||||||
|
"docx": {
|
||||||
|
"com.sun.star.text.TextDocument": { "FilterName": "MS Word 2007 XML" },
|
||||||
|
"com.sun.star.text.WebDocument": { "FilterName": "MS Word 2007 XML" }
|
||||||
|
},
|
||||||
|
"xlsx": {
|
||||||
|
#"com.sun.star.sheet.SpreadsheetDocument": { "FilterName": "Calc MS Excel 2007 XML" }
|
||||||
|
"com.sun.star.sheet.SpreadsheetDocument": { "FilterName": "Calc Office Open XML" }
|
||||||
|
},
|
||||||
|
"pptx": {
|
||||||
|
"com.sun.star.presentation.PresentationDocument": { "FilterName": "Impress MS PowerPoint 2007 XML" }
|
||||||
|
},
|
||||||
|
"pdf": {
|
||||||
|
"com.sun.star.text.TextDocument": { "FilterName": "writer_pdf_Export" },
|
||||||
|
"com.sun.star.text.WebDocument": { "FilterName": "writer_web_pdf_Export" },
|
||||||
|
"com.sun.star.sheet.SpreadsheetDocument": { "FilterName": "calc_pdf_Export" },
|
||||||
|
"com.sun.star.presentation.PresentationDocument": { "FilterName": "impress_pdf_Export" },
|
||||||
|
"com.sun.star.drawing.DrawingDocument": { "FilterName": "draw_pdf_Export" }
|
||||||
|
},
|
||||||
|
"html": {
|
||||||
|
"com.sun.star.text.TextDocument": { "FilterName": "HTML (StarWriter)" },
|
||||||
|
"com.sun.star.sheet.SpreadsheetDocument": { "FilterName": "HTML (StarCalc)" },
|
||||||
|
"com.sun.star.presentation.PresentationDocument": { "FilterName": "impress_html_Export" }
|
||||||
|
},
|
||||||
|
"odt": {
|
||||||
|
"com.sun.star.text.TextDocument": { "FilterName": "writer8" },
|
||||||
|
"com.sun.star.text.WebDocument": { "FilterName": "writerweb8_writer" }
|
||||||
|
},
|
||||||
|
"doc": {
|
||||||
|
"com.sun.star.text.TextDocument": { "FilterName": "MS Word 97" }
|
||||||
|
},
|
||||||
|
"rtf": {
|
||||||
|
"com.sun.star.text.TextDocument": { "FilterName": "Rich Text Format" }
|
||||||
|
},
|
||||||
|
"txt": {
|
||||||
|
"com.sun.star.text.TextDocument": {
|
||||||
|
"FilterName": "Text",
|
||||||
|
"FilterOptions": "utf8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ods": {
|
||||||
|
"com.sun.star.sheet.SpreadsheetDocument": { "FilterName": "calc8" }
|
||||||
|
},
|
||||||
|
"xls": {
|
||||||
|
"com.sun.star.sheet.SpreadsheetDocument": { "FilterName": "MS Excel 97" }
|
||||||
|
},
|
||||||
|
"csv": {
|
||||||
|
"com.sun.star.sheet.SpreadsheetDocument": {
|
||||||
|
"FilterName": "Text - txt - csv (StarCalc)",
|
||||||
|
"FilterOptions": "44,34,0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"odp": {
|
||||||
|
"com.sun.star.presentation.PresentationDocument": { "FilterName": "impress8" }
|
||||||
|
},
|
||||||
|
"ppt": {
|
||||||
|
"com.sun.star.presentation.PresentationDocument": { "FilterName": "MS PowerPoint 97" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pageStyleProp = {
|
||||||
|
"com.sun.star.sheet.SpreadsheetDocument": {
|
||||||
|
#--- Scale options: uncomment 1 of the 3 ---
|
||||||
|
# a) 'Reduce / enlarge printout': 'Scaling factor'
|
||||||
|
"PageScale": 100,
|
||||||
|
# b) 'Fit print range(s) to width / height': 'Width in pages' and 'Height in pages'
|
||||||
|
#"ScaleToPagesX": 1, "ScaleToPagesY": 1000,
|
||||||
|
# c) 'Fit print range(s) on number of pages': 'Fit print range(s) on number of pages'
|
||||||
|
#"ScaleToPages": 1,
|
||||||
|
"PrintGrid": False
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#---Fun---
|
||||||
|
writeAlert = True
|
||||||
|
logging.basicConfig(filename="/var/log/onlyoffice/documentserver/FileConverter.log",level=logging.ERROR,format="%(asctime)s %(levelname)s %(name)s - %(message)s")
|
||||||
|
def alert(text, err=False):
|
||||||
|
if writeAlert:
|
||||||
|
if err:
|
||||||
|
logging.error(text)
|
||||||
|
else:
|
||||||
|
logging.debug(text)
|
||||||
|
print(text)
|
||||||
|
|
||||||
|
def readXml(pathToXml):
|
||||||
|
parser = ET.XMLParser(encoding="utf-8")
|
||||||
|
tree = ET.parse(pathToXml, parser=parser)
|
||||||
|
root = tree.getroot()
|
||||||
|
oTaskQueueDataConvert = {}
|
||||||
|
for child in root:
|
||||||
|
oTaskQueueDataConvert[child.tag] = child.text
|
||||||
|
alert("Reading xml complete")
|
||||||
|
return (oTaskQueueDataConvert, tree)
|
||||||
|
|
||||||
|
def writeXml(pathToXml, postfix, tree, sFileFrom, sFormatFrom, sFileTo, sFormatTo):
|
||||||
|
newXml = None
|
||||||
|
eResult = ErrorTypes["NoError"]
|
||||||
|
try:
|
||||||
|
root = tree.getroot()
|
||||||
|
for child in root:
|
||||||
|
if "m_sFileFrom" == child.tag:
|
||||||
|
child.text = sFileFrom
|
||||||
|
elif "m_nFormatFrom" == child.tag:
|
||||||
|
child.text = sFormatFrom
|
||||||
|
elif "m_sFileTo" == child.tag:
|
||||||
|
child.text = sFileTo
|
||||||
|
elif "m_nFormatTo" == child.tag:
|
||||||
|
child.text = sFormatTo
|
||||||
|
pathSplit = splitext(pathToXml)
|
||||||
|
newXml = pathSplit[0] + postfix + pathSplit[1]
|
||||||
|
tree.write(newXml, encoding='utf-8', xml_declaration=True, default_namespace=None, method="xml")
|
||||||
|
except :
|
||||||
|
alert("Error writeXml", True)
|
||||||
|
eResult = ErrorTypes["Convert"]
|
||||||
|
else :
|
||||||
|
alert("Write xml complete:" + newXml)
|
||||||
|
return (eResult, newXml)
|
||||||
|
|
||||||
|
def incorrectXmlData(oTaskQueueDataConvert):
|
||||||
|
sFileFrom = oTaskQueueDataConvert.get("m_sFileFrom")
|
||||||
|
if not sFileFrom:
|
||||||
|
return "m_sFileFrom is null"
|
||||||
|
if not os.path.exists(sFileFrom):
|
||||||
|
return "{} not found".format(sFileFrom)
|
||||||
|
|
||||||
|
sFileTo = oTaskQueueDataConvert.get("m_sFileTo")
|
||||||
|
if not sFileTo:
|
||||||
|
return "m_sFileTo is null"
|
||||||
|
if os.path.exists(sFileTo):
|
||||||
|
os.remove(sFileTo)
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def getFileExt(path):
|
||||||
|
ext = splitext(path)[1]
|
||||||
|
if ext is not None:
|
||||||
|
return ext[1:].lower()
|
||||||
|
|
||||||
|
def getStoreProperties(document, outputExt):
|
||||||
|
family = detectFamily(document)
|
||||||
|
try:
|
||||||
|
propertiesByFamily = exportFilterMap[outputExt]
|
||||||
|
except KeyError:
|
||||||
|
raise Exception("unknown output format: '{}'".format(outputExt))
|
||||||
|
try:
|
||||||
|
return propertiesByFamily[family]
|
||||||
|
except KeyError:
|
||||||
|
raise Exception("unsupported conversion: from '{}' to '{}'".format(family, outputExt))
|
||||||
|
|
||||||
|
def detectFamily(document):
|
||||||
|
if document.supportsService("com.sun.star.text.WebDocument"):
|
||||||
|
return "com.sun.star.text.WebDocument"
|
||||||
|
if document.supportsService("com.sun.star.text.GenericTextDocument"):
|
||||||
|
# must be TextDocument or GlobalDocument
|
||||||
|
return "com.sun.star.text.TextDocument"
|
||||||
|
if document.supportsService("com.sun.star.sheet.SpreadsheetDocument"):
|
||||||
|
return "com.sun.star.sheet.SpreadsheetDocument"
|
||||||
|
if document.supportsService("com.sun.star.presentation.PresentationDocument"):
|
||||||
|
return "com.sun.star.presentation.PresentationDocument"
|
||||||
|
raise Exception("unknown document family: {}".format(document))
|
||||||
|
|
||||||
|
def overridePageStyleProperties(document, family):
|
||||||
|
if pageStyleProp.get(family):
|
||||||
|
properties = pageStyleProp[family]
|
||||||
|
pageStyles = document.getStyleFamilies().getByName("PageStyles")
|
||||||
|
for styleName in pageStyles.getElementNames():
|
||||||
|
pageStyle = pageStyles.getByName(styleName)
|
||||||
|
for name, value in properties.items():
|
||||||
|
pageStyle.setPropertyValue(name, value)
|
||||||
|
|
||||||
|
def toProperties(dict):
|
||||||
|
props = []
|
||||||
|
for key in dict:
|
||||||
|
prop = PropertyValue()
|
||||||
|
prop.Name = key
|
||||||
|
prop.Value = dict[key]
|
||||||
|
props.append(prop)
|
||||||
|
return tuple(props)
|
||||||
|
|
||||||
|
def initOffice():
|
||||||
|
alert("init office")
|
||||||
|
|
||||||
|
#subprocess.Popen(converterToX, shell = True)
|
||||||
|
alert("office started")
|
||||||
|
|
||||||
|
componentContext = uno.getComponentContext()
|
||||||
|
alert("uno context")
|
||||||
|
|
||||||
|
resolver = componentContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", componentContext)
|
||||||
|
alert("instance created")
|
||||||
|
|
||||||
|
try:
|
||||||
|
officeContext = resolver.resolve("uno:" + converterToXarg + ".ComponentContext")
|
||||||
|
alert("ComponentContext resolved")
|
||||||
|
except NoConnectException:
|
||||||
|
alert("failed to connect to OpenOffice.org on port " + converterToXport, True)
|
||||||
|
raise Exception("failed to connect to OpenOffice.org on port " + converterToXport)
|
||||||
|
|
||||||
|
return officeContext.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", officeContext)
|
||||||
|
|
||||||
|
def convertOfficeWithHtmlZip(inputFileUrl, outputFileUrl, outputFormatCode, pathToXml, tree):
|
||||||
|
eResult = ErrorTypes["NoError"]
|
||||||
|
if AVS_OFFICESTUDIO_FILE_OTHER_HTMLZIP == outputFormatCode :
|
||||||
|
outputHtmlDir = join(split(inputFileUrl)[0], "htmlzip")
|
||||||
|
if not os.path.exists(outputHtmlDir):
|
||||||
|
os.makedirs(outputHtmlDir)
|
||||||
|
outputFileUrlHtml = join(outputHtmlDir, "output.html")
|
||||||
|
eResult = convertOffice(inputFileUrl, outputFileUrlHtml)
|
||||||
|
if eResult == ErrorTypes["NoError"] :
|
||||||
|
writeXmlRes = writeXml(pathToXml, "_htmlzip", tree, outputHtmlDir, AVS_OFFICESTUDIO_FILE_UNKNOWN, outputFileUrl, AVS_OFFICESTUDIO_FILE_OTHER_ZIP)
|
||||||
|
eResult = writeXmlRes[0]
|
||||||
|
if eResult == ErrorTypes["NoError"] :
|
||||||
|
eResult = convertASC(writeXmlRes[1])
|
||||||
|
else :
|
||||||
|
eResult = convertOffice(inputFileUrl, outputFileUrl)
|
||||||
|
return eResult
|
||||||
|
|
||||||
|
def convertOffice(inputFileUrl, outputFileUrl):
|
||||||
|
nRes = ErrorTypes["NoError"]
|
||||||
|
try:
|
||||||
|
desktop = initOffice()
|
||||||
|
alert("office desktop created")
|
||||||
|
|
||||||
|
inputFileUrl = uno.systemPathToFileUrl(abspath(inputFileUrl))
|
||||||
|
alert("from " + inputFileUrl)
|
||||||
|
outputFileUrl = uno.systemPathToFileUrl(abspath(outputFileUrl))
|
||||||
|
alert("to " + outputFileUrl)
|
||||||
|
|
||||||
|
loadProperties = { "Hidden": True }
|
||||||
|
inputExt = getFileExt(inputFileUrl)
|
||||||
|
if importFilterMap.get(inputExt):
|
||||||
|
loadProperties.update(importFilterMap[inputExt])
|
||||||
|
|
||||||
|
alert("document loading")
|
||||||
|
document = desktop.loadComponentFromURL(inputFileUrl, "_blank", 0, toProperties(loadProperties))
|
||||||
|
alert("document loaded")
|
||||||
|
|
||||||
|
try:
|
||||||
|
document.refresh()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
family = detectFamily(document)
|
||||||
|
overridePageStyleProperties(document, family)
|
||||||
|
|
||||||
|
outputExt = getFileExt(outputFileUrl)
|
||||||
|
storeProperties = getStoreProperties(document, outputExt)
|
||||||
|
|
||||||
|
alert("document storing")
|
||||||
|
try:
|
||||||
|
document.storeToURL(outputFileUrl, toProperties(storeProperties))
|
||||||
|
alert("document stored")
|
||||||
|
finally:
|
||||||
|
document.close(True)
|
||||||
|
except:
|
||||||
|
alert("Error convert", True)
|
||||||
|
nRes = ErrorTypes["ConvertLibreOffice"]
|
||||||
|
return nRes
|
||||||
|
|
||||||
|
def convertASC(paramXml):
|
||||||
|
alert("convert with x2t")
|
||||||
|
processPath = converterToT + ' "' + paramXml + '"'
|
||||||
|
alert(processPath)
|
||||||
|
p = subprocess.Popen(processPath, shell = True)
|
||||||
|
returnCode = p.wait()
|
||||||
|
alert("convert with x2t return:{}".format(returnCode))
|
||||||
|
return returnCode
|
||||||
|
|
||||||
|
#---Begin---
|
||||||
|
if __name__ == "__main__":
|
||||||
|
from sys import argv, exit
|
||||||
|
|
||||||
|
eResult = ErrorTypes["NoError"]
|
||||||
|
|
||||||
|
if len(argv) < 2:
|
||||||
|
alert("Not found xml")
|
||||||
|
exit(ErrorTypes["ConvertReadFile"])
|
||||||
|
pathToXml = argv[1]
|
||||||
|
alert("pathToXml: " + pathToXml)
|
||||||
|
|
||||||
|
if not os.path.exists(pathToXml):
|
||||||
|
alert("{} not found".format(pathToXml), True)
|
||||||
|
exit(ErrorTypes["ConvertReadFile"])
|
||||||
|
|
||||||
|
try:
|
||||||
|
alert("read xml")
|
||||||
|
resultReadXml = readXml(pathToXml)
|
||||||
|
oTaskQueueDataConvert = resultReadXml[0]
|
||||||
|
incorrect = incorrectXmlData(oTaskQueueDataConvert)
|
||||||
|
if incorrect:
|
||||||
|
alert(incorrect)
|
||||||
|
exit(ErrorTypes["ConvertReadFile"])
|
||||||
|
alert("correct data")
|
||||||
|
except:
|
||||||
|
alert("Error xml read", True)
|
||||||
|
exit(ErrorTypes["Convert"])
|
||||||
|
|
||||||
|
inputFileUrl = oTaskQueueDataConvert.get("m_sFileFrom")
|
||||||
|
alert("from " + inputFileUrl)
|
||||||
|
inputFormatCode = oTaskQueueDataConvert.get("m_nFormatFrom")
|
||||||
|
outputFileUrl = oTaskQueueDataConvert.get("m_sFileTo")
|
||||||
|
alert("to " + outputFileUrl)
|
||||||
|
outputFormatCode = oTaskQueueDataConvert.get("m_nFormatTo")
|
||||||
|
fromT = InternalFormatsCode.get(inputFormatCode)
|
||||||
|
bFromT = fromT is not None
|
||||||
|
toT = InternalFormatsCode.get(outputFormatCode)
|
||||||
|
bToT = toT is not None
|
||||||
|
|
||||||
|
if inputFormatCode == outputFormatCode :
|
||||||
|
alert("from equal to")
|
||||||
|
if inputFileUrl != outputFileUrl :
|
||||||
|
shutil.copyfile(inputFileUrl, outputFileUrl)
|
||||||
|
exit(eResult)
|
||||||
|
elif AVS_OFFICESTUDIO_FILE_UNKNOWN == inputFormatCode and AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_PDF == outputFormatCode :
|
||||||
|
alert("convert from bin to pdf")
|
||||||
|
eResult = convertASC(pathToXml)
|
||||||
|
exit(eResult)
|
||||||
|
elif AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSX == inputFormatCode :
|
||||||
|
alert("convert from ppsx to")
|
||||||
|
eResult = convertASC(pathToXml)
|
||||||
|
exit(eResult)
|
||||||
|
elif bFromT or bToT :
|
||||||
|
if (bFromT and bToT) or (bFromT and fromT[1] == outputFormatCode) or (bToT and toT[1] == inputFormatCode) :
|
||||||
|
eResult = convertASC(pathToXml)
|
||||||
|
else :
|
||||||
|
if bFromT :
|
||||||
|
tempFile = join(split(inputFileUrl)[0], "temp." + fromT[0])
|
||||||
|
alert("tempFile " + tempFile)
|
||||||
|
writeXmlRes = writeXml(pathToXml, "_t2x", resultReadXml[1], inputFileUrl, inputFormatCode, tempFile, fromT[1])
|
||||||
|
eResult = writeXmlRes[0]
|
||||||
|
if eResult == ErrorTypes["NoError"] :
|
||||||
|
eResult = convertASC(writeXmlRes[1])
|
||||||
|
if eResult == ErrorTypes["NoError"] :
|
||||||
|
eResult = convertOfficeWithHtmlZip(tempFile, outputFileUrl, outputFormatCode, pathToXml, resultReadXml[1])
|
||||||
|
else :
|
||||||
|
tempFile = join(split(inputFileUrl)[0], "temp." + toT[0])
|
||||||
|
alert("tempFile " + tempFile)
|
||||||
|
eResult = convertOfficeWithHtmlZip(inputFileUrl, tempFile, toT[1], pathToXml, resultReadXml[1])
|
||||||
|
if eResult == ErrorTypes["NoError"] :
|
||||||
|
writeXmlRes = writeXml(pathToXml, "_x2t", resultReadXml[1], tempFile, toT[1], outputFileUrl, outputFormatCode)
|
||||||
|
eResult = writeXmlRes[0]
|
||||||
|
if eResult == ErrorTypes["NoError"] :
|
||||||
|
eResult = convertASC(writeXmlRes[1])
|
||||||
|
else :
|
||||||
|
eResult = convertOfficeWithHtmlZip(inputFileUrl, outputFileUrl, outputFormatCode, pathToXml, resultReadXml[1])
|
||||||
|
|
||||||
|
alert("Exit code:{}".format(eResult))
|
||||||
|
exit(eResult)
|
BIN
ServerComponents/Bin/FileConverterService2.exe
Normal file
BIN
ServerComponents/Bin/FileConverterService2.exe
Normal file
Binary file not shown.
49
ServerComponents/Bin/FileConverterService2.exe.config
Normal file
49
ServerComponents/Bin/FileConverterService2.exe.config
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<configSections>
|
||||||
|
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
|
||||||
|
</configSections>
|
||||||
|
<log4net>
|
||||||
|
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
|
||||||
|
<layout type="log4net.Layout.PatternLayout">
|
||||||
|
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
|
||||||
|
<conversionPattern value="%date %-5level [%thread] %logger - %message%newline" />
|
||||||
|
</layout>
|
||||||
|
<file value="/var/log/onlyoffice/documentserver/FileConverterService.log" />
|
||||||
|
<appendToFile value="true" />
|
||||||
|
<rollingStyle value="Date" />
|
||||||
|
<datePattern value="yyyyMMdd-HHmm" />
|
||||||
|
</appender>
|
||||||
|
<root>
|
||||||
|
<level value="WARN" />
|
||||||
|
<appender-ref ref="RollingFileAppender" />
|
||||||
|
</root>
|
||||||
|
</log4net>
|
||||||
|
<system.data>
|
||||||
|
<DbProviderFactories>
|
||||||
|
<clear />
|
||||||
|
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
|
||||||
|
</DbProviderFactories>
|
||||||
|
</system.data>
|
||||||
|
<connectionStrings configSource="ConnectionStrings.config" />
|
||||||
|
<appSettings file="/var/www/onlyoffice/documentserver/DocService/Settings.config">
|
||||||
|
<add key="sleeptimeout" value="5" />
|
||||||
|
<add key="sleeptimeoutiddle" value="5" />
|
||||||
|
<add key="maxconverttime" value="60" />
|
||||||
|
<add key="maxconverttimeiddle" value="300" />
|
||||||
|
<add key="maxconverttimequeuedelay" value="20" />
|
||||||
|
<add key="maxconvertiddlefiles" value="5" />
|
||||||
|
<add key="maxdownloadbytes" value="100000000" />
|
||||||
|
<!--number of processes per processor-->
|
||||||
|
<add key="maxprocesscount" value="1" />
|
||||||
|
<!--download folder-->
|
||||||
|
<add key="fileconverterservice.gc.removedtaskatonce" value="10" />
|
||||||
|
<add key="fileconverterservice.gc.runperiod" value="3600" />
|
||||||
|
<add key="fileconverterservice.percent.runperiod" value="500" />
|
||||||
|
<add key="fileconverterservice.converter.filepath" value="python3" />
|
||||||
|
<add key="fileconverterservice.converter.args" value="FileConverter.py" />
|
||||||
|
<add key="fileconverterservice.converter.errorfiles" value="error" />
|
||||||
|
<add key="fileconverterservice.converter.presentationthemesdir" value="/var/www/onlyoffice/documentserver/FileConverterService/presentationthemes" />
|
||||||
|
<add key="fileconverterservice.usewinfonts" value="false" />
|
||||||
|
</appSettings>
|
||||||
|
</configuration>
|
BIN
ServerComponents/Bin/FileConverterUtils2.dll
Normal file
BIN
ServerComponents/Bin/FileConverterUtils2.dll
Normal file
Binary file not shown.
BIN
ServerComponents/Bin/Interop.OfficeCore.dll
Normal file
BIN
ServerComponents/Bin/Interop.OfficeCore.dll
Normal file
Binary file not shown.
16
ServerComponents/Bin/Settings.config
Normal file
16
ServerComponents/Bin/Settings.config
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<appSettings>
|
||||||
|
<add key="utils.common.fontdir" value="/usr/share/fonts" />
|
||||||
|
<add key="utils.storage.impl" value="fs" />
|
||||||
|
<!--Filesystem storage settings-->
|
||||||
|
<add key="utils.storage.fs.keyfiles" value="/var/lib/onlyoffice/documentserver/App_Data" />
|
||||||
|
<add key="utils.taskresult.impl" value="db" />
|
||||||
|
<add key="utils.taskresult.ttl" value="7.00:00:00" />
|
||||||
|
<add key="utils.taskresult.db.connectionstring" value="ConnectionString2" />
|
||||||
|
<add key="utils.taskqueue.impl" value="db" />
|
||||||
|
<add key="utils.taskqueue.db.connectionstring" value="ConnectionString2" />
|
||||||
|
<add key="utils.taskqueue.db.visibility_timeout" value="300" />
|
||||||
|
<add key="utils.taskqueue.db.retention_period" value="900" />
|
||||||
|
<add key="utils.filestatistic.impl" value="db" />
|
||||||
|
<add key="utils.filestatistic.db.connectionstring" value="ConnectionString2" />
|
||||||
|
</appSettings>
|
81703
ServerComponents/Bin/icudtl_dat.S
Normal file
81703
ServerComponents/Bin/icudtl_dat.S
Normal file
File diff suppressed because it is too large
Load diff
BIN
ServerComponents/Bin/libdoctrenderer.so
Normal file
BIN
ServerComponents/Bin/libdoctrenderer.so
Normal file
Binary file not shown.
BIN
ServerComponents/Bin/x2t
Normal file
BIN
ServerComponents/Bin/x2t
Normal file
Binary file not shown.
50
ServerComponents/FileConverterService2/App.config
Normal file
50
ServerComponents/FileConverterService2/App.config
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<configuration>
|
||||||
|
<configSections>
|
||||||
|
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
|
||||||
|
</configSections>
|
||||||
|
<log4net>
|
||||||
|
<appender name="DebugAppender" type="log4net.Appender.DebugAppender">
|
||||||
|
<layout type="log4net.Layout.PatternLayout">
|
||||||
|
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
|
||||||
|
</layout>
|
||||||
|
</appender>
|
||||||
|
<root>
|
||||||
|
<level value="ERROR" />
|
||||||
|
<appender-ref ref="DebugAppender" />
|
||||||
|
</root>
|
||||||
|
</log4net>
|
||||||
|
<system.data>
|
||||||
|
<DbProviderFactories>
|
||||||
|
<clear />
|
||||||
|
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
|
||||||
|
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite"/>
|
||||||
|
<add name="dotConnect for MySQL" invariant="Devart.Data.MySql" description="Devart dotConnect for MySQL" type="Devart.Data.MySql.MySqlProviderFactory, Devart.Data.MySql, Version=7.4.164.0, Culture=neutral, PublicKeyToken=09af7300eec23701" />
|
||||||
|
<add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" support="FF" />
|
||||||
|
</DbProviderFactories>
|
||||||
|
</system.data>
|
||||||
|
<connectionStrings configSource="ConnectionStrings.config"/>
|
||||||
|
<appSettings file="Settings.config">
|
||||||
|
<add key="sleeptimeout" value="5"/>
|
||||||
|
<add key="sleeptimeoutiddle" value="5"/>
|
||||||
|
<add key="maxconverttime" value="60"/>
|
||||||
|
<add key="maxconverttimeiddle" value="300"/>
|
||||||
|
<add key="maxconverttimequeuedelay" value="20"/>
|
||||||
|
<add key="maxconvertiddlefiles" value="5"/>
|
||||||
|
<add key="maxdownloadbytes" value="100000000"/>
|
||||||
|
<!--number of processes per processor-->
|
||||||
|
<add key="maxprocesscount" value="1"/>
|
||||||
|
|
||||||
|
<!--download folder-->
|
||||||
|
<add key="fileconverterservice.gc.removedtaskatonce" value="10" />
|
||||||
|
<add key="fileconverterservice.gc.runperiod" value="3600" />
|
||||||
|
<add key="fileconverterservice.percent.runperiod" value="500" />
|
||||||
|
|
||||||
|
<add key="fileconverterservice.converter.filepath" value="FileConverter2.exe" />
|
||||||
|
<add key="fileconverterservice.converter.args" value="" />
|
||||||
|
<add key="fileconverterservice.converter.errorfiles" value="error" />
|
||||||
|
<add key="fileconverterservice.converter.presentationthemesdir" value="..\presentationthemes" />
|
||||||
|
|
||||||
|
<add key="fileconverterservice.usewinfonts" value="true" />
|
||||||
|
</appSettings>
|
||||||
|
</configuration>
|
1004
ServerComponents/FileConverterService2/FileConverter.cs
Normal file
1004
ServerComponents/FileConverterService2/FileConverter.cs
Normal file
File diff suppressed because it is too large
Load diff
125
ServerComponents/FileConverterService2/FileConverterService2.cs
Normal file
125
ServerComponents/FileConverterService2/FileConverterService2.cs
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System.ServiceProcess;
|
||||||
|
using log4net;
|
||||||
|
using log4net.Config;
|
||||||
|
|
||||||
|
namespace FileConverterService2
|
||||||
|
{
|
||||||
|
public sealed class FileConverterService2 : ServiceBase
|
||||||
|
{
|
||||||
|
public const string AscFileConverterServiceName = "ASC File Converter Service2";
|
||||||
|
private readonly ILog _log;
|
||||||
|
private readonly FileConverter fileConverter;
|
||||||
|
|
||||||
|
public FileConverterService2()
|
||||||
|
{
|
||||||
|
log4net.Config.XmlConfigurator.Configure();
|
||||||
|
_log = LogManager.GetLogger(typeof(FileConverterService2));
|
||||||
|
|
||||||
|
this.ServiceName = AscFileConverterServiceName;
|
||||||
|
this.EventLog.Log = "Application";
|
||||||
|
fileConverter = new FileConverter(System.Environment.MachineName);
|
||||||
|
|
||||||
|
this.CanHandlePowerEvent = false;
|
||||||
|
this.CanHandleSessionChangeEvent = false;
|
||||||
|
this.CanPauseAndContinue = false;
|
||||||
|
this.CanShutdown = true;
|
||||||
|
this.CanStop = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnStart(string[] args)
|
||||||
|
{
|
||||||
|
_log.Info("Service start");
|
||||||
|
StartDaemon();
|
||||||
|
base.OnStart(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnStop()
|
||||||
|
{
|
||||||
|
_log.Info("Service stop");
|
||||||
|
fileConverter.Stop();
|
||||||
|
base.OnStop();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnPause()
|
||||||
|
{
|
||||||
|
_log.Info("Service pause");
|
||||||
|
base.OnPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnContinue()
|
||||||
|
{
|
||||||
|
_log.Info("Service continue");
|
||||||
|
base.OnContinue();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnShutdown()
|
||||||
|
{
|
||||||
|
_log.Info("Service shutdown");
|
||||||
|
fileConverter.Stop();
|
||||||
|
base.OnShutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnCustomCommand(int command)
|
||||||
|
{
|
||||||
|
|
||||||
|
base.OnCustomCommand(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
|
||||||
|
{
|
||||||
|
if (powerStatus == PowerBroadcastStatus.Suspend)
|
||||||
|
{
|
||||||
|
fileConverter.Stop();
|
||||||
|
}
|
||||||
|
return base.OnPowerEvent(powerStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnSessionChange(
|
||||||
|
SessionChangeDescription changeDescription)
|
||||||
|
{
|
||||||
|
base.OnSessionChange(changeDescription);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StartDaemon()
|
||||||
|
{
|
||||||
|
fileConverter.Start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,145 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProductVersion>9.0.21022</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{290A48D1-F7E2-4478-AFE6-AE5C744CD633}</ProjectGuid>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>FileConverterService2</RootNamespace>
|
||||||
|
<AssemblyName>FileConverterService2</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugOpenSource|AnyCPU' ">
|
||||||
|
<IsOpenSource>true</IsOpenSource>
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE;OPEN_SOURCE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseOpenSource|AnyCPU' ">
|
||||||
|
<IsOpenSource>true</IsOpenSource>
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE;OPEN_SOURCE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="FileConverter.cs" />
|
||||||
|
<Compile Include="FileConverterService2.cs">
|
||||||
|
<SubType>Component</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="FileConverterService2Installer.cs">
|
||||||
|
<SubType>Component</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="AWSSDK, Version=1.3.19.0, Culture=neutral, PublicKeyToken=cd2d24cd2bace800, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\..\wwwroot\Bin\AWSSDK.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="FileConverterUtils2, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\..\wwwroot\Bin\FileConverterUtils2.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\..\wwwroot\Bin\log4net.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="MySql.Data, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\..\wwwroot\Bin\MySql.Data.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Configuration" />
|
||||||
|
<Reference Include="System.Configuration.Install" />
|
||||||
|
<Reference Include="System.Core">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Runtime.Serialization">
|
||||||
|
<RequiredTargetFramework>3.0</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.ServiceProcess" />
|
||||||
|
<Reference Include="System.Web" />
|
||||||
|
<Reference Include="System.Web.Extensions">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Xml.Linq">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Data.DataSetExtensions">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="App.config" />
|
||||||
|
<None Include="Settings.config">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<COMReference Condition=" '$(IsOpenSource)' == '' " Include="AVSGraphics">
|
||||||
|
<Guid>{AB5F2678-2773-44C4-A637-33DFBC51233B}</Guid>
|
||||||
|
<VersionMajor>1</VersionMajor>
|
||||||
|
<VersionMinor>0</VersionMinor>
|
||||||
|
<Lcid>0</Lcid>
|
||||||
|
<WrapperTool>tlbimp</WrapperTool>
|
||||||
|
<Isolated>False</Isolated>
|
||||||
|
</COMReference>
|
||||||
|
<COMReference Condition=" '$(IsOpenSource)' == 'true' " Include="OfficeCore">
|
||||||
|
<Guid>{2FA8EF81-55E5-4F98-B399-2DF9A5DA5E41}</Guid>
|
||||||
|
<VersionMajor>1</VersionMajor>
|
||||||
|
<VersionMinor>0</VersionMinor>
|
||||||
|
<Lcid>0</Lcid>
|
||||||
|
<WrapperTool>tlbimp</WrapperTool>
|
||||||
|
<Isolated>False</Isolated>
|
||||||
|
</COMReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<PostBuildEvent>copy $(ProjectDir)..\..\..\wwwroot\Bin\Settings.config $(TargetDir)
|
||||||
|
copy $(ProjectDir)..\..\..\wwwroot\Bin\ConnectionStrings.config $(TargetDir)
|
||||||
|
copy $(TargetPath) $(ProjectDir)..\..\..\wwwroot\Bin\</PostBuildEvent>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Configuration.Install;
|
||||||
|
using System.ServiceProcess;
|
||||||
|
|
||||||
|
namespace FileConverterService2
|
||||||
|
{
|
||||||
|
|
||||||
|
[RunInstaller(true)]
|
||||||
|
public class FileConverterServiceInstaller : Installer
|
||||||
|
{
|
||||||
|
|
||||||
|
public FileConverterServiceInstaller()
|
||||||
|
{
|
||||||
|
ServiceProcessInstaller serviceProcessInstaller =
|
||||||
|
new ServiceProcessInstaller();
|
||||||
|
ServiceInstaller serviceInstaller = new ServiceInstaller();
|
||||||
|
|
||||||
|
serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
|
||||||
|
serviceProcessInstaller.Username = null;
|
||||||
|
serviceProcessInstaller.Password = null;
|
||||||
|
|
||||||
|
serviceInstaller.DisplayName = FileConverterService2.AscFileConverterServiceName;
|
||||||
|
serviceInstaller.StartType = ServiceStartMode.Automatic;
|
||||||
|
|
||||||
|
serviceInstaller.ServiceName = FileConverterService2.AscFileConverterServiceName;
|
||||||
|
this.Installers.Add(serviceProcessInstaller);
|
||||||
|
this.Installers.Add(serviceInstaller);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
52
ServerComponents/FileConverterService2/Program.cs
Normal file
52
ServerComponents/FileConverterService2/Program.cs
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.ServiceProcess;
|
||||||
|
|
||||||
|
namespace FileConverterService2
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
var service = new FileConverterService2();
|
||||||
|
if ((args.Length > 0 && args[0] == "-d") || Environment.UserInteractive)
|
||||||
|
{
|
||||||
|
service.StartDaemon();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ServiceBase.Run(service);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
[assembly: AssemblyTitle("FileConverterService2")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("Ascensio System SIA")]
|
||||||
|
[assembly: AssemblyProduct("FileConverterService2")]
|
||||||
|
[assembly: AssemblyCopyright("Ascensio System SIA Copyright (c) 2014")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
[assembly: Guid("2f0ef597-725c-4954-976e-9808c513f9a5")]
|
||||||
|
|
||||||
|
[assembly: AssemblyVersion("1.0.0.56")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.56")]
|
894
ServerComponents/FileConverterUtils2/AsyncOperation.cs
Normal file
894
ServerComponents/FileConverterUtils2/AsyncOperation.cs
Normal file
|
@ -0,0 +1,894 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Web;
|
||||||
|
using System.IO;
|
||||||
|
using System.Xml;
|
||||||
|
using System.Net;
|
||||||
|
using log4net;
|
||||||
|
|
||||||
|
namespace FileConverterUtils2
|
||||||
|
{
|
||||||
|
#region TransportClass
|
||||||
|
public class TransportClassMainAshx
|
||||||
|
{
|
||||||
|
public HttpContext m_oHttpContext;
|
||||||
|
public AsyncCallback m_oAsyncCallback;
|
||||||
|
public TransportClassMainAshx(HttpContext oHttpContext, AsyncCallback oAsyncCallback)
|
||||||
|
{
|
||||||
|
m_oHttpContext = oHttpContext;
|
||||||
|
m_oAsyncCallback = oAsyncCallback;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class TransportClassContextRead : TransportClassMainAshx
|
||||||
|
{
|
||||||
|
public AsyncContextReadOperation m_oAsyncContextReadOperation;
|
||||||
|
public TransportClassContextRead(TransportClassMainAshx m_oTransportClassMainAshx, AsyncContextReadOperation oAsyncContextReadOperation)
|
||||||
|
: base(m_oTransportClassMainAshx.m_oHttpContext, m_oTransportClassMainAshx.m_oAsyncCallback)
|
||||||
|
{
|
||||||
|
m_oAsyncContextReadOperation = oAsyncContextReadOperation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public abstract class TransportClassAsyncOperation
|
||||||
|
{
|
||||||
|
public AsyncCallback m_fCallback = null;
|
||||||
|
public object m_oParam = null;
|
||||||
|
public TransportClassAsyncOperation(AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_fCallback = fCallback;
|
||||||
|
m_oParam = oParam;
|
||||||
|
}
|
||||||
|
public abstract void Close();
|
||||||
|
public abstract void Dispose();
|
||||||
|
public void DisposeAndCallback()
|
||||||
|
{
|
||||||
|
Dispose();
|
||||||
|
FireCallback();
|
||||||
|
}
|
||||||
|
public void FireCallback()
|
||||||
|
{
|
||||||
|
m_fCallback(new AsyncOperationData(m_oParam));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class AsyncOperationData : IAsyncResult
|
||||||
|
{
|
||||||
|
protected bool _completed;
|
||||||
|
protected Object _state;
|
||||||
|
|
||||||
|
bool IAsyncResult.IsCompleted { get { return _completed; } }
|
||||||
|
WaitHandle IAsyncResult.AsyncWaitHandle { get { return null; } }
|
||||||
|
Object IAsyncResult.AsyncState { get { return _state; } }
|
||||||
|
bool IAsyncResult.CompletedSynchronously { get { return false; } }
|
||||||
|
|
||||||
|
public AsyncOperationData(Object state)
|
||||||
|
{
|
||||||
|
_state = state;
|
||||||
|
_completed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region For action
|
||||||
|
public class AsyncContextReadOperation
|
||||||
|
{
|
||||||
|
private static readonly ILog _log = LogManager.GetLogger(typeof(AsyncContextReadOperation));
|
||||||
|
private Stream m_oStream = null;
|
||||||
|
private byte[] m_aBuffer = new byte[Constants.mc_nBufferSize];
|
||||||
|
public MemoryStream m_aOutput = new MemoryStream();
|
||||||
|
private ErrorTypes m_eError = ErrorTypes.NoError;
|
||||||
|
private AsyncCallback m_fAsyncCallback;
|
||||||
|
private object m_oParam;
|
||||||
|
private Int64 m_nMaxSize = -1;
|
||||||
|
public AsyncContextReadOperation()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public AsyncContextReadOperation(Int64 nMaxSize)
|
||||||
|
{
|
||||||
|
m_nMaxSize = nMaxSize;
|
||||||
|
}
|
||||||
|
public ErrorTypes ReadContext(Stream oStream)
|
||||||
|
{
|
||||||
|
ErrorTypes eError = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
byte[] aBuffer = new byte[Constants.mc_nBufferSize];
|
||||||
|
int read;
|
||||||
|
while ((read = oStream.Read(aBuffer, 0, aBuffer.Length)) > 0)
|
||||||
|
{
|
||||||
|
m_aOutput.Write(aBuffer, 0, read);
|
||||||
|
if (m_nMaxSize > 0 && m_aOutput.Length > m_nMaxSize)
|
||||||
|
{
|
||||||
|
_log.ErrorFormat("ReadContext object size {0} exceed max {1}", m_aOutput.Length, m_nMaxSize);
|
||||||
|
eError = ErrorTypes.ReadRequestStream;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (oStream.CanSeek && oStream.Length != m_aOutput.Length)
|
||||||
|
_log.ErrorFormat("ClearCacheTaskResultCallback read {0} of {1}", m_aOutput.Length, oStream.Length);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eError = ErrorTypes.ReadRequestStream;
|
||||||
|
}
|
||||||
|
return eError;
|
||||||
|
}
|
||||||
|
public void ReadContextBegin(Stream oStream, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
ErrorTypes eError = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_oStream = oStream;
|
||||||
|
m_fAsyncCallback = fCallback;
|
||||||
|
m_oParam = oParam;
|
||||||
|
m_oStream.BeginRead(m_aBuffer, 0, m_aBuffer.Length, ClearCacheTaskResultCallback, null);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eError = ErrorTypes.ReadRequestStream;
|
||||||
|
}
|
||||||
|
if (ErrorTypes.NoError != eError)
|
||||||
|
{
|
||||||
|
m_eError = eError;
|
||||||
|
fCallback.Invoke(new AsyncOperationData(oParam));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ClearCacheTaskResultCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int nByteRead = m_oStream.EndRead(ar);
|
||||||
|
if (nByteRead > 0)
|
||||||
|
{
|
||||||
|
m_aOutput.Write(m_aBuffer, 0, nByteRead);
|
||||||
|
if (m_nMaxSize > 0 && m_aOutput.Length > m_nMaxSize)
|
||||||
|
{
|
||||||
|
_log.ErrorFormat("ClearCacheTaskResultCallback object size {0} exceed max {1}", m_aOutput.Length, m_nMaxSize);
|
||||||
|
m_eError = ErrorTypes.ReadRequestStream;
|
||||||
|
m_fAsyncCallback.Invoke(new AsyncOperationData(m_oParam));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_oStream.BeginRead(m_aBuffer, 0, m_aBuffer.Length, ClearCacheTaskResultCallback, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (m_oStream.CanSeek && m_oStream.Length != m_aOutput.Length)
|
||||||
|
_log.ErrorFormat("ClearCacheTaskResultCallback read {0} of {1}", m_aOutput.Length, m_oStream.Length);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
m_fAsyncCallback.Invoke(new AsyncOperationData(m_oParam));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_log.Error("Exception catched in ClearCacheTaskResultCallback:", e);
|
||||||
|
m_eError = ErrorTypes.ReadRequestStream;
|
||||||
|
m_fAsyncCallback.Invoke(new AsyncOperationData(m_oParam));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ErrorTypes ReadContextEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
return m_eError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class AsyncClearCacheOperation
|
||||||
|
{
|
||||||
|
private static readonly ILog _log = LogManager.GetLogger(typeof(AsyncClearCacheOperation));
|
||||||
|
private string m_sKey;
|
||||||
|
private ITaskResultInterface m_oTaskResult = TaskResult.NewTaskResult();
|
||||||
|
private Storage m_oStorage = new Storage();
|
||||||
|
private ErrorTypes m_eError = ErrorTypes.NoError;
|
||||||
|
private AsyncCallback m_fAsyncCallback;
|
||||||
|
private object m_oParam;
|
||||||
|
public void ClearCacheBegin(string sKey, AsyncCallback fAsyncCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_sKey = sKey;
|
||||||
|
m_fAsyncCallback = fAsyncCallback;
|
||||||
|
m_oParam = oParam;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_oTaskResult.RemoveBegin(m_sKey, ClearCacheTaskResultCallback, null);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
_log.ErrorFormat("Exception catched in ClearCacheBegin:", e);
|
||||||
|
m_eError = ErrorTypes.Unknown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ErrorTypes ClearCacheEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
return m_eError;
|
||||||
|
}
|
||||||
|
private void FireCallback()
|
||||||
|
{
|
||||||
|
m_fAsyncCallback.Invoke(new AsyncOperationData(m_oParam));
|
||||||
|
}
|
||||||
|
private void ClearCacheTaskResultCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_eError = m_oTaskResult.RemoveEnd(ar);
|
||||||
|
if (ErrorTypes.NoError == m_eError)
|
||||||
|
{
|
||||||
|
m_oStorage.RemovePathBegin(m_sKey, ClearCacheAllCallback, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_log.ErrorFormat("m_oTaskResult.RemoveEnd return:", m_eError);
|
||||||
|
FireCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
_log.ErrorFormat("Exception catched in ClearCacheTaskResultCallback:", e);
|
||||||
|
m_eError = ErrorTypes.Unknown;
|
||||||
|
FireCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ClearCacheAllCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_eError = m_oStorage.RemovePathEnd(ar);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
_log.ErrorFormat("Exception catched in ClearCacheAllCallback:", e);
|
||||||
|
m_eError = ErrorTypes.Unknown;
|
||||||
|
}
|
||||||
|
FireCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class AsyncMediaXmlOperation
|
||||||
|
{
|
||||||
|
private class TransportClass : TransportClassAsyncOperation
|
||||||
|
{
|
||||||
|
public string m_sPath;
|
||||||
|
public Storage m_oStorage = new Storage();
|
||||||
|
public MemoryStream m_oMemoryStream = new MemoryStream();
|
||||||
|
public Dictionary<string, string> m_aMediaXmlMapHash;
|
||||||
|
public Dictionary<string, string> m_aMediaXmlMapFilename;
|
||||||
|
public Utils.getMD5HexStringDelegate m_ogetMD5HexStringDelegate;
|
||||||
|
public StorageTreeNode m_oStorageTreeNode;
|
||||||
|
public int m_nIndex;
|
||||||
|
public int m_nLength;
|
||||||
|
public ErrorTypes m_eError = ErrorTypes.NoError;
|
||||||
|
public TransportClass(AsyncCallback fCallback, object oParam)
|
||||||
|
: base(fCallback, oParam)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public override void Close()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
m_eError = ErrorTypes.Unknown;
|
||||||
|
}
|
||||||
|
public void SetStorageTreeNode(StorageTreeNode oStorageTreeNode)
|
||||||
|
{
|
||||||
|
m_oStorageTreeNode = oStorageTreeNode;
|
||||||
|
m_nIndex = -1;
|
||||||
|
m_nLength = oStorageTreeNode.m_aSubNodes.Count;
|
||||||
|
}
|
||||||
|
public StorageTreeNode getNextTreeNode()
|
||||||
|
{
|
||||||
|
StorageTreeNode oRes = null;
|
||||||
|
if (m_nIndex < 0)
|
||||||
|
m_nIndex = 0;
|
||||||
|
else
|
||||||
|
m_nIndex++;
|
||||||
|
if (m_nIndex < m_nLength)
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
StorageTreeNode oCurItem = m_oStorageTreeNode.m_aSubNodes[m_nIndex];
|
||||||
|
if (false == oCurItem.m_bIsDirectory)
|
||||||
|
{
|
||||||
|
oRes = oCurItem;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (m_nIndex >= m_nLength)
|
||||||
|
break;
|
||||||
|
m_nIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return oRes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private TransportClass m_oGetMediaXml;
|
||||||
|
private TransportClass m_oWriteMediaXml;
|
||||||
|
public ErrorTypes GenerateMediaXmlRealPath(string sPath)
|
||||||
|
{
|
||||||
|
ErrorTypes eRes = ErrorTypes.NoError;
|
||||||
|
Dictionary<string, string> aMediaXmlMapHash = new Dictionary<string, string>();
|
||||||
|
Dictionary<string, string> aMediaXmlMapFilename = new Dictionary<string, string>();
|
||||||
|
string sDir = Path.GetDirectoryName(sPath);
|
||||||
|
if (Directory.Exists(sDir))
|
||||||
|
{
|
||||||
|
string[] aFiles = Directory.GetFiles(sDir);
|
||||||
|
for (int i = 0; i < aFiles.Length; ++i)
|
||||||
|
{
|
||||||
|
var filepath = aFiles[i];
|
||||||
|
using (FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read))
|
||||||
|
AddToMediaXmlBytes(aMediaXmlMapHash, aMediaXmlMapFilename, Path.GetFileName(filepath),fs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
eRes = ErrorTypes.Unknown;
|
||||||
|
File.WriteAllBytes(sPath, GetMediaXmlBytes(aMediaXmlMapHash));
|
||||||
|
return eRes;
|
||||||
|
}
|
||||||
|
public ErrorTypes GenerateMediaXml(string sPath)
|
||||||
|
{
|
||||||
|
ErrorTypes eRes = ErrorTypes.NoError;
|
||||||
|
Dictionary<string, string> aMediaXmlMapHash = new Dictionary<string, string>();
|
||||||
|
Dictionary<string, string> aMediaXmlMapFilename = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
Storage oStorage = new Storage();
|
||||||
|
StorageTreeNode oStorageTreeNode = oStorage.GetTreeNode(Path.GetDirectoryName(sPath));
|
||||||
|
if (null != oStorageTreeNode)
|
||||||
|
{
|
||||||
|
for (int i = 0, length = oStorageTreeNode.m_aSubNodes.Count; i < length; ++i)
|
||||||
|
{
|
||||||
|
StorageTreeNode oSubNode = oStorageTreeNode.m_aSubNodes[i];
|
||||||
|
if (!oSubNode.m_bIsDirectory)
|
||||||
|
{
|
||||||
|
string sFilePath = Path.Combine(Path.GetDirectoryName(sPath), oSubNode.m_sName);
|
||||||
|
using (MemoryStream ms = new MemoryStream())
|
||||||
|
{
|
||||||
|
int nReadWriteBytes;
|
||||||
|
ErrorTypes eReadError = oStorage.ReadFile(sFilePath, ms, out nReadWriteBytes);
|
||||||
|
if (ErrorTypes.NoError == eReadError && nReadWriteBytes > 0)
|
||||||
|
{
|
||||||
|
ms.Position = 0;
|
||||||
|
AddToMediaXmlBytes(aMediaXmlMapHash, aMediaXmlMapFilename, oSubNode.m_sName, ms);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
byte[] aBuffer = GetMediaXmlBytes(aMediaXmlMapHash);
|
||||||
|
using (MemoryStream ms = new MemoryStream(aBuffer))
|
||||||
|
{
|
||||||
|
int nReadWriteBytes;
|
||||||
|
eRes = oStorage.WriteFile(sPath, ms, out nReadWriteBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
eRes = ErrorTypes.Unknown;
|
||||||
|
return eRes;
|
||||||
|
}
|
||||||
|
public void GetMediaXmlBegin(string sPath, AsyncCallback fAsyncCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oGetMediaXml = new TransportClass(fAsyncCallback, oParam);
|
||||||
|
m_oGetMediaXml.m_sPath = sPath;
|
||||||
|
m_oGetMediaXml.m_aMediaXmlMapFilename = new Dictionary<string, string>();
|
||||||
|
m_oGetMediaXml.m_aMediaXmlMapHash = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
StorageFileInfo oStorageFileInfo;
|
||||||
|
ErrorTypes eFileExist = m_oGetMediaXml.m_oStorage.GetFileInfo(sPath, out oStorageFileInfo);
|
||||||
|
if (ErrorTypes.NoError == eFileExist && null != oStorageFileInfo)
|
||||||
|
{
|
||||||
|
|
||||||
|
m_oGetMediaXml.m_oStorage.ReadFileBegin(sPath, m_oGetMediaXml.m_oMemoryStream, ReadMediaXmlCallback, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
m_oGetMediaXml.m_oStorage.GetTreeNodeBegin(Path.GetDirectoryName(sPath), GetTreeNodeCallback, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ErrorTypes GetMediaXmlEnd(IAsyncResult ar, out Dictionary<string, string> aMediaXmlMapHash, out Dictionary<string, string> aMediaXmlMapFilename)
|
||||||
|
{
|
||||||
|
aMediaXmlMapHash = m_oGetMediaXml.m_aMediaXmlMapHash;
|
||||||
|
aMediaXmlMapFilename = m_oGetMediaXml.m_aMediaXmlMapFilename;
|
||||||
|
return ErrorTypes.NoError;
|
||||||
|
}
|
||||||
|
private void ReadMediaXmlCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int nReadWriteBytes;
|
||||||
|
m_oGetMediaXml.m_eError = m_oGetMediaXml.m_oStorage.ReadFileEnd(ar, out nReadWriteBytes);
|
||||||
|
if (ErrorTypes.NoError == m_oGetMediaXml.m_eError || ErrorTypes.StorageFileNoFound == m_oGetMediaXml.m_eError)
|
||||||
|
{
|
||||||
|
MemoryStream oMemoryStream = m_oGetMediaXml.m_oMemoryStream;
|
||||||
|
if (nReadWriteBytes > 0)
|
||||||
|
{
|
||||||
|
string sXml = Encoding.UTF8.GetString(oMemoryStream.GetBuffer(), 0, (int)oMemoryStream.Position);
|
||||||
|
using (XmlTextReader reader = new XmlTextReader(new StringReader(sXml)))
|
||||||
|
{
|
||||||
|
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
if ("image" == reader.Name)
|
||||||
|
{
|
||||||
|
string sHash = null;
|
||||||
|
string sFilename = null;
|
||||||
|
while (reader.MoveToNextAttribute())
|
||||||
|
{
|
||||||
|
if ("md5" == reader.Name)
|
||||||
|
sHash = reader.Value;
|
||||||
|
else if ("filename" == reader.Name)
|
||||||
|
sFilename = reader.Value;
|
||||||
|
}
|
||||||
|
if (null != sHash && null != sFilename)
|
||||||
|
{
|
||||||
|
m_oGetMediaXml.m_aMediaXmlMapHash[sHash] = sFilename;
|
||||||
|
m_oGetMediaXml.m_aMediaXmlMapFilename[sFilename] = sHash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_oGetMediaXml.FireCallback();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oGetMediaXml.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void GetTreeNodeCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_oGetMediaXml.SetStorageTreeNode(m_oGetMediaXml.m_oStorage.GetTreeNodeEnd(ar));
|
||||||
|
m_oGetMediaXml.m_ogetMD5HexStringDelegate = new Utils.getMD5HexStringDelegate(Utils.getMD5HexString);
|
||||||
|
m_oGetMediaXml.m_oMemoryStream = new MemoryStream();
|
||||||
|
StorageTreeNode oFirstItem = m_oGetMediaXml.getNextTreeNode();
|
||||||
|
if (null != oFirstItem)
|
||||||
|
{
|
||||||
|
|
||||||
|
m_oGetMediaXml.m_oStorage.ReadFileBegin(Path.Combine(Path.GetDirectoryName(m_oGetMediaXml.m_sPath), oFirstItem.m_sName), m_oGetMediaXml.m_oMemoryStream, ReadNextMediaXmlCallback, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_oGetMediaXml.FireCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oGetMediaXml.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ReadNextMediaXmlCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int nReadWriteBytes;
|
||||||
|
ErrorTypes eError = m_oGetMediaXml.m_oStorage.ReadFileEnd(ar, out nReadWriteBytes);
|
||||||
|
if (ErrorTypes.NoError == eError)
|
||||||
|
{
|
||||||
|
StorageTreeNode oCurNode = m_oGetMediaXml.m_oStorageTreeNode.m_aSubNodes[m_oGetMediaXml.m_nIndex];
|
||||||
|
|
||||||
|
m_oGetMediaXml.m_oMemoryStream.Position = 0;
|
||||||
|
string sHex = Utils.getMD5HexString(m_oGetMediaXml.m_oMemoryStream);
|
||||||
|
if (false == m_oGetMediaXml.m_aMediaXmlMapFilename.ContainsKey(oCurNode.m_sName))
|
||||||
|
m_oGetMediaXml.m_aMediaXmlMapFilename.Add(oCurNode.m_sName, sHex);
|
||||||
|
if (false == m_oGetMediaXml.m_aMediaXmlMapHash.ContainsKey(sHex))
|
||||||
|
m_oGetMediaXml.m_aMediaXmlMapHash.Add(sHex, oCurNode.m_sName);
|
||||||
|
oCurNode = m_oGetMediaXml.getNextTreeNode();
|
||||||
|
if (null == oCurNode)
|
||||||
|
{
|
||||||
|
m_oGetMediaXml.FireCallback();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_oGetMediaXml.m_oMemoryStream = new MemoryStream();
|
||||||
|
m_oGetMediaXml.m_oStorage.ReadFileBegin(Path.Combine(Path.GetDirectoryName(m_oGetMediaXml.m_sPath), oCurNode.m_sName), m_oGetMediaXml.m_oMemoryStream, ReadNextMediaXmlCallback, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_oGetMediaXml.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oGetMediaXml.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void WriteMediaXmlBegin(string sPath, Dictionary<string, string> aMediaXmlMapHash, AsyncCallback fAsyncCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oWriteMediaXml = new TransportClass(fAsyncCallback, oParam);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
byte[] aBuffer = GetMediaXmlBytes(aMediaXmlMapHash);
|
||||||
|
MemoryStream ms = new MemoryStream(aBuffer);
|
||||||
|
m_oWriteMediaXml.m_oStorage = new Storage();
|
||||||
|
m_oWriteMediaXml.m_oStorage.WriteFileBegin(sPath, ms, fAsyncCallback, oParam);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oWriteMediaXml.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void AddToMediaXmlBytes(Dictionary<string, string> aMediaXmlMapHash, Dictionary<string, string> aMediaXmlMapFilename, string sFilename, Stream ms)
|
||||||
|
{
|
||||||
|
string sHex = Utils.getMD5HexString(ms);
|
||||||
|
if (false == aMediaXmlMapFilename.ContainsKey(sFilename))
|
||||||
|
aMediaXmlMapFilename.Add(sFilename, sHex);
|
||||||
|
if (false == aMediaXmlMapHash.ContainsKey(sHex))
|
||||||
|
aMediaXmlMapHash.Add(sHex, sFilename);
|
||||||
|
}
|
||||||
|
private byte[] GetMediaXmlBytes(Dictionary<string, string> aMediaXmlMapHash)
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||||
|
sb.Append("<images>");
|
||||||
|
foreach (KeyValuePair<string, string> kvp in aMediaXmlMapHash)
|
||||||
|
sb.AppendFormat("<image md5=\"{0}\" filename=\"{1}\"/>", kvp.Key, kvp.Value);
|
||||||
|
sb.Append("</images>");
|
||||||
|
return Encoding.UTF8.GetBytes(sb.ToString());
|
||||||
|
}
|
||||||
|
public ErrorTypes WriteMediaXmlEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int nReadWriteBytes;
|
||||||
|
m_oWriteMediaXml.m_eError = m_oWriteMediaXml.m_oStorage.WriteFileEnd(ar, out nReadWriteBytes);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oWriteMediaXml.Dispose();
|
||||||
|
}
|
||||||
|
return m_oWriteMediaXml.m_eError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class AsyncWebRequestOperation
|
||||||
|
{
|
||||||
|
private static readonly ILog _log = LogManager.GetLogger(typeof(AsyncWebRequestOperation));
|
||||||
|
private class TransportClass
|
||||||
|
{
|
||||||
|
public AsyncCallback m_fAsyncCallback;
|
||||||
|
public object m_oParam;
|
||||||
|
public string m_sUrl;
|
||||||
|
public string m_sMethod;
|
||||||
|
public string m_sContentType;
|
||||||
|
public byte[] m_aInput;
|
||||||
|
|
||||||
|
public Timer m_oTimer;
|
||||||
|
public HttpWebRequest m_oWebRequest;
|
||||||
|
public HttpWebResponse m_oHttpWebResponse;
|
||||||
|
public Stream m_oStream;
|
||||||
|
public AsyncContextReadOperation m_oAsyncContextReadOperation;
|
||||||
|
|
||||||
|
public byte[] m_aOutput;
|
||||||
|
public ErrorTypes m_eError;
|
||||||
|
|
||||||
|
public uint m_nAttemptCount;
|
||||||
|
public uint m_nAttemptDelay;
|
||||||
|
public TransportClass(AsyncCallback fCallback, object oParam, string sUrl, string sMethod, string sContentType, byte[] aData, uint nAttemptCount, uint nAttemptDelay)
|
||||||
|
{
|
||||||
|
m_fAsyncCallback = fCallback;
|
||||||
|
m_oParam = oParam;
|
||||||
|
m_sUrl = sUrl;
|
||||||
|
m_sMethod = sMethod;
|
||||||
|
m_sContentType = sContentType;
|
||||||
|
m_aInput = aData;
|
||||||
|
|
||||||
|
m_oTimer = null;
|
||||||
|
m_oWebRequest = null;
|
||||||
|
m_oHttpWebResponse = null;
|
||||||
|
m_oStream = null;
|
||||||
|
m_oAsyncContextReadOperation = null;
|
||||||
|
|
||||||
|
m_aOutput = null;
|
||||||
|
m_eError = ErrorTypes.NoError;
|
||||||
|
|
||||||
|
m_nAttemptCount = nAttemptCount;
|
||||||
|
m_nAttemptDelay = nAttemptDelay;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private uint m_nAttemptCount = 1;
|
||||||
|
private uint m_nAttemptDelay = 0;
|
||||||
|
private Int64 m_nMaxSize = -1;
|
||||||
|
public AsyncWebRequestOperation()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public AsyncWebRequestOperation(Int64 nMaxSize)
|
||||||
|
{
|
||||||
|
m_nMaxSize = nMaxSize;
|
||||||
|
}
|
||||||
|
public AsyncWebRequestOperation(uint nAttemptCount, uint nAttemptDelay)
|
||||||
|
{
|
||||||
|
m_nAttemptCount = nAttemptCount;
|
||||||
|
m_nAttemptDelay = nAttemptDelay;
|
||||||
|
}
|
||||||
|
public AsyncWebRequestOperation(Int64 nMaxSize, uint nAttemptCount, uint nAttemptDelay)
|
||||||
|
{
|
||||||
|
m_nAttemptCount = nAttemptCount;
|
||||||
|
m_nAttemptDelay = nAttemptDelay;
|
||||||
|
m_nMaxSize = nMaxSize;
|
||||||
|
}
|
||||||
|
private void Clear(TransportClass oTransportClass)
|
||||||
|
{
|
||||||
|
if (null != oTransportClass.m_oStream)
|
||||||
|
oTransportClass.m_oStream.Close();
|
||||||
|
if (null != oTransportClass.m_oHttpWebResponse)
|
||||||
|
oTransportClass.m_oHttpWebResponse.Close();
|
||||||
|
}
|
||||||
|
private void FireCallback(TransportClass oTransportClass)
|
||||||
|
{
|
||||||
|
if (null != oTransportClass.m_fAsyncCallback)
|
||||||
|
oTransportClass.m_fAsyncCallback.Invoke(new AsyncOperationData(oTransportClass.m_oParam));
|
||||||
|
}
|
||||||
|
private void ClearAndCallback(TransportClass oTransportClass)
|
||||||
|
{
|
||||||
|
ClearAndCallback(oTransportClass, false);
|
||||||
|
}
|
||||||
|
private void ClearAndCallback(TransportClass oTransportClass, bool bRepeatIfCan)
|
||||||
|
{
|
||||||
|
oTransportClass.m_nAttemptCount--;
|
||||||
|
Clear(oTransportClass);
|
||||||
|
if (!bRepeatIfCan || oTransportClass.m_nAttemptCount <= 0)
|
||||||
|
{
|
||||||
|
FireCallback(oTransportClass);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
oTransportClass.m_eError = ErrorTypes.NoError;
|
||||||
|
Timer oTimer = new Timer(WaitEndTimerCallback, oTransportClass, TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1));
|
||||||
|
oTransportClass.m_oTimer = oTimer;
|
||||||
|
oTimer.Change(TimeSpan.FromMilliseconds(oTransportClass.m_nAttemptDelay), TimeSpan.FromMilliseconds(-1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void WaitEndTimerCallback(Object stateInfo)
|
||||||
|
{
|
||||||
|
TransportClass oTransportClass1 = stateInfo as TransportClass;
|
||||||
|
if (null != oTransportClass1.m_oTimer)
|
||||||
|
oTransportClass1.m_oTimer.Dispose();
|
||||||
|
RequestBeginExec(oTransportClass1);
|
||||||
|
}
|
||||||
|
public ErrorTypes Request(string sUrl, string sMethod, string sContentType, byte[] aData, out byte[] aOutput)
|
||||||
|
{
|
||||||
|
ErrorTypes eError = ErrorTypes.NoError;
|
||||||
|
aOutput = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
ServicePointManager.ServerCertificateValidationCallback = (s, c, h, p) => true;
|
||||||
|
|
||||||
|
WebResponse oWebResponse = null;
|
||||||
|
int nAttemptCount = 0;
|
||||||
|
bool bComplete = false;
|
||||||
|
while (!bComplete && nAttemptCount < m_nAttemptCount)
|
||||||
|
{
|
||||||
|
eError = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpWebRequest oWebRequest = (HttpWebRequest)HttpWebRequest.Create(sUrl);
|
||||||
|
oWebRequest.UserAgent = Constants.mc_sWebClientUserAgent;
|
||||||
|
if (!string.IsNullOrEmpty(sMethod))
|
||||||
|
oWebRequest.Method = sMethod;
|
||||||
|
if ("POST" == oWebRequest.Method)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(sContentType))
|
||||||
|
oWebRequest.ContentType = sContentType;
|
||||||
|
else
|
||||||
|
oWebRequest.ContentType = "text/plain";
|
||||||
|
if (null != aData)
|
||||||
|
oWebRequest.ContentLength = aData.Length;
|
||||||
|
using (Stream postStream = oWebRequest.GetRequestStream())
|
||||||
|
{
|
||||||
|
if (null != aData)
|
||||||
|
postStream.Write(aData, 0, aData.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
oWebResponse = oWebRequest.GetResponse();
|
||||||
|
bComplete = true;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_log.Error("Exception catched in Request:", e);
|
||||||
|
eError = ErrorTypes.WebRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
nAttemptCount++;
|
||||||
|
if (!bComplete && nAttemptCount < m_nAttemptCount)
|
||||||
|
Thread.Sleep((int)m_nAttemptDelay);
|
||||||
|
}
|
||||||
|
if (null != oWebResponse)
|
||||||
|
{
|
||||||
|
Int64 ContentLength = 0;
|
||||||
|
if (!Int64.TryParse(oWebResponse.Headers.Get("Content-Length"), out ContentLength))
|
||||||
|
ContentLength = 0;
|
||||||
|
if (m_nMaxSize > 0 && ContentLength > m_nMaxSize)
|
||||||
|
{
|
||||||
|
_log.ErrorFormat("Downloaded object size {0} exceed max {1}", ContentLength, m_nMaxSize);
|
||||||
|
eError = ErrorTypes.WebRequest;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
using (Stream oResponseStream = oWebResponse.GetResponseStream())
|
||||||
|
{
|
||||||
|
AsyncContextReadOperation oAsyncContextReadOperation = new AsyncContextReadOperation(m_nMaxSize);
|
||||||
|
if (ErrorTypes.NoError == oAsyncContextReadOperation.ReadContext(oResponseStream))
|
||||||
|
aOutput = oAsyncContextReadOperation.m_aOutput.ToArray();
|
||||||
|
else
|
||||||
|
eError = ErrorTypes.WebRequest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
oWebResponse.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_log.Error("Exception catched in Request:", e);
|
||||||
|
eError = ErrorTypes.WebRequest;
|
||||||
|
}
|
||||||
|
return eError;
|
||||||
|
}
|
||||||
|
public IAsyncResult RequestBegin(string sUrl, string sMethod, string sContentType, byte[] aData, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
TransportClass oTransportClass = new TransportClass(fCallback, oParam, sUrl, sMethod, sContentType, aData, m_nAttemptCount, m_nAttemptDelay);
|
||||||
|
AsyncOperationData oAsyncOperationData = new AsyncOperationData(oTransportClass);
|
||||||
|
RequestBeginExec(oTransportClass);
|
||||||
|
return oAsyncOperationData;
|
||||||
|
}
|
||||||
|
private void RequestBeginExec(TransportClass oTransportClass)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
ServicePointManager.ServerCertificateValidationCallback = (s, c, h, p) => true;
|
||||||
|
|
||||||
|
HttpWebRequest oWebRequest = (HttpWebRequest)HttpWebRequest.Create(oTransportClass.m_sUrl);
|
||||||
|
oWebRequest.UserAgent = Constants.mc_sWebClientUserAgent;
|
||||||
|
oTransportClass.m_oWebRequest = oWebRequest;
|
||||||
|
if (!string.IsNullOrEmpty(oTransportClass.m_sMethod))
|
||||||
|
oWebRequest.Method = oTransportClass.m_sMethod;
|
||||||
|
if ("GET" == oWebRequest.Method)
|
||||||
|
{
|
||||||
|
oWebRequest.BeginGetResponse(GetResponseCallback, oTransportClass);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(oTransportClass.m_sContentType))
|
||||||
|
oWebRequest.ContentType = oTransportClass.m_sContentType;
|
||||||
|
else
|
||||||
|
oWebRequest.ContentType = "text/plain";
|
||||||
|
if (null != oTransportClass.m_aInput)
|
||||||
|
oWebRequest.ContentLength = oTransportClass.m_aInput.Length;
|
||||||
|
oWebRequest.BeginGetRequestStream(GetRequestStreamCallback, oTransportClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_log.Error("Exception catched in RequestBeginExec:", e);
|
||||||
|
oTransportClass.m_eError = ErrorTypes.WebRequest;
|
||||||
|
ClearAndCallback(oTransportClass, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void GetRequestStreamCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
TransportClass oTransportClass = ar.AsyncState as TransportClass;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Stream postStream = oTransportClass.m_oWebRequest.EndGetRequestStream(ar);
|
||||||
|
if (null != oTransportClass.m_aInput)
|
||||||
|
postStream.Write(oTransportClass.m_aInput, 0, oTransportClass.m_aInput.Length);
|
||||||
|
postStream.Close();
|
||||||
|
oTransportClass.m_oWebRequest.BeginGetResponse(GetResponseCallback, oTransportClass);
|
||||||
|
}
|
||||||
|
catch (WebException e)
|
||||||
|
{
|
||||||
|
_log.Error("WebException catched in GetResponseCallback:", e);
|
||||||
|
_log.ErrorFormat("The Uri requested is {0}", oTransportClass.m_oWebRequest.RequestUri);
|
||||||
|
oTransportClass.m_eError = ErrorTypes.WebRequest;
|
||||||
|
ClearAndCallback(oTransportClass, true);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_log.Error("Exception catched in GetResponseCallback:", e);
|
||||||
|
oTransportClass.m_eError = ErrorTypes.WebRequest;
|
||||||
|
ClearAndCallback(oTransportClass, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void GetResponseCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
TransportClass oTransportClass = ar.AsyncState as TransportClass;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpWebResponse response = (HttpWebResponse)oTransportClass.m_oWebRequest.EndGetResponse(ar);
|
||||||
|
Int64 ContentLength = 0;
|
||||||
|
if (!Int64.TryParse(response.Headers.Get("Content-Length"), out ContentLength))
|
||||||
|
ContentLength = 0;
|
||||||
|
if (m_nMaxSize > 0 && ContentLength > m_nMaxSize)
|
||||||
|
{
|
||||||
|
_log.ErrorFormat("Downloaded object size {0} exceed max {1}", ContentLength, m_nMaxSize);
|
||||||
|
oTransportClass.m_eError = ErrorTypes.WebRequest;
|
||||||
|
ClearAndCallback(oTransportClass);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Stream streamResponse = response.GetResponseStream();
|
||||||
|
AsyncContextReadOperation oAsyncContextReadOperation = new AsyncContextReadOperation(m_nMaxSize);
|
||||||
|
oTransportClass.m_oHttpWebResponse = response;
|
||||||
|
oTransportClass.m_oStream = streamResponse;
|
||||||
|
oTransportClass.m_oAsyncContextReadOperation = oAsyncContextReadOperation;
|
||||||
|
oAsyncContextReadOperation.ReadContextBegin(streamResponse, ReadContextCallback, oTransportClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_log.Error("Exception catched in GetRequestStreamCallback:", e);
|
||||||
|
oTransportClass.m_eError = ErrorTypes.WebRequest;
|
||||||
|
ClearAndCallback(oTransportClass, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ReadContextCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
TransportClass oTransportClass = ar.AsyncState as TransportClass;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ErrorTypes eError = oTransportClass.m_oAsyncContextReadOperation.ReadContextEnd(ar);
|
||||||
|
if (ErrorTypes.NoError == eError)
|
||||||
|
oTransportClass.m_aOutput = oTransportClass.m_oAsyncContextReadOperation.m_aOutput.ToArray();
|
||||||
|
else
|
||||||
|
oTransportClass.m_eError = ErrorTypes.WebRequest;
|
||||||
|
ClearAndCallback(oTransportClass);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_log.Error("Exception catched in ReadContextCallback:", e);
|
||||||
|
oTransportClass.m_eError = ErrorTypes.WebRequest;
|
||||||
|
ClearAndCallback(oTransportClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ErrorTypes RequestEnd(IAsyncResult ar, out byte[] aOutput)
|
||||||
|
{
|
||||||
|
aOutput = null;
|
||||||
|
ErrorTypes eError = ErrorTypes.WebRequest;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TransportClass oTransportClass = ar.AsyncState as TransportClass;
|
||||||
|
aOutput = oTransportClass.m_aOutput;
|
||||||
|
eError = oTransportClass.m_eError;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_log.Error("Exception catched in RequestEnd:", e);
|
||||||
|
eError = ErrorTypes.WebRequest;
|
||||||
|
}
|
||||||
|
return eError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
837
ServerComponents/FileConverterUtils2/AsyncOperation.cs.bak
Normal file
837
ServerComponents/FileConverterUtils2/AsyncOperation.cs.bak
Normal file
|
@ -0,0 +1,837 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Web;
|
||||||
|
using System.IO;
|
||||||
|
using System.Xml;
|
||||||
|
using System.Net;
|
||||||
|
using log4net;
|
||||||
|
|
||||||
|
namespace FileConverterUtils2
|
||||||
|
{
|
||||||
|
#region TransportClass
|
||||||
|
public class TransportClassMainAshx
|
||||||
|
{
|
||||||
|
public HttpContext m_oHttpContext;
|
||||||
|
public AsyncCallback m_oAsyncCallback;
|
||||||
|
public TransportClassMainAshx(HttpContext oHttpContext, AsyncCallback oAsyncCallback)
|
||||||
|
{
|
||||||
|
m_oHttpContext = oHttpContext;
|
||||||
|
m_oAsyncCallback = oAsyncCallback;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class TransportClassContextRead : TransportClassMainAshx
|
||||||
|
{
|
||||||
|
public AsyncContextReadOperation m_oAsyncContextReadOperation;
|
||||||
|
public TransportClassContextRead(TransportClassMainAshx m_oTransportClassMainAshx, AsyncContextReadOperation oAsyncContextReadOperation)
|
||||||
|
: base(m_oTransportClassMainAshx.m_oHttpContext, m_oTransportClassMainAshx.m_oAsyncCallback)
|
||||||
|
{
|
||||||
|
m_oAsyncContextReadOperation = oAsyncContextReadOperation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public abstract class TransportClassAsyncOperation
|
||||||
|
{
|
||||||
|
public AsyncCallback m_fCallback = null;
|
||||||
|
public object m_oParam = null;
|
||||||
|
public TransportClassAsyncOperation(AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_fCallback = fCallback;
|
||||||
|
m_oParam = oParam;
|
||||||
|
}
|
||||||
|
public abstract void Close();
|
||||||
|
public abstract void Dispose();
|
||||||
|
public void DisposeAndCallback()
|
||||||
|
{
|
||||||
|
Dispose();
|
||||||
|
FireCallback();
|
||||||
|
}
|
||||||
|
public void FireCallback()
|
||||||
|
{
|
||||||
|
m_fCallback(new AsyncOperationData(m_oParam));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class AsyncOperationData : IAsyncResult
|
||||||
|
{
|
||||||
|
protected bool _completed;
|
||||||
|
protected Object _state;
|
||||||
|
|
||||||
|
bool IAsyncResult.IsCompleted { get { return _completed; } }
|
||||||
|
WaitHandle IAsyncResult.AsyncWaitHandle { get { return null; } }
|
||||||
|
Object IAsyncResult.AsyncState { get { return _state; } }
|
||||||
|
bool IAsyncResult.CompletedSynchronously { get { return false; } }
|
||||||
|
|
||||||
|
public AsyncOperationData(Object state)
|
||||||
|
{
|
||||||
|
_state = state;
|
||||||
|
_completed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region For action
|
||||||
|
public class AsyncContextReadOperation
|
||||||
|
{
|
||||||
|
private Stream m_oStream = null;
|
||||||
|
private const int mc_nBufferSize = 1024*1024;
|
||||||
|
private byte[] m_aBuffer = new byte[mc_nBufferSize];
|
||||||
|
public MemoryStream m_aOutput = new MemoryStream();
|
||||||
|
private ErrorTypes m_eError = ErrorTypes.NoError;
|
||||||
|
private AsyncCallback m_fAsyncCallback;
|
||||||
|
private object m_oParam;
|
||||||
|
public AsyncContextReadOperation()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public void ReadContextBegin(Stream oStream, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_oStream = oStream;
|
||||||
|
m_fAsyncCallback = fCallback;
|
||||||
|
m_oParam = oParam;
|
||||||
|
m_oStream.BeginRead(m_aBuffer, 0, mc_nBufferSize, ClearCacheTaskResultCallback, null);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_eError = ErrorTypes.ReadRequestStream;
|
||||||
|
}
|
||||||
|
if (ErrorTypes.NoError != m_eError)
|
||||||
|
m_fAsyncCallback.Invoke(new AsyncOperationData(m_oParam));
|
||||||
|
}
|
||||||
|
private void ClearCacheTaskResultCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int nByteRead = m_oStream.EndRead(ar);
|
||||||
|
if (nByteRead > 0)
|
||||||
|
{
|
||||||
|
m_aOutput.Write(m_aBuffer, 0, nByteRead);
|
||||||
|
m_oStream.BeginRead(m_aBuffer, 0, mc_nBufferSize, ClearCacheTaskResultCallback, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_fAsyncCallback.Invoke(new AsyncOperationData(m_oParam));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_eError = ErrorTypes.ReadRequestStream;
|
||||||
|
m_fAsyncCallback.Invoke(new AsyncOperationData(m_oParam));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ErrorTypes ReadContextEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
return m_eError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class AsyncClearCacheOperation
|
||||||
|
{
|
||||||
|
private static readonly ILog _log = LogManager.GetLogger(typeof(AsyncClearCacheOperation));
|
||||||
|
private string m_sKey;
|
||||||
|
private ITaskResultInterface m_oTaskResult = TaskResult.NewTaskResult();
|
||||||
|
private Storage m_oStorage = new Storage();
|
||||||
|
private ErrorTypes m_eError = ErrorTypes.NoError;
|
||||||
|
private AsyncCallback m_fAsyncCallback;
|
||||||
|
private object m_oParam;
|
||||||
|
public void ClearCacheBegin(string sKey, AsyncCallback fAsyncCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_sKey = sKey;
|
||||||
|
m_fAsyncCallback = fAsyncCallback;
|
||||||
|
m_oParam = oParam;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_oTaskResult.RemoveBegin(m_sKey, ClearCacheTaskResultCallback, null);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
_log.ErrorFormat("Exception catched in ClearCacheBegin:", e);
|
||||||
|
m_eError = ErrorTypes.Unknown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ErrorTypes ClearCacheEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
return m_eError;
|
||||||
|
}
|
||||||
|
private void FireCallback()
|
||||||
|
{
|
||||||
|
m_fAsyncCallback.Invoke(new AsyncOperationData(m_oParam));
|
||||||
|
}
|
||||||
|
private void ClearCacheTaskResultCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_eError = m_oTaskResult.RemoveEnd(ar);
|
||||||
|
if (ErrorTypes.NoError == m_eError)
|
||||||
|
{
|
||||||
|
m_oStorage.RemovePathBegin(m_sKey, ClearCacheAllCallback, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_log.ErrorFormat("m_oTaskResult.RemoveEnd return:", m_eError);
|
||||||
|
FireCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
_log.ErrorFormat("Exception catched in ClearCacheTaskResultCallback:", e);
|
||||||
|
m_eError = ErrorTypes.Unknown;
|
||||||
|
FireCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ClearCacheAllCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_eError = m_oStorage.RemovePathEnd(ar);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
_log.ErrorFormat("Exception catched in ClearCacheAllCallback:", e);
|
||||||
|
m_eError = ErrorTypes.Unknown;
|
||||||
|
}
|
||||||
|
FireCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class AsyncMediaXmlOperation
|
||||||
|
{
|
||||||
|
private class TransportClass : TransportClassAsyncOperation
|
||||||
|
{
|
||||||
|
public string m_sPath;
|
||||||
|
public Storage m_oStorage = new Storage();
|
||||||
|
public MemoryStream m_oMemoryStream = new MemoryStream();
|
||||||
|
public Dictionary<string, string> m_aMediaXmlMapHash;
|
||||||
|
public Dictionary<string, string> m_aMediaXmlMapFilename;
|
||||||
|
public Utils.getMD5HexStringDelegate m_ogetMD5HexStringDelegate;
|
||||||
|
public StorageTreeNode m_oStorageTreeNode;
|
||||||
|
public int m_nIndex;
|
||||||
|
public int m_nLength;
|
||||||
|
public ErrorTypes m_eError = ErrorTypes.NoError;
|
||||||
|
public TransportClass(AsyncCallback fCallback, object oParam)
|
||||||
|
: base(fCallback, oParam)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public override void Close()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
m_eError = ErrorTypes.Unknown;
|
||||||
|
}
|
||||||
|
public void SetStorageTreeNode(StorageTreeNode oStorageTreeNode)
|
||||||
|
{
|
||||||
|
m_oStorageTreeNode = oStorageTreeNode;
|
||||||
|
m_nIndex = -1;
|
||||||
|
m_nLength = oStorageTreeNode.m_aSubNodes.Count;
|
||||||
|
}
|
||||||
|
public StorageTreeNode getNextTreeNode()
|
||||||
|
{
|
||||||
|
StorageTreeNode oRes = null;
|
||||||
|
if (m_nIndex < 0)
|
||||||
|
m_nIndex = 0;
|
||||||
|
else
|
||||||
|
m_nIndex++;
|
||||||
|
if (m_nIndex < m_nLength)
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
StorageTreeNode oCurItem = m_oStorageTreeNode.m_aSubNodes[m_nIndex];
|
||||||
|
if (false == oCurItem.m_bIsDirectory)
|
||||||
|
{
|
||||||
|
oRes = oCurItem;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (m_nIndex >= m_nLength)
|
||||||
|
break;
|
||||||
|
m_nIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return oRes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private TransportClass m_oGetMediaXml;
|
||||||
|
private TransportClass m_oWriteMediaXml;
|
||||||
|
public ErrorTypes GenerateMediaXmlRealPath(string sPath)
|
||||||
|
{
|
||||||
|
ErrorTypes eRes = ErrorTypes.NoError;
|
||||||
|
Dictionary<string, string> aMediaXmlMapHash = new Dictionary<string, string>();
|
||||||
|
Dictionary<string, string> aMediaXmlMapFilename = new Dictionary<string, string>();
|
||||||
|
string sDir = Path.GetDirectoryName(sPath);
|
||||||
|
if (Directory.Exists(sDir))
|
||||||
|
{
|
||||||
|
string[] aFiles = Directory.GetFiles(sDir);
|
||||||
|
for (int i = 0; i < aFiles.Length; ++i)
|
||||||
|
{
|
||||||
|
var filepath = aFiles[i];
|
||||||
|
using (FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read))
|
||||||
|
AddToMediaXmlBytes(aMediaXmlMapHash, aMediaXmlMapFilename, Path.GetFileName(filepath),fs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
eRes = ErrorTypes.Unknown;
|
||||||
|
File.WriteAllBytes(sPath, GetMediaXmlBytes(aMediaXmlMapHash));
|
||||||
|
return eRes;
|
||||||
|
}
|
||||||
|
public ErrorTypes GenerateMediaXml(string sPath)
|
||||||
|
{
|
||||||
|
ErrorTypes eRes = ErrorTypes.NoError;
|
||||||
|
Dictionary<string, string> aMediaXmlMapHash = new Dictionary<string, string>();
|
||||||
|
Dictionary<string, string> aMediaXmlMapFilename = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
Storage oStorage = new Storage();
|
||||||
|
StorageTreeNode oStorageTreeNode = oStorage.GetTreeNode(Path.GetDirectoryName(sPath));
|
||||||
|
if (null != oStorageTreeNode)
|
||||||
|
{
|
||||||
|
for (int i = 0, length = oStorageTreeNode.m_aSubNodes.Count; i < length; ++i)
|
||||||
|
{
|
||||||
|
StorageTreeNode oSubNode = oStorageTreeNode.m_aSubNodes[i];
|
||||||
|
if (!oSubNode.m_bIsDirectory)
|
||||||
|
{
|
||||||
|
string sFilePath = Path.Combine(Path.GetDirectoryName(sPath), oSubNode.m_sName);
|
||||||
|
using (MemoryStream ms = new MemoryStream())
|
||||||
|
{
|
||||||
|
int nReadWriteBytes;
|
||||||
|
ErrorTypes eReadError = oStorage.ReadFile(sFilePath, ms, out nReadWriteBytes);
|
||||||
|
if (ErrorTypes.NoError == eReadError && nReadWriteBytes > 0)
|
||||||
|
{
|
||||||
|
ms.Position = 0;
|
||||||
|
AddToMediaXmlBytes(aMediaXmlMapHash, aMediaXmlMapFilename, oSubNode.m_sName, ms);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
byte[] aBuffer = GetMediaXmlBytes(aMediaXmlMapHash);
|
||||||
|
using (MemoryStream ms = new MemoryStream(aBuffer))
|
||||||
|
{
|
||||||
|
int nReadWriteBytes;
|
||||||
|
eRes = oStorage.WriteFile(sPath, ms, out nReadWriteBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
eRes = ErrorTypes.Unknown;
|
||||||
|
return eRes;
|
||||||
|
}
|
||||||
|
public void GetMediaXmlBegin(string sPath, AsyncCallback fAsyncCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oGetMediaXml = new TransportClass(fAsyncCallback, oParam);
|
||||||
|
m_oGetMediaXml.m_sPath = sPath;
|
||||||
|
m_oGetMediaXml.m_aMediaXmlMapFilename = new Dictionary<string, string>();
|
||||||
|
m_oGetMediaXml.m_aMediaXmlMapHash = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
StorageFileInfo oStorageFileInfo;
|
||||||
|
ErrorTypes eFileExist = m_oGetMediaXml.m_oStorage.GetFileInfo(sPath, out oStorageFileInfo);
|
||||||
|
if (ErrorTypes.NoError == eFileExist && null != oStorageFileInfo)
|
||||||
|
{
|
||||||
|
//получаем media.xml
|
||||||
|
m_oGetMediaXml.m_oStorage.ReadFileBegin(sPath, m_oGetMediaXml.m_oMemoryStream, ReadMediaXmlCallback, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//создаем media.xml
|
||||||
|
m_oGetMediaXml.m_oStorage.GetTreeNodeBegin(Path.GetDirectoryName(sPath), GetTreeNodeCallback, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ErrorTypes GetMediaXmlEnd(IAsyncResult ar, out Dictionary<string, string> aMediaXmlMapHash, out Dictionary<string, string> aMediaXmlMapFilename)
|
||||||
|
{
|
||||||
|
aMediaXmlMapHash = m_oGetMediaXml.m_aMediaXmlMapHash;
|
||||||
|
aMediaXmlMapFilename = m_oGetMediaXml.m_aMediaXmlMapFilename;
|
||||||
|
return ErrorTypes.NoError;
|
||||||
|
}
|
||||||
|
private void ReadMediaXmlCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int nReadWriteBytes;
|
||||||
|
m_oGetMediaXml.m_eError = m_oGetMediaXml.m_oStorage.ReadFileEnd(ar, out nReadWriteBytes);
|
||||||
|
if (ErrorTypes.NoError == m_oGetMediaXml.m_eError || ErrorTypes.StorageFileNoFound == m_oGetMediaXml.m_eError)
|
||||||
|
{
|
||||||
|
MemoryStream oMemoryStream = m_oGetMediaXml.m_oMemoryStream;
|
||||||
|
if (nReadWriteBytes > 0)
|
||||||
|
{
|
||||||
|
string sXml = Encoding.UTF8.GetString(oMemoryStream.GetBuffer(), 0, (int)oMemoryStream.Position);
|
||||||
|
using (XmlTextReader reader = new XmlTextReader(new StringReader(sXml)))
|
||||||
|
{
|
||||||
|
// Parse the file and display each of the nodes.
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
if ("image" == reader.Name)
|
||||||
|
{
|
||||||
|
string sHash = null;
|
||||||
|
string sFilename = null;
|
||||||
|
while (reader.MoveToNextAttribute()) // Чтение атрибутов.
|
||||||
|
{
|
||||||
|
if ("md5" == reader.Name)
|
||||||
|
sHash = reader.Value;
|
||||||
|
else if ("filename" == reader.Name)
|
||||||
|
sFilename = reader.Value;
|
||||||
|
}
|
||||||
|
if (null != sHash && null != sFilename)
|
||||||
|
{
|
||||||
|
m_oGetMediaXml.m_aMediaXmlMapHash[sHash] = sFilename;
|
||||||
|
m_oGetMediaXml.m_aMediaXmlMapFilename[sFilename] = sHash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_oGetMediaXml.FireCallback();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oGetMediaXml.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void GetTreeNodeCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_oGetMediaXml.SetStorageTreeNode(m_oGetMediaXml.m_oStorage.GetTreeNodeEnd(ar));
|
||||||
|
m_oGetMediaXml.m_ogetMD5HexStringDelegate = new Utils.getMD5HexStringDelegate(Utils.getMD5HexString);
|
||||||
|
m_oGetMediaXml.m_oMemoryStream = new MemoryStream();
|
||||||
|
StorageTreeNode oFirstItem = m_oGetMediaXml.getNextTreeNode();
|
||||||
|
if (null != oFirstItem)
|
||||||
|
{
|
||||||
|
//надо составлять новую media.xml
|
||||||
|
m_oGetMediaXml.m_oStorage.ReadFileBegin(Path.Combine(Path.GetDirectoryName(m_oGetMediaXml.m_sPath), oFirstItem.m_sName), m_oGetMediaXml.m_oMemoryStream, ReadNextMediaXmlCallback, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_oGetMediaXml.FireCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oGetMediaXml.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ReadNextMediaXmlCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int nReadWriteBytes;
|
||||||
|
ErrorTypes eError = m_oGetMediaXml.m_oStorage.ReadFileEnd(ar, out nReadWriteBytes);
|
||||||
|
if (ErrorTypes.NoError == eError)
|
||||||
|
{
|
||||||
|
StorageTreeNode oCurNode = m_oGetMediaXml.m_oStorageTreeNode.m_aSubNodes[m_oGetMediaXml.m_nIndex];
|
||||||
|
//поскольку данные точно в памяти - читаем вызываем синхронный метод
|
||||||
|
m_oGetMediaXml.m_oMemoryStream.Position = 0;
|
||||||
|
string sHex = Utils.getMD5HexString(m_oGetMediaXml.m_oMemoryStream);
|
||||||
|
if (false == m_oGetMediaXml.m_aMediaXmlMapFilename.ContainsKey(oCurNode.m_sName))
|
||||||
|
m_oGetMediaXml.m_aMediaXmlMapFilename.Add(oCurNode.m_sName, sHex);
|
||||||
|
if (false == m_oGetMediaXml.m_aMediaXmlMapHash.ContainsKey(sHex))
|
||||||
|
m_oGetMediaXml.m_aMediaXmlMapHash.Add(sHex, oCurNode.m_sName);
|
||||||
|
oCurNode = m_oGetMediaXml.getNextTreeNode();
|
||||||
|
if (null == oCurNode)
|
||||||
|
{
|
||||||
|
m_oGetMediaXml.FireCallback();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_oGetMediaXml.m_oMemoryStream = new MemoryStream();
|
||||||
|
m_oGetMediaXml.m_oStorage.ReadFileBegin(Path.Combine(Path.GetDirectoryName(m_oGetMediaXml.m_sPath), oCurNode.m_sName), m_oGetMediaXml.m_oMemoryStream, ReadNextMediaXmlCallback, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_oGetMediaXml.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oGetMediaXml.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void WriteMediaXmlBegin(string sPath, Dictionary<string, string> aMediaXmlMapHash, AsyncCallback fAsyncCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oWriteMediaXml = new TransportClass(fAsyncCallback, oParam);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//сохраняем новую media.xml
|
||||||
|
byte[] aBuffer = GetMediaXmlBytes(aMediaXmlMapHash);
|
||||||
|
MemoryStream ms = new MemoryStream(aBuffer);
|
||||||
|
m_oWriteMediaXml.m_oStorage = new Storage();
|
||||||
|
m_oWriteMediaXml.m_oStorage.WriteFileBegin(sPath, ms, fAsyncCallback, oParam);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oWriteMediaXml.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void AddToMediaXmlBytes(Dictionary<string, string> aMediaXmlMapHash, Dictionary<string, string> aMediaXmlMapFilename, string sFilename, Stream ms)
|
||||||
|
{
|
||||||
|
string sHex = Utils.getMD5HexString(ms);
|
||||||
|
if (false == aMediaXmlMapFilename.ContainsKey(sFilename))
|
||||||
|
aMediaXmlMapFilename.Add(sFilename, sHex);
|
||||||
|
if (false == aMediaXmlMapHash.ContainsKey(sHex))
|
||||||
|
aMediaXmlMapHash.Add(sHex, sFilename);
|
||||||
|
}
|
||||||
|
private byte[] GetMediaXmlBytes(Dictionary<string, string> aMediaXmlMapHash)
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||||
|
sb.Append("<images>");
|
||||||
|
foreach (KeyValuePair<string, string> kvp in aMediaXmlMapHash)
|
||||||
|
sb.AppendFormat("<image md5=\"{0}\" filename=\"{1}\"/>", kvp.Key, kvp.Value);
|
||||||
|
sb.Append("</images>");
|
||||||
|
return Encoding.UTF8.GetBytes(sb.ToString());
|
||||||
|
}
|
||||||
|
public ErrorTypes WriteMediaXmlEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int nReadWriteBytes;
|
||||||
|
m_oWriteMediaXml.m_eError = m_oWriteMediaXml.m_oStorage.WriteFileEnd(ar, out nReadWriteBytes);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oWriteMediaXml.Dispose();
|
||||||
|
}
|
||||||
|
return m_oWriteMediaXml.m_eError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class AsyncDownloadOperation
|
||||||
|
{
|
||||||
|
private int m_nMaxSize;
|
||||||
|
private AsyncCallback m_fAsyncCallback;
|
||||||
|
private object m_oParam;
|
||||||
|
private WebClient m_oWebClient;
|
||||||
|
private Stream m_oReadStream;
|
||||||
|
private byte[] m_aBuffer;
|
||||||
|
private MemoryStream m_oOutput;
|
||||||
|
private ErrorTypes m_eError;
|
||||||
|
public AsyncDownloadOperation(int nMaxSize)
|
||||||
|
{
|
||||||
|
m_nMaxSize = nMaxSize;
|
||||||
|
m_eError = ErrorTypes.NoError;
|
||||||
|
m_oWebClient = null;
|
||||||
|
m_oReadStream = null;
|
||||||
|
m_oOutput = null;
|
||||||
|
}
|
||||||
|
private void Clear()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (null != m_oWebClient)
|
||||||
|
m_oWebClient.Dispose();
|
||||||
|
if (null != m_oReadStream)
|
||||||
|
m_oReadStream.Dispose();
|
||||||
|
if (null != m_oOutput)
|
||||||
|
m_oOutput.Dispose();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void FireCallback()
|
||||||
|
{
|
||||||
|
if (null != m_fAsyncCallback)
|
||||||
|
m_fAsyncCallback.Invoke(new AsyncOperationData(m_oParam));
|
||||||
|
}
|
||||||
|
private void ClearAndCallback()
|
||||||
|
{
|
||||||
|
Clear();
|
||||||
|
FireCallback();
|
||||||
|
}
|
||||||
|
public void DownloadBegin(string sUrl, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_fAsyncCallback = fCallback;
|
||||||
|
m_oParam = oParam;
|
||||||
|
m_oWebClient = new WebClient();
|
||||||
|
m_oWebClient.Headers.Add(HttpRequestHeader.UserAgent, Constants.mc_sWebClientUserAgent);
|
||||||
|
m_oWebClient.OpenReadCompleted += new OpenReadCompletedEventHandler(m_oWebClient_OpenReadCompleted);
|
||||||
|
m_oWebClient.OpenReadAsync(new Uri(sUrl));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_eError = ErrorTypes.Upload;
|
||||||
|
ClearAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void m_oWebClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!e.Cancelled && e.Error == null)
|
||||||
|
{
|
||||||
|
m_oReadStream = e.Result;
|
||||||
|
int nCurBytes = Convert.ToInt32(m_oWebClient.ResponseHeaders["Content-Length"]);
|
||||||
|
if (nCurBytes <= 0)
|
||||||
|
nCurBytes = 10 * 1024 * 1024;
|
||||||
|
if (m_nMaxSize > 0 && nCurBytes > m_nMaxSize)
|
||||||
|
{
|
||||||
|
m_eError = ErrorTypes.UploadContentLength;
|
||||||
|
ClearAndCallback();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_oOutput = new MemoryStream((int)nCurBytes);
|
||||||
|
m_aBuffer = new byte[nCurBytes];
|
||||||
|
m_oReadStream.BeginRead(m_aBuffer, 0, nCurBytes, ReadCallback, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_eError = ErrorTypes.Upload;
|
||||||
|
ClearAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_eError = ErrorTypes.Upload;
|
||||||
|
ClearAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ReadCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int nBytesReaded = m_oReadStream.EndRead(ar);
|
||||||
|
if (nBytesReaded > 0)
|
||||||
|
{
|
||||||
|
m_oOutput.Write(m_aBuffer, 0, nBytesReaded);
|
||||||
|
m_oReadStream.BeginRead(m_aBuffer, 0, m_aBuffer.Length, ReadCallback, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FireCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_eError = ErrorTypes.Upload;
|
||||||
|
ClearAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void DownloadEnd(IAsyncResult ar, out ErrorTypes eError, out byte[] aBuffer)
|
||||||
|
{
|
||||||
|
eError = m_eError;
|
||||||
|
aBuffer = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (ErrorTypes.NoError == m_eError)
|
||||||
|
aBuffer = m_oOutput.ToArray();
|
||||||
|
Clear();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_eError = ErrorTypes.Upload;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class AsyncWebRequestOperation
|
||||||
|
{
|
||||||
|
private static readonly ILog _log = LogManager.GetLogger(typeof(AsyncWebRequestOperation));
|
||||||
|
private class TransportClass
|
||||||
|
{
|
||||||
|
public AsyncCallback m_fAsyncCallback;
|
||||||
|
public object m_oParam;
|
||||||
|
public string m_sUrl;
|
||||||
|
public string m_sMethod;
|
||||||
|
public string m_sContentType;
|
||||||
|
public byte[] m_aInput;
|
||||||
|
|
||||||
|
public Timer m_oTimer;
|
||||||
|
public WebRequest m_oWebRequest;
|
||||||
|
public HttpWebResponse m_oHttpWebResponse;
|
||||||
|
public Stream m_oStream;
|
||||||
|
public AsyncContextReadOperation m_oAsyncContextReadOperation;
|
||||||
|
|
||||||
|
public byte[] m_aOutput;
|
||||||
|
public ErrorTypes m_eError;
|
||||||
|
|
||||||
|
public uint m_nAttemptCount;
|
||||||
|
public uint m_nAttemptDelay;
|
||||||
|
public TransportClass(AsyncCallback fCallback, object oParam, string sUrl, string sMethod, string sContentType, byte[] aData, uint nAttemptCount, uint nAttemptDelay)
|
||||||
|
{
|
||||||
|
m_fAsyncCallback = fCallback;
|
||||||
|
m_oParam = oParam;
|
||||||
|
m_sUrl = sUrl;
|
||||||
|
m_sMethod = sMethod;
|
||||||
|
m_sContentType = sContentType;
|
||||||
|
m_aInput = aData;
|
||||||
|
|
||||||
|
m_oTimer = null;
|
||||||
|
m_oWebRequest = null;
|
||||||
|
m_oHttpWebResponse = null;
|
||||||
|
m_oStream = null;
|
||||||
|
m_oAsyncContextReadOperation = null;
|
||||||
|
|
||||||
|
m_aOutput = null;
|
||||||
|
m_eError = ErrorTypes.NoError;
|
||||||
|
|
||||||
|
m_nAttemptCount = nAttemptCount;
|
||||||
|
m_nAttemptDelay = nAttemptDelay;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private uint m_nAttemptCount;
|
||||||
|
private uint m_nAttemptDelay;
|
||||||
|
public AsyncWebRequestOperation()
|
||||||
|
{
|
||||||
|
m_nAttemptCount = 1;
|
||||||
|
m_nAttemptDelay = 0;
|
||||||
|
}
|
||||||
|
public AsyncWebRequestOperation(uint nAttemptCount, uint nAttemptDelay)
|
||||||
|
{
|
||||||
|
m_nAttemptCount = nAttemptCount;
|
||||||
|
m_nAttemptDelay = nAttemptDelay;
|
||||||
|
}
|
||||||
|
private void Clear(TransportClass oTransportClass)
|
||||||
|
{
|
||||||
|
if (null != oTransportClass.m_oStream)
|
||||||
|
oTransportClass.m_oStream.Close();
|
||||||
|
if (null != oTransportClass.m_oHttpWebResponse)
|
||||||
|
oTransportClass.m_oHttpWebResponse.Close();
|
||||||
|
}
|
||||||
|
private void FireCallback(TransportClass oTransportClass)
|
||||||
|
{
|
||||||
|
if (null != oTransportClass.m_fAsyncCallback)
|
||||||
|
oTransportClass.m_fAsyncCallback.Invoke(new AsyncOperationData(oTransportClass.m_oParam));
|
||||||
|
}
|
||||||
|
private void ClearAndCallback(TransportClass oTransportClass)
|
||||||
|
{
|
||||||
|
ClearAndCallback(oTransportClass, false);
|
||||||
|
}
|
||||||
|
private void ClearAndCallback(TransportClass oTransportClass, bool bRepeatIfCan)
|
||||||
|
{
|
||||||
|
oTransportClass.m_nAttemptCount--;
|
||||||
|
Clear(oTransportClass);
|
||||||
|
if (!bRepeatIfCan || oTransportClass.m_nAttemptCount <= 0)
|
||||||
|
{
|
||||||
|
FireCallback(oTransportClass);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
oTransportClass.m_eError = ErrorTypes.NoError;
|
||||||
|
Timer oTimer = new Timer(WaitEndTimerCallback, oTransportClass, TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1));
|
||||||
|
oTransportClass.m_oTimer = oTimer;
|
||||||
|
oTimer.Change(TimeSpan.FromMilliseconds(oTransportClass.m_nAttemptDelay), TimeSpan.FromMilliseconds(-1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void WaitEndTimerCallback(Object stateInfo)
|
||||||
|
{
|
||||||
|
TransportClass oTransportClass1 = stateInfo as TransportClass;
|
||||||
|
if (null != oTransportClass1.m_oTimer)
|
||||||
|
oTransportClass1.m_oTimer.Dispose();
|
||||||
|
RequestBeginExec(oTransportClass1);
|
||||||
|
}
|
||||||
|
public IAsyncResult RequestBegin(string sUrl, string sMethod, string sContentType, byte[] aData, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
TransportClass oTransportClass = new TransportClass(fCallback, oParam, sUrl, sMethod, sContentType, aData, m_nAttemptCount, m_nAttemptDelay);
|
||||||
|
AsyncOperationData oAsyncOperationData = new AsyncOperationData(oTransportClass);
|
||||||
|
RequestBeginExec(oTransportClass);
|
||||||
|
return oAsyncOperationData;
|
||||||
|
}
|
||||||
|
private void RequestBeginExec(TransportClass oTransportClass)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Ignore ssl certifacate validation. See details: http://www.mono-project.com/docs/faq/security/
|
||||||
|
// Import the root certificates don't work on mono 3.2.8.
|
||||||
|
ServicePointManager.ServerCertificateValidationCallback = (s, c, h, p) => true;
|
||||||
|
|
||||||
|
WebRequest oWebRequest = WebRequest.Create(oTransportClass.m_sUrl);
|
||||||
|
oTransportClass.m_oWebRequest = oWebRequest;
|
||||||
|
if (!string.IsNullOrEmpty(oTransportClass.m_sMethod))
|
||||||
|
oWebRequest.Method = oTransportClass.m_sMethod;
|
||||||
|
if ("GET" == oWebRequest.Method)
|
||||||
|
{
|
||||||
|
oWebRequest.BeginGetResponse(GetResponseCallback, oTransportClass);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(oTransportClass.m_sContentType))
|
||||||
|
oWebRequest.ContentType = "text/html";
|
||||||
|
if (null != oTransportClass.m_aInput)
|
||||||
|
oWebRequest.ContentLength = oTransportClass.m_aInput.Length;
|
||||||
|
oWebRequest.BeginGetRequestStream(GetRequestStreamCallback, oTransportClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_log.Error("Exception catched in RequestBeginExec:", e);
|
||||||
|
oTransportClass.m_eError = ErrorTypes.WebRequest;
|
||||||
|
ClearAndCallback(oTransportClass, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void GetRequestStreamCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
TransportClass oTransportClass = ar.AsyncState as TransportClass;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Stream postStream = oTransportClass.m_oWebRequest.EndGetRequestStream(ar);
|
||||||
|
if (null != oTransportClass.m_aInput)
|
||||||
|
postStream.Write(oTransportClass.m_aInput, 0, oTransportClass.m_aInput.Length);
|
||||||
|
postStream.Close();
|
||||||
|
oTransportClass.m_oWebRequest.BeginGetResponse(GetResponseCallback, oTransportClass);
|
||||||
|
}
|
||||||
|
catch (WebException e)
|
||||||
|
{
|
||||||
|
_log.Error("WebException catched in GetResponseCallback:", e);
|
||||||
|
_log.ErrorFormat("The Uri requested is {0}", oTransportClass.m_oWebRequest.RequestUri);
|
||||||
|
oTransportClass.m_eError = ErrorTypes.WebRequest;
|
||||||
|
ClearAndCallback(oTransportClass, true);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_log.Error("Exception catched in GetResponseCallback:", e);
|
||||||
|
oTransportClass.m_eError = ErrorTypes.WebRequest;
|
||||||
|
ClearAndCallback(oTransportClass, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void GetResponseCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
TransportClass oTransportClass = ar.AsyncState as TransportClass;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpWebResponse response = (HttpWebResponse)oTransportClass.m_oWebRequest.EndGetResponse(ar);
|
||||||
|
Stream streamResponse = response.GetResponseStream();
|
||||||
|
AsyncContextReadOperation oAsyncContextReadOperation = new AsyncContextReadOperation();
|
||||||
|
oTransportClass.m_oHttpWebResponse = response;
|
||||||
|
oTransportClass.m_oStream = streamResponse;
|
||||||
|
oTransportClass.m_oAsyncContextReadOperation = oAsyncContextReadOperation;
|
||||||
|
oAsyncContextReadOperation.ReadContextBegin(streamResponse, ReadContextCallback, oTransportClass);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_log.Error("Exception catched in GetRequestStreamCallback:", e);
|
||||||
|
oTransportClass.m_eError = ErrorTypes.WebRequest;
|
||||||
|
ClearAndCallback(oTransportClass, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ReadContextCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
TransportClass oTransportClass = ar.AsyncState as TransportClass;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ErrorTypes eError = oTransportClass.m_oAsyncContextReadOperation.ReadContextEnd(ar);
|
||||||
|
if (ErrorTypes.NoError == eError)
|
||||||
|
oTransportClass.m_aOutput = oTransportClass.m_oAsyncContextReadOperation.m_aOutput.ToArray();
|
||||||
|
else
|
||||||
|
oTransportClass.m_eError = ErrorTypes.WebRequest;
|
||||||
|
ClearAndCallback(oTransportClass);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_log.Error("Exception catched in ReadContextCallback:", e);
|
||||||
|
oTransportClass.m_eError = ErrorTypes.WebRequest;
|
||||||
|
ClearAndCallback(oTransportClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ErrorTypes RequestEnd(IAsyncResult ar, out byte[] aOutput)
|
||||||
|
{
|
||||||
|
aOutput = null;
|
||||||
|
ErrorTypes eError = ErrorTypes.WebRequest;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TransportClass oTransportClass = ar.AsyncState as TransportClass;
|
||||||
|
aOutput = oTransportClass.m_aOutput;
|
||||||
|
eError = oTransportClass.m_eError;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_log.Error("Exception catched in RequestEnd:", e);
|
||||||
|
eError = ErrorTypes.WebRequest;
|
||||||
|
}
|
||||||
|
return eError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
149
ServerComponents/FileConverterUtils2/DocsCallbacks.cs
Normal file
149
ServerComponents/FileConverterUtils2/DocsCallbacks.cs
Normal file
|
@ -0,0 +1,149 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Data;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
|
namespace FileConverterUtils2
|
||||||
|
{
|
||||||
|
public class DocsCallbacks
|
||||||
|
{
|
||||||
|
private delegate ErrorTypes DelegateGet(string sKey, out string sUrl);
|
||||||
|
private delegate ErrorTypes DelegateRemove(string sKey);
|
||||||
|
private DelegateGet m_oGet = null;
|
||||||
|
private DelegateRemove m_oRemove = null;
|
||||||
|
public ErrorTypes Get(string sKey, out string sUrl)
|
||||||
|
{
|
||||||
|
sUrl = null;
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (IDbConnection sqlCon = GetDbConnection())
|
||||||
|
{
|
||||||
|
sqlCon.Open();
|
||||||
|
using (IDbCommand oSelCommand = sqlCon.CreateCommand())
|
||||||
|
{
|
||||||
|
oSelCommand.CommandText = GetSELECTString(sKey);
|
||||||
|
using (IDataReader oReader = oSelCommand.ExecuteReader())
|
||||||
|
{
|
||||||
|
if (true == oReader.Read())
|
||||||
|
sUrl = Convert.ToString(oReader["dc_callback"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eErrorTypes = ErrorTypes.Unknown;
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
public void GetBegin(string sKey, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oGet = Get;
|
||||||
|
string sUrl;
|
||||||
|
m_oGet.BeginInvoke(sKey, out sUrl, fCallback, oParam);
|
||||||
|
}
|
||||||
|
public ErrorTypes GetEnd(IAsyncResult ar, out string sUrl)
|
||||||
|
{
|
||||||
|
sUrl = null;
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
eErrorTypes = m_oGet.EndInvoke(out sUrl, ar);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eErrorTypes = ErrorTypes.NoError;
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
public ErrorTypes Remove(string sKey)
|
||||||
|
{
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (IDbConnection sqlCon = GetDbConnection())
|
||||||
|
{
|
||||||
|
sqlCon.Open();
|
||||||
|
using (IDbCommand oSelCommand = sqlCon.CreateCommand())
|
||||||
|
{
|
||||||
|
oSelCommand.CommandText = GetDELETEString(sKey);
|
||||||
|
oSelCommand.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eErrorTypes = ErrorTypes.Unknown;
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
public void RemoveBegin(string sKey, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oRemove = Remove;
|
||||||
|
m_oRemove.BeginInvoke(sKey, fCallback, oParam);
|
||||||
|
}
|
||||||
|
public ErrorTypes RemoveEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
eErrorTypes = m_oRemove.EndInvoke(ar);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eErrorTypes = ErrorTypes.Unknown;
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
private IDbConnection GetDbConnection()
|
||||||
|
{
|
||||||
|
var cs = ConfigurationManager.ConnectionStrings[ConfigurationManager.AppSettings["utils.taskqueue.db.connectionstring"]];
|
||||||
|
var dbProvider = System.Data.Common.DbProviderFactories.GetFactory(cs.ProviderName);
|
||||||
|
var connection = dbProvider.CreateConnection();
|
||||||
|
connection.ConnectionString = cs.ConnectionString;
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
private string GetSELECTString(string sKey)
|
||||||
|
{
|
||||||
|
return string.Format("SELECT * FROM doc_callbacks WHERE dc_key='{0}'", sKey);
|
||||||
|
}
|
||||||
|
private string GetDELETEString(string sKey)
|
||||||
|
{
|
||||||
|
return string.Format("DELETE FROM doc_callbacks WHERE dc_key='{0}';", sKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
137
ServerComponents/FileConverterUtils2/DocsChanges.cs
Normal file
137
ServerComponents/FileConverterUtils2/DocsChanges.cs
Normal file
|
@ -0,0 +1,137 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Data;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
|
namespace FileConverterUtils2
|
||||||
|
{
|
||||||
|
public class DocsChange
|
||||||
|
{
|
||||||
|
public string data;
|
||||||
|
public string userid;
|
||||||
|
}
|
||||||
|
public class DocsChanges
|
||||||
|
{
|
||||||
|
private delegate ErrorTypes DelegateRemove(string sKey);
|
||||||
|
private DelegateRemove m_oRemove = null;
|
||||||
|
public ErrorTypes GetChanges(string sKey, out List<DocsChange> aChanges)
|
||||||
|
{
|
||||||
|
aChanges = new List<DocsChange>();
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (IDbConnection sqlCon = GetDbConnection())
|
||||||
|
{
|
||||||
|
sqlCon.Open();
|
||||||
|
using (IDbCommand oSelCommand = sqlCon.CreateCommand())
|
||||||
|
{
|
||||||
|
oSelCommand.CommandText = GetSELECTString(sKey);
|
||||||
|
using (IDataReader oReader = oSelCommand.ExecuteReader())
|
||||||
|
{
|
||||||
|
while (true == oReader.Read())
|
||||||
|
{
|
||||||
|
DocsChange oDocsChange = new DocsChange();
|
||||||
|
oDocsChange.data = Convert.ToString(oReader["dc_data"]);
|
||||||
|
oDocsChange.userid = Convert.ToString(oReader["dc_user_id_original"]);
|
||||||
|
aChanges.Add(oDocsChange);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eErrorTypes = ErrorTypes.EditorChanges;
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
public ErrorTypes RemoveChanges(string sKey)
|
||||||
|
{
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (IDbConnection sqlCon = GetDbConnection())
|
||||||
|
{
|
||||||
|
sqlCon.Open();
|
||||||
|
using (IDbCommand oSelCommand = sqlCon.CreateCommand())
|
||||||
|
{
|
||||||
|
oSelCommand.CommandText = GetDELETEString(sKey);
|
||||||
|
oSelCommand.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eErrorTypes = ErrorTypes.EditorChanges;
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
public void RemoveChangesBegin(string sKey, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oRemove = RemoveChanges;
|
||||||
|
m_oRemove.BeginInvoke(sKey, fCallback, oParam);
|
||||||
|
}
|
||||||
|
public ErrorTypes RemoveChangesEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
eErrorTypes = m_oRemove.EndInvoke(ar);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eErrorTypes = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
private IDbConnection GetDbConnection()
|
||||||
|
{
|
||||||
|
var cs = ConfigurationManager.ConnectionStrings[ConfigurationManager.AppSettings["utils.taskqueue.db.connectionstring"]];
|
||||||
|
var dbProvider = System.Data.Common.DbProviderFactories.GetFactory(cs.ProviderName);
|
||||||
|
var connection = dbProvider.CreateConnection();
|
||||||
|
connection.ConnectionString = cs.ConnectionString;
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
private string GetSELECTString(string sKey)
|
||||||
|
{
|
||||||
|
return string.Format("SELECT * FROM doc_changes WHERE dc_key='{0}' ORDER BY dc_change_id ASC;", sKey);
|
||||||
|
}
|
||||||
|
private string GetDELETEString(string sKey)
|
||||||
|
{
|
||||||
|
return string.Format("DELETE FROM doc_changes WHERE dc_key='{0}';", sKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1099
ServerComponents/FileConverterUtils2/FileConverterUtils2.cs
Normal file
1099
ServerComponents/FileConverterUtils2/FileConverterUtils2.cs
Normal file
File diff suppressed because it is too large
Load diff
130
ServerComponents/FileConverterUtils2/FileConverterUtils2.csproj
Normal file
130
ServerComponents/FileConverterUtils2/FileConverterUtils2.csproj
Normal file
|
@ -0,0 +1,130 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProductVersion>9.0.30729</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{665D791F-4A42-4EB0-A766-300783379D40}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>FileConverterUtils2</RootNamespace>
|
||||||
|
<AssemblyName>FileConverterUtils2</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="ASC.Common, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\..\wwwroot\Bin\ASC.Common.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="ASC.Core.Common, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\..\wwwroot\Bin\ASC.Core.Common.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="AWSSDK, Version=1.5.2.2, Culture=neutral, PublicKeyToken=cd2d24cd2bace800, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\..\wwwroot\Bin\AWSSDK.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Enyim.Caching, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\..\wwwroot\Bin\Enyim.Caching.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Ionic.Zip.Reduced, Version=1.9.1.5, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\..\wwwroot\Bin\Ionic.Zip.Reduced.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\..\wwwroot\Bin\log4net.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="MySql.Data, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\..\wwwroot\Bin\MySql.Data.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="OpenMcdf, Version=1.5.4.22637, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\..\wwwroot\Bin\OpenMcdf.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.configuration" />
|
||||||
|
<Reference Include="System.Core">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.Runtime.Serialization">
|
||||||
|
<RequiredTargetFramework>3.0</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Security" />
|
||||||
|
<Reference Include="System.ServiceModel">
|
||||||
|
<RequiredTargetFramework>3.0</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.ServiceModel.Web">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Web" />
|
||||||
|
<Reference Include="System.Web.Extensions">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Xml.Linq">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Data.DataSetExtensions">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="AsyncOperation.cs" />
|
||||||
|
<Compile Include="DocsCallbacks.cs" />
|
||||||
|
<Compile Include="DocsChanges.cs" />
|
||||||
|
<Compile Include="FileConverterUtils2.cs" />
|
||||||
|
<Compile Include="LicenseInfo.cs" />
|
||||||
|
<Compile Include="LicenseMerger.cs" />
|
||||||
|
<Compile Include="LicenseReader.cs" />
|
||||||
|
<Compile Include="LicenseUtils.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="QueueData.cs" />
|
||||||
|
<Compile Include="Storage.cs" />
|
||||||
|
<Compile Include="TaskQueue.cs" />
|
||||||
|
<Compile Include="TaskQueueAmazonSQS.cs" />
|
||||||
|
<Compile Include="TaskQueueDB.cs" />
|
||||||
|
<Compile Include="TaskResult.cs" />
|
||||||
|
<Compile Include="TaskResultCachedDB.cs" />
|
||||||
|
<Compile Include="TaskResultDB.cs" />
|
||||||
|
<Compile Include="TrackingInfo.cs" />
|
||||||
|
<Compile Include="VariousUtils.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<WCFMetadata Include="Service References\" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
<PropertyGroup>
|
||||||
|
<PostBuildEvent>copy $(TargetPath) $(ProjectDir)..\..\..\wwwroot\Bin\</PostBuildEvent>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
54
ServerComponents/FileConverterUtils2/LicenseInfo.cs
Normal file
54
ServerComponents/FileConverterUtils2/LicenseInfo.cs
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
|
namespace FileConverterUtils2
|
||||||
|
{
|
||||||
|
|
||||||
|
public abstract class LicenseInfo
|
||||||
|
{
|
||||||
|
|
||||||
|
public enum EditorType : int
|
||||||
|
{
|
||||||
|
Word = 0,
|
||||||
|
Spreadsheet = 1,
|
||||||
|
Presentation = 2,
|
||||||
|
Convertation = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
43
ServerComponents/FileConverterUtils2/LicenseMerger.cs
Normal file
43
ServerComponents/FileConverterUtils2/LicenseMerger.cs
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
using System.Xml;
|
||||||
|
|
||||||
|
namespace FileConverterUtils2
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
45
ServerComponents/FileConverterUtils2/LicenseReader.cs
Normal file
45
ServerComponents/FileConverterUtils2/LicenseReader.cs
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Security.Cryptography.Xml;
|
||||||
|
using System.Xml;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
|
namespace FileConverterUtils2
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
44
ServerComponents/FileConverterUtils2/LicenseUtils.cs
Normal file
44
ServerComponents/FileConverterUtils2/LicenseUtils.cs
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Security.Cryptography.Xml;
|
||||||
|
using System.Xml;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace FileConverterUtils2
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
[assembly: AssemblyTitle("FileConverterUtils2")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("Ascensio System SIA")]
|
||||||
|
[assembly: AssemblyProduct("FileConverterUtils2")]
|
||||||
|
[assembly: AssemblyCopyright("Ascensio System SIA Copyright (c) 2015")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
[assembly: Guid("9a6d8058-b3ef-4586-8492-0136f44cedd5")]
|
||||||
|
|
||||||
|
[assembly: AssemblyVersion("1.0.0.114")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.114")]
|
46
ServerComponents/FileConverterUtils2/QueueData.cs
Normal file
46
ServerComponents/FileConverterUtils2/QueueData.cs
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace FileConverterUtils2
|
||||||
|
{
|
||||||
|
public abstract class IQueueData
|
||||||
|
{
|
||||||
|
public abstract string SerializeToXml();
|
||||||
|
public abstract byte[] SerializeToBinary();
|
||||||
|
public abstract void DeserializeFromBinary(byte[] aBuffer);
|
||||||
|
public abstract void DeserializeFromXml(string sXml);
|
||||||
|
}
|
||||||
|
}
|
1282
ServerComponents/FileConverterUtils2/Storage.cs
Normal file
1282
ServerComponents/FileConverterUtils2/Storage.cs
Normal file
File diff suppressed because it is too large
Load diff
211
ServerComponents/FileConverterUtils2/TaskQueue.cs
Normal file
211
ServerComponents/FileConverterUtils2/TaskQueue.cs
Normal file
|
@ -0,0 +1,211 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Xml;
|
||||||
|
using System.Xml.Serialization;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Data;
|
||||||
|
using log4net;
|
||||||
|
|
||||||
|
namespace FileConverterUtils2
|
||||||
|
{
|
||||||
|
[Serializable()]
|
||||||
|
public class TaskQueueData
|
||||||
|
{
|
||||||
|
public string m_sKey;
|
||||||
|
public int m_nToFormat;
|
||||||
|
public string m_sToFile;
|
||||||
|
|
||||||
|
public string m_sFromFormat = "";
|
||||||
|
public string m_sFromUrl;
|
||||||
|
public string m_sFromKey;
|
||||||
|
|
||||||
|
public object m_oDataKey;
|
||||||
|
|
||||||
|
public string m_sToUrl;
|
||||||
|
public int? m_nCsvTxtEncoding;
|
||||||
|
public int? m_nCsvDelimiter;
|
||||||
|
public bool? m_bFromOrigin;
|
||||||
|
public bool? m_bFromSettings;
|
||||||
|
public bool? m_bFromChanges;
|
||||||
|
public bool? m_bPaid;
|
||||||
|
public bool? m_bEmbeddedFonts;
|
||||||
|
public string m_sResultCallbackUrl;
|
||||||
|
public string m_sResultCallbackData;
|
||||||
|
|
||||||
|
[XmlIgnore]
|
||||||
|
public TimeSpan VisibilityTimeout { get; set; }
|
||||||
|
|
||||||
|
public long VisibilityTimeoutTick
|
||||||
|
{
|
||||||
|
get { return VisibilityTimeout.Ticks; }
|
||||||
|
set { VisibilityTimeout = new TimeSpan(value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public TaskQueueData()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public TaskQueueData(string sKey, int nToFormat, string sToFile)
|
||||||
|
{
|
||||||
|
m_sKey = sKey;
|
||||||
|
m_nToFormat = nToFormat;
|
||||||
|
m_sToFile = sToFile;
|
||||||
|
}
|
||||||
|
public static string SerializeToXml(TaskQueueData oData)
|
||||||
|
{
|
||||||
|
return Utils.SerializeToXml(typeof(TaskQueueData), oData);
|
||||||
|
}
|
||||||
|
public static TaskQueueData DeserializeFromXml(string sXml)
|
||||||
|
{
|
||||||
|
return Utils.DeserializeFromXml(typeof(TaskQueueData), sXml) as TaskQueueData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[Serializable()]
|
||||||
|
public class TaskQueueDataConvert
|
||||||
|
{
|
||||||
|
public string m_sKey;
|
||||||
|
public string m_sFileFrom;
|
||||||
|
public string m_sFileTo;
|
||||||
|
public int m_nFormatFrom;
|
||||||
|
public int m_nFormatTo;
|
||||||
|
|
||||||
|
public int? m_nCsvTxtEncoding;
|
||||||
|
public int? m_nCsvDelimiter;
|
||||||
|
public bool? m_bPaid;
|
||||||
|
public bool? m_bEmbeddedFonts;
|
||||||
|
public bool? m_bFromChanges;
|
||||||
|
public string m_sFontDir;
|
||||||
|
public string m_sThemeDir;
|
||||||
|
|
||||||
|
public DateTime m_oTimestamp;
|
||||||
|
|
||||||
|
public TaskQueueDataConvert()
|
||||||
|
{
|
||||||
|
m_oTimestamp = DateTime.UtcNow;
|
||||||
|
m_sFontDir = null;
|
||||||
|
m_sThemeDir = null;
|
||||||
|
}
|
||||||
|
public TaskQueueDataConvert(string sKey, string sFileFrom, int nFormatFrom, string sFileTo, int nFormatTo)
|
||||||
|
{
|
||||||
|
m_oTimestamp = DateTime.UtcNow;
|
||||||
|
m_sKey = sKey;
|
||||||
|
m_sFileFrom = sFileFrom;
|
||||||
|
m_nFormatFrom = nFormatFrom;
|
||||||
|
m_sFileTo = sFileTo;
|
||||||
|
m_nFormatTo = nFormatTo;
|
||||||
|
m_sFontDir = null;
|
||||||
|
m_sThemeDir = null;
|
||||||
|
}
|
||||||
|
public static string SerializeToXml(TaskQueueDataConvert oData)
|
||||||
|
{
|
||||||
|
return Utils.SerializeToXml(typeof(TaskQueueDataConvert), oData);
|
||||||
|
}
|
||||||
|
public static TaskQueueDataConvert DeserializeFromXml(string sXml)
|
||||||
|
{
|
||||||
|
return Utils.DeserializeFromXml(typeof(TaskQueueDataConvert), sXml) as TaskQueueDataConvert;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public interface ITaskQueue
|
||||||
|
{
|
||||||
|
ErrorTypes AddTask(TaskQueueData oTask, Priority oPriority);
|
||||||
|
void AddTaskBegin(TaskQueueData oTask, Priority oPriority, AsyncCallback fCallback, object oParam);
|
||||||
|
ErrorTypes AddTaskEnd(IAsyncResult ar);
|
||||||
|
|
||||||
|
TaskQueueData GetTask();
|
||||||
|
void GetTaskBegin(AsyncCallback fCallback, object oParam);
|
||||||
|
TaskQueueData GetTaskEnd(IAsyncResult ar);
|
||||||
|
|
||||||
|
ErrorTypes RemoveTask(object key);
|
||||||
|
void RemoveTaskBegin(object key, AsyncCallback fCallback, object oParam);
|
||||||
|
ErrorTypes RemoveTaskEnd(IAsyncResult ar);
|
||||||
|
}
|
||||||
|
public class CTaskQueue : ITaskQueue
|
||||||
|
{
|
||||||
|
private ITaskQueue m_oTaskQueue;
|
||||||
|
public CTaskQueue()
|
||||||
|
{
|
||||||
|
switch (ConfigurationManager.AppSettings["utils.taskqueue.impl"])
|
||||||
|
{
|
||||||
|
case "sqs":
|
||||||
|
m_oTaskQueue = new CTaskQueueAmazonSQS();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "db":
|
||||||
|
default:
|
||||||
|
m_oTaskQueue = new CTaskQueueDataBase();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ErrorTypes AddTask(TaskQueueData oTask, Priority oPriority)
|
||||||
|
{
|
||||||
|
return m_oTaskQueue.AddTask(oTask, oPriority);
|
||||||
|
}
|
||||||
|
public void AddTaskBegin(TaskQueueData oTask, Priority oPriority, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oTaskQueue.AddTaskBegin(oTask, oPriority, fCallback, oParam);
|
||||||
|
}
|
||||||
|
public ErrorTypes AddTaskEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
return m_oTaskQueue.AddTaskEnd(ar);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TaskQueueData GetTask()
|
||||||
|
{
|
||||||
|
return m_oTaskQueue.GetTask();
|
||||||
|
}
|
||||||
|
public void GetTaskBegin(AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oTaskQueue.GetTaskBegin(fCallback, oParam);
|
||||||
|
}
|
||||||
|
public TaskQueueData GetTaskEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
return m_oTaskQueue.GetTaskEnd(ar);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorTypes RemoveTask(object key)
|
||||||
|
{
|
||||||
|
return m_oTaskQueue.RemoveTask(key);
|
||||||
|
}
|
||||||
|
public void RemoveTaskBegin(object key, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oTaskQueue.RemoveTaskBegin(key, fCallback, oParam);
|
||||||
|
}
|
||||||
|
public ErrorTypes RemoveTaskEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
return m_oTaskQueue.RemoveTaskEnd(ar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
422
ServerComponents/FileConverterUtils2/TaskQueueAmazonSQS.cs
Normal file
422
ServerComponents/FileConverterUtils2/TaskQueueAmazonSQS.cs
Normal file
|
@ -0,0 +1,422 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Xml;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Data;
|
||||||
|
using Amazon;
|
||||||
|
using Amazon.SQS;
|
||||||
|
using Amazon.SQS.Model;
|
||||||
|
using log4net;
|
||||||
|
|
||||||
|
namespace FileConverterUtils2
|
||||||
|
{
|
||||||
|
|
||||||
|
class CTaskQueueAmazonSQS : ITaskQueue
|
||||||
|
{
|
||||||
|
private static readonly ILog _log = LogManager.GetLogger(typeof(CTaskQueueAmazonSQS));
|
||||||
|
private struct SQSDataKey
|
||||||
|
{
|
||||||
|
public string m_strReceiptHandle;
|
||||||
|
public Priority m_oPriority;
|
||||||
|
}
|
||||||
|
|
||||||
|
private const string m_cstrLowPriorityQueueSettings = "utils.taskqueue.sqs.lp";
|
||||||
|
private const string m_cstrNormalPriorityQueueSettings = "utils.taskqueue.sqs.np";
|
||||||
|
private const string m_cstrHighPriorityQueueSettings = "utils.taskqueue.sqs.hp";
|
||||||
|
|
||||||
|
private string m_strLowPriorityQueueUrl;
|
||||||
|
private string m_strNormalPriorityQueueUrl;
|
||||||
|
private string m_strHighPriorityQueueUrl;
|
||||||
|
private bool m_LongPoolingEnable;
|
||||||
|
|
||||||
|
private TimeSpan m_oVisibilityTimeout;
|
||||||
|
|
||||||
|
private static int m_nIsHPRead;
|
||||||
|
private static int m_nIsNPRead;
|
||||||
|
private static int m_nIsLPRead;
|
||||||
|
|
||||||
|
private delegate ErrorTypes ExecuteTaskAdder(TaskQueueData oTask, Priority oPriority);
|
||||||
|
private delegate TaskQueueData ExecuteTaskGetter();
|
||||||
|
private delegate ErrorTypes ExecuteTaskRemover(object key);
|
||||||
|
|
||||||
|
private class TransportClass : TransportClassAsyncOperation
|
||||||
|
{
|
||||||
|
public ExecuteTaskAdder m_delegateAdder = null;
|
||||||
|
public ExecuteTaskGetter m_delegateGetter = null;
|
||||||
|
public ExecuteTaskRemover m_delegateRemover = null;
|
||||||
|
|
||||||
|
public ErrorTypes m_eError = ErrorTypes.NoError;
|
||||||
|
public TransportClass(AsyncCallback fCallback, object oParam)
|
||||||
|
: base(fCallback, oParam)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public override void Close()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
m_eError = ErrorTypes.TaskQueue;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private TransportClass m_oAddTask = null;
|
||||||
|
private TransportClass m_oGetTask = null;
|
||||||
|
private TransportClass m_oRemoveTask = null;
|
||||||
|
|
||||||
|
public CTaskQueueAmazonSQS()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_strLowPriorityQueueUrl = ConfigurationManager.AppSettings[m_cstrLowPriorityQueueSettings];
|
||||||
|
m_strNormalPriorityQueueUrl = ConfigurationManager.AppSettings[m_cstrNormalPriorityQueueSettings];
|
||||||
|
m_strHighPriorityQueueUrl = ConfigurationManager.AppSettings[m_cstrHighPriorityQueueSettings];
|
||||||
|
|
||||||
|
m_LongPoolingEnable = bool.Parse(ConfigurationManager.AppSettings["utils.taskqueue.sqs.longpooling"] ?? "false");
|
||||||
|
|
||||||
|
m_oVisibilityTimeout = TimeSpan.FromSeconds(double.Parse(ConfigurationManager.AppSettings["utils.taskqueue.db.visibility_timeout"] ?? "60"));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetQueueUrl(Priority oPriority)
|
||||||
|
{
|
||||||
|
string strUrlQueue = "";
|
||||||
|
switch (oPriority)
|
||||||
|
{
|
||||||
|
case Priority.Low:
|
||||||
|
strUrlQueue = m_strLowPriorityQueueUrl;
|
||||||
|
break;
|
||||||
|
case Priority.Normal:
|
||||||
|
strUrlQueue = m_strNormalPriorityQueueUrl;
|
||||||
|
break;
|
||||||
|
case Priority.High:
|
||||||
|
strUrlQueue = m_strHighPriorityQueueUrl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return strUrlQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorTypes AddTask(TaskQueueData oTask, Priority oPriority)
|
||||||
|
{
|
||||||
|
ErrorTypes eResult = ErrorTypes.Unknown;
|
||||||
|
string strUrlQueue = GetQueueUrl(oPriority);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
oTask.VisibilityTimeout = m_oVisibilityTimeout;
|
||||||
|
|
||||||
|
string strData = TaskQueueData.SerializeToXml(oTask);
|
||||||
|
|
||||||
|
using (AmazonSQS oSQSClient = AWSClientFactory.CreateAmazonSQSClient())
|
||||||
|
{
|
||||||
|
|
||||||
|
SendMessageRequest oSendMessageRequest = new SendMessageRequest();
|
||||||
|
oSendMessageRequest.QueueUrl = strUrlQueue;
|
||||||
|
oSendMessageRequest.MessageBody = strData;
|
||||||
|
oSQSClient.SendMessage(oSendMessageRequest);
|
||||||
|
eResult = ErrorTypes.NoError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (AmazonSQSException)
|
||||||
|
{
|
||||||
|
eResult = ErrorTypes.TaskQueue;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eResult = ErrorTypes.TaskQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return eResult;
|
||||||
|
}
|
||||||
|
public void AddTaskBegin(TaskQueueData oTask, Priority oPriority, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
|
||||||
|
m_oAddTask = new TransportClass(fCallback, oParam);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_oAddTask.m_delegateAdder = AddTask;
|
||||||
|
m_oAddTask.m_delegateAdder.BeginInvoke(oTask, oPriority, m_oAddTask.m_fCallback, m_oAddTask.m_oParam);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oAddTask.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorTypes AddTaskEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
ErrorTypes eResult = m_oAddTask.m_eError;
|
||||||
|
if (ErrorTypes.NoError == m_oAddTask.m_eError)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_oAddTask.m_delegateAdder.EndInvoke(ar);
|
||||||
|
m_oAddTask.Close();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oAddTask.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return eResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
private TaskQueueData GetTask(Priority oPriority)
|
||||||
|
{
|
||||||
|
string strUrlQueue = GetQueueUrl(oPriority);
|
||||||
|
|
||||||
|
TaskQueueData oData = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
using (AmazonSQS oSQSClient = AWSClientFactory.CreateAmazonSQSClient())
|
||||||
|
{
|
||||||
|
|
||||||
|
ReceiveMessageRequest oReceiveMessageRequest = new ReceiveMessageRequest();
|
||||||
|
oReceiveMessageRequest.QueueUrl = strUrlQueue;
|
||||||
|
oReceiveMessageRequest.MaxNumberOfMessages = 1;
|
||||||
|
|
||||||
|
ReceiveMessageResponse oReceiveMessageResponse = oSQSClient.ReceiveMessage(oReceiveMessageRequest);
|
||||||
|
if (oReceiveMessageResponse.IsSetReceiveMessageResult())
|
||||||
|
{
|
||||||
|
ReceiveMessageResult oReceiveMessageResult = oReceiveMessageResponse.ReceiveMessageResult;
|
||||||
|
foreach (Message oMessage in oReceiveMessageResult.Message)
|
||||||
|
{
|
||||||
|
oData = TaskQueueData.DeserializeFromXml(oMessage.Body);
|
||||||
|
|
||||||
|
SQSDataKey oSQSDataKey = new SQSDataKey();
|
||||||
|
oSQSDataKey.m_oPriority = oPriority;
|
||||||
|
oSQSDataKey.m_strReceiptHandle = oMessage.ReceiptHandle;
|
||||||
|
oData.m_oDataKey = oSQSDataKey;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (AmazonSQSException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
return oData;
|
||||||
|
}
|
||||||
|
public TaskQueueData GetTask()
|
||||||
|
{
|
||||||
|
TaskQueueData oData = null;
|
||||||
|
|
||||||
|
if (m_LongPoolingEnable)
|
||||||
|
oData = GetTaskFromLongPoolingQueue();
|
||||||
|
else
|
||||||
|
oData = GetTaskFromQueue();
|
||||||
|
|
||||||
|
return oData;
|
||||||
|
}
|
||||||
|
private TaskQueueData GetTaskFromLongPoolingQueue()
|
||||||
|
{
|
||||||
|
TaskQueueData oData = null;
|
||||||
|
|
||||||
|
if (0 == Interlocked.CompareExchange(ref m_nIsHPRead, 1, 0))
|
||||||
|
{
|
||||||
|
_log.Debug("Try to get high priority task...");
|
||||||
|
oData = GetTask(Priority.High);
|
||||||
|
Interlocked.Exchange(ref m_nIsHPRead, 0);
|
||||||
|
}
|
||||||
|
else if (0 == Interlocked.CompareExchange(ref m_nIsNPRead, 1, 0))
|
||||||
|
{
|
||||||
|
_log.Debug("Try to get normal priority task...");
|
||||||
|
oData = GetTask(Priority.Normal);
|
||||||
|
Interlocked.Exchange(ref m_nIsNPRead, 0);
|
||||||
|
}
|
||||||
|
else if (0 == Interlocked.CompareExchange(ref m_nIsLPRead, 1, 0))
|
||||||
|
{
|
||||||
|
_log.Debug("Try to get low priority task...");
|
||||||
|
oData = GetTask(Priority.Low);
|
||||||
|
Interlocked.Exchange(ref m_nIsLPRead, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_log.Debug("All task queue listening!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return oData;
|
||||||
|
}
|
||||||
|
private TaskQueueData GetTaskFromQueue()
|
||||||
|
{
|
||||||
|
TaskQueueData oData = null;
|
||||||
|
|
||||||
|
oData = GetTask(Priority.High);
|
||||||
|
if (null != oData)
|
||||||
|
return oData;
|
||||||
|
|
||||||
|
oData = GetTask(Priority.Normal);
|
||||||
|
if (null != oData)
|
||||||
|
return oData;
|
||||||
|
|
||||||
|
oData = GetTask(Priority.Low);
|
||||||
|
|
||||||
|
return oData;
|
||||||
|
}
|
||||||
|
public void GetTaskBegin(AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oGetTask = new TransportClass(fCallback, oParam);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_oGetTask.m_delegateGetter = GetTask;
|
||||||
|
m_oGetTask.m_delegateGetter.BeginInvoke(m_oGetTask.m_fCallback, m_oGetTask.m_oParam);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oGetTask.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public TaskQueueData GetTaskEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
TaskQueueData oTaskQueueDate = null;
|
||||||
|
if (ErrorTypes.NoError == m_oGetTask.m_eError)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (null != m_oGetTask.m_delegateGetter)
|
||||||
|
{
|
||||||
|
oTaskQueueDate = m_oGetTask.m_delegateGetter.EndInvoke(ar);
|
||||||
|
}
|
||||||
|
m_oGetTask.Close();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oGetTask.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return oTaskQueueDate;
|
||||||
|
}
|
||||||
|
public ErrorTypes RemoveTask(object key)
|
||||||
|
{
|
||||||
|
ErrorTypes eResult = ErrorTypes.Unknown;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SQSDataKey oSQSDataKey = (SQSDataKey)key;
|
||||||
|
string strUrlQueue = GetQueueUrl(oSQSDataKey.m_oPriority);
|
||||||
|
|
||||||
|
using (AmazonSQS oSQSClient = AWSClientFactory.CreateAmazonSQSClient())
|
||||||
|
{
|
||||||
|
|
||||||
|
DeleteMessageRequest oDeleteRequest = new DeleteMessageRequest();
|
||||||
|
oDeleteRequest.QueueUrl = strUrlQueue;
|
||||||
|
oDeleteRequest.ReceiptHandle = (string)oSQSDataKey.m_strReceiptHandle;
|
||||||
|
|
||||||
|
oSQSClient.DeleteMessage(oDeleteRequest);
|
||||||
|
eResult = ErrorTypes.NoError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (AmazonSQSException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
return eResult;
|
||||||
|
}
|
||||||
|
public void RemoveTaskBegin(object key, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oRemoveTask = new TransportClass(fCallback, oParam);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_oRemoveTask.m_delegateRemover = RemoveTask;
|
||||||
|
m_oRemoveTask.m_delegateRemover.BeginInvoke(key, fCallback, oParam);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oRemoveTask.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ErrorTypes RemoveTaskEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
if (ErrorTypes.NoError == m_oRemoveTask.m_eError)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_oRemoveTask.m_delegateRemover.EndInvoke(ar);
|
||||||
|
m_oRemoveTask.Close();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oRemoveTask.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ErrorTypes.NoError;
|
||||||
|
}
|
||||||
|
|
||||||
|
private GetQueueAttributesResult GetTaskQueueAttr(Priority oPriority)
|
||||||
|
{
|
||||||
|
string strUrlQueue = GetQueueUrl(oPriority);
|
||||||
|
|
||||||
|
GetQueueAttributesResult oGetQueueAttributesResult = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
using (AmazonSQS oSQSClient = AWSClientFactory.CreateAmazonSQSClient())
|
||||||
|
{
|
||||||
|
GetQueueAttributesRequest oGetQueueAttributesRequest = new GetQueueAttributesRequest();
|
||||||
|
oGetQueueAttributesRequest.QueueUrl = strUrlQueue;
|
||||||
|
|
||||||
|
GetQueueAttributesResponse oGetQueueAttributesResponse = oSQSClient.GetQueueAttributes(oGetQueueAttributesRequest);
|
||||||
|
if (oGetQueueAttributesResponse.IsSetGetQueueAttributesResult())
|
||||||
|
{
|
||||||
|
oGetQueueAttributesResult = oGetQueueAttributesResponse.GetQueueAttributesResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (AmazonSQSException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
return oGetQueueAttributesResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
441
ServerComponents/FileConverterUtils2/TaskQueueDB.cs
Normal file
441
ServerComponents/FileConverterUtils2/TaskQueueDB.cs
Normal file
|
@ -0,0 +1,441 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Xml;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Data;
|
||||||
|
using log4net;
|
||||||
|
|
||||||
|
namespace FileConverterUtils2
|
||||||
|
{
|
||||||
|
|
||||||
|
class CTaskQueueDataBase : ITaskQueue
|
||||||
|
{
|
||||||
|
private static readonly ILog _log = LogManager.GetLogger(typeof(CTaskQueueDataBase));
|
||||||
|
private string m_sConnectionString = ConfigurationManager.AppSettings["utils.taskqueue.db.connectionstring"];
|
||||||
|
private const string m_cstrTableName = "convert_queue";
|
||||||
|
|
||||||
|
private TimeSpan m_oRetentionPeriod;
|
||||||
|
private TimeSpan m_oVisibilityTimeout;
|
||||||
|
|
||||||
|
private delegate IDataReader ExecuteReader();
|
||||||
|
private delegate int ExecuteNonQuery();
|
||||||
|
|
||||||
|
private enum BusyType : int
|
||||||
|
{
|
||||||
|
not_busy = 0,
|
||||||
|
busy = 1
|
||||||
|
}
|
||||||
|
private delegate ErrorTypes DelegateRemoveTask(object key);
|
||||||
|
private delegate ErrorTypes DelegateAddTask(TaskQueueData oTask, Priority oPriority);
|
||||||
|
private class TransportClass : TransportClassAsyncOperation
|
||||||
|
{
|
||||||
|
public ExecuteReader m_delegateReader = null;
|
||||||
|
public ExecuteNonQuery m_delegateNonQuery = null;
|
||||||
|
public IDbConnection m_oSqlCon = null;
|
||||||
|
public IDbCommand m_oCommand = null;
|
||||||
|
public TaskQueueData m_oTaskQueueData = null;
|
||||||
|
public ErrorTypes m_eError = ErrorTypes.NoError;
|
||||||
|
public TransportClass(AsyncCallback fCallback, object oParam)
|
||||||
|
: base(fCallback, oParam)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public override void Close()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (null != m_oCommand)
|
||||||
|
{
|
||||||
|
m_oCommand.Dispose();
|
||||||
|
m_oCommand = null;
|
||||||
|
}
|
||||||
|
if (null != m_oSqlCon)
|
||||||
|
{
|
||||||
|
m_oSqlCon.Close();
|
||||||
|
m_oSqlCon.Dispose();
|
||||||
|
m_oSqlCon = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_eError = ErrorTypes.TaskQueue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
m_eError = ErrorTypes.TaskQueue;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (null != m_oCommand)
|
||||||
|
{
|
||||||
|
m_oCommand.Dispose();
|
||||||
|
m_oCommand = null;
|
||||||
|
}
|
||||||
|
if (null != m_oSqlCon)
|
||||||
|
{
|
||||||
|
m_oSqlCon.Dispose();
|
||||||
|
m_oSqlCon = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private TransportClass m_GetTask = null;
|
||||||
|
private DelegateRemoveTask m_RemoveTask = null;
|
||||||
|
private DelegateAddTask m_AddTask = null;
|
||||||
|
|
||||||
|
public CTaskQueueDataBase()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_oVisibilityTimeout = TimeSpan.FromSeconds(double.Parse(ConfigurationManager.AppSettings["utils.taskqueue.db.visibility_timeout"] ?? "60"));
|
||||||
|
m_oRetentionPeriod = TimeSpan.FromSeconds(double.Parse(ConfigurationManager.AppSettings["utils.taskqueue.db.retention_period"] ?? "600"));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorTypes AddTask(TaskQueueData oTask, Priority oPriority)
|
||||||
|
{
|
||||||
|
ErrorTypes eResult = ErrorTypes.TaskQueue;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
oTask.VisibilityTimeout = m_oVisibilityTimeout;
|
||||||
|
|
||||||
|
string strId = (string)oTask.m_sKey;
|
||||||
|
|
||||||
|
string strInsertRow = GetInsertString(oTask, oPriority);
|
||||||
|
using (System.Data.IDbConnection dbConnection = GetDbConnection())
|
||||||
|
{
|
||||||
|
dbConnection.Open();
|
||||||
|
using (System.Data.IDbCommand oInsertCommand = dbConnection.CreateCommand())
|
||||||
|
{
|
||||||
|
oInsertCommand.CommandText = strInsertRow;
|
||||||
|
oInsertCommand.ExecuteNonQuery();
|
||||||
|
|
||||||
|
eResult = ErrorTypes.NoError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eResult = ErrorTypes.TaskQueue;
|
||||||
|
}
|
||||||
|
return eResult;
|
||||||
|
}
|
||||||
|
public void AddTaskBegin(TaskQueueData oTask, Priority oPriority, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_AddTask = AddTask;
|
||||||
|
m_AddTask.BeginInvoke(oTask, oPriority, fCallback, oParam);
|
||||||
|
}
|
||||||
|
public ErrorTypes AddTaskEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
ErrorTypes eRes = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
eRes = m_AddTask.EndInvoke(ar);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eRes = ErrorTypes.TaskQueue;
|
||||||
|
}
|
||||||
|
return eRes;
|
||||||
|
}
|
||||||
|
public TaskQueueData GetTask()
|
||||||
|
{
|
||||||
|
TaskQueueData oData = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (System.Data.IDbConnection dbConnection = GetDbConnection())
|
||||||
|
{
|
||||||
|
dbConnection.Open();
|
||||||
|
using (IDbCommand oSelectCommand = dbConnection.CreateCommand())
|
||||||
|
{
|
||||||
|
oSelectCommand.CommandText = GetSelectString();
|
||||||
|
using (System.Data.IDataReader oDataReader = oSelectCommand.ExecuteReader())
|
||||||
|
{
|
||||||
|
|
||||||
|
while (true == oDataReader.Read())
|
||||||
|
{
|
||||||
|
uint ncq_id = Convert.ToUInt32(oDataReader["cq_id"]);
|
||||||
|
|
||||||
|
DateTime oTaskCreateTime = Convert.ToDateTime(oDataReader["cq_create_time"]);
|
||||||
|
|
||||||
|
if (DateTime.UtcNow < (oTaskCreateTime + m_oRetentionPeriod))
|
||||||
|
{
|
||||||
|
DateTime oTaskUpdateTime = Convert.ToDateTime(oDataReader["cq_update_time"]);
|
||||||
|
|
||||||
|
if (TryUpdateTask(ncq_id, oTaskUpdateTime))
|
||||||
|
{
|
||||||
|
|
||||||
|
oData = TaskQueueData.DeserializeFromXml(Convert.ToString(oDataReader["cq_data"]));
|
||||||
|
oData.m_oDataKey = ncq_id;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
RemoveTask(ncq_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
return oData;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryUpdateTask(uint ncq_id, DateTime oTaskUpdateTime)
|
||||||
|
{
|
||||||
|
bool bResult = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (System.Data.IDbConnection dbConnection = GetDbConnection())
|
||||||
|
{
|
||||||
|
dbConnection.Open();
|
||||||
|
using (System.Data.IDbCommand oUpdateCommand = dbConnection.CreateCommand())
|
||||||
|
{
|
||||||
|
oUpdateCommand.CommandText = GetUpdateString(ncq_id, oTaskUpdateTime);
|
||||||
|
|
||||||
|
bResult = (oUpdateCommand.ExecuteNonQuery() > 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return bResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void GetTaskBegin(AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_GetTask = new TransportClass(fCallback, oParam);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
string strSelectSQL = GetSelectString();
|
||||||
|
|
||||||
|
m_GetTask.m_oSqlCon = GetDbConnection();
|
||||||
|
m_GetTask.m_oSqlCon.Open();
|
||||||
|
IDbCommand oSelCommand = m_GetTask.m_oSqlCon.CreateCommand();
|
||||||
|
oSelCommand.CommandText = strSelectSQL;
|
||||||
|
m_GetTask.m_oCommand = oSelCommand;
|
||||||
|
m_GetTask.m_delegateReader = new ExecuteReader(oSelCommand.ExecuteReader);
|
||||||
|
m_GetTask.m_delegateReader.BeginInvoke(GetTaskCallback, null);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
_log.Error("Exception cathed in GetTaskBegin:", e);
|
||||||
|
m_GetTask.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public TaskQueueData GetTaskEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
bool bResult = false;
|
||||||
|
if (ErrorTypes.NoError == m_GetTask.m_eError)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (null != m_GetTask.m_delegateNonQuery)
|
||||||
|
{
|
||||||
|
if (m_GetTask.m_delegateNonQuery.EndInvoke(ar) > 0)
|
||||||
|
bResult = true;
|
||||||
|
else
|
||||||
|
bResult = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
m_GetTask.Close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
_log.Error("Exception cathed in GetTaskEnd:", e);
|
||||||
|
m_GetTask.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (bResult) ? m_GetTask.m_oTaskQueueData : null;
|
||||||
|
}
|
||||||
|
public ErrorTypes RemoveTask(object key)
|
||||||
|
{
|
||||||
|
ErrorTypes eResult = ErrorTypes.TaskQueue;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
uint nId = (uint)key;
|
||||||
|
string strDeleteRow = GetDeleteString(nId);
|
||||||
|
using (System.Data.IDbConnection dbConnection = GetDbConnection())
|
||||||
|
{
|
||||||
|
dbConnection.Open();
|
||||||
|
using (IDbCommand oDelCommand = dbConnection.CreateCommand())
|
||||||
|
{
|
||||||
|
oDelCommand.CommandText = strDeleteRow;
|
||||||
|
oDelCommand.ExecuteNonQuery();
|
||||||
|
|
||||||
|
eResult = ErrorTypes.NoError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
return eResult;
|
||||||
|
}
|
||||||
|
public void RemoveTaskBegin(object key, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_RemoveTask = RemoveTask;
|
||||||
|
m_RemoveTask.BeginInvoke(key, fCallback, oParam);
|
||||||
|
}
|
||||||
|
public ErrorTypes RemoveTaskEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
ErrorTypes eRes = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
eRes = m_RemoveTask.EndInvoke(ar);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eRes = ErrorTypes.TaskQueue;
|
||||||
|
}
|
||||||
|
return eRes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GetTaskCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
uint ncq_id = 0;
|
||||||
|
DateTime oTaskUpdateTime = DateTime.UtcNow;
|
||||||
|
bool bIsExist = false;
|
||||||
|
using (IDataReader oReader = m_GetTask.m_delegateReader.EndInvoke(ar))
|
||||||
|
{
|
||||||
|
|
||||||
|
if (true == oReader.Read())
|
||||||
|
{
|
||||||
|
ncq_id = Convert.ToUInt32(oReader["cq_id"]);
|
||||||
|
oTaskUpdateTime = Convert.ToDateTime(oReader["cq_update_time"]);
|
||||||
|
|
||||||
|
m_GetTask.m_oTaskQueueData = TaskQueueData.DeserializeFromXml(Convert.ToString(oReader["cq_data"]));
|
||||||
|
m_GetTask.m_oTaskQueueData.m_oDataKey = ncq_id;
|
||||||
|
|
||||||
|
bIsExist = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (null != m_GetTask.m_oCommand)
|
||||||
|
{
|
||||||
|
m_GetTask.m_oCommand.Dispose();
|
||||||
|
m_GetTask.m_oCommand = null;
|
||||||
|
}
|
||||||
|
m_GetTask.Close();
|
||||||
|
if (bIsExist)
|
||||||
|
{
|
||||||
|
|
||||||
|
IDbCommand oUpdateCommand = m_GetTask.m_oSqlCon.CreateCommand();
|
||||||
|
oUpdateCommand.CommandText = GetUpdateString(ncq_id, oTaskUpdateTime);
|
||||||
|
m_GetTask.m_oCommand = oUpdateCommand;
|
||||||
|
m_GetTask.m_delegateNonQuery = new ExecuteNonQuery(oUpdateCommand.ExecuteNonQuery);
|
||||||
|
m_GetTask.m_delegateNonQuery.BeginInvoke(m_GetTask.m_fCallback, m_GetTask.m_oParam);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_GetTask.m_delegateNonQuery = null;
|
||||||
|
m_GetTask.FireCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
_log.Error("Exception cathed in GetTaskCallback:", e);
|
||||||
|
m_GetTask.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private System.Data.IDbConnection GetDbConnection()
|
||||||
|
{
|
||||||
|
ConnectionStringSettings oConnectionSettings = ConfigurationManager.ConnectionStrings[m_sConnectionString];
|
||||||
|
System.Data.Common.DbProviderFactory dbProvider = System.Data.Common.DbProviderFactories.GetFactory(oConnectionSettings.ProviderName);
|
||||||
|
System.Data.IDbConnection newConnection = dbProvider.CreateConnection();
|
||||||
|
newConnection.ConnectionString = oConnectionSettings.ConnectionString;
|
||||||
|
return newConnection;
|
||||||
|
}
|
||||||
|
private string GetSelectString()
|
||||||
|
{
|
||||||
|
|
||||||
|
DateTime oMinPosibleStartHandleTime = DateTime.UtcNow.Subtract(m_oVisibilityTimeout);
|
||||||
|
|
||||||
|
return string.Format("SELECT * FROM {0} WHERE cq_isbusy <> '{1}' OR cq_update_time <= '{2}' ORDER BY cq_priority DESC;",
|
||||||
|
m_cstrTableName,
|
||||||
|
BusyType.busy.ToString("d"),
|
||||||
|
oMinPosibleStartHandleTime.ToString(Constants.mc_sDateTimeFormat));
|
||||||
|
}
|
||||||
|
private string GetInsertString(TaskQueueData oTask, Priority ePriority)
|
||||||
|
{
|
||||||
|
|
||||||
|
string sData = TaskQueueData.SerializeToXml(oTask);
|
||||||
|
|
||||||
|
return string.Format("INSERT INTO {0} " +
|
||||||
|
"(cq_data, cq_priority, cq_update_time, cq_create_time, cq_isbusy) " +
|
||||||
|
"VALUES ('{1}', '{2}', '{3}', '{3}', '{4}');",
|
||||||
|
m_cstrTableName,
|
||||||
|
Utils.MySqlEscape(sData, m_sConnectionString),
|
||||||
|
ePriority.ToString("d"),
|
||||||
|
DateTime.UtcNow.ToString(Constants.mc_sDateTimeFormat),
|
||||||
|
BusyType.not_busy.ToString("d"));
|
||||||
|
}
|
||||||
|
private string GetDeleteString(uint nId)
|
||||||
|
{
|
||||||
|
return "DELETE FROM " + m_cstrTableName + " WHERE cq_id='" + nId.ToString() + "'";
|
||||||
|
}
|
||||||
|
private string GetUpdateString(uint nCqId, DateTime oTaskUpdateTime)
|
||||||
|
{
|
||||||
|
|
||||||
|
return string.Format("UPDATE {0} SET cq_isbusy = '{1}', cq_update_time = '{2}' WHERE (cq_id = '{3}' AND cq_update_time = '{4}');",
|
||||||
|
m_cstrTableName,
|
||||||
|
BusyType.busy.ToString("d"),
|
||||||
|
DateTime.UtcNow.ToString(Constants.mc_sDateTimeFormat),
|
||||||
|
nCqId,
|
||||||
|
oTaskUpdateTime.ToString(Constants.mc_sDateTimeFormat));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
178
ServerComponents/FileConverterUtils2/TaskResult.cs
Normal file
178
ServerComponents/FileConverterUtils2/TaskResult.cs
Normal file
|
@ -0,0 +1,178 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Data;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
|
using ASC.Common.Data;
|
||||||
|
using ASC.Common.Data.Sql;
|
||||||
|
using ASC.Common.Data.Sql.Expressions;
|
||||||
|
|
||||||
|
namespace FileConverterUtils2
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
public class TaskResultData
|
||||||
|
{
|
||||||
|
public string sKey;
|
||||||
|
public string sFormat;
|
||||||
|
public FileStatus eStatus;
|
||||||
|
public int nStatusInfo;
|
||||||
|
public DateTime oLastOpenDate;
|
||||||
|
public string sTitle;
|
||||||
|
public TaskResultData()
|
||||||
|
{
|
||||||
|
sFormat = "";
|
||||||
|
sKey = "";
|
||||||
|
eStatus = FileStatus.None;
|
||||||
|
nStatusInfo = 0;
|
||||||
|
oLastOpenDate = DateTime.UtcNow;
|
||||||
|
sTitle = "";
|
||||||
|
}
|
||||||
|
public TaskResultData Clone()
|
||||||
|
{
|
||||||
|
TaskResultData oRes = new TaskResultData();
|
||||||
|
oRes.sFormat = sFormat;
|
||||||
|
oRes.sKey = sKey;
|
||||||
|
oRes.eStatus = eStatus;
|
||||||
|
oRes.nStatusInfo = nStatusInfo;
|
||||||
|
oRes.oLastOpenDate = oLastOpenDate;
|
||||||
|
oRes.sTitle = sTitle;
|
||||||
|
return oRes;
|
||||||
|
}
|
||||||
|
public void Update(TaskResultDataToUpdate oUpdate)
|
||||||
|
{
|
||||||
|
if (oUpdate != null)
|
||||||
|
{
|
||||||
|
if (oUpdate.eStatus != null)
|
||||||
|
this.eStatus = (FileStatus)oUpdate.eStatus;
|
||||||
|
|
||||||
|
if (oUpdate.oLastOpenDate.HasValue)
|
||||||
|
this.oLastOpenDate = oUpdate.oLastOpenDate.Value;
|
||||||
|
|
||||||
|
if (oUpdate.nStatusInfo != null)
|
||||||
|
this.nStatusInfo = (int)oUpdate.nStatusInfo;
|
||||||
|
|
||||||
|
if (oUpdate.sFormat != null)
|
||||||
|
this.sFormat = oUpdate.sFormat;
|
||||||
|
|
||||||
|
if (oUpdate.sTitle != null)
|
||||||
|
this.sTitle = oUpdate.sTitle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public bool IsValidMask(TaskResultDataToUpdate oMask)
|
||||||
|
{
|
||||||
|
bool bRes = true;
|
||||||
|
if (oMask != null)
|
||||||
|
{
|
||||||
|
if (oMask.eStatus != null)
|
||||||
|
bRes = bRes && (this.eStatus == oMask.eStatus.Value);
|
||||||
|
|
||||||
|
if (oMask.oLastOpenDate != null)
|
||||||
|
bRes = bRes && (this.oLastOpenDate == oMask.oLastOpenDate.Value);
|
||||||
|
|
||||||
|
if (oMask.nStatusInfo != null)
|
||||||
|
bRes = bRes && (this.nStatusInfo == oMask.nStatusInfo.Value);
|
||||||
|
|
||||||
|
if (oMask.sFormat != null)
|
||||||
|
bRes = bRes && (this.sFormat == oMask.sFormat);
|
||||||
|
|
||||||
|
if (oMask.sTitle != null)
|
||||||
|
bRes = bRes && (this.sTitle == oMask.sTitle);
|
||||||
|
}
|
||||||
|
return bRes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class TaskResultDataToUpdate
|
||||||
|
{
|
||||||
|
public string sFormat;
|
||||||
|
public FileStatus? eStatus;
|
||||||
|
public int? nStatusInfo;
|
||||||
|
public DateTime? oLastOpenDate;
|
||||||
|
public string sTitle;
|
||||||
|
public TaskResultDataToUpdate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public interface ITaskResultInterface
|
||||||
|
{
|
||||||
|
ErrorTypes Add(string sKey, TaskResultData oTast);
|
||||||
|
void AddBegin(string sKey, TaskResultData oTast, AsyncCallback fCallback, object oParam);
|
||||||
|
ErrorTypes AddEnd(IAsyncResult ar);
|
||||||
|
ErrorTypes AddRandomKey(string sKey, TaskResultData oTastToAdd, out TaskResultData oTastAdded);
|
||||||
|
void AddRandomKeyBegin(string sKey, TaskResultData oTastToAdd, AsyncCallback fCallback, object oParam);
|
||||||
|
ErrorTypes AddRandomKeyEnd(IAsyncResult ar, out TaskResultData oTastAdded);
|
||||||
|
ErrorTypes Update(string sKey, TaskResultDataToUpdate oTast);
|
||||||
|
void UpdateBegin(string sKey, TaskResultDataToUpdate oTast, AsyncCallback fCallback, object oParam);
|
||||||
|
ErrorTypes UpdateEnd(IAsyncResult ar);
|
||||||
|
ErrorTypes UpdateIf(string sKey, TaskResultDataToUpdate oMask, TaskResultDataToUpdate oTast, out bool bUpdate);
|
||||||
|
void UpdateIfBegin(string sKey, TaskResultDataToUpdate oMask, TaskResultDataToUpdate oTast, AsyncCallback fCallback, object oParam);
|
||||||
|
ErrorTypes UpdateIfEnd(IAsyncResult ar, out bool bUpdate);
|
||||||
|
ErrorTypes Get(string sKey, out TaskResultData oTast);
|
||||||
|
void GetBegin(string sKey, AsyncCallback fCallback, object oParam);
|
||||||
|
ErrorTypes GetEnd(IAsyncResult ar, out TaskResultData oTast);
|
||||||
|
ErrorTypes Get(string[] aKeys, out TaskResultData[] oTast);
|
||||||
|
void GetBegin(string[] aKeys, AsyncCallback fCallback, object oParam);
|
||||||
|
ErrorTypes GetEnd(IAsyncResult ar, out TaskResultData[] oTast);
|
||||||
|
ErrorTypes GetEditing(out TaskResultData[] oTast);
|
||||||
|
void GetEditingBegin(AsyncCallback fCallback, object oParam);
|
||||||
|
ErrorTypes GetEditingEnd(IAsyncResult ar, out TaskResultData[] oTast);
|
||||||
|
ErrorTypes GetExpired( int nMaxCount, out List <TaskResultData> aTasts);
|
||||||
|
ErrorTypes GetOrCreate(string sKey, TaskResultData oDataToAdd, out TaskResultData oDataAdded, out bool bCreate);
|
||||||
|
void GetOrCreateBegin(string sKey, TaskResultData oDataToAdd, AsyncCallback fCallback, object oParam);
|
||||||
|
ErrorTypes GetOrCreateEnd(IAsyncResult ar, out TaskResultData oDataAdded, out bool bCreate);
|
||||||
|
ErrorTypes Remove(string sKey);
|
||||||
|
void RemoveBegin(string sKey, AsyncCallback fCallback, object oParam);
|
||||||
|
ErrorTypes RemoveEnd(IAsyncResult ar);
|
||||||
|
}
|
||||||
|
public class TaskResult
|
||||||
|
{
|
||||||
|
public static ITaskResultInterface NewTaskResult()
|
||||||
|
{
|
||||||
|
ITaskResultInterface piTaskResult = null;
|
||||||
|
string sTaskResultImpl = ConfigurationManager.AppSettings["utils.taskresult.impl"];
|
||||||
|
switch (sTaskResultImpl)
|
||||||
|
{
|
||||||
|
case "cacheddb":
|
||||||
|
piTaskResult = new TaskResultCachedDB();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "db":
|
||||||
|
default:
|
||||||
|
piTaskResult = new TaskResultDataBase();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return piTaskResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
518
ServerComponents/FileConverterUtils2/TaskResultCachedDB.cs
Normal file
518
ServerComponents/FileConverterUtils2/TaskResultCachedDB.cs
Normal file
|
@ -0,0 +1,518 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Data;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Net;
|
||||||
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
|
using ASC.Common.Data;
|
||||||
|
using ASC.Common.Data.Sql;
|
||||||
|
using ASC.Common.Data.Sql.Expressions;
|
||||||
|
|
||||||
|
using Enyim.Caching;
|
||||||
|
using Enyim.Caching.Configuration;
|
||||||
|
using Enyim.Caching.Memcached;
|
||||||
|
|
||||||
|
namespace FileConverterUtils2
|
||||||
|
{
|
||||||
|
class TaskResultCachedDB : ITaskResultInterface
|
||||||
|
{
|
||||||
|
private static System.Random m_oRandom = new System.Random();
|
||||||
|
private string m_sConnectionString = ConfigurationManager.AppSettings["utils.taskresult.db.connectionstring"];
|
||||||
|
private TimeSpan m_oTtl = TimeSpan.Parse(ConfigurationManager.AppSettings["utils.taskresult.cacheddb.ttl"] ?? "0.00:15:00");
|
||||||
|
|
||||||
|
private TaskResultDataBase m_oTaskResultDB = new TaskResultDataBase();
|
||||||
|
MemcachedClientConfiguration m_oMcConfig = null;
|
||||||
|
|
||||||
|
private delegate IDataReader ExecuteReader();
|
||||||
|
private delegate int ExecuteNonQuery();
|
||||||
|
private delegate ErrorTypes DelegateAdd(string sKey, TaskResultData oTast);
|
||||||
|
private delegate ErrorTypes DelegateUpdate(string sKey, TaskResultDataToUpdate oTast);
|
||||||
|
private delegate ErrorTypes DelegateGet(string sKey, out TaskResultData oTaskResultData);
|
||||||
|
private delegate ErrorTypes DelegateGetBegin(string sKey, AsyncCallback fCallback, object oParam);
|
||||||
|
private delegate ErrorTypes DelegateRemove(string sKey);
|
||||||
|
|
||||||
|
private delegate ErrorTypes DelegateAddToMC(string sKey, TaskResultData oTast);
|
||||||
|
|
||||||
|
private class TransportClass : TransportClassAsyncOperation
|
||||||
|
{
|
||||||
|
|
||||||
|
public ExecuteReader m_delegateReader = null;
|
||||||
|
public ExecuteNonQuery m_delegateNonQuery = null;
|
||||||
|
public DelegateGet m_delegateGet = null;
|
||||||
|
|
||||||
|
public TaskResultData m_oTast = null;
|
||||||
|
public ErrorTypes m_eError = ErrorTypes.NoError;
|
||||||
|
public bool m_bCreate = false;
|
||||||
|
public string m_sKey = null;
|
||||||
|
public bool m_bReadFromDB = false;
|
||||||
|
public TransportClass(AsyncCallback fCallback, object oParam)
|
||||||
|
: base(fCallback, oParam)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public override void Close()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
m_eError = ErrorTypes.TaskResult;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private TransportClass m_oGetOrCreate = null;
|
||||||
|
|
||||||
|
private TransportClass m_oGet = null;
|
||||||
|
|
||||||
|
public TaskResultCachedDB()
|
||||||
|
{
|
||||||
|
InitMC();
|
||||||
|
}
|
||||||
|
private void InitMC()
|
||||||
|
{
|
||||||
|
if (null == m_oMcConfig)
|
||||||
|
{
|
||||||
|
m_oMcConfig = new MemcachedClientConfiguration();
|
||||||
|
|
||||||
|
string sServerName = ConfigurationManager.AppSettings["utils.taskresult.cacheddb.mc.server"] ?? "localhost:11211";
|
||||||
|
|
||||||
|
m_oMcConfig.AddServer(sServerName);
|
||||||
|
m_oMcConfig.Protocol = MemcachedProtocol.Text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ErrorTypes Add(string sKey, TaskResultData oTast)
|
||||||
|
{
|
||||||
|
AddToMC(sKey, oTast);
|
||||||
|
|
||||||
|
return m_oTaskResultDB.Add(sKey, oTast);
|
||||||
|
}
|
||||||
|
public void AddBegin(string sKey, TaskResultData oTast, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
DelegateAdd oDelegateAdd = new DelegateAdd(AddToMC);
|
||||||
|
|
||||||
|
oDelegateAdd.BeginInvoke(sKey, oTast, null, null);
|
||||||
|
|
||||||
|
m_oTaskResultDB.AddBegin(sKey, oTast, fCallback, oParam);
|
||||||
|
}
|
||||||
|
public ErrorTypes AddEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
return m_oTaskResultDB.AddEnd(ar);
|
||||||
|
}
|
||||||
|
public ErrorTypes AddRandomKey(string sKey, TaskResultData oTastToAdd, out TaskResultData oTastAdded)
|
||||||
|
{
|
||||||
|
return m_oTaskResultDB.AddRandomKey(sKey, oTastToAdd, out oTastAdded);
|
||||||
|
}
|
||||||
|
public void AddRandomKeyBegin(string sKey, TaskResultData oTastToAdd, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
|
||||||
|
m_oTaskResultDB.AddRandomKeyBegin(sKey, oTastToAdd, fCallback, oParam);
|
||||||
|
}
|
||||||
|
public ErrorTypes AddRandomKeyEnd(IAsyncResult ar, out TaskResultData oTast)
|
||||||
|
{
|
||||||
|
|
||||||
|
return m_oTaskResultDB.AddRandomKeyEnd(ar, out oTast);
|
||||||
|
}
|
||||||
|
public ErrorTypes Update(string sKey, TaskResultDataToUpdate oTast)
|
||||||
|
{
|
||||||
|
ErrorTypes oError = ErrorTypes.NoError;
|
||||||
|
bool bUpdate;
|
||||||
|
UpdateIfInMC(sKey, oTast, null, out bUpdate);
|
||||||
|
|
||||||
|
return oError;
|
||||||
|
}
|
||||||
|
public void UpdateBegin(string sKey, TaskResultDataToUpdate oTast, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oTaskResultDB.UpdateBegin(sKey, oTast, fCallback, oParam);
|
||||||
|
|
||||||
|
}
|
||||||
|
public ErrorTypes UpdateEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
return m_oTaskResultDB.UpdateEnd(ar);
|
||||||
|
}
|
||||||
|
public ErrorTypes UpdateIf(string sKey, TaskResultDataToUpdate oMask, TaskResultDataToUpdate oTast, out bool bUpdate)
|
||||||
|
{
|
||||||
|
|
||||||
|
ErrorTypes oError = ErrorTypes.NoError;
|
||||||
|
|
||||||
|
UpdateIfInMC(sKey, oTast, oMask, out bUpdate);
|
||||||
|
|
||||||
|
return oError;
|
||||||
|
}
|
||||||
|
public void UpdateIfBegin(string sKey, TaskResultDataToUpdate oMask, TaskResultDataToUpdate oTast, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oTaskResultDB.UpdateIfBegin(sKey, oMask, oTast, fCallback, oParam);
|
||||||
|
}
|
||||||
|
public ErrorTypes UpdateIfEnd(IAsyncResult ar, out bool bUpdate)
|
||||||
|
{
|
||||||
|
return m_oTaskResultDB.UpdateIfEnd(ar, out bUpdate);
|
||||||
|
}
|
||||||
|
public ErrorTypes Get(string sKey, out TaskResultData oTaskResultData)
|
||||||
|
{
|
||||||
|
oTaskResultData = null;
|
||||||
|
ErrorTypes oError = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
GetFromMC(sKey, out oTaskResultData);
|
||||||
|
|
||||||
|
if (null == oTaskResultData)
|
||||||
|
{
|
||||||
|
oError = m_oTaskResultDB.Get(sKey, out oTaskResultData);
|
||||||
|
if (oError == ErrorTypes.NoError && oTaskResultData != null)
|
||||||
|
{
|
||||||
|
AddToMC(sKey, oTaskResultData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
oError = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
return oError;
|
||||||
|
}
|
||||||
|
public void GetBegin(string sKey, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oGet = new TransportClass(fCallback, oParam);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_oGet.m_sKey = sKey;
|
||||||
|
m_oGet.m_delegateGet = new DelegateGet(GetFromMC);
|
||||||
|
m_oGet.m_delegateGet.BeginInvoke(sKey, out m_oGet.m_oTast, GetCallback, null);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oGet.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ErrorTypes GetEnd(IAsyncResult ar, out TaskResultData oTast)
|
||||||
|
{
|
||||||
|
oTast = null;
|
||||||
|
if (m_oGet.m_eError == ErrorTypes.NoError)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (m_oGet.m_bReadFromDB)
|
||||||
|
{
|
||||||
|
m_oTaskResultDB.GetEnd(ar, out oTast);
|
||||||
|
DelegateAddToMC oDelegateAdd = new DelegateAddToMC(AddToMC);
|
||||||
|
oDelegateAdd.BeginInvoke(m_oGet.m_sKey, oTast, null, null);
|
||||||
|
}
|
||||||
|
else if (m_oGet.m_oTast != null)
|
||||||
|
oTast = m_oGet.m_oTast.Clone();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oGet.m_eError = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m_oGet.m_eError;
|
||||||
|
}
|
||||||
|
public ErrorTypes Get(string[] aKeys, out TaskResultData[] sTaskResults)
|
||||||
|
{
|
||||||
|
|
||||||
|
return m_oTaskResultDB.Get(aKeys, out sTaskResults);
|
||||||
|
}
|
||||||
|
public void GetBegin(string[] aKeys, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oTaskResultDB.GetBegin(aKeys, fCallback, oParam);
|
||||||
|
}
|
||||||
|
public ErrorTypes GetEnd(IAsyncResult ar, out TaskResultData[] sTaskResults)
|
||||||
|
{
|
||||||
|
return m_oTaskResultDB.GetEnd(ar, out sTaskResults);
|
||||||
|
}
|
||||||
|
public ErrorTypes GetEditing(out TaskResultData[] oTast)
|
||||||
|
{
|
||||||
|
return m_oTaskResultDB.GetEditing(out oTast);
|
||||||
|
}
|
||||||
|
public void GetEditingBegin(AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oTaskResultDB.GetEditingBegin(fCallback, oParam);
|
||||||
|
}
|
||||||
|
public ErrorTypes GetEditingEnd(IAsyncResult ar, out TaskResultData[] oTast)
|
||||||
|
{
|
||||||
|
return m_oTaskResultDB.GetEditingEnd(ar, out oTast);
|
||||||
|
}
|
||||||
|
public ErrorTypes GetExpired(int nMaxCount, out List<TaskResultData> aTasts)
|
||||||
|
{
|
||||||
|
return m_oTaskResultDB.GetExpired(nMaxCount, out aTasts);
|
||||||
|
}
|
||||||
|
public ErrorTypes GetOrCreate(string sKey, TaskResultData oDefaultTast, out TaskResultData oTaskResultData, out bool bCreate)
|
||||||
|
{
|
||||||
|
return m_oTaskResultDB.GetOrCreate(sKey, oDefaultTast, out oTaskResultData, out bCreate);
|
||||||
|
}
|
||||||
|
public void GetOrCreateBegin(string sKey, TaskResultData oDataToAdd, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oGetOrCreate = new TransportClass(fCallback, oParam);
|
||||||
|
m_oGetOrCreate.m_oTast = oDataToAdd;
|
||||||
|
m_oGetOrCreate.m_bCreate = true;
|
||||||
|
m_oGetOrCreate.m_sKey = sKey;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TaskResultData oTast = null;
|
||||||
|
m_oGetOrCreate.m_delegateGet = new DelegateGet(GetFromMC);
|
||||||
|
m_oGetOrCreate.m_delegateGet.BeginInvoke(sKey, out oTast, GetOrCreateCallback, null);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oGetOrCreate.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ErrorTypes GetOrCreateEnd(IAsyncResult ar, out TaskResultData oDataAdded, out bool bCreate)
|
||||||
|
{
|
||||||
|
bCreate = m_oGetOrCreate.m_bCreate;
|
||||||
|
oDataAdded = null;
|
||||||
|
if (ErrorTypes.NoError == m_oGetOrCreate.m_eError)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (m_oGetOrCreate.m_bReadFromDB)
|
||||||
|
{
|
||||||
|
m_oTaskResultDB.GetOrCreateEnd(ar, out oDataAdded, out bCreate);
|
||||||
|
if (oDataAdded != null)
|
||||||
|
{
|
||||||
|
DelegateAddToMC oDelegateAddToMC = new DelegateAddToMC(AddToMC);
|
||||||
|
oDelegateAddToMC.BeginInvoke(m_oGetOrCreate.m_sKey, oDataAdded, null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (null != m_oGetOrCreate.m_oTast)
|
||||||
|
oDataAdded = m_oGetOrCreate.m_oTast.Clone();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oGetOrCreate.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m_oGetOrCreate.m_eError;
|
||||||
|
}
|
||||||
|
public ErrorTypes Remove(string sKey)
|
||||||
|
{
|
||||||
|
RemoveFromMC(sKey);
|
||||||
|
return m_oTaskResultDB.Remove(sKey);
|
||||||
|
}
|
||||||
|
public void RemoveBegin(string sKey, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
DelegateRemove oDelegateRemove = new DelegateRemove(RemoveFromMC);
|
||||||
|
oDelegateRemove.BeginInvoke(sKey, null, null);
|
||||||
|
m_oTaskResultDB.RemoveBegin(sKey, fCallback, oParam);
|
||||||
|
}
|
||||||
|
public ErrorTypes RemoveEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
eErrorTypes = m_oTaskResultDB.RemoveEnd(ar);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eErrorTypes = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
private ErrorTypes AddToMC(string sKey, TaskResultData oTast)
|
||||||
|
{
|
||||||
|
return AddToMCWithCas(sKey, oTast, 0);
|
||||||
|
}
|
||||||
|
private ErrorTypes AddToMCWithCas(string sKey, TaskResultData oTast, ulong cas)
|
||||||
|
{
|
||||||
|
ErrorTypes oError = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (MemcachedClient oMc = new MemcachedClient(m_oMcConfig))
|
||||||
|
{
|
||||||
|
string sDataToStore = null;
|
||||||
|
|
||||||
|
XmlSerializer oXmlSerializer = new XmlSerializer(typeof(TaskResultData));
|
||||||
|
using (StringWriter oStringWriter = new StringWriter())
|
||||||
|
{
|
||||||
|
oXmlSerializer.Serialize(oStringWriter, oTast);
|
||||||
|
sDataToStore = oStringWriter.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cas != 0)
|
||||||
|
oMc.Cas(StoreMode.Set, sKey, sDataToStore, m_oTtl, cas);
|
||||||
|
else
|
||||||
|
oMc.Store(StoreMode.Set, sKey, sDataToStore, m_oTtl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
oError = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
return oError;
|
||||||
|
}
|
||||||
|
private ErrorTypes GetFromMC(string sKey, out TaskResultData oTast)
|
||||||
|
{
|
||||||
|
ulong cas = 0;
|
||||||
|
return GetFromMCWithCas(sKey, out oTast, out cas);
|
||||||
|
}
|
||||||
|
private ErrorTypes GetFromMCWithCas(string sKey, out TaskResultData oTast, out ulong cas)
|
||||||
|
{
|
||||||
|
ErrorTypes oError = ErrorTypes.NoError;
|
||||||
|
oTast = null;
|
||||||
|
cas = 0;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (MemcachedClient oMc = new MemcachedClient(m_oMcConfig))
|
||||||
|
{
|
||||||
|
CasResult<string> oGetData = oMc.GetWithCas<string>(sKey);
|
||||||
|
|
||||||
|
if (oGetData.Result != null)
|
||||||
|
{
|
||||||
|
cas = oGetData.Cas;
|
||||||
|
|
||||||
|
XmlSerializer oXmlSerializer = new XmlSerializer(typeof(TaskResultData));
|
||||||
|
using (StringReader oStringReader = new StringReader(oGetData.Result))
|
||||||
|
{
|
||||||
|
oTast = (TaskResultData)oXmlSerializer.Deserialize(oStringReader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
oError = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
return oError;
|
||||||
|
}
|
||||||
|
private ErrorTypes UpdateIfInMC(string sKey, TaskResultDataToUpdate oTast, TaskResultDataToUpdate oMask, out bool bUpdate)
|
||||||
|
{
|
||||||
|
ErrorTypes oError = ErrorTypes.NoError;
|
||||||
|
bUpdate = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TaskResultData oTask = null;
|
||||||
|
ulong cas = 0;
|
||||||
|
GetFromMCWithCas(sKey, out oTask, out cas);
|
||||||
|
|
||||||
|
if (oTask == null)
|
||||||
|
m_oTaskResultDB.Get(sKey, out oTask);
|
||||||
|
|
||||||
|
if (oTask != null && oTask.eStatus != FileStatus.Ok && oTask.IsValidMask(oMask))
|
||||||
|
{
|
||||||
|
bUpdate = true;
|
||||||
|
oTask.Update(oTast);
|
||||||
|
|
||||||
|
AddToMCWithCas(sKey, oTask, cas);
|
||||||
|
|
||||||
|
if (oTask.eStatus != FileStatus.Convert)
|
||||||
|
oError = m_oTaskResultDB.Update(sKey, oTast);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
oError = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
return oError;
|
||||||
|
}
|
||||||
|
private ErrorTypes RemoveFromMC(string sKey)
|
||||||
|
{
|
||||||
|
ErrorTypes oError = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (MemcachedClient oMc = new MemcachedClient(m_oMcConfig))
|
||||||
|
{
|
||||||
|
oMc.Remove(sKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
oError = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
return oError;
|
||||||
|
}
|
||||||
|
private void GetCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TaskResultData oTast = null;
|
||||||
|
m_oGet.m_eError = m_oGet.m_delegateGet.EndInvoke(out oTast, ar);
|
||||||
|
m_oGet.m_delegateGet = null;
|
||||||
|
|
||||||
|
if (oTast != null)
|
||||||
|
{
|
||||||
|
m_oGet.m_sKey = null;
|
||||||
|
m_oGet.m_oTast = oTast;
|
||||||
|
m_oGet.FireCallback();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_oGet.m_bReadFromDB = true;
|
||||||
|
m_oTaskResultDB.GetBegin(m_oGet.m_sKey, m_oGet.m_fCallback, m_oGet.m_oParam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oGet.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void GetOrCreateCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
TaskResultData oTaskResult = null;
|
||||||
|
m_oGetOrCreate.m_delegateGet.EndInvoke(out oTaskResult, ar);
|
||||||
|
m_oGetOrCreate.m_delegateGet = null;
|
||||||
|
|
||||||
|
if (oTaskResult != null)
|
||||||
|
{
|
||||||
|
m_oGetOrCreate.m_bCreate = false;
|
||||||
|
m_oGetOrCreate.m_oTast = oTaskResult;
|
||||||
|
m_oGetOrCreate.FireCallback();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_oGetOrCreate.m_bReadFromDB = true;
|
||||||
|
m_oTaskResultDB.GetOrCreateBegin(m_oGetOrCreate.m_sKey, m_oGetOrCreate.m_oTast, m_oGetOrCreate.m_fCallback, m_oGetOrCreate.m_oParam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oGetOrCreate.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
938
ServerComponents/FileConverterUtils2/TaskResultDB.cs
Normal file
938
ServerComponents/FileConverterUtils2/TaskResultDB.cs
Normal file
|
@ -0,0 +1,938 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Data;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
|
using ASC.Common.Data;
|
||||||
|
using ASC.Common.Data.Sql;
|
||||||
|
using ASC.Common.Data.Sql.Expressions;
|
||||||
|
|
||||||
|
using log4net;
|
||||||
|
|
||||||
|
namespace FileConverterUtils2
|
||||||
|
{
|
||||||
|
class TaskResultDataBase : ITaskResultInterface
|
||||||
|
{
|
||||||
|
private static readonly ILog _log = LogManager.GetLogger(typeof(TaskResultDataBase));
|
||||||
|
private static int mc_nRandomMaxNumber = 10000;
|
||||||
|
private static System.Random m_oRandom = new System.Random();
|
||||||
|
private string m_sConnectionString = ConfigurationManager.AppSettings["utils.taskresult.db.connectionstring"];
|
||||||
|
|
||||||
|
private delegate IDataReader ExecuteReader();
|
||||||
|
private delegate int ExecuteNonQuery();
|
||||||
|
private delegate ErrorTypes DelegateAdd(string sKey, TaskResultData oTast);
|
||||||
|
private delegate ErrorTypes DelegateUpdate(string sKey, TaskResultDataToUpdate oTast);
|
||||||
|
private delegate ErrorTypes DelegateUpdateIf(string sKey, TaskResultDataToUpdate oMask, TaskResultDataToUpdate oTast, out bool bUpdate);
|
||||||
|
private delegate ErrorTypes DelegateGet(string sKey, out TaskResultData oTaskResultData);
|
||||||
|
private delegate ErrorTypes DelegateGets(string[] aKeys, out TaskResultData[] aTaskResultDatas);
|
||||||
|
private delegate ErrorTypes DelegateGetEditing(out TaskResultData[] oTast);
|
||||||
|
private delegate ErrorTypes DelegateRemove(string sKey);
|
||||||
|
|
||||||
|
private class TransportClass : TransportClassAsyncOperation
|
||||||
|
{
|
||||||
|
public ExecuteReader m_delegateReader = null;
|
||||||
|
public ExecuteNonQuery m_delegateNonQuery = null;
|
||||||
|
public IDbConnection m_oSqlCon = null;
|
||||||
|
public IDbCommand m_oCommand = null;
|
||||||
|
public TaskResultData m_oTast = null;
|
||||||
|
public ErrorTypes m_eError = ErrorTypes.NoError;
|
||||||
|
public bool m_bCreate = false;
|
||||||
|
public TransportClass(AsyncCallback fCallback, object oParam)
|
||||||
|
: base(fCallback, oParam)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public override void Close()
|
||||||
|
{
|
||||||
|
if (null != m_oCommand)
|
||||||
|
{
|
||||||
|
m_oCommand.Dispose();
|
||||||
|
m_oCommand = null;
|
||||||
|
}
|
||||||
|
if (null != m_oSqlCon)
|
||||||
|
{
|
||||||
|
m_oSqlCon.Close();
|
||||||
|
m_oSqlCon.Dispose();
|
||||||
|
m_oSqlCon = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
m_eError = ErrorTypes.TaskResult;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (null != m_oCommand)
|
||||||
|
{
|
||||||
|
m_oCommand.Dispose();
|
||||||
|
m_oCommand = null;
|
||||||
|
}
|
||||||
|
if (null != m_oSqlCon)
|
||||||
|
{
|
||||||
|
m_oSqlCon.Dispose();
|
||||||
|
m_oSqlCon = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private TransportClass m_oAddRandomKey = null;
|
||||||
|
private TransportClass m_oGetOrCreate = null;
|
||||||
|
private DelegateAdd m_oAdd = null;
|
||||||
|
private DelegateUpdate m_oUpdate = null;
|
||||||
|
private DelegateUpdateIf m_oUpdateIf = null;
|
||||||
|
private DelegateGet m_oGet = null;
|
||||||
|
private DelegateGets m_oGets = null;
|
||||||
|
private DelegateGetEditing m_oGetEditing = null;
|
||||||
|
private DelegateRemove m_oRemove = null;
|
||||||
|
|
||||||
|
public ErrorTypes Add(string sKey, TaskResultData oTast)
|
||||||
|
{
|
||||||
|
ErrorTypes eError = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (IDbConnection sqlCon = GetDbConnection())
|
||||||
|
{
|
||||||
|
sqlCon.Open();
|
||||||
|
using (IDbCommand oSelCommand = sqlCon.CreateCommand())
|
||||||
|
{
|
||||||
|
oSelCommand.CommandText = GetINSERTString(oTast);
|
||||||
|
oSelCommand.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eError = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
return eError;
|
||||||
|
}
|
||||||
|
public void AddBegin(string sKey, TaskResultData oTast, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
DelegateAdd oDelegateAdd = new DelegateAdd(Add);
|
||||||
|
m_oAdd = oDelegateAdd;
|
||||||
|
oDelegateAdd.BeginInvoke(sKey, oTast, fCallback, oParam);
|
||||||
|
}
|
||||||
|
public ErrorTypes AddEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
ErrorTypes eError = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
eError = m_oAdd.EndInvoke(ar);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eError = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
return eError;
|
||||||
|
}
|
||||||
|
public ErrorTypes AddRandomKey(string sKey, TaskResultData oTastToAdd, out TaskResultData oTastAdded)
|
||||||
|
{
|
||||||
|
ErrorTypes eError = ErrorTypes.TaskResult;
|
||||||
|
oTastAdded = oTastToAdd.Clone();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (IDbConnection sqlCon = GetDbConnection())
|
||||||
|
{
|
||||||
|
sqlCon.Open();
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
string sNewKey = sKey + "_" + m_oRandom.Next(mc_nRandomMaxNumber);
|
||||||
|
oTastAdded.sKey = sNewKey;
|
||||||
|
using (IDbCommand oAddCommand = sqlCon.CreateCommand())
|
||||||
|
{
|
||||||
|
oAddCommand.CommandText = GetINSERTString(oTastAdded);
|
||||||
|
bool bExist = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
oAddCommand.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
bExist = true;
|
||||||
|
}
|
||||||
|
if (false == bExist)
|
||||||
|
{
|
||||||
|
eError = ErrorTypes.NoError;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eError = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
if (ErrorTypes.NoError != eError)
|
||||||
|
{
|
||||||
|
oTastAdded = null;
|
||||||
|
}
|
||||||
|
return eError;
|
||||||
|
}
|
||||||
|
public void AddRandomKeyBegin(string sKey, TaskResultData oTastToAdd, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oAddRandomKey = new TransportClass(fCallback, oParam);
|
||||||
|
m_oAddRandomKey.m_oTast = oTastToAdd.Clone();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_oAddRandomKey.m_oSqlCon = GetDbConnection();
|
||||||
|
m_oAddRandomKey.m_oSqlCon.Open();
|
||||||
|
string sNewKey = sKey + "_" + m_oRandom.Next(mc_nRandomMaxNumber);
|
||||||
|
m_oAddRandomKey.m_oTast.sKey = sNewKey;
|
||||||
|
IDbCommand oSelCommand = m_oAddRandomKey.m_oSqlCon.CreateCommand();
|
||||||
|
m_oAddRandomKey.m_oCommand = oSelCommand;
|
||||||
|
oSelCommand.CommandText = GetINSERTString(m_oAddRandomKey.m_oTast);
|
||||||
|
m_oAddRandomKey.m_delegateNonQuery = new ExecuteNonQuery(oSelCommand.ExecuteNonQuery);
|
||||||
|
m_oAddRandomKey.m_delegateNonQuery.BeginInvoke(AddRandomKeyCallback, null);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oAddRandomKey.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ErrorTypes AddRandomKeyEnd(IAsyncResult ar, out TaskResultData oTast)
|
||||||
|
{
|
||||||
|
oTast = null;
|
||||||
|
if (ErrorTypes.NoError == m_oAddRandomKey.m_eError)
|
||||||
|
{
|
||||||
|
oTast = m_oAddRandomKey.m_oTast;
|
||||||
|
}
|
||||||
|
return m_oAddRandomKey.m_eError;
|
||||||
|
}
|
||||||
|
public ErrorTypes Update(string sKey, TaskResultDataToUpdate oTast)
|
||||||
|
{
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (IDbConnection sqlCon = GetDbConnection())
|
||||||
|
{
|
||||||
|
sqlCon.Open();
|
||||||
|
using (IDbCommand oSelCommand = sqlCon.CreateCommand())
|
||||||
|
{
|
||||||
|
oSelCommand.CommandText = GetUPDATEString(sKey, oTast);
|
||||||
|
oSelCommand.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eErrorTypes = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
public void UpdateBegin(string sKey, TaskResultDataToUpdate oTast, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oUpdate = Update;
|
||||||
|
m_oUpdate.BeginInvoke(sKey, oTast, fCallback, oParam);
|
||||||
|
}
|
||||||
|
public ErrorTypes UpdateEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
eErrorTypes = m_oUpdate.EndInvoke(ar);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eErrorTypes = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
public ErrorTypes UpdateIf(string sKey, TaskResultDataToUpdate oMask, TaskResultDataToUpdate oTast, out bool bUpdate)
|
||||||
|
{
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.NoError;
|
||||||
|
bUpdate = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (IDbConnection sqlCon = GetDbConnection())
|
||||||
|
{
|
||||||
|
sqlCon.Open();
|
||||||
|
using (IDbCommand oSelCommand = sqlCon.CreateCommand())
|
||||||
|
{
|
||||||
|
oSelCommand.CommandText = GetUPDATEIFString(sKey, oMask, oTast);
|
||||||
|
if (oSelCommand.ExecuteNonQuery() > 0)
|
||||||
|
bUpdate = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eErrorTypes = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
public void UpdateIfBegin(string sKey, TaskResultDataToUpdate oMask, TaskResultDataToUpdate oTast, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oUpdateIf = UpdateIf;
|
||||||
|
bool bUpdate;
|
||||||
|
m_oUpdateIf.BeginInvoke(sKey, oMask, oTast, out bUpdate, fCallback, oParam);
|
||||||
|
}
|
||||||
|
public ErrorTypes UpdateIfEnd(IAsyncResult ar, out bool bUpdate)
|
||||||
|
{
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.NoError;
|
||||||
|
bUpdate = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
eErrorTypes = m_oUpdateIf.EndInvoke(out bUpdate, ar);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eErrorTypes = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
public ErrorTypes Get(string sKey, out TaskResultData oTaskResultData)
|
||||||
|
{
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.TaskResult;
|
||||||
|
oTaskResultData = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (IDbConnection sqlCon = GetDbConnection())
|
||||||
|
{
|
||||||
|
sqlCon.Open();
|
||||||
|
using (IDbCommand oSelCommand = sqlCon.CreateCommand())
|
||||||
|
{
|
||||||
|
oSelCommand.CommandText = GetSELECTString(sKey);
|
||||||
|
using (IDataReader oReader = oSelCommand.ExecuteReader())
|
||||||
|
{
|
||||||
|
if (true == oReader.Read())
|
||||||
|
{
|
||||||
|
oTaskResultData = new TaskResultData();
|
||||||
|
TaskResultFromReader(oTaskResultData, oReader);
|
||||||
|
eErrorTypes = ErrorTypes.NoError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
public void GetBegin(string sKey, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
TaskResultData oTast;
|
||||||
|
m_oGet = Get;
|
||||||
|
m_oGet.BeginInvoke(sKey, out oTast, fCallback, oParam);
|
||||||
|
}
|
||||||
|
public ErrorTypes GetEnd(IAsyncResult ar, out TaskResultData oTast)
|
||||||
|
{
|
||||||
|
oTast = null;
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
eErrorTypes = m_oGet.EndInvoke(out oTast, ar);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eErrorTypes = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
public ErrorTypes Get(string[] aKeys, out TaskResultData[] sTaskResults)
|
||||||
|
{
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.NoError;
|
||||||
|
sTaskResults = new TaskResultData[aKeys.Length];
|
||||||
|
for (int i = 0, length = sTaskResults.Length; i < length; ++i)
|
||||||
|
sTaskResults[i] = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (IDbConnection sqlCon = GetDbConnection())
|
||||||
|
{
|
||||||
|
sqlCon.Open();
|
||||||
|
using (IDbCommand oSelCommand = sqlCon.CreateCommand())
|
||||||
|
{
|
||||||
|
oSelCommand.CommandText = GetSELECTString(aKeys);
|
||||||
|
using (IDataReader oReader = oSelCommand.ExecuteReader())
|
||||||
|
{
|
||||||
|
Dictionary<string, int> mapKeyToIndex = new Dictionary<string, int>();
|
||||||
|
for (int i = 0, length = aKeys.Length; i < length; ++i)
|
||||||
|
mapKeyToIndex[aKeys[i]] = i;
|
||||||
|
|
||||||
|
while (oReader.Read())
|
||||||
|
{
|
||||||
|
TaskResultData oTaskResultData = new TaskResultData();
|
||||||
|
TaskResultFromReader(oTaskResultData, oReader);
|
||||||
|
int nIndex;
|
||||||
|
if (mapKeyToIndex.TryGetValue(oTaskResultData.sKey, out nIndex))
|
||||||
|
sTaskResults[nIndex] = oTaskResultData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eErrorTypes = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
public void GetBegin(string[] aKeys, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
TaskResultData[] oTast;
|
||||||
|
m_oGets = Get;
|
||||||
|
m_oGets.BeginInvoke(aKeys, out oTast, fCallback, oParam);
|
||||||
|
}
|
||||||
|
public ErrorTypes GetEnd(IAsyncResult ar, out TaskResultData[] sTaskResults)
|
||||||
|
{
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.NoError;
|
||||||
|
sTaskResults = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
eErrorTypes = m_oGets.EndInvoke(out sTaskResults, ar);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eErrorTypes = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
public ErrorTypes GetEditing(out TaskResultData[] oTast)
|
||||||
|
{
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.NoError;
|
||||||
|
oTast = new TaskResultData[0];
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (IDbConnection sqlCon = GetDbConnection())
|
||||||
|
{
|
||||||
|
sqlCon.Open();
|
||||||
|
using (IDbCommand oSelCommand = sqlCon.CreateCommand())
|
||||||
|
{
|
||||||
|
oSelCommand.CommandText = GetSELECTEditingString();
|
||||||
|
using (IDataReader oReader = oSelCommand.ExecuteReader())
|
||||||
|
{
|
||||||
|
List<TaskResultData> aData = new List<TaskResultData>();
|
||||||
|
while (oReader.Read())
|
||||||
|
{
|
||||||
|
TaskResultData oTaskResultData = new TaskResultData();
|
||||||
|
TaskResultFromReader(oTaskResultData, oReader);
|
||||||
|
aData.Add(oTaskResultData);
|
||||||
|
}
|
||||||
|
oTast = aData.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eErrorTypes = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
public void GetEditingBegin(AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
TaskResultData[] oTast;
|
||||||
|
m_oGetEditing = GetEditing;
|
||||||
|
m_oGetEditing.BeginInvoke(out oTast, fCallback, oParam);
|
||||||
|
}
|
||||||
|
public ErrorTypes GetEditingEnd(IAsyncResult ar, out TaskResultData[] oTast)
|
||||||
|
{
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.NoError;
|
||||||
|
oTast = new TaskResultData[0];
|
||||||
|
try
|
||||||
|
{
|
||||||
|
eErrorTypes = m_oGetEditing.EndInvoke(out oTast, ar);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eErrorTypes = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
public ErrorTypes GetExpired(int nMaxCount, out List<TaskResultData> aTasts)
|
||||||
|
{
|
||||||
|
aTasts = null;
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (IDbConnection sqlCon = GetDbConnection())
|
||||||
|
{
|
||||||
|
sqlCon.Open();
|
||||||
|
using (IDbCommand oSelCommand = sqlCon.CreateCommand())
|
||||||
|
{
|
||||||
|
oSelCommand.CommandText = GetSELECTExpiredTasksString(nMaxCount);
|
||||||
|
using (IDataReader oReader = oSelCommand.ExecuteReader())
|
||||||
|
{
|
||||||
|
aTasts = new List<TaskResultData>();
|
||||||
|
while (oReader.Read())
|
||||||
|
{
|
||||||
|
TaskResultData oTaskResultData = new TaskResultData();
|
||||||
|
TaskResultFromReader(oTaskResultData, oReader);
|
||||||
|
aTasts.Add(oTaskResultData);
|
||||||
|
eErrorTypes = ErrorTypes.NoError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
public ErrorTypes GetOrCreate(string sKey, TaskResultData oDefaultTast, out TaskResultData oTaskResultData, out bool bCreate)
|
||||||
|
{
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.TaskResult;
|
||||||
|
oTaskResultData = null;
|
||||||
|
bCreate = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (IDbConnection sqlCon = GetDbConnection())
|
||||||
|
{
|
||||||
|
sqlCon.Open();
|
||||||
|
if (Constants.mc_sPostgreProvider == Utils.GetDbConnectionProviderName(m_sConnectionString))
|
||||||
|
{
|
||||||
|
using (IDbCommand oAddCommand = sqlCon.CreateCommand())
|
||||||
|
{
|
||||||
|
oAddCommand.CommandText = GetINSERTString(oDefaultTast);
|
||||||
|
bool bExist = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
oAddCommand.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
bExist = true;
|
||||||
|
}
|
||||||
|
if (bExist)
|
||||||
|
{
|
||||||
|
using (IDbCommand oSelCommand = sqlCon.CreateCommand())
|
||||||
|
{
|
||||||
|
TaskResultDataToUpdate oToUpdate = new TaskResultDataToUpdate();
|
||||||
|
oToUpdate.oLastOpenDate = DateTime.UtcNow;
|
||||||
|
oSelCommand.CommandText = GetUPDATEString(sKey, oToUpdate) + GetSELECTString(sKey);
|
||||||
|
using (IDataReader oReader = oSelCommand.ExecuteReader())
|
||||||
|
{
|
||||||
|
if (true == oReader.Read())
|
||||||
|
{
|
||||||
|
oTaskResultData = new TaskResultData();
|
||||||
|
TaskResultFromReader(oTaskResultData, oReader);
|
||||||
|
|
||||||
|
bCreate = false;
|
||||||
|
eErrorTypes = ErrorTypes.NoError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
oTaskResultData = oDefaultTast.Clone();
|
||||||
|
bCreate = true;
|
||||||
|
eErrorTypes = ErrorTypes.NoError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
using (IDbCommand oAddCommand = sqlCon.CreateCommand())
|
||||||
|
{
|
||||||
|
oAddCommand.CommandText = GetUPSERTString(oDefaultTast);
|
||||||
|
bool bExist = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int nNumRowsAffected = oAddCommand.ExecuteNonQuery();
|
||||||
|
|
||||||
|
oTaskResultData = oDefaultTast.Clone();
|
||||||
|
eErrorTypes = ErrorTypes.NoError;
|
||||||
|
|
||||||
|
bCreate = (nNumRowsAffected == 1);
|
||||||
|
bExist = (nNumRowsAffected > 1);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
bExist = true;
|
||||||
|
}
|
||||||
|
if (bExist)
|
||||||
|
{
|
||||||
|
using (IDbCommand oSelCommand = sqlCon.CreateCommand())
|
||||||
|
{
|
||||||
|
oSelCommand.CommandText = GetSELECTString(sKey);
|
||||||
|
using (IDataReader oReader = oSelCommand.ExecuteReader())
|
||||||
|
{
|
||||||
|
if (true == oReader.Read())
|
||||||
|
{
|
||||||
|
oTaskResultData = new TaskResultData();
|
||||||
|
TaskResultFromReader(oTaskResultData, oReader);
|
||||||
|
|
||||||
|
bCreate = false;
|
||||||
|
eErrorTypes = ErrorTypes.NoError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
public void GetOrCreateBegin(string sKey, TaskResultData oDataToAdd, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oGetOrCreate = new TransportClass(fCallback, oParam);
|
||||||
|
m_oGetOrCreate.m_oTast = oDataToAdd;
|
||||||
|
m_oGetOrCreate.m_bCreate = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_oGetOrCreate.m_oSqlCon = GetDbConnection();
|
||||||
|
m_oGetOrCreate.m_oSqlCon.Open();
|
||||||
|
|
||||||
|
if (Constants.mc_sPostgreProvider == Utils.GetDbConnectionProviderName(m_sConnectionString))
|
||||||
|
{
|
||||||
|
IDbCommand oInsCommand = m_oGetOrCreate.m_oSqlCon.CreateCommand();
|
||||||
|
oInsCommand.CommandText = GetINSERTString(m_oGetOrCreate.m_oTast);
|
||||||
|
m_oGetOrCreate.m_oCommand = oInsCommand;
|
||||||
|
m_oGetOrCreate.m_delegateNonQuery = new ExecuteNonQuery(oInsCommand.ExecuteNonQuery);
|
||||||
|
m_oGetOrCreate.m_delegateNonQuery.BeginInvoke(GetOrCreateCallback, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
IDbCommand oSelCommand = m_oGetOrCreate.m_oSqlCon.CreateCommand();
|
||||||
|
oSelCommand.CommandText = GetUPSERTString(m_oGetOrCreate.m_oTast);
|
||||||
|
m_oGetOrCreate.m_oCommand = oSelCommand;
|
||||||
|
m_oGetOrCreate.m_delegateNonQuery = new ExecuteNonQuery(oSelCommand.ExecuteNonQuery);
|
||||||
|
m_oGetOrCreate.m_delegateNonQuery.BeginInvoke(GetOrCreateCallback2, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oGetOrCreate.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ErrorTypes GetOrCreateEnd(IAsyncResult ar, out TaskResultData oDataAdded, out bool bCreate)
|
||||||
|
{
|
||||||
|
bCreate = m_oGetOrCreate.m_bCreate;
|
||||||
|
oDataAdded = null;
|
||||||
|
if (ErrorTypes.NoError == m_oGetOrCreate.m_eError)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (null != m_oGetOrCreate.m_delegateReader)
|
||||||
|
{
|
||||||
|
using (IDataReader oReader = m_oGetOrCreate.m_delegateReader.EndInvoke(ar))
|
||||||
|
{
|
||||||
|
if (true == oReader.Read())
|
||||||
|
{
|
||||||
|
m_oGetOrCreate.m_oTast = new TaskResultData();
|
||||||
|
TaskResultFromReader(m_oGetOrCreate.m_oTast, oReader);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_oGetOrCreate.m_eError = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_oGetOrCreate.Close();
|
||||||
|
if (null != m_oGetOrCreate.m_oTast)
|
||||||
|
oDataAdded = m_oGetOrCreate.m_oTast.Clone();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
_log.Error("Exception catch in GetOrCreateEnd:", e);
|
||||||
|
m_oGetOrCreate.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m_oGetOrCreate.m_eError;
|
||||||
|
}
|
||||||
|
public ErrorTypes Remove(string sKey)
|
||||||
|
{
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.TaskResult;
|
||||||
|
using (IDbConnection sqlCon = GetDbConnection())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sqlCon.Open();
|
||||||
|
using (IDbCommand oSelCommand = sqlCon.CreateCommand())
|
||||||
|
{
|
||||||
|
oSelCommand.CommandText = GetDELETEString(sKey);
|
||||||
|
oSelCommand.ExecuteNonQuery();
|
||||||
|
eErrorTypes = ErrorTypes.NoError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
public void RemoveBegin(string sKey, AsyncCallback fCallback, object oParam)
|
||||||
|
{
|
||||||
|
m_oRemove = Remove;
|
||||||
|
m_oRemove.BeginInvoke(sKey, fCallback, oParam);
|
||||||
|
}
|
||||||
|
public ErrorTypes RemoveEnd(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
ErrorTypes eErrorTypes = ErrorTypes.NoError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
eErrorTypes = m_oRemove.EndInvoke(ar);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
eErrorTypes = ErrorTypes.TaskResult;
|
||||||
|
}
|
||||||
|
return eErrorTypes;
|
||||||
|
}
|
||||||
|
private void GetOrCreateCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bool bExist = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_oGetOrCreate.m_delegateNonQuery.EndInvoke(ar);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
bExist = true;
|
||||||
|
}
|
||||||
|
if(bExist)
|
||||||
|
{
|
||||||
|
m_oGetOrCreate.m_bCreate = false;
|
||||||
|
if (null != m_oGetOrCreate.m_oCommand)
|
||||||
|
{
|
||||||
|
m_oGetOrCreate.m_oCommand.Dispose();
|
||||||
|
m_oGetOrCreate.m_oCommand = null;
|
||||||
|
}
|
||||||
|
IDbCommand oSelCommand = m_oGetOrCreate.m_oSqlCon.CreateCommand();
|
||||||
|
TaskResultDataToUpdate oToUpdate = new TaskResultDataToUpdate();
|
||||||
|
oToUpdate.oLastOpenDate = DateTime.UtcNow;
|
||||||
|
oSelCommand.CommandText = GetUPDATEString(m_oGetOrCreate.m_oTast.sKey, oToUpdate) + GetSELECTString(m_oGetOrCreate.m_oTast.sKey);
|
||||||
|
m_oGetOrCreate.m_oCommand = oSelCommand;
|
||||||
|
m_oGetOrCreate.m_delegateReader = new ExecuteReader(oSelCommand.ExecuteReader);
|
||||||
|
m_oGetOrCreate.m_delegateReader.BeginInvoke(m_oGetOrCreate.m_fCallback, m_oGetOrCreate.m_oParam);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_oGetOrCreate.m_bCreate = true;
|
||||||
|
m_oGetOrCreate.m_delegateReader = null;
|
||||||
|
m_oGetOrCreate.FireCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oGetOrCreate.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void GetOrCreateCallback2(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bool bExist = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int nNumRowsAffected = m_oGetOrCreate.m_delegateNonQuery.EndInvoke(ar);
|
||||||
|
|
||||||
|
m_oGetOrCreate.m_bCreate = (nNumRowsAffected == 1);
|
||||||
|
bExist = (nNumRowsAffected > 1);
|
||||||
|
|
||||||
|
if (null != m_oGetOrCreate.m_oCommand)
|
||||||
|
{
|
||||||
|
m_oGetOrCreate.m_oCommand.Dispose();
|
||||||
|
m_oGetOrCreate.m_oCommand = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_log.Error("Exception;", e);
|
||||||
|
m_oGetOrCreate.m_bCreate = false;
|
||||||
|
bExist = true;
|
||||||
|
}
|
||||||
|
if (bExist)
|
||||||
|
{
|
||||||
|
IDbCommand oSelCommand = m_oGetOrCreate.m_oSqlCon.CreateCommand();
|
||||||
|
oSelCommand.CommandText = GetSELECTString(m_oGetOrCreate.m_oTast.sKey);
|
||||||
|
m_oGetOrCreate.m_oCommand = oSelCommand;
|
||||||
|
m_oGetOrCreate.m_delegateReader = new ExecuteReader(oSelCommand.ExecuteReader);
|
||||||
|
m_oGetOrCreate.m_delegateReader.BeginInvoke(m_oGetOrCreate.m_fCallback, m_oGetOrCreate.m_oParam);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_oGetOrCreate.m_delegateReader = null;
|
||||||
|
m_oGetOrCreate.FireCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oGetOrCreate.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void AddRandomKeyCallback(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bool bExist = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_oAddRandomKey.m_delegateNonQuery.EndInvoke(ar);
|
||||||
|
if (null != m_oAddRandomKey.m_oCommand)
|
||||||
|
{
|
||||||
|
m_oAddRandomKey.m_oCommand.Dispose();
|
||||||
|
m_oAddRandomKey.m_oCommand = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
bExist = true;
|
||||||
|
}
|
||||||
|
if(bExist)
|
||||||
|
{
|
||||||
|
string sNewKey = m_oAddRandomKey.m_oTast.sKey + "_" + m_oRandom.Next(mc_nRandomMaxNumber);
|
||||||
|
m_oAddRandomKey.m_oTast.sKey = sNewKey;
|
||||||
|
IDbCommand oSelCommand = m_oAddRandomKey.m_oSqlCon.CreateCommand();
|
||||||
|
m_oAddRandomKey.m_oCommand = oSelCommand;
|
||||||
|
oSelCommand.CommandText = GetINSERTString(m_oAddRandomKey.m_oTast);
|
||||||
|
m_oAddRandomKey.m_delegateNonQuery = new ExecuteNonQuery(oSelCommand.ExecuteNonQuery);
|
||||||
|
m_oAddRandomKey.m_delegateNonQuery.BeginInvoke(AddRandomKeyCallback, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_oAddRandomKey.Close();
|
||||||
|
m_oAddRandomKey.FireCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
m_oAddRandomKey.DisposeAndCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private IDbConnection GetDbConnection()
|
||||||
|
{
|
||||||
|
var cs = ConfigurationManager.ConnectionStrings[m_sConnectionString];
|
||||||
|
var dbProvider = System.Data.Common.DbProviderFactories.GetFactory(cs.ProviderName);
|
||||||
|
var connection = dbProvider.CreateConnection();
|
||||||
|
connection.ConnectionString = cs.ConnectionString;
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
private DbManager GetDbManager(string connectionStringName)
|
||||||
|
{
|
||||||
|
var cs = ConfigurationManager.ConnectionStrings[connectionStringName];
|
||||||
|
if (!DbRegistry.IsDatabaseRegistered(connectionStringName))
|
||||||
|
{
|
||||||
|
DbRegistry.RegisterDatabase(connectionStringName, cs);
|
||||||
|
}
|
||||||
|
return new DbManager(connectionStringName);
|
||||||
|
}
|
||||||
|
private void TaskResultFromReader(TaskResultData oTaskResultData, IDataReader oReader)
|
||||||
|
{
|
||||||
|
oTaskResultData.sKey = Convert.ToString(oReader["tr_key"]);
|
||||||
|
oTaskResultData.sFormat = Convert.ToString(oReader["tr_format"]);
|
||||||
|
oTaskResultData.eStatus = (FileStatus)Convert.ToByte(oReader["tr_status"]);
|
||||||
|
oTaskResultData.nStatusInfo = Convert.ToInt32(oReader["tr_status_info"]);
|
||||||
|
oTaskResultData.oLastOpenDate = Convert.ToDateTime(oReader["tr_last_open_date"]);
|
||||||
|
oTaskResultData.sTitle = Convert.ToString(oReader["tr_title"]);
|
||||||
|
}
|
||||||
|
private string GetUPSERTString(TaskResultData oTast)
|
||||||
|
{
|
||||||
|
return string.Format("INSERT INTO tast_result ( tr_key, tr_format, tr_status, tr_status_info, tr_last_open_date, tr_title ) VALUES ('{0}', '{1}', '{2}' , '{3}', '{4}', '{5}') ON DUPLICATE KEY UPDATE tr_last_open_date = '{6}';",
|
||||||
|
Utils.MySqlEscape(oTast.sKey, m_sConnectionString),
|
||||||
|
Utils.MySqlEscape(oTast.sFormat, m_sConnectionString),
|
||||||
|
oTast.eStatus.ToString("d"),
|
||||||
|
oTast.nStatusInfo.ToString(),
|
||||||
|
DateTime.UtcNow.ToString(Constants.mc_sDateTimeFormat),
|
||||||
|
Utils.MySqlEscape(oTast.sTitle, m_sConnectionString),
|
||||||
|
DateTime.UtcNow.ToString(Constants.mc_sDateTimeFormat));
|
||||||
|
}
|
||||||
|
private string GetINSERTString(TaskResultData oTast)
|
||||||
|
{
|
||||||
|
return string.Format("INSERT INTO tast_result ( tr_key, tr_format, tr_status, tr_status_info, tr_last_open_date, tr_title ) VALUES ('{0}', '{1}', '{2}' , '{3}', '{4}', '{5}');", Utils.MySqlEscape(oTast.sKey, m_sConnectionString), Utils.MySqlEscape(oTast.sFormat, m_sConnectionString), oTast.eStatus.ToString("d"), oTast.nStatusInfo.ToString(), DateTime.UtcNow.ToString(Constants.mc_sDateTimeFormat), Utils.MySqlEscape(oTast.sTitle, m_sConnectionString));
|
||||||
|
}
|
||||||
|
private string GetUPDATEString(string sKey, TaskResultDataToUpdate oTast)
|
||||||
|
{
|
||||||
|
List<string> aValues = new List<string>();
|
||||||
|
TaskResultDataToUpdateToArray(aValues, oTast, true);
|
||||||
|
return string.Format("UPDATE tast_result SET {0} WHERE tr_key='{1}';", string.Join(",", aValues.ToArray()), Utils.MySqlEscape(sKey, m_sConnectionString));
|
||||||
|
}
|
||||||
|
private string GetUPDATEIFString(string sKey, TaskResultDataToUpdate oMask, TaskResultDataToUpdate oTast)
|
||||||
|
{
|
||||||
|
List<string> aValues = new List<string>();
|
||||||
|
TaskResultDataToUpdateToArray(aValues, oTast, true);
|
||||||
|
|
||||||
|
List<string> aWheres = new List<string>();
|
||||||
|
aWheres.Add("tr_key='" + Utils.MySqlEscape(sKey, m_sConnectionString) + "'");
|
||||||
|
TaskResultDataToUpdateToArray(aWheres, oMask, false);
|
||||||
|
|
||||||
|
return string.Format("UPDATE tast_result SET {0} WHERE {1};", string.Join(",", aValues.ToArray()), string.Join(" AND ", aWheres.ToArray()));
|
||||||
|
}
|
||||||
|
private string GetSELECTString(string sKey)
|
||||||
|
{
|
||||||
|
return string.Format("SELECT * FROM tast_result WHERE tr_key='{0}';", Utils.MySqlEscape(sKey, m_sConnectionString));
|
||||||
|
}
|
||||||
|
private string GetSELECTString(string[] aKeys)
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int i = 0, length = aKeys.Length; i < length; ++i)
|
||||||
|
{
|
||||||
|
if(0 == i)
|
||||||
|
sb.AppendFormat("'{0}'", Utils.MySqlEscape(aKeys[i], m_sConnectionString));
|
||||||
|
else
|
||||||
|
sb.AppendFormat(",'{0}'", Utils.MySqlEscape(aKeys[i], m_sConnectionString));
|
||||||
|
}
|
||||||
|
return string.Format("SELECT * FROM tast_result WHERE tr_key IN({0});", sb.ToString());
|
||||||
|
}
|
||||||
|
private string GetSELECTEditingString()
|
||||||
|
{
|
||||||
|
return string.Format("SELECT * FROM tast_result WHERE tr_editing='{0}' OR tr_status='{1}';", FileStatus.Ok, FileStatus.UpdateVersion);
|
||||||
|
}
|
||||||
|
private string GetDELETEString(string sKey)
|
||||||
|
{
|
||||||
|
return string.Format("DELETE FROM tast_result WHERE tr_key='{0}';", Utils.MySqlEscape(sKey, m_sConnectionString));
|
||||||
|
}
|
||||||
|
private string GetSELECTExpiredTasksString(int nMaxCount)
|
||||||
|
{
|
||||||
|
DateTime oDateTimeExpired = DateTime.UtcNow - TimeSpan.Parse(ConfigurationManager.AppSettings["utils.taskresult.ttl"] ?? "7.00:00:00");
|
||||||
|
string strDateTimeExpired = oDateTimeExpired.ToString(Constants.mc_sDateTimeFormat);
|
||||||
|
return string.Format("SELECT * FROM tast_result WHERE tr_last_open_date <= '{0}' AND tr_key NOT IN (SELECT dp_key FROM doc_pucker) LIMIT {1};",
|
||||||
|
strDateTimeExpired, nMaxCount);
|
||||||
|
}
|
||||||
|
private void TaskResultDataToUpdateToArray(List<string> aValues, TaskResultDataToUpdate oTask, bool bUpdateTime)
|
||||||
|
{
|
||||||
|
if (false == string.IsNullOrEmpty(oTask.sFormat))
|
||||||
|
aValues.Add("tr_format='" + Utils.MySqlEscape(oTask.sFormat, m_sConnectionString) + "'");
|
||||||
|
if (oTask.eStatus.HasValue)
|
||||||
|
aValues.Add("tr_status='" + oTask.eStatus.Value.ToString("d") + "'");
|
||||||
|
if (oTask.nStatusInfo.HasValue)
|
||||||
|
aValues.Add("tr_status_info='" + oTask.nStatusInfo.Value.ToString() + "'");
|
||||||
|
if(bUpdateTime)
|
||||||
|
aValues.Add("tr_last_open_date='" + DateTime.UtcNow.ToString(Constants.mc_sDateTimeFormat) + "'");
|
||||||
|
if (false == string.IsNullOrEmpty(oTask.sTitle))
|
||||||
|
aValues.Add("tr_title='" + Utils.MySqlEscape(oTask.sTitle, m_sConnectionString) + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
41
ServerComponents/FileConverterUtils2/TrackingInfo.cs
Normal file
41
ServerComponents/FileConverterUtils2/TrackingInfo.cs
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
|
namespace FileConverterUtils2
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
275
ServerComponents/FileConverterUtils2/VariousUtils.cs
Normal file
275
ServerComponents/FileConverterUtils2/VariousUtils.cs
Normal file
|
@ -0,0 +1,275 @@
|
||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2015
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
|
||||||
|
* EU, LV-1021.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Data;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Caching;
|
||||||
|
using System.Web.Script.Serialization;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
|
using ASC.Common.Data;
|
||||||
|
|
||||||
|
namespace FileConverterUtils2
|
||||||
|
{
|
||||||
|
public class FileStatistic
|
||||||
|
{
|
||||||
|
private string m_sConnectionString = ConfigurationManager.AppSettings["utils.filestatistic.db.connectionstring"];
|
||||||
|
private IDbConnection GetDbConnection(string connectionStringName)
|
||||||
|
{
|
||||||
|
var cs = ConfigurationManager.ConnectionStrings[connectionStringName];
|
||||||
|
var dbProvider = System.Data.Common.DbProviderFactories.GetFactory(cs.ProviderName);
|
||||||
|
var connection = dbProvider.CreateConnection();
|
||||||
|
connection.ConnectionString = cs.ConnectionString;
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
private DbManager GetDbManager(string connectionStringName)
|
||||||
|
{
|
||||||
|
var cs = ConfigurationManager.ConnectionStrings[connectionStringName];
|
||||||
|
if (!DbRegistry.IsDatabaseRegistered(connectionStringName))
|
||||||
|
{
|
||||||
|
DbRegistry.RegisterDatabase(connectionStringName, cs);
|
||||||
|
}
|
||||||
|
return new DbManager(connectionStringName);
|
||||||
|
|
||||||
|
}
|
||||||
|
public bool insert(string sAffiliateID, string sFileName, DateTime dtTime, string sTag)
|
||||||
|
{
|
||||||
|
|
||||||
|
bool bResult = true;
|
||||||
|
string sInsertSQL = string.Format("INSERT INTO file_statistic2 (fsc_affiliate, fsc_filename, fsc_time, fsc_tag) VALUES ('{0}', '{1}', '{2}', '{3}')",
|
||||||
|
sAffiliateID, Utils.MySqlEscape(sFileName, m_sConnectionString), dtTime.ToString(Constants.mc_sDateTimeFormat), sTag);
|
||||||
|
|
||||||
|
using (IDbConnection sqlCon = GetDbConnection(m_sConnectionString))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sqlCon.Open();
|
||||||
|
|
||||||
|
using (IDbCommand oInsertCommand = sqlCon.CreateCommand())
|
||||||
|
{
|
||||||
|
oInsertCommand.CommandText = sInsertSQL;
|
||||||
|
oInsertCommand.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
bResult = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bResult;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Signature
|
||||||
|
{
|
||||||
|
private const double mc_dKeyDateEpsilon = 300;
|
||||||
|
|
||||||
|
public static string Create<T>(T obj, string secret)
|
||||||
|
{
|
||||||
|
var serializer = new JavaScriptSerializer();
|
||||||
|
var str = serializer.Serialize(obj);
|
||||||
|
var payload = GetHashBase64(str + secret) + "?" + str;
|
||||||
|
return HttpServerUtility.UrlTokenEncode(Encoding.UTF8.GetBytes(payload));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetHashBase64(string str)
|
||||||
|
{
|
||||||
|
return Convert.ToBase64String(SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(str)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetHashBase64MD5(string str)
|
||||||
|
{
|
||||||
|
return Convert.ToBase64String(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(str)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static T Read<T>(string signature, string secret, bool bUseSecret)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var payloadParts = Encoding.UTF8.GetString(HttpServerUtility.UrlTokenDecode(signature)).Split('?');
|
||||||
|
if (false == bUseSecret || (GetHashBase64(payloadParts[1] + secret) == payloadParts[0]) || (GetHashBase64MD5(payloadParts[1] + secret) == payloadParts[0]))
|
||||||
|
{
|
||||||
|
|
||||||
|
return new JavaScriptSerializer().Deserialize<T>(payloadParts[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
return default(T);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ErrorTypes isAccept(string strVKey, string strCurrentKey, bool bCheckIP, string strCurrentIp)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string strKeyId = null;
|
||||||
|
System.Collections.Generic.Dictionary<string, object> arrElements = null;
|
||||||
|
ASC.Core.Billing.PaymentOffice oPaymentOffice = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
getVKeyStringParam(strVKey, ConfigurationSettings.AppSettings["keyKeyID"], out strKeyId);
|
||||||
|
|
||||||
|
oPaymentOffice = getPaymentOffice(strKeyId);
|
||||||
|
var vElement = Read<object>(strVKey, oPaymentOffice.Key2, true);
|
||||||
|
if (null == vElement)
|
||||||
|
return ErrorTypes.VKeyEncrypt;
|
||||||
|
arrElements = (System.Collections.Generic.Dictionary<string, object>)vElement;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return ErrorTypes.VKeyEncrypt;
|
||||||
|
}
|
||||||
|
object objValue = null;
|
||||||
|
|
||||||
|
DateTime oDateTimeNow = DateTime.UtcNow;
|
||||||
|
|
||||||
|
if (false == ( (oDateTimeNow - oPaymentOffice.EndDate).TotalSeconds < mc_dKeyDateEpsilon))
|
||||||
|
return ErrorTypes.VKeyKeyExpire;
|
||||||
|
|
||||||
|
int nUserCount = 0;
|
||||||
|
|
||||||
|
arrElements.TryGetValue(ConfigurationSettings.AppSettings["keyUserCount"], out objValue);
|
||||||
|
|
||||||
|
if (null != objValue)
|
||||||
|
nUserCount = (int)objValue;
|
||||||
|
|
||||||
|
if (nUserCount > oPaymentOffice.UsersCount)
|
||||||
|
return ErrorTypes.VKeyUserCountExceed;
|
||||||
|
|
||||||
|
if (bCheckIP)
|
||||||
|
{
|
||||||
|
arrElements.TryGetValue(ConfigurationSettings.AppSettings["keyIp"], out objValue);
|
||||||
|
if (null == objValue)
|
||||||
|
return ErrorTypes.VKey;
|
||||||
|
string strUserIp = (string)objValue;
|
||||||
|
if (strCurrentIp != strUserIp)
|
||||||
|
return ErrorTypes.VKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
arrElements.TryGetValue(ConfigurationSettings.AppSettings["keyKey"], out objValue);
|
||||||
|
if (null == objValue)
|
||||||
|
return ErrorTypes.VKey;
|
||||||
|
string strKey = (string)objValue;
|
||||||
|
|
||||||
|
if (strCurrentKey.Length > strKey.Length)
|
||||||
|
{
|
||||||
|
int nIndexStartFormat = strCurrentKey.LastIndexOf(".");
|
||||||
|
if (-1 != nIndexStartFormat)
|
||||||
|
strCurrentKey = strCurrentKey.Substring(0, nIndexStartFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strKey != strCurrentKey && strKey + "_temp" != strCurrentKey)
|
||||||
|
return ErrorTypes.VKey;
|
||||||
|
|
||||||
|
arrElements.TryGetValue(ConfigurationSettings.AppSettings["keyDate"], out objValue);
|
||||||
|
if (null != objValue)
|
||||||
|
{
|
||||||
|
DateTime oDateTimeKey = (DateTime)objValue;
|
||||||
|
DateTime oDateTimeKeyAddHour = oDateTimeKey;
|
||||||
|
oDateTimeKeyAddHour = oDateTimeKeyAddHour.AddHours(double.Parse(ConfigurationSettings.AppSettings["keyDateInterval"] ?? "1", Constants.mc_oCultureInfo));
|
||||||
|
|
||||||
|
if ((oDateTimeKey - oDateTimeNow).TotalSeconds > mc_dKeyDateEpsilon)
|
||||||
|
return ErrorTypes.VKeyTimeIncorrect;
|
||||||
|
|
||||||
|
if( mc_dKeyDateEpsilon < (oDateTimeNow - oDateTimeKeyAddHour).TotalSeconds)
|
||||||
|
return ErrorTypes.VKeyTimeExpire;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { return ErrorTypes.VKey; }
|
||||||
|
return ErrorTypes.NoError;
|
||||||
|
}
|
||||||
|
public static void getVKeyParams(string strVKey, out bool bPaid)
|
||||||
|
{
|
||||||
|
bPaid = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string strKeyId = null;
|
||||||
|
getVKeyStringParam(strVKey, ConfigurationSettings.AppSettings["keyKeyID"], out strKeyId);
|
||||||
|
|
||||||
|
ASC.Core.Billing.PaymentOffice oPaymentOffice = getPaymentOffice(strKeyId);
|
||||||
|
|
||||||
|
var vElement = Read<object>(strVKey, oPaymentOffice.Key2, true);
|
||||||
|
if (null == vElement)
|
||||||
|
return;
|
||||||
|
System.Collections.Generic.Dictionary<string, object> arrElements = (System.Collections.Generic.Dictionary<string, object>)vElement;
|
||||||
|
object objValue = null;
|
||||||
|
arrElements.TryGetValue(ConfigurationSettings.AppSettings["keyPaid"], out objValue);
|
||||||
|
if (null == objValue)
|
||||||
|
return;
|
||||||
|
bPaid = (bool)objValue;
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
public static void getVKeyStringParam(string strVKey, string strParamName, out string strParam)
|
||||||
|
{
|
||||||
|
strParam = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var vElement = Read<object>(strVKey, null, false);
|
||||||
|
if (null == vElement)
|
||||||
|
return;
|
||||||
|
System.Collections.Generic.Dictionary<string, object> arrElements = (System.Collections.Generic.Dictionary<string, object>)vElement;
|
||||||
|
object objValue = null;
|
||||||
|
arrElements.TryGetValue(strParamName, out objValue);
|
||||||
|
if (null == objValue)
|
||||||
|
return;
|
||||||
|
strParam = (string)objValue;
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ASC.Core.Billing.PaymentOffice getPaymentOffice(string strKeyId)
|
||||||
|
{
|
||||||
|
ASC.Core.Billing.PaymentOffice oPaymentOffice = null;
|
||||||
|
Cache oCache = HttpRuntime.Cache;
|
||||||
|
object oCacheVal = oCache.Get(strKeyId);
|
||||||
|
if (null == oCacheVal)
|
||||||
|
{
|
||||||
|
ASC.Core.Billing.BillingClient oBillingClient = new ASC.Core.Billing.BillingClient();
|
||||||
|
oPaymentOffice = oBillingClient.GetPaymentOffice(strKeyId);
|
||||||
|
string sWebCacheExpireSeconds = ConfigurationSettings.AppSettings["WebCacheExpireSeconds"];
|
||||||
|
oCache.Add(strKeyId, oPaymentOffice, null, DateTime.Now.AddSeconds(int.Parse(sWebCacheExpireSeconds)), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
oPaymentOffice = oCacheVal as ASC.Core.Billing.PaymentOffice;
|
||||||
|
return oPaymentOffice;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue