Example #1
0
        public void valid(string id)
        {
            var tid = new TerminalId(id);

            Assert.Equal(int.Parse(id), tid.Value);
            Assert.Equal(id, tid.ToString());
        }
Example #2
0
 /// <ToBeCompleted></ToBeCompleted>
 public void LoadInnerObjects(string propertyName, IRepositoryReader reader, int version)
 {
     if (propertyName == null)
     {
         throw new ArgumentNullException("propertyName");
     }
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     if (propertyName == "ConnectionPointMappings")
     {
         // load ConnectionPoint mappings
         reader.BeginReadInnerObjects();
         while (reader.BeginReadInnerObject())
         {
             ControlPointId connectionPointId = reader.ReadInt32();
             TerminalId     terminalId        = reader.ReadInt32();
             // The following is the essence of MapTerminal without the checks.
             if (connectionPointMappings.ContainsKey(connectionPointId))
             {
                 connectionPointMappings[connectionPointId] = terminalId;
             }
             else
             {
                 connectionPointMappings.Add(connectionPointId, terminalId);
             }
             reader.EndReadInnerObject();
         }
         reader.EndReadInnerObjects();
     }
 }
 /// <summary>
 /// Validates this request as much as possible prior to sending it to the Zip API.
 /// </summary>
 /// <exception cref="System.ArgumentNullException">Thrown if any required properties are null.</exception>
 /// <exception cref="System.ArgumentException">Thrown if any of request properties are invalid.</exception>
 public override void Validate()
 {
     MerchantRefundReference.GuardNullOrWhiteSpace(nameof(MerchantRefundReference));
     OrderId.GuardNullOrWhiteSpace(nameof(OrderId));
     Amount.GuardZeroOrNegative(nameof(Amount));
     Operator.GuardNullOrWhiteSpace(nameof(Operator));
     TerminalId.GuardNullOrWhiteSpace(nameof(TerminalId));
 }
Example #4
0
 /// <ToBeCompleted></ToBeCompleted>
 public TemplateControllerPointMappingChangedEventArgs(Template template, ControlPointId controlPointId,
                                                       TerminalId oldTerminalId, TerminalId newTerminalId)
     : base(template)
 {
     this.controlPointId = controlPointId;
     this.oldTerminalId  = oldTerminalId;
     this.newTerminalId  = newTerminalId;
 }
Example #5
0
 /// <summary>
 /// Validates this request as much as possible prior to sending it to the Zip API.
 /// </summary>
 /// <exception cref="System.ArgumentNullException">Thrown if <see cref="Order"/> or any of it's required sub-properties are null.</exception>
 /// <exception cref="System.ArgumentException">Thrown if any of the sub-properties of <see cref="Order"/> are determined to be invalid.</exception>
 public override void Validate()
 {
     TerminalId.GuardNullOrWhiteSpace(nameof(TerminalId));
     Order.GuardNull(nameof(Order));
     Order.CustomerApprovalCode.GuardNullOrWhiteSpace(nameof(Order), nameof(Order.CustomerApprovalCode));
     Order.MerchantReference.GuardNullOrWhiteSpace(nameof(Order), nameof(Order.MerchantReference));
     Order.Operator.GuardNullOrWhiteSpace(nameof(Order), nameof(Order.Operator));
     Order.PaymentFlow.GuardNullOrWhiteSpace(nameof(Order), nameof(Order.PaymentFlow));
     Order.Amount.GuardZeroOrNegative(nameof(Order), nameof(Order.Amount));
 }
        public static void Initialize(IRegistrar registrar)
        {
            // Register library
            registrar.RegisterLibrary(namespaceName, preferredRepositoryVersion);
            // Register model object types
            TerminalId maxTerminalId = 2;

            registrar.RegisterModelObjectType(new GenericModelObjectType("ValueDevice", namespaceName, categoryTitle,
                                                                         ValueDevice.CreateInstance, ValueDevice.GetPropertyDefinitions, maxTerminalId));
        }
Example #7
0
        /// <summary>
        /// If the template has no Modelobject, this method enables/disables ConnectionPoints of the shape.
        /// If the template has a ModelObject, this method assigns a ModelObject terminal to a ConnectionPoint of the shape
        /// </summary>
        /// <param name="controlPointId">Id of the shape's ControlPoint</param>
        /// <param name="terminalId">Id of the Modelobject's Terminal. Pass -1 in order to clear the mapping.</param>
        public void SetTerminalConnectionPointMapping(ControlPointId controlPointId, TerminalId terminalId)
        {
            TerminalId oldTerminalId = workTemplate.GetMappedTerminalId(controlPointId);

            workTemplate.MapTerminal(terminalId, controlPointId);
            TemplateWasChanged = true;

            if (TemplateShapeControlPointMappingChanged != null)
            {
                controlPointMappingChangedEventArgs.ControlPointId = controlPointId;
                controlPointMappingChangedEventArgs.OldTerminalId  = oldTerminalId;
                controlPointMappingChangedEventArgs.NewTerminalId  = terminalId;
                TemplateShapeControlPointMappingChanged(this, controlPointMappingChangedEventArgs);
            }
        }
Example #8
0
        private void Initialize(int lowerBound, int upperBound, int initial)
        {
            if (initial < lowerBound || initial >= upperBound)
            {
                throw new ArgumentException($"Initial TerminalId {initial} must not be less in range [{lowerBound};{upperBound}[ ");
            }

            LowerBound     = new TerminalId(lowerBound.ToString());
            UpperBound     = new TerminalId(upperBound.ToString());
            History        = new ConcurrentDictionary <int, DateTime>();
            _nextMessageId =
                new MessageId(
                    new TerminalId(initial.ToString()),
                    ConstantSequenceNumber,
                    new CheckNumber(initial % CheckNumber.MaxValue));
        }
Example #9
0
        /// <ToBeCompleted></ToBeCompleted>
        public string GetMappedTerminalName(ControlPointId connectionPointId)
        {
            TerminalId terminalId = GetMappedTerminalId(connectionPointId);

            if (terminalId == TerminalId.Invalid)
            {
                return(null);
            }
            else
            {
                if (shape.ModelObject != null)
                {
                    return(shape.ModelObject.Type.GetTerminalName(terminalId));
                }
                else
                {
                    return(activatedTag);
                }
            }
        }
Example #10
0
 /// <ToBeCompleted></ToBeCompleted>
 public void MapTerminal(TerminalId terminalId, ControlPointId connectionPointId)
 {
     // check if terminalId and connectionPointId are valid values
     if (shape == null)
     {
         throw new InvalidOperationException("Template has no shape.");
     }
     if (!shape.HasControlPointCapability(connectionPointId, ControlPointCapabilities.Glue | ControlPointCapabilities.Connect))
     {
         throw new NShapeException("Control point {0} is not a valid glue- or connection point.", connectionPointId);
     }
     //
     if (connectionPointMappings.ContainsKey(connectionPointId))
     {
         connectionPointMappings[connectionPointId] = terminalId;
     }
     else
     {
         connectionPointMappings.Add(connectionPointId, terminalId);
     }
 }
Example #11
0
 /// <ToBeCompleted></ToBeCompleted>
 public void MapTerminal(TerminalId terminalId, ControlPointId connectionPointId)
 {
     // check if terminalId and connectionPointId are valid values
     if (_shape == null)
     {
         throw new InvalidOperationException(Dataweb.NShape.Properties.Resources.MessageTxt_TemplateHasNoShape);
     }
     if (!_shape.HasControlPointCapability(connectionPointId, ControlPointCapabilities.Glue | ControlPointCapabilities.Connect))
     {
         throw new NShapeException(Dataweb.NShape.Properties.Resources.MessageFmt_ControlPoint0IsNotAValidGlueOrConnectionPoint, connectionPointId);
     }
     //
     if (_connectionPointMappings.ContainsKey(connectionPointId))
     {
         _connectionPointMappings[connectionPointId] = terminalId;
     }
     else
     {
         _connectionPointMappings.Add(connectionPointId, terminalId);
     }
 }
Example #12
0
        public override string ToString()
        {
            StringBuilder result = new StringBuilder();

            // Message type (= Payment request), Length: 4, Fieldtype: AN
            result.Append(StringValueAttribute.GetStringValue(MessageType));
            // Terminal number, Length: 8, Fieldtype: N
            result.Append(TerminalId.ToString(CultureInfo.InvariantCulture).PadLeft(8, '0'));
            // Message version number, Length: 1, Fieldtype: N
            // 0 = No addittional information, 1 = additional information
            result.Append(HasAdditionalInformation ? "1" : "0");
            // Amount, Length: 11, Fieldtype: N
            result.Append(Amount.ToString("#.##", CultureInfo.CurrentCulture).Replace(
                              CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator, "").PadLeft(11, '0'));
            // Product info, Length: 20, Fieldtype: AN (Future use)
            result.Append(new String(' ', 20));
            // Receipt number, Length: 6, Fieldtype: N
            result.Append(ReceiptNumber.ToString(CultureInfo.InvariantCulture).PadLeft(6, '0'));
            // Transaction type, Length: 2, Fieldtype: N
            // 00 = Purchase
            result.Append(StringValueAttribute.GetStringValue(TransactionType));
            // Length of additional information, Length: 3, Fieldtype: N
            result.Append(AdditionalInformation.Length.ToString(CultureInfo.InvariantCulture).PadLeft(3, '0'));
            // Indicator additional information, Length: 2, Fieldtype: N
            // 01 = Currency, 02 = Product information (only for petrol)
            // 03 = Product information (Special terminal)
            result.Append(StringValueAttribute.GetStringValue(AdditionalInformationType));
            // Additional information, Length: variable, Fieldtype: AN
            result.Append(AdditionalInformation);
            // End of text
            result.Append((Char)TwoStepProtocol.EndOfText);
            // LRC Checksum
            result.Append(TerminalRequest.CalculateLongitudinalRedundancyCheck(result.ToString()));
            // Start of text
            result.Insert(0, (Char)TwoStepProtocol.StartOfText);
            return(result.ToString());
        }
Example #13
0
		public void Disconnect(TerminalId ownTerminalId, IModelObject otherModelObject, TerminalId otherTerminalId) {
			throw new NotImplementedException();
		}
Example #14
0
		/// <ToBeCompleted></ToBeCompleted>
		public TemplateControllerPointMappingChangedEventArgs(Template template, ControlPointId controlPointId,
		                                                      TerminalId oldTerminalId, TerminalId newTerminalId)
			: base(template)
		{
			this.controlPointId = controlPointId;
			this.oldTerminalId = oldTerminalId;
			this.newTerminalId = newTerminalId;
		}
Example #15
0
		/// <summary>
		/// If the template has no Modelobject, this method enables/disables ConnectionPoints of the shape.
		/// If the template has a ModelObject, this method assigns a ModelObject terminal to a ConnectionPoint of the shape
		/// </summary>
		/// <param name="controlPointId">Id of the shape's ControlPoint</param>
		/// <param name="terminalId">Id of the Modelobject's Terminal. Pass -1 in order to clear the mapping.</param>
		public void SetTerminalConnectionPointMapping(ControlPointId controlPointId, TerminalId terminalId)
		{
			TerminalId oldTerminalId = workTemplate.GetMappedTerminalId(controlPointId);
			workTemplate.MapTerminal(terminalId, controlPointId);
			TemplateWasChanged = true;

			if (TemplateShapeControlPointMappingChanged != null) {
				controlPointMappingChangedEventArgs.ControlPointId = controlPointId;
				controlPointMappingChangedEventArgs.OldTerminalId = oldTerminalId;
				controlPointMappingChangedEventArgs.NewTerminalId = terminalId;
				TemplateShapeControlPointMappingChanged(this, controlPointMappingChangedEventArgs);
			}
		}
 /// <override></override>
 public override void Disconnect(TerminalId ownTerminalId, IModelObject targetConnector, TerminalId targetTerminalId)
 {
     throw new NotImplementedException();
 }
Example #17
0
        private void PrintTransaction(string OrderType)
        {
            try
            {
                int    TransactionId       = 0;
                string NumeratorCurrency   = "BTC"; //TODO: make currencies classes, with code as properties.
                string DenominatorCurrency = CryptoCurrency.FiatCode;
                string Reference           = "";

                // Write transaction to database
                //change terminal id to int
                Decimal tx = cardClient.WriteTransaction(TagId, OrderType, TerminalId.ToString(), NumeratorCurrency, DenominatorCurrency, CryptoCurrency.Fiat, Price, Reference, TransactionId);
                if (tx > 0)
                {
                    // Get the text for the paper receipt.
                    string receiptText = Environment.NewLine;
                    receiptText += Environment.NewLine;
                    receiptText += Environment.NewLine;
                    receiptText += Environment.NewLine;

                    receiptText += String.Format("DATE:{0}", DateTime.Now) + Environment.NewLine;
                    receiptText += "TERMINAL:" + TerminalId + Environment.NewLine;
                    receiptText += "TRANS ID:" + TransactionId + Environment.NewLine;
                    receiptText += "TAG ID:" + TagId + Environment.NewLine;
                    receiptText += "TRANS TYPE:" + OrderType + Environment.NewLine;
                    receiptText += "COIN NAME:" + NumeratorCurrency + Environment.NewLine;
                    receiptText += "FIAT TYPE" + DenominatorCurrency + Environment.NewLine;
                    receiptText += "FIAT AMOUNT:" + CryptoCurrency.Fiat + Environment.NewLine;
                    receiptText += "COIN AMOUNT:" + CryptoCurrency.Amount + Environment.NewLine;
                    receiptText += "RATE:" + Price + Environment.NewLine;
                    receiptText += "http://diamondcircle.net";
                    receiptText += Environment.NewLine;
                    receiptText += Environment.NewLine;
                    receiptText += Environment.NewLine;
                    receiptText += Environment.NewLine;
                    receiptText += Environment.NewLine;

                    // Initialise the printer if required.
                    if (!Factory.GetPrinter().Initialised)
                    {
                        try
                        {
                            Factory.GetPrinter().Initialise();
                        }
                        catch (Exception ex)
                        {
                            lblStatusMessage.Text = "Cannot Print Receipt.";
                            GeneralExceptions("PrintTransaction - Initalise", System.Diagnostics.TraceEventType.Error, ex);
                            return;
                        }
                    }
                    // Print the receipt.
                    ErrorCode writeErrorCode = Factory.GetPrinter().PrintText(receiptText);
                    if (writeErrorCode != ErrorCode.None)
                    {
                        lblStatusMessage.Text = "Cannot Print Receipt";
                        throw new System.InvalidOperationException("PrintTransaction - Cannot Print Receipt");
                    }
                }
                else
                {
                    throw new System.InvalidOperationException("Could not Write Transaction to Database - System Error");
                }
            }
            catch (Exception ex)
            {
                lblStatusMessage.Text = "Cannot Print Receipt.";
                GeneralExceptions("PrintTransaction", System.Diagnostics.TraceEventType.Critical, ex);
                ReturnToMainMenu();
                return;
            }
        }
Example #18
0
 private void AssertMessageId(TerminalId terminalId, SequenceNumber sequenceNumber, MessageId messageId)
 {
     Assert.Equal(terminalId.Value, messageId.TerminalId.Value);
     Assert.Equal(sequenceNumber.Value, messageId.SequenceNumber.Value);
 }
Example #19
0
			public ControlPointMappingInfo(ControlPointId pointId, TerminalId terminalId, string terminalName) {
				this.pointId = pointId;
				this.terminalId = terminalId;
				this.terminalName = terminalName;
			}
Example #20
0
 public string GetTerminalOutput(TerminalId terminalId)
 {
     if (!TerminalOutput.ContainsKey(terminalId)) return "";
     var terminalOutput = TerminalOutput[terminalId].Skip(1).DefaultIfEmpty().Aggregate((s, s1) => s + s1+ "\r\n") ?? "";
     return terminalOutput;
 }
Example #21
0
		/// <ToBeCompleted></ToBeCompleted>
		public void MapTerminal(TerminalId terminalId, ControlPointId connectionPointId) {
			// check if terminalId and connectionPointId are valid values
			if (shape == null)
				throw new InvalidOperationException("Template has no shape.");
			if (!shape.HasControlPointCapability(connectionPointId, ControlPointCapabilities.Glue | ControlPointCapabilities.Connect))
				throw new NShapeException("Control point {0} is not a valid connection point.", connectionPointId);
			//
			if (connectionPointMappings.ContainsKey(connectionPointId))
				connectionPointMappings[connectionPointId] = terminalId;
			else
				connectionPointMappings.Add(connectionPointId, terminalId);
		}
Example #22
0
 public void Disconnect(TerminalId ownTerminalId, IModelObject otherModelObject, TerminalId otherTerminalId)
 {
     throw new NotImplementedException();
 }
 public FixedStrategy(TerminalId terminalId, SequenceNumber sequenceNumber, CheckNumber checkNumber)
 {
     _terminalId     = terminalId;
     _sequenceNumber = sequenceNumber;
     _checkNumber    = checkNumber;
 }
Example #24
0
 /// <override></override>
 public override void Disconnect(TerminalId ownTerminalId, IModelObject targetConnector, TerminalId targetTerminalId)
 {
     throw new NotImplementedException();
 }
Example #25
0
 public MessageId(TerminalId terminalId, SequenceNumber sequenceNumber, CheckNumber checkNumber)
 {
     TerminalId     = terminalId;
     SequenceNumber = sequenceNumber;
     CheckNumber    = checkNumber;
 }