Exemplo n.º 1
0
 public CodeGeneratorVisitor(ProgramAnalysis analysis, TextWriter outputStream) : base(analysis)
 {
     Out = outputStream;
     WhileLabelGenerator             = new LabelGenerator("While");
     ElseLabelGenerator              = new LabelGenerator("Else");
     BooleanExpressionLabelGenerator = new LabelGenerator("BooleanExpression");
 }
Exemplo n.º 2
0
        public void MapEnumToLabelValues_will_generate_labels_with_snake_cased_names()
        {
            var labels = LabelGenerator.MapEnumToLabelValues <DotNetRuntimeEventSource.GCReason>();

            Assert.That(labels[DotNetRuntimeEventSource.GCReason.AllocLarge], Is.EqualTo("alloc_large"));
            Assert.That(labels[DotNetRuntimeEventSource.GCReason.OutOfSpaceLOH], Is.EqualTo("out_of_space_loh"));
        }
Exemplo n.º 3
0
 public CodeGeneratorVisitor(ProgramAnalysis analysis, TextWriter outputStream)
     : base(analysis)
 {
     Out = outputStream;
     WhileLabelGenerator = new LabelGenerator("While");
     ElseLabelGenerator = new LabelGenerator("Else");
     BooleanExpressionLabelGenerator = new LabelGenerator("BooleanExpression");
 }
 bool GetVisibility(LabelGenerator labelGenerator)
 {
     try
     {
         return strategy.GetVisibility();
     }
     catch
     {
         return false;
     }
 }
 bool GetVisibility(LabelGenerator labelGenerator)
 {
     try
     {
         return(strategy.GetVisibility());
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 6
0
    void Update() // Update is called once per frame
    {
        loaded = arrowObj.activeSelf ? false : true;

        category = GetCategory();

        if (movementVector.magnitude > 0)
        {
            orientation = new Vector3(arrowOffset * movementVector.x, arrowOffset * movementVector.y, -1);
            label       = LabelGenerator.GetLabel(orientation);
        }
        spriteResolver.SetCategoryAndLabel(category, label);
    }
Exemplo n.º 7
0
        public void GenerateBarcodeTest(string appName, int quantity, bool callFunc, bool generateFlag)
        {
            byte[] bytes = CreateDummyBitmap();

            var mockedConverter = new Mock <IHtmlConverter>();

            mockedConverter.Setup(p => p.FromHtmlString(It.IsAny <string>())).Returns(bytes);

            LabelGenerator generator = new LabelGenerator();

            generator.SetHtmlConverter(mockedConverter.Object);

            generatedCount = 0;

            BarcodeGeneratorApplication app = (BarcodeGeneratorApplication)FactoryConsoleApplication.CreateConsoleApplicationObject(appName);

            app.SetLabelGnerator(generator);
            app.SetFilePerFolder(10);
            app.SetProgressPerImage(2);
            if (callFunc)
            {
                app.SetUpdateProgressFunc(BarcodeGenerateProgressUpdate);
            }

            OptionSet opt = app.CreateOptionSet();

            opt.Parse(args);

            //Update the same key if already exist
            app.AddArgument("outpath", Path.GetTempPath());
            app.AddArgument("quantity", quantity.ToString());

            imgGenerateFlag = false;
            if (generateFlag)
            {
                imgGenerateFlag = true;
                app.AddArgument("generate", "Y");
            }

            INoSqlContext ctx = new Mock <INoSqlContext>().Object;

            app.SetNoSqlContext(ctx);

            app.Run();

            if (callFunc)
            {
                Assert.AreEqual(quantity, generatedCount, "Generated file count is wrong!!!");
            }
        }
Exemplo n.º 8
0
 public void SetMovement(Vector2 newMovement) // set the arrow's movement
 {
     movement = newMovement;
     spriteResolver.SetCategoryAndLabel("arrow", LabelGenerator.GetLabel(movement));
 }
Exemplo n.º 9
0
        public Models.GenerateLabelResponse GenerateLabel(Models.GenerateLabelRequest request)
        {
            try
            {
                // lets authenticate the user and make sure we have their config details
                Classes.AuthorizationConfig auth = Classes.AuthorizationConfig.Load(request.AuthorizationToken);
                if (auth == null)
                {
                    return(new Models.GenerateLabelResponse("Authorization failed for token " + request.AuthorizationToken));
                }

                // load all the services we have (either for this user specifically or all services)
                List <Classes.CourierService> services = Services.GetServices;

                //linnworks will send the serviceId as defined in list of services, we will need to find the service by id
                Classes.CourierService selectedService = services.Find(s => s.ServiceUniqueId == request.ServiceId);
                if (selectedService == null)
                {
                    throw new Exception("Service Id " + request.ServiceId.ToString() + " is not available");
                }

                // get the service code
                string serviceCode = selectedService.ServiceCode;
                //and some other information, whatever we need
                string VendorCode = selectedService.ServiceGroup;

                //create response class, we will be adding packages to it
                Models.GenerateLabelResponse response = new Models.GenerateLabelResponse();


                /* If you need to do any validation of services or consignment data, do it before you generate labels and simply throw an error
                 * on the whole request
                 */

                foreach (var package in request.Packages)   // we need to generate a label for each package in the consignment
                {
                    // an order may have extended property bound to it, here we can pass any specific parameter we need
                    // in this specific example we will be taking SafePlace extended property of the order and outputting it on the label
                    string safePlace1 = "";
                    if (request.OrderExtendedProperties.Find(s => s.Name == "SafePlace1") != null)
                    {
                        safePlace1 = request.OrderExtendedProperties.Find(s => s.Name == "SafePlace1").Value;
                    }

                    //generate new tracking number
                    string newTrackingNumber = request.CountryCode + " " + Guid.NewGuid().ToString().Substring(0, 8).ToUpper();

                    // each consignment must have lead tracking number. In case of multiple packages this will be the main tracking number which allows us to track the whole shipment by one tracking number. When the courier doesn't support this simply allocate the first package tracking number as a lead tracking number
                    if (response.LeadTrackingNumber == "")
                    {
                        response.LeadTrackingNumber = newTrackingNumber;
                    }

                    // we now need to add packages back into response, one item per package which contains label and any associated documentation
                    response.Package.Add(new Models.PackageResponse()
                    {
                        LabelHeight                 = 6,                                                                                                                                                                                                         // label height in inches
                        LabelWidth                  = 4,                                                                                                                                                                                                         // label width in inches
                        PNGLabelDataBase64          = Convert.ToBase64String(imageToByteArray(LabelGenerator.GenerateLabel(request.ServiceConfigItems, safePlace1, serviceCode, request.OrderReference, newTrackingNumber, CodeHelper.FormatAddress(request)))), // generate the label image, get its bytes and convert bytes to Base64 string
                        SequenceNumber              = package.SequenceNumber,                                                                                                                                                                                    //VERY IMPORTANT TO PRESERVE Sequence number for each package!!!!
                        PDFBytesDocumentationBase64 = new string[] { },                                                                                                                                                                                          // here we can add any additional documentation, such as customs forms, declarations etc. PDF files converted to Base64 string
                        TrackingNumber              = newTrackingNumber                                                                                                                                                                                          // package tracking number
                    });

                    /* Here you can also save the consignment data and associate package/label information in some sort of database
                     * if you need to have manifestation or label cancelation reference numbers associated with orderReferences or Order Ids in linnworks
                     */
                }



                return(response);
            }
            catch (Exception ex) {
                return(new Models.GenerateLabelResponse("Unhandled error " + ex.Message));
            }
        }
 public void SetLabelGnerator(LabelGenerator labelGenerator)
 {
     generator = labelGenerator;
 }