Пример #1
0
    def encode_job(self, job):
        random_bytes = Array.CreateInstance(Byte, 2)
        Random().NextBytes(random_bytes)

        data = Encoding.UTF8.GetBytes(JavaScriptSerializer().Serialize(job))
        with MemoryStream(data.Length) as initialStream:
            initialStream.Write(data, 0, data.Length)
            initialStream.Seek(0, SeekOrigin.Begin)
            with MemoryStream() as resultStream:
                with GZipStream(resultStream,
                                CompressionMode.Compress) as zipStream:
                    buffer = Array.CreateInstance(Byte, 4096)
                    bytesRead = initialStream.Read(buffer, 0, buffer.Length)
                    zipStream.Write(buffer, 0, bytesRead)
                    while bytesRead != 0:
                        bytesRead = initialStream.Read(buffer, 0,
                                                       buffer.Length)
                        zipStream.Write(buffer, 0, bytesRead)

                result = resultStream.ToArray()
                result[:2] = random_bytes
                return {
                    Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Substring(
                        0, 8):
                    Convert.ToBase64String(Guid.NewGuid().ToByteArray()),
                    "data":
                    Convert.ToBase64String(result)
                }
Пример #2
0
def setEntryBySrcEntry():
    ''' 由源单明细表体写入明细表体
	'''
    srcEntry = this.View.Model.DataObject["RECEIVEBILLSRCENTRY"]

    entry = this.View.Model.DataObject["RECEIVEBILLENTRY"]
    rowNum = this.View.Model.GetEntryRowCount("FRECEIVEBILLENTRY")
    if rowNum > 0:
        if (str(entry[rowNum - 1]["RECTOTALAMOUNTFOR"]) == "0"
                and str(entry[rowNum - 1]["RECAMOUNTFOR_E"]) == "0"
                and str(entry[rowNum - 1]["SETTLERECAMOUNTFOR"]) == "0"):
            this.View.Model.DeleteEntryRow("FRECEIVEBILLENTRY", rowNum - 1)
    for idx, row in enumerate(srcEntry):
        srcBillType = str(row["SRCBILLTYPEID"])
        if srcBillType == "ora_CZ_ReceiptSplit":
            guid = str(Guid.NewGuid())
            amount = str(row["REALRECAMOUNT"])  #本次收款金额
            this.View.Model.CreateNewEntryRow("FRECEIVEBILLENTRY")
            i = this.View.Model.GetEntryRowCount("FRECEIVEBILLENTRY") - 1
            this.View.Model.SetValue("FRECTOTALAMOUNTFOR", amount, i)  #应收金额
            this.View.Model.SetValue("FRECAMOUNTFOR_E", amount, i)  #收款金额
            this.View.Model.SetValue("FSETTLERECAMOUNTFOR", amount, i)  #折后金额
            this.View.Model.SetValue("F_ora_ReGuid", guid, i)  #明细表体
            this.View.Model.SetValue("F_ora_RseGuid", guid, idx)  #源单明细表体

    this.View.UpdateView("FRECEIVEBILLENTRY")
Пример #3
0
def test_struct_constructor():
    """Test struct constructor args"""
    from System import Guid
    from Python.Test import StructConstructorTest

    guid = Guid.NewGuid()
    ob = StructConstructorTest(guid)
    assert ob.value == guid
Пример #4
0
    def testStructConstructor(self):
        """Test struct constructor args"""
        from System import Guid
        from Python.Test import StructConstructorTest

        guid = Guid.NewGuid()
        ob = StructConstructorTest(guid)
        self.assertTrue(ob.value == guid)
Пример #5
0
    def testMethodCallStructConversion(self):
        """Test struct conversion in method call."""
        from System import Guid

        object = MethodTest()
        guid = Guid.NewGuid()
        temp = guid.ToString()
        r = object.TestStructConversion(guid)
        self.assertTrue(r.ToString() == temp)
Пример #6
0
def test_method_call_struct_conversion():
    """Test struct conversion in method call."""
    from System import Guid

    ob = MethodTest()
    guid = Guid.NewGuid()
    temp = guid.ToString()
    r = ob.TestStructConversion(guid)
    assert r.ToString() == temp
Пример #7
0
def randtest(doc):
    #生成1w个测试点
    with dbtrans(doc) as tr:
        btr = tr.opencurrspace()
        from System import Guid, Random
        r = Random(Guid.NewGuid().GetHashCode())
        for i in range(10000):
            tr.addentity(
                btr,
                acdb.DBPoint(acge.Point3d(r.Next(0, 1000), r.Next(0, 1000),
                                          0)))
Пример #8
0
    def __init__(self, name, ptype, group="pypevitmep", guid=None,
                 description="", modifiable=True, visible=True, new=True):
        # type: (str, ParameterType or str, str, Guid or None, str, bool, bool, bool) -> None

        self.name = name
        self.description = description
        self.group = group

        true_tuple = (True, "", None, "True", "Yes", "Oui", 1)

        if modifiable in true_tuple:
            self.modifiable = True
        else:
            self.modifiable = False

        if visible in true_tuple:
            self.visible = True
        else:
            self.visible = False

        # Check if a Guid is given. If not a new one is created
        if not guid:
            self.guid = Guid.NewGuid()
        else:
            self.guid = guid
        # Check if given parameter type is valid. If not user is prompted to choose one.
        if isinstance(ptype, ParameterType):
            self.type = ptype
        else:
            try:
                self.type = getattr(ParameterType, ptype)
            except AttributeError:
                selected_type = rpw.ui.forms.SelectFromList(
                    "Select ParameterType",
                    ParameterType.GetNames(ParameterType),
                    "Parameter {} ParameterType: {} is not valid. Please select a parameter type".format(name, ptype),
                    sort=False)
                self.type = getattr(ParameterType, selected_type)

        self.initial_values = {}
        if new is True:
            self.new = new
        else:
            self.new = False
            self.initial_values_update()

        self.changed = False
Пример #9
0
    def createCodes(self):
        try:
            guid = Guid.NewGuid().ToString('N')         # global unique ID

            # get configuration from web.config
            codeSource         = WebConfigurationManager.AppSettings['CodeGenQueue']
            lengthCaptchaStrng = int(WebConfigurationManager.AppSettings['captchaStrngLngth'])

            # create captcha code
            captcha = ''
            for a in range(lengthCaptchaStrng):
                apd = random.choice(codeSource)
                captcha += apd

            # save to session cache
            self.usrDt.addNewItem('GUID', guid)
            self.usrDt.addNewItem('CAPTCHA', captcha)

            return guid
        except Exception,e:
            self.log.w2lgError(traceback.format_exc())
Пример #10
0
from System import Guid

g = Guid.NewGuid()
print("Hello! Your Python-made GUID is: {}".format(g))


def new_guid():
    return Guid.NewGuid()
Пример #11
0
def guid(gid = None):
    from System import Guid
    return gid and Guid(gid) or Guid.NewGuid()
Пример #12
0
def test_negative():
    AssertError(ValueError, clr.LoadTypeLibrary, "DlrComLibrary.DlrComServer")
    AssertError(ValueError, clr.LoadTypeLibrary, 42)

    AssertError(EnvironmentError, clr.LoadTypeLibrary, Guid.NewGuid())
Пример #13
0
try:
    assert DEBUG
    clr.AddReference(IronPythonDLL)
except NameError:
    DEBUG = True
    print "Set DEBUG: {}".format(DEBUG)
    try:
        import traceback
    except ImportError:
        print "[!] Error importing traceback module, full tracebacks will not be displayed"
    clr.AddReference("IronPython")

try:
    assert GUID
except NameError:
    GUID = Guid.NewGuid().ToString()
    print "Created GUID: {}".format(GUID)

try:
    assert URL
except NameError:
    URL = Uri(Uri("https://172.16.164.1:5000/"), GUID)
    print "Set URL: {}\n".format(URL)

clr.AddReference("System.Management")
clr.AddReference("System.Web.Extensions")
clr.AddReference("Microsoft.VisualBasic")
clr.AddReference("Boo.Lang.Interpreter")
from System.Text import Encoding
from System.Management import ManagementObject
from System.Diagnostics import Process
Пример #14
0
def new_uuid():
    """Create a new UUID (using dotnet Guid.NewGuid)"""
    # RE: https://github.com/eirannejad/pyRevit/issues/413
    # return uuid.uuid1()
    return str(Guid.NewGuid())
Пример #15
0
 def gen_random_string(self, length=8):
     return Guid.NewGuid().ToString("n").Substring(0, length)
PINVOKE_METHOD_ATTRIBUTES = (Refl.MethodAttributes.Public
                             | Refl.MethodAttributes.Static
                             | Refl.MethodAttributes.HideBySig
                             | Refl.MethodAttributes.PinvokeImpl)

PUBLIC_STATIC_BINDING_FLAGS = Refl.BindingFlags.Static | Refl.BindingFlags.Public

WIN_API_CALLING_CONVENTION = Interop.CallingConvention.StdCall

assemblyBuilder = (Emit.AssemblyBuilder.DefineDynamicAssembly(
    Refl.AssemblyName(WIN32_PINVOKE_DYNAMIC_ASSEMBLY_NAME),
    Emit.AssemblyBuilderAccess.Run))

MODULE_BUILDER = assemblyBuilder.DefineDynamicModule("WIN_API_MODULE_" +
                                                     Guid.NewGuid().ToString())


def GetWinApiFunctionImpl(functionName, moduleName, charSet, returnType,
                          *parameterTypes):
    tbuilder = MODULE_BUILDER.DefineType("WIN_API_TYPE" + "_" + moduleName +
                                         "_" + functionName)
    mbuilder = tbuilder.DefinePInvokeMethod(
        functionName, moduleName, PINVOKE_METHOD_ATTRIBUTES,
        Refl.CallingConventions.Standard, clr.GetClrType(returnType),
        [clr.GetClrType(t) for t in parameterTypes].ToArray[System.Type](),
        WIN_API_CALLING_CONVENTION, charSet)
    mbuilder.SetImplementationFlags(mbuilder.MethodImplementationFlags
                                    | Refl.MethodImplAttributes.PreserveSig)
    winApiType = tbuilder.CreateType()
    methodInfo = winApiType.GetMethod(functionName,
Пример #17
0
        Refl.MethodAttributes.HideBySig |
        Refl.MethodAttributes.PinvokeImpl
    )

PUBLIC_STATIC_BINDING_FLAGS = Refl.BindingFlags.Static | Refl.BindingFlags.Public

WIN_API_CALLING_CONVENTION = Interop.CallingConvention.StdCall

assemblyBuilder = (
    Emit.AssemblyBuilder.DefineDynamicAssembly(
        Refl.AssemblyName(WIN32_PINVOKE_DYNAMIC_ASSEMBLY_NAME),
        Emit.AssemblyBuilderAccess.Run
      )
  )

MODULE_BUILDER = assemblyBuilder.DefineDynamicModule("WIN_API_MODULE_" + Guid.NewGuid().ToString())

def GetWinApiFunctionImpl(
        functionName,
        moduleName,
        charSet,
        returnType,
        *parameterTypes
    ):
    tbuilder = MODULE_BUILDER.DefineType("WIN_API_TYPE" + "_" + moduleName + "_" + functionName)
    mbuilder = tbuilder.DefinePInvokeMethod(
            functionName,
            moduleName,
            PINVOKE_METHOD_ATTRIBUTES,
            Refl.CallingConventions.Standard,
            clr.GetClrType(returnType),
Пример #18
0
    def __init__(self,
                 name,
                 ptype,
                 group=None,
                 guid=None,
                 description="",
                 modifiable=True,
                 visible=True,
                 new=True):
        # type: (str, ParameterType or str, str, Guid or None, str, bool, bool, bool) -> None

        self.name = name
        self.description = description
        if group:
            self.group = group
        else:
            self.group = "pyrevitmep"

        true_tuple = (True, "", None, "True", "Yes", "Oui", 1, "1")

        if modifiable in true_tuple:
            self.modifiable = True
        else:
            self.modifiable = False

        if visible in true_tuple:
            self.visible = True
        else:
            self.visible = False

        # Check if a Guid is given. If not a new one is created
        if not guid:
            self.guid = Guid.NewGuid()
        elif not isinstance(guid, Guid):
            try:
                self.guid = Guid(guid)
            except SystemError:
                self.guid = Guid.NewGuid()
        else:
            self.guid = guid

        # Check if given parameter type is valid. If not user is prompted to choose one.
        if isinstance(ptype, ParameterType):
            self.type = ptype
        else:
            try:
                self.type = getattr(ParameterType, ptype)
            except AttributeError:
                self.type = ptype
                while not isinstance(self.type, ParameterType):
                    self.type = SelectFromList.show(
                        PType.enum_generator(),
                        "Parameter {} ParameterType: {} not valid. Please select a parameter type"
                        .format(name, ptype))

        self.initial_values = {}
        if new is True:
            self.new = new
        else:
            self.new = False
            self.initial_values_update()

        self.changed = False
Пример #19
0
 def __init__(self, _center, _radius):
     self.center = _center
     self.radius = _radius
     self.guid = guid.NewGuid()
Пример #20
0
def new_guid():
    return Guid.NewGuid()
Пример #21
0
def new_uuid():
    # RE: https://github.com/eirannejad/pyRevit/issues/413
    # return uuid.uuid1()
    return str(Guid.NewGuid())
Пример #22
0
 def __init__(self, center, radius):
     self.__center = center
     self.__radius = radius
     self.__guid = guid.NewGuid()