示例#1
0
        public virtual void HandleSync(Sync e)
        {
            var storageNode = e.StorageNode;
            var log         = e.Log;

            if (!IsUpToDate(log))
            {
                m_messages.Add(new Message <Sync>()
                {
                    Id = Id, Event = e, Value = $"request replication again: { storageNode.Id }, data: { m_dataToReplicate }"
                });
                storageNode.ReplReq(new ReplReq(m_dataToReplicate));
            }
            else
            {
                if (VerifyReplication(storageNode.Id))
                {
                    m_safetyMonitor.Ack(new Ack());
                    m_livenessMonitor.Ack(new Ack());
                    m_client.Ack(new Ack());
                    m_log = DateTime.Now.Ticks;
                    m_messages.Add(new Message <Sync>()
                    {
                        Id = Id, Event = e, Value = $"response ack: { m_client.Id }, log: { m_log }"
                    });
                    RefreshReplication();
                }
            }
        }
示例#2
0
        public override MessageCollection Verify()
        {
            try
            {
                var retval = new MessageCollection();
                retval.AddRange(base.Verify());

                var parameter = (Parameter)this.Object;

                //Check valid name
                if (!ValidationHelper.ValidDatabaseIdenitifer(parameter.DatabaseName))
                {
                    retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, parameter.Name), this);
                }
                if (!ValidationHelper.ValidCodeIdentifier(parameter.PascalName))
                {
                    retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, parameter.Name), this);
                }

                return(retval);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public async Task Search(int start, int stop)
        {
            _messages.AddHeading("Finding Wikileak Hashes stored in the BlockChain");

            for (var blockNumber = start; blockNumber <= stop; blockNumber++)
            {
                if (_messages.Cancel)
                {
                    break;
                }

                var fileName = Path.Combine(Settings.Default.InputPath, $"blk{blockNumber:D5}.dat");

                _messages.Add($"File: {Path.GetFileNameWithoutExtension(fileName)}", MessageType.Heading);

                if (Path.GetFileName(fileName) == "blk00000.dat")
                {
                    continue;
                }

                Blocks.ClearAll();
                await Blocks.Add(fileName);

                SearchTransaction();
            }

            _messages.AddCompletion();
        }
示例#4
0
        public ChatBubblesWindow()
        {
            InitializeComponent();

            // FOLLOWING CODEBLOCK IS ONLY FOR DEMONSTRATION PURPOSES
            messages.Add(new Message()
            {
                Side = MessageSide.You,
                Text = "Hello sir. How may I help you?"
            });

            curside = MessageSide.You;
            // END OF DEMO BLOCK

            this.DataContext = messages;

            scrollViewerScrollToEndAnim = new DoubleAnimation()
            {
                Duration       = TimeSpan.FromSeconds(1),
                EasingFunction = new SineEase()
            };
            Storyboard.SetTarget(scrollViewerScrollToEndAnim, this);
            Storyboard.SetTargetProperty(scrollViewerScrollToEndAnim, new PropertyPath(VerticalOffsetProperty));

            scrollViewerStoryboard = new Storyboard();
            scrollViewerStoryboard.Children.Add(scrollViewerScrollToEndAnim);
            this.Resources.Add("foo", scrollViewerStoryboard);

            TextInput.Focus();
        }
        public async Task Search(int start, int stop)
        {
            _messages.NewLine();
            _messages.Add("Finding Transactions that used Shatoshi's Upload File Transaction");

            for (var blockNumber = start; blockNumber <= stop; blockNumber++)
            {
                var fileName = Path.Combine(Settings.Default.InputPath, $"blk{blockNumber:D5}.dat");

                _messages.Add($"File: {Path.GetFileNameWithoutExtension(fileName)}", MessageType.Heading);

                if (Path.GetFileName(fileName) == "blk00000.dat")
                {
                    continue;
                }

                Blocks.ClearAll();
                await Blocks.Add(fileName);

                foreach (var block in Blocks)
                {
                    foreach (var transaction in block.Transactions)
                    {
                        if (transaction.GetSatoshiUploadedBytes() != null)
                        {
                            _messages.Add($"{transaction}", MessageType.Transaction);
                        }
                    }
                }
            }
        }
示例#6
0
        public override MessageCollection Verify()
        {
            try
            {
                var retval = new MessageCollection();
                retval.AddRange(base.Verify());

                var customRetrieveRule = (CustomRetrieveRule)this.Object;

                //Check valid name
                if (!ValidationHelper.ValidDatabaseIdenitifer(customRetrieveRule.DatabaseName))
                {
                    retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, customRetrieveRule.Name), this);
                }
                if (!ValidationHelper.ValidCodeIdentifier(customRetrieveRule.PascalName))
                {
                    retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, customRetrieveRule.Name), this);
                }

                //Check SQL
                if (string.IsNullOrEmpty(customRetrieveRule.SQL))
                {
                    retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextSQLRequired, this);
                }

                return(retval);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#7
0
        /// <summary>
        /// 将错误添加到待显示的错误列表。同一目标对象的多个错误不会被重复添加,将始终使用第一个错误
        /// </summary>
        /// <param name="forum">表单名称</param>
        /// <param name="target">错误的目标对象</param>
        /// <param name="message">错误提示</param>
        public void AddError(string name, int line, string message)
        {
            if (string.IsNullOrEmpty(name))
            {
                name = Key_UnnamedTarget;
            }

            bool named = false;

            if (m_NamedErrors != null)
            {
                foreach (string namedError in m_NamedErrors)
                {
                    if (string.Compare(name, namedError, true) == 0)
                    {
                        named = true;
                        break;
                    }
                }
            }

            if (named)
            {
                m_Errors.Add(name, line, message);
            }
            else
            {
                m_Errors.Add(Key_UnnamedTarget, line, message);
            }
        }
        public MainWindow()
        {
            InitializeComponent();

            messages.Add(new Message()
            {
                Side = MessageSide.You,
                Text = "Hello sir. How may I help you?"
            });

            curside = MessageSide.You;

            this.DataContext = messages;

            scrollViewerScrollToEndAnim = new DoubleAnimation()
            {
                Duration       = TimeSpan.FromSeconds(1),
                EasingFunction = new SineEase()
            };
            Storyboard.SetTarget(scrollViewerScrollToEndAnim, this);
            Storyboard.SetTargetProperty(scrollViewerScrollToEndAnim, new PropertyPath(VerticalOffsetProperty));

            scrollViewerStoryboard = new Storyboard();
            scrollViewerStoryboard.Children.Add(scrollViewerScrollToEndAnim);
            this.Resources.Add("foo", scrollViewerStoryboard);

            TextInput.Focus();
        }
示例#9
0
        public async Task Search(int start, int stop)
        {
            _messages.NewLine();
            _messages.Add("Searching for base64 messages", MessageType.Heading);

            for (var blockNumber = start; blockNumber <= stop; blockNumber++)
            {
                var fileName = Path.Combine(Settings.Default.InputPath, $"blk{blockNumber:D5}.dat");

                _messages.Add($"File: {Path.GetFileNameWithoutExtension(fileName)}", MessageType.Heading);

                if (Path.GetFileName(fileName) == "blk00000.dat")
                {
                    continue;
                }

                Blocks.ClearAll();
                await Blocks.Add(fileName);

                foreach (var block in Blocks)
                {
                    foreach (var transaction in block.Transactions)
                    {
                        SearchTransaction(transaction);
                    }
                }
            }

            _messages.Add("Search complete", MessageType.Heading);
        }
示例#10
0
        public async Task Search(string txId, int start, int stop)
        {
            txId = txId.Trim('\r', '\n');

            _messages.NewLine();
            _messages.Add($"Searching For Transaction ID {txId}", MessageType.Heading);

            for (var blockNumber = start; blockNumber <= stop; blockNumber++)
            {
                var fileName = Path.Combine(Settings.Default.InputPath, $"blk{blockNumber:D5}.dat");

                _messages.Add($"File: {Path.GetFileNameWithoutExtension(fileName)}", MessageType.Heading);

                if (Path.GetFileName(fileName) == "blk00000.dat")
                {
                    continue;
                }

                Blocks.ClearAll();
                await Blocks.Add(fileName);

                if (Blocks[txId] != null)
                {
                    _messages.Add("Transaction found", MessageType.Error);
                    break;
                }
            }

            _messages.Add($"Search Complete", MessageType.Heading);
        }
        public void Execute(string txId)
        {
            txId = txId.Trim('\r', '\n');

            var transaction = _blocks[txId];

            if (transaction == null)
            {
                _messages.Add("Transaction not found");
                return;
            }

            _messages.NewLine();
            _messages.Add($"Transaction: {transaction}", MessageType.Transaction);
            _messages.Add($"Fee Amount: {transaction.Fees}");
            _messages.Add($"Fee Per Out: {transaction.FeePerOut}");

            _messages.NewLine();
            _messages.Add("In Transactions");
            _messages.Add($"In Amount: {transaction.Ins.Amount}");

            foreach (var txIn in transaction.Ins)
            {
                _messages.Add($"\t#{txIn.PreviousOutput.N}-{txIn.PreviousOutput.TransactionHash}");
            }

            _messages.NewLine();
            _messages.Add("Out Transactions");
            _messages.Add($"Out Amount: {transaction.Outs.Amount}");

            foreach (var txOut in transaction.Outs)
            {
                _messages.Add($"\t#{txOut.N}-{txOut.Value}-{txOut.Script.OpString}");
            }
        }
        private void AddMessage(string typeName, string summary)
        {
            Location location = new Location(typeName, String.Empty, 0);
            Message  message  = new Message(summary, location, MessageType.Error);

            messageCollection.Add(message);
        }
示例#13
0
        public MessageCollection CheckType(TypeDefinition type, Runner runner)
        {
            MessageCollection messageCollection = new MessageCollection();

            EqualsOrGetHashCode(type);

            if (equals == true && getHashCode == false)
            {
                Location location = new Location(type.FullName, type.Name, 0);
                Message  message  = new Message("Implements Object.Equals (Object) but does not implement Object.GetHashCode ()", location, MessageType.Error);
                messageCollection.Add(message);
            }
            else if (equals == false && getHashCode == true)
            {
                Location location = new Location(type.FullName, type.Name, 0);
                Message  message  = new Message("Implements Object.GetHashCode () but does not implement Object.Equals (Object)", location, MessageType.Error);
                messageCollection.Add(message);
            }
            else
            {
                return(runner.RuleSuccess);
            }

            if (messageCollection.Count == 0)
            {
                return(null);
            }
            return(messageCollection);
        }
        public async Task Search(string byteText, int start, int stop)
        {
            byteText = byteText.Trim(' ', '\r', '\n');

            _messages.AddHeading($"Searching For Byte Array {byteText}");

            var bytes = byteText.ToByteArray();

            for (var blockNumber = start; blockNumber <= stop; blockNumber++)
            {
                if (_messages.Cancel)
                {
                    break;
                }

                var fileName = Path.Combine(Settings.Default.InputPath, $"blk{blockNumber:D5}.dat");

                _messages.Add($"File: {Path.GetFileNameWithoutExtension(fileName)}", MessageType.Heading);

                if (Path.GetFileName(fileName) == "blk00000.dat")
                {
                    continue;
                }

                Blocks.ClearAll();
                await Blocks.Add(fileName);

                foreach (var transaction in Blocks.TransactionList)
                {
                    SearchTransaction(transaction.Value, bytes);
                }
            }

            _messages.AddCompletion();
        }
示例#15
0
        public override MessageCollection Verify()
        {
            var retval = new MessageCollection();

            retval.AddRange(base.Verify());

            var root = (ModelRoot)this.Object;

            //Check valid name
            if (!ValidationHelper.ValidDatabaseIdenitifer(root.CompanyName) || !ValidationHelper.ValidCodeIdentifier(root.CompanyName))
            {
                retval.Add(ValidationHelper.ErrorTextInvalidCompany, this);
            }
            if (!ValidationHelper.ValidDatabaseIdenitifer(root.ProjectName) || !ValidationHelper.ValidCodeIdentifier(root.ProjectName))
            {
                retval.Add(ValidationHelper.ErrorTextInvalidProject, this);
            }

            if (!string.IsNullOrEmpty(root.DefaultNamespace))
            {
                if (!ValidationHelper.IsValidNamespace(root.DefaultNamespace))
                {
                    retval.Add(ValidationHelper.ErrorTextInvalidNamespace, this);
                }
            }

            return(retval);
        }
示例#16
0
        private void addTextMe(string text)
        {
            messages.Add(new Message()
            {
                Side     = MessageSide.Me,
                Text     = text,
                PrevSide = curside
            });

            curside = MessageSide.Me;

            ScrollConversationToEnd();

            TextInput.Text = "";
            TextInput.Focus();

            // Send message to server

            // FOLLOWING CODEBLOCK IS ONLY FOR DEMONSTRATION PURPOSES
            // DELETE FOR NORMAL USE!

            //addTextYou(text);

            //addTextYou(text);

            //messages.Add(new Message()
            //{
            //    Side = MessageSide.Me,
            //    Text = text,
            //    PrevSide = curside
            //});

            //curside = MessageSide.Me;

            //ScrollConversationToEnd();

            //TextInput.Text = "";
            //TextInput.Focus();

            //messages.Add(new Message()
            //{
            //    Side = MessageSide.Me,
            //    Text = text,
            //    PrevSide = curside
            //});

            //curside = MessageSide.Me;

            //ScrollConversationToEnd();

            //TextInput.Text = "";
            //TextInput.Focus();

            // END OF DEMO BLOCK
        }
示例#17
0
        public virtual void EnterActive()
        {
            var dataToReplicate = RandomInteger(43);

            lock (m_messages)
                m_messages.Add(new Message <ReturnActive>()
                {
                    Id = Id, Event = new ReturnActive(), Value = $"client: { Id }, data to replicate: { dataToReplicate }"
                });
            m_server.ClientReq(new ClientReq(dataToReplicate));
        }
示例#18
0
        public void HandleLogUpdated(LogUpdated e)
        {
            var storageNode = e.StorageNode;
            var log         = e.Log;

            m_replicas[storageNode.Id] = true;
            lock (m_messages)
                m_messages.Add(new Message <LogUpdated>()
                {
                    Id = Id, Event = e, Value = $"storage node: { storageNode.Id }, log: { log }"
                });
        }
示例#19
0
        public virtual void HandleReplReq(ReplReq e)
        {
            var log  = DateTime.Now.Ticks;
            var data = e.Data;

            m_safetyMonitor.LogUpdated(new LogUpdated(Self, log));
            lock (m_messages)
                m_messages.Add(new Message <ReplReq>()
                {
                    Id = Id, Event = e, Value = $"storage node: { Id }, data: { data }, log: { log }"
                });
            m_log = log;
        }
示例#20
0
 protected async void Startup()
 {
     Conversation.Add(new Message("What can I do for you?", MessageSide.Cloud));
     try
     {
         IAsyncAction action = this.Synthesizer.SpeakTextAsync("What can I do for you?");
         this.BeginScrollDown();
         await action;
     }
     catch
     {
     }
 }
        public override MessageCollection Verify()
        {
            try
            {
                var retval = new MessageCollection();
                retval.AddRange(base.Verify());

                var tableComponentCollection = (TableComponentCollection)this.Object;

                //Check for duplicate names
                var nameList = new Dictionary <string, TableComponent>();
                foreach (TableComponent component in tableComponentCollection)
                {
                    var name = component.Name.ToLower();
                    if (nameList.ContainsKey(name))
                    {
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateName, component.Name), component.Controller);
                    }
                    else
                    {
                        nameList.Add(name, component);
                    }
                }

                //Check to ensure all items have at least one column
                foreach (var component in tableComponentCollection.ToList())
                {
                    if (component.Columns.Count == 0)
                    {
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextTableComponentNoColumns, component.Name), component.Controller);
                    }
                }

                //Check for duplicate names with tables
                foreach (Table table in ((ModelRoot)tableComponentCollection.Root).Database.Tables)
                {
                    if (nameList.ContainsKey(table.Name.ToLower()))
                    {
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextComponentTableDuplicateName, nameList[table.Name.ToLower()].Name), nameList[table.Name.ToLower()].Controller);
                    }
                }

                return(retval);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#22
0
        public async Task Execute(string[] fileNames)
        {
            _block.Clear();

            foreach (var file in fileNames)
            {
                _messages.Add($"Opening file {Path.GetFileNameWithoutExtension(file)} ", MessageType.Heading);

                await _block.Add(file);

                _block.JoinInsAndOuts();
            }

            _messages.Add("Opening file complete", MessageType.Heading);
        }
        public async Task Search(string txId)
        {
            txId = txId.Trim(' ', '\r', '\n');

            _messages.AddHeading("Walking down Transactions");

            try{
                await SearchTransaction(txId);
            }
            catch (Exception ex) {
                _messages.Add(ex.Message, MessageType.Error);
            }

            _messages.AddCompletion();
        }
        private void AddProblem(MethodDefinition method, Instruction instruction, MessageCollection messageCollection)
        {
            Location location = new Location(method.DeclaringType.Name, method.Name, instruction.Offset);
            Message  message  = new Message(MessageString, location, MessageType.Error);

            messageCollection.Add(message);
        }
示例#25
0
        public override MessageCollection Verify()
        {
            try
            {
                var retval = new MessageCollection();
                retval.AddRange(base.Verify());

                //Check for duplicate names
                var nameList            = new Hashtable();
                var referenceCollection = (ReferenceCollection)this.Object;
                foreach (Reference reference in referenceCollection)
                {
                    var parameter = (Parameter)reference.Object;
                    var name      = parameter.Name.ToLower();
                    if (nameList.ContainsKey(name))
                    {
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateName, name), parameter.Controller);
                    }
                    else
                    {
                        nameList.Add(name, string.Empty);
                    }
                }

                return(retval);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
		public MessageCollection CheckType(TypeDefinition type, Runner runner)
		{
			MessageCollection messageCollection = new MessageCollection();

			foreach (MethodDefinition method in type.Methods)
			{
				if (!method.IsStatic)
				{
					return null;
				}
			}

			foreach (FieldDefinition field in type.Fields)
			{
				if (!field.IsStatic)
				{
					return null;
				}
			}
			
			foreach (MethodDefinition ctor in type.Constructors)
			{
				if (!ctor.IsStatic && (ctor.Attributes & MethodAttributes.Public) == MethodAttributes.Public)
				{
					Location location = new Location(type.Name, ctor.Name, 0);
					Message message = new Message(MessageString, location, MessageType.Error);
					messageCollection.Add(message);
				}
			}

			return messageCollection.Count > 0 ? messageCollection : null;
			
		}
        public override MessageCollection Verify()
        {
            try
            {
                var retval = new MessageCollection();
                retval.AddRange(base.Verify());

                //Check for duplicate names
                var nameList            = new Hashtable();
                var referenceCollection = (ReferenceCollection)this.Object;
                foreach (Reference reference in referenceCollection)
                {
                    var customAggregateColumn = (CustomAggregateColumn)reference.Object;
                    var name = customAggregateColumn.Name.ToLower();
                    if (nameList.ContainsKey(name))
                    {
                        retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateName, name), customAggregateColumn.Controller);
                    }
                    else
                    {
                        nameList.Add(name, string.Empty);
                    }
                }

                //CustomAggregateColumn testCustomAggregateColumn = (CustomAggregateColumn)referenceCollection[0].Object;
                //if(!((CustomAggregateColumn)testCustomAggregateColumn.ParentViewRef.Object).Generated)
                //  return retval;

                return(retval);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public override MessageCollection Verify()
        {
            try
            {
                var retval = new MessageCollection();
                retval.AddRange(base.Verify());

                //Check for duplicate names
                var nameList = new Hashtable();
                foreach (CustomView customView in (CustomViewCollection)this.Object)
                {
                    if (customView.Generated)
                    {
                        var name = customView.Name.ToLower();
                        if (nameList.ContainsKey(name))
                        {
                            retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateName, name), this);
                        }
                        else
                        {
                            nameList.Add(name, string.Empty);
                        }
                    }
                }

                return(retval);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
		public MessageCollection CheckMethod(MethodDefinition method, Runner runner)
		{
			MessageCollection messageCollection = new MessageCollection();

			if (method.Body == null || method.Body.Instructions == null)
			{
				return null;
			}

			foreach (Instruction instruction in method.Body.Instructions)
			{
				if (instruction.OpCode.Code == Code.Pop)
				{
					Message message = CheckForViolation(instruction.Previous);

					if (message != null)
					{
						messageCollection.Add(message);
					}
				}
			}
			

			return messageCollection.Count == 0 ? runner.RuleSuccess : messageCollection;
		}
示例#30
0
        public static bool ExecuteRequestRegisterValidation <T>(UserBase user, MessageCollection messages, DbContextManagerService <T> service) where T : DbContextManager
        {
            bool success = false;

            try
            {
                UserActivationCode activationCode = new UserActivationCode();
                success = Rp3.Security.User.RequestValidityRegisterEmail(user, activationCode, service);

                if (success)
                {
                    List <MailContact> contacts = new List <MailContact>();
                    contacts.Add(new MailContact()
                    {
                        Mail = user.Contact.Email,
                        Name = user.Contact.Email
                    });

                    new MailController().SendAsEmail(Rp3.Resources.TitleFor.RequestRegisterValidationMailSubject,
                                                     contacts, "RequestValidationRegister", activationCode).DeliverAsync();
                }
            }
            catch
            {
                messages.Add(new Message(Rp3.Resources.MessageFor.RequestValidationRegisterFail, Data.MessageType.Error));
                success = false;
            }
            return(success);
        }
        public MessageCollection CheckMethod(MethodDefinition method, Runner runner)
        {
            MessageCollection messageCollection = new MessageCollection();

            if (method.Body == null || method.Body.Instructions == null)
            {
                return(null);
            }

            foreach (Instruction instruction in method.Body.Instructions)
            {
                if (instruction.OpCode.Code == Code.Pop)
                {
                    Message message = CheckForViolation(instruction.Previous);

                    if (message != null)
                    {
                        messageCollection.Add(message);
                    }
                }
            }


            return(messageCollection.Count == 0 ? runner.RuleSuccess : messageCollection);
        }
示例#32
0
        public void CanCreateTransaction()
        {
            SendPipelineWrapper pipeline =
            PipelineFactory.CreateSendPipeline(typeof(XMLTransmit));

             using ( TransactionControl control = pipeline.EnableTransactions() )
             {
            // Create the input message to pass through the pipeline
            Stream stream = DocLoader.LoadStream("SampleDocument.xml");
            IBaseMessage inputMessage = MessageHelper.CreateFromStream(stream);

            // Add the necessary schemas to the pipeline, so that
            // disassembling works
            pipeline.AddDocSpec(typeof(Schema1_NPP));
            pipeline.AddDocSpec(typeof(Schema2_WPP));

            MessageCollection inputMessages = new MessageCollection();
            inputMessages.Add(inputMessage);

            // Execute the pipeline, and check the output
            IBaseMessage outputMessage = pipeline.Execute(inputMessages);

            Assert.IsNotNull(outputMessage);
            control.SetComplete();
             }
        }
示例#33
0
        public MessageCollection CheckType(TypeDefinition type, Runner runner)
        {
            MessageCollection messageCollection = new MessageCollection();

            if (ImplementsICloneable(type))
            {
                foreach (MethodDefinition method in type.Methods)
                {
                    if (method.Name == "Clone" && method.Parameters.Count == 0)
                    {
                        foreach (Instruction instruction in method.Body.Instructions)
                        {
                            Instruction prevInstr = instruction.Previous;
                            if (instruction.OpCode.Name == "ret" && prevInstr.OpCode.Name == "ldnull")
                            {
                                Location location = new Location(type.FullName, type.Name, instruction.Offset);
                                Message  message  = new Message("The ICloneable.Clone () method returns null", location, MessageType.Error);
                                messageCollection.Add(message);
                            }
                        }
                    }
                }
            }
            if (messageCollection.Count == 0)
            {
                return(null);
            }
            return(messageCollection);
        }
示例#34
0
        public MessageCollection GlobalMessages()
        {
            MessageCollection messageCollection = new MessageCollection();

            lock(lockObject)
            {
                foreach(Message message in globalMessages)
                {
                    messageCollection.Add(message);
                }
            }

            return(messageCollection);
        }
		public MessageCollection CheckType (TypeDefinition typeDefinition, Runner runner)
		{
			MessageCollection messageCollection = new MessageCollection ();
			if (InheritsFromAttribute (typeDefinition)) {
				if (!typeDefinition.Name.EndsWith ("Attribute")) {
					Location location = new Location (typeDefinition.FullName, typeDefinition.Name, 0);
					Message message = new Message ("The class name doesn't end with Attribute Suffix", location, MessageType.Error);
					messageCollection.Add (message);                        
				}
			}
			if (messageCollection.Count == 0)
				return null;
			return messageCollection;
		}
		public MessageCollection CheckType (TypeDefinition type, Runner runner)
		{
			MessageCollection messageCollection = new MessageCollection ();
			
			if (!ImplementsInternalsVisibleToAttribute (type) && (type.GetType ().IsAnsiClass || type.GetType ().IsClass || type.GetType ().IsAutoClass) && type.Name != "<Module>" && IsInstantiable (type) && !IsInstantiated (type, type)) {
				Location location = new Location (type.FullName, type.Name, 0);
				Message message = new Message ("There is no call for any of the types constructor found", location, MessageType.Error);
				messageCollection.Add (message);
			}
			
			if (messageCollection.Count == 0)
				return null;
			return messageCollection;
		}
示例#37
0
 /// <summary>
 /// ensures that phone number has at least 10 digits
 /// </summary>
 public static bool ValidatePhone(string p_phoneNumber, MessageCollection p_errors, string p_message, bool p_isRequired = false)
 {
     if (string.IsNullOrEmpty(p_phoneNumber)) {
         if (p_isRequired) {
             p_errors.Add(p_message);
             return false;
         }
         return true;
     }
     if (Helpers.ValidateLength(p_phoneNumber, p_errors, p_message, 10, 50, p_isRequired)) {
         var phoneNumber = Regex.Replace(p_phoneNumber, "[^0-9]", "");
         return Helpers.ValidateLength(phoneNumber, p_errors, p_message, 10, 50, p_isRequired);
     }
     return false;
 }
		public MessageCollection CheckType (TypeDefinition type, Runner runner)
		{
			MessageCollection messageCollection = new MessageCollection ();
			if (!ImplementsICloneable (type))
				foreach (MethodDefinition method in type.Methods)
					if (method.Name == "Clone" && method.ReturnType.ReturnType.ToString ().Equals ("System.Object") && method.Parameters.Count == 0) {
						Location location = new Location (type.FullName, type.Name, 0);
						Message message = new Message ("The Clone () method is used, but ICloneable is not implemented", location, MessageType.Error);
						messageCollection.Add (message);
					}
					    
			if (messageCollection.Count == 0)
					return null;
			return messageCollection;
		}
		public MessageCollection CheckType (TypeDefinition typeDefinition, Runner runner) 
		{
			messageCollection = new MessageCollection ();
			CodeDuplicatedLocator codeDuplicatedLocator = new CodeDuplicatedLocator ();
			foreach (MethodDefinition currentMethod in typeDefinition.Methods) {
				foreach (Message message in codeDuplicatedLocator.CompareMethodAgainstTypeMethods (currentMethod, typeDefinition)) {
					messageCollection.Add (message);
				}
				codeDuplicatedLocator.CheckedMethods.Add (currentMethod.Name);
			}
			
			if (messageCollection.Count == 0)
				return null;
			return messageCollection;
		}
		public MessageCollection CheckType (TypeDefinition type, Runner runner)
		{
			MessageCollection messageCollection = new MessageCollection ();
			EqualsOrGetHashCode (type);
			
			if (equals == true && getHashCode == false)
			{
				Location location = new Location (type.FullName, type.Name, 0);
				Message message = new Message ("Implements Object.Equals (Object) but does not implement Object.GetHashCode ()", location, MessageType.Error);
				messageCollection.Add (message);
			}
			else if (equals == false && getHashCode == true)
			{
				Location location = new Location (type.FullName, type.Name, 0);
				Message message = new Message ("Implements Object.GetHashCode () but does not implement Object.Equals (Object)", location, MessageType.Error);
				messageCollection.Add (message);
			}
			else
				return runner.RuleSuccess;
			
			if (messageCollection.Count == 0)
				return null;
			return messageCollection;
		}
		public MessageCollection CheckMethod (MethodDefinition method, Runner runner)
		{
			MessageCollection messageCollection = new MessageCollection ();
			TypeDefinition type = method.DeclaringType as TypeDefinition;
			
			if (MemberIsCallable (type, method) && !MemberIsCalled (type, method)) {
				Location location = new Location (method.DeclaringType.FullName, method.Name, 0);
				Message message = new Message ("The private or internal code is not called", location, MessageType.Error);
				messageCollection.Add (message);
			}
			
			if (messageCollection.Count == 0)
				return null;
			return messageCollection;
		}
		public MessageCollection CheckType (TypeDefinition type, Runner runner)
		{
			MessageCollection messageCollection = new MessageCollection ();
			if (type.IsSealed) {
				foreach (FieldDefinition field in type.Fields) {
					if (field.Attributes.ToString () == "Family") {
						Location location = new Location (type.FullName, type.Name, 0);
						Message message = new Message ("This sealed class contains protected field(s)", location, MessageType.Error);
						messageCollection.Add (message);
					}
				}
			}
			if (messageCollection.Count == 0)
				return null;
			return messageCollection;
		}
		public MessageCollection CheckType (TypeDefinition typeDefinition, Runner runner)
		{
			MessageCollection messageCollection = new MessageCollection ();
			if (typeDefinition.IsEnum) {
				if (!HasFlagsAttribute (typeDefinition)) {
					if (IsPlural (typeDefinition.Name)) {
						Location location = new Location (typeDefinition.FullName, typeDefinition.Name, 0);
						Message message = new Message ("The enum has a plural name.", location, MessageType.Error);
						messageCollection.Add (message);
					}
				}
			}
			if (messageCollection.Count == 0)
				return null;
			return messageCollection;
		}
		public MessageCollection CheckMethod (MethodDefinition method, Runner runner)
		{
			MessageCollection messageCollection = new MessageCollection ();
			
			if (method.HasBody && method.Name == "Equals" && method.ReturnType.ReturnType.ToString () == "System.Boolean" && method.IsVirtual && !method.IsNewSlot)
				foreach (ParameterDefinition param in method.Parameters)
					if (param.ParameterType.FullName == "System.Object")
						if (!HandlesNullArg (method)) {
						Location location = new Location (method.DeclaringType.FullName, method.Name, 0);
						Message message = new Message ("The overridden method Object.Equals (Object) does not return false if null value is found", location, MessageType.Error);
						messageCollection.Add (message);
					}
			
			if (messageCollection.Count == 0)
				return null;
			return messageCollection;
		}
示例#45
0
        static void Main(string[] args)
        {
            if (args.Length < 2) {
                Console.WriteLine("Android SMS HTMLifer");
                Console.WriteLine("Usage: android-sms-htmlifier.exe name filename");
                Console.WriteLine();
                return;
            }

            string ownerName = args[0];
            string xmlPath = args[1];
            string htmlPath = Path.ChangeExtension(xmlPath, ".html");

            MessageCollection msgCollection = new MessageCollection();
            Array.ForEach(Sms.FromXmlFile(xmlPath, ownerName), x => msgCollection.Add(x));
            msgCollection.OutputHtml(htmlPath);
        }
		public MessageCollection CheckType (TypeDefinition type, Runner runner)
		{
			MessageCollection messageCollection = new MessageCollection ();
			if (ImplementsICloneable (type))
				foreach (MethodDefinition method in type.Methods) 
					if (method.Name == "Clone" && method.Parameters.Count == 0)
						foreach (Instruction instruction in method.Body.Instructions) {
							Instruction prevInstr = instruction.Previous;
							if (instruction.OpCode.Name == "ret" && prevInstr.OpCode.Name == "ldnull") {
								Location location = new Location (type.FullName, type.Name, instruction.Offset);
								Message message = new Message ("The ICloneable.Clone () method returns null", location, MessageType.Error);
								messageCollection.Add (message);
							}
						}
			if (messageCollection.Count == 0)
					return null;
			return messageCollection;
		}
		public MessageCollection CheckType (TypeDefinition type, Runner runner)
		{
			string [] access_spec  = type.Attributes.ToString ().Split(',');
			MessageCollection messageCollection = new MessageCollection ();
			
			// Compiler generates an error for any other non alpha-numerics than underscore ('_'), so we just need to check the presence of underscore in type names 
			
			if (access_spec[0] != "NestedPrivate" && type.Name.IndexOf ("_") != -1)
			{
				Location location = new Location (type.FullName, type.Name, 0);
				Message message = new Message ("Type name contains underscore", location, MessageType.Error);
				messageCollection.Add (message);
			}
			
			if (messageCollection.Count == 0)
				return null;
			return messageCollection;
		}
		public MessageCollection CheckMethod (MethodDefinition method, Runner runner)
		{			
			MessageCollection messageCollection = new MessageCollection ();
			
			foreach (Instruction ins in method.Body.Instructions)
				if (ins.OpCode == OpCodes.Call || ins.OpCode == OpCodes.Callvirt) {
					MethodReference calledMethod = (MethodReference) ins.Operand;
					if (calledMethod.Name == "Equals" && calledMethod.ReturnType.ReturnType.FullName == "System.Boolean")
						if (ins.Previous.OpCode == OpCodes.Ldnull) {
							Location location = new Location (method.DeclaringType.FullName, method.Name, 0);
							Message message = new Message ("You should not call Equals (null), i.e., argument should not be null", location, MessageType.Error);
							messageCollection.Add (message);
						}
				}
		
			if (messageCollection.Count == 0)
				return null;
			return messageCollection;
		}
		public MessageCollection CheckMethod (MethodDefinition method, Runner runner)
		{
			string [] access_spec  = method.Attributes.ToString ().Split(',');
			MessageCollection messageCollection = new MessageCollection ();
			
			if(!IsPropertyEventOrOperator(method))
			{
				// Compiler generates an error for any other non alpha-numerics than underscore ('_'), so we just need to check the presence of underscore in method names
				if (access_spec[0] != "Private" && method.Name.IndexOf("_") != -1)
				{
					Location location = new Location (method.DeclaringType.ToString(), method.Name, 0);
					Message message = new Message ("Method name contains underscore", location, MessageType.Error);
					messageCollection.Add (message);
				}
			}
			
			if (messageCollection.Count == 0)
				return null;
			return messageCollection;
		}
		public MessageCollection CheckMethod (MethodDefinition method, Runner runner)
		{
			MessageCollection messageCollection = new MessageCollection ();
			
			foreach (Instruction instruction in method.Body.Instructions) {					
				if (instruction.Operand != null) {
					if (instruction.Operand.ToString () == "System.Boolean System.String::Equals(System.String)") {
						Instruction prevInstr = instruction.Previous;
						if (prevInstr.OpCode.Name == "ldstr" && prevInstr.Operand.ToString().Length == 0) {
							Location location = new Location (method.DeclaringType.ToString(), method.Name, instruction.Offset);
							Message message = new Message ("Method uses .Equals (\"\") method to check for empty string instead of using Length property ", location, MessageType.Error);
							messageCollection.Add (message);
						}
					}
				}
			}
			
			if (messageCollection.Count == 0)
				return null;
			return messageCollection;
		}
      /// <summary>
      /// Executes the receive pipeline
      /// </summary>
      /// <param name="inputMessage">Input message to feed to the pipeline</param>
      /// <returns>A collection of messages that were generated by the pipeline</returns>
      public MessageCollection Execute(IBaseMessage inputMessage)
      {
         if ( inputMessage == null )
            throw new ArgumentNullException("inputMessage");

         Pipeline.InputMessages.Add(inputMessage);
         MessageCollection output = new MessageCollection();
         Pipeline.Execute(Context);

         IBaseMessage om = null;
         while ( (om = Pipeline.GetNextOutputMessage(Context)) != null )
         {
            output.Add(om);
            // we have to consume the entire stream for the body part.
            // Otherwise, the disassembler might enter an infinite loop.
            // We currently copy the output into a new memory stream
            if ( om.BodyPart != null && om.BodyPart.Data != null ) {
               om.BodyPart.Data = CopyStream(om.BodyPart.Data);
            }
        }

         return output;
      }
		public MessageCollection CheckMethod (MethodDefinition methodDefinition, Runner runner)
		{
			MessageCollection messageCollection = new MessageCollection ();
			if (methodDefinition.HasBody) {
				ExceptionHandlerCollection exceptionHandlerCollection = methodDefinition.Body.ExceptionHandlers;
				foreach (ExceptionHandler exceptionHandler in exceptionHandlerCollection) {
					if (exceptionHandler.Type == ExceptionHandlerType.Catch) {
						string catchTypeName = exceptionHandler.CatchType.FullName;
						if (IsForbiddenTypeInCatches (catchTypeName)) {
							if (!ThrowsGeneralException (exceptionHandler)) {
								Location location = new Location (methodDefinition.Name, methodDefinition.Name, exceptionHandler.HandlerStart.Offset);
								Message message = new Message ("Do not swallow errors catching nonspecific exceptions.", location, MessageType.Error);
								messageCollection.Add (message);
							}
						}
					}
				}
			}
			
			if (messageCollection.Count == 0)
				return null;
			return messageCollection;
		}
		public MessageCollection CheckMethod (MethodDefinition method, Runner runner)
		{
			MessageCollection messageCollection = new MessageCollection ();
			Instruction prevIns;
			int offset = 0;
			bool nullReturned = false;
			foreach (Instruction ins in method.Body.Instructions)
				if (method.Name == "ToString")
					if (ins.OpCode == OpCodes.Ret) {
						prevIns = ins.Previous;
						if (prevIns.OpCode != OpCodes.Ldnull) {
							string opCodeSt;
							if (prevIns.OpCode == OpCodes.Call || prevIns.OpCode == OpCodes.Callvirt)
								opCodeSt = ReturnSt (method, prevIns.Previous);
							else 
								opCodeSt = ReturnSt (method, prevIns);
							if (opCodeSt == null && prevIns.Operand.ToString () != "System.String System.Convert::ToString(System.Object)")
								nullReturned = true;
							if (MethodReturnsNull (method, opCodeSt)) {
								nullReturned = true;
								offset = ins.Offset;
							}
						}
						else {
							nullReturned = true;
							offset = ins.Offset;
						}
					}
			if (nullReturned) {
				Location location = new Location (method.DeclaringType.FullName, method.Name, offset);
				Message message = new Message ("ToString () seems to returns null in some condition", location, MessageType.Error);
				messageCollection.Add (message);
			}
			if (messageCollection.Count == 0)
				return null;
			return messageCollection;
		}
		public MessageCollection CheckMethod(MethodDefinition method, Runner runner)
		{
			MessageCollection messageCollection = new MessageCollection();

			if ((method.Attributes & MethodAttributes.SpecialName) == MethodAttributes.SpecialName && method.Name.StartsWith("set_"))
			{
				bool valueAccessed = false;
				foreach (Instruction instruction in method.Body.Instructions)
				{
					if (instruction.OpCode.Code == Code.Ldarg_1)
					{
						valueAccessed = true;
					}
				}
				if (!valueAccessed)
				{
					Location location = new Location(method.DeclaringType.Name, method.Name, 0);
					Message message = new Message(MessageString, location, MessageType.Error);
					messageCollection.Add(message);
				}
			}
			
			return messageCollection.Count > 0 ? messageCollection : null;
		}
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				var customAggregate = (CustomAggregate)this.Object;
				if(customAggregate.Generated)
				{
					//Check valid name
					if (!ValidationHelper.ValidDatabaseIdenitifer(customAggregate.DatabaseName))
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, customAggregate.Name), this);
					if (!ValidationHelper.ValidCodeIdentifier(customAggregate.PascalName))
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, customAggregate.Name), this);

					//Check Aggregate SQL
					if (string.IsNullOrEmpty(customAggregate.SQL))
						retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextSQLRequired, this);

					//Check that object has at least one generated column
					if(customAggregate.GeneratedColumns.Count() == 0)
						retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextColumnsRequired, this);

				}

				return retval;

			}
			catch(Exception ex)
			{
				throw;
			}

		}
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				//Check for duplicate names
				var nameList = new Hashtable();
				var referenceCollection = (ReferenceCollection)this.Object;
				foreach(Reference reference in referenceCollection)
				{
					var customViewColumn = (CustomViewColumn)reference.Object;
					var name = customViewColumn.Name.ToLower();
					if(nameList.ContainsKey(name))
						retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextDuplicateName, name), customViewColumn.Controller);
					else
						nameList.Add(name, string.Empty);
				}

				//CustomViewColumn testCustomViewColumn = (CustomViewColumn)referenceCollection[0].Object;
				//if(!((CustomViewColumn)testCustomViewColumn.ParentViewRef.Object).Generated)
				//  return retval;

				return retval;

			}
			catch(Exception ex)
			{
				throw;
			}
		}
		public override MessageCollection Verify()
		{
			try
			{
				var retval = new MessageCollection();
				retval.AddRange(base.Verify());

				var customRetrieveRule = (CustomRetrieveRule)this.Object;

				//Check valid name
				if (!ValidationHelper.ValidDatabaseIdenitifer(customRetrieveRule.DatabaseName))
					retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, customRetrieveRule.Name), this);
				if (!ValidationHelper.ValidCodeIdentifier(customRetrieveRule.PascalName))
					retval.Add(MessageTypeConstants.Error, string.Format(ValidationHelper.ErrorTextInvalidIdentifier, customRetrieveRule.Name), this);

				//Check SQL
				if (string.IsNullOrEmpty(customRetrieveRule.SQL))
					retval.Add(MessageTypeConstants.Error, ValidationHelper.ErrorTextSQLRequired, this);

				return retval;

			}
			catch(Exception ex)
			{
				throw;
			}

		}
      public void CanExecuteBtfAssembler()
      {
         SendPipelineWrapper pipeline =
            PipelineFactory.CreateEmptySendPipeline();
         pipeline.GroupSigningCertificate = "9302859B216AB1E97A2EB4F94E894A128E4A3B6E";

         MIME_SMIME_Encoder mime = new MIME_SMIME_Encoder();
         mime.SignatureType = MIME_SMIME_Encoder.SMIME_SignatureType.BlobSign;
         mime.SendBodyPartAsAttachment = true;
         mime.AddSigningCertToMessage = true;
         mime.EnableEncryption = false;
         mime.ContentTransferEncoding = MIME_SMIME_Encoder.MIMETransferEncodingType.SevenBit;
         pipeline.AddComponent(mime, PipelineStage.Encode);

         BTFAsmComp asm = new BTFAsmComp();
         asm.DesignProp_epsFromAddress = "asdasd";
         asm.DesignProp_epsFromAddressType = "asdad";
         asm.DesignProp_epsToAddress = "eweww";
         asm.DesignProp_epsToAddressType = " asdd";
         asm.DesignProp_isReliable = true;
         asm.DesignProp_propTopic = "wewew";
         asm.DesignProp_svcDeliveryRctRqtSendBy = 4;
         asm.DesignProp_svcDeliveryRctRqtSendToAddress = "ddd";
         asm.DesignProp_svcDeliveryRctRqtSendToAddressType = "sss";

         pipeline.AddComponent(asm, PipelineStage.Assemble);
         pipeline.AddDocSpec(typeof(BTF2Schemas.btf2_endpoints_header));
         pipeline.AddDocSpec(typeof(BTF2Schemas.btf2_envelope));
         pipeline.AddDocSpec(typeof(BTF2Schemas.btf2_manifest_header));
         pipeline.AddDocSpec(typeof(BTF2Schemas.btf2_process_header));
         pipeline.AddDocSpec(typeof(BTF2Schemas.btf2_receipt_header));
         pipeline.AddDocSpec(typeof(BTF2Schemas.btf2_services_header));
         pipeline.AddDocSpec(typeof(SampleSchemas.SimpleBody));

         string body =
            @"<o:Body xmlns:o='http://SampleSchemas.SimpleBody'>
               this is a body</o:Body>";
         MessageCollection inputMessages = new MessageCollection();
         IBaseMessage inputMsg = MessageHelper.CreateFromString(body);
         inputMsg.Context.Write("PassThroughBTF", "http://schemas.microsoft.com/BizTalk/2003/mime-properties", false);
         inputMessages.Add(inputMsg);
         inputMsg.BodyPart.PartProperties.Write("ContentTransferEncoding", "http://schemas.microsoft.com/BizTalk/2003/mime-properties", "7bit");
         IBaseMessage output = pipeline.Execute(inputMessages);

         byte[] buffer = new byte[64 * 1024];
         Stream input = output.BodyPart.Data;
         int bytesRead;

         Stream outputs = new FileStream("c:\\temp\\t.xml", 
            FileMode.Truncate, FileAccess.Write);
         using ( outputs )
         {
            while ( (bytesRead = input.Read(buffer, 0, buffer.Length)) > 0 )
               outputs.Write(buffer, 0, bytesRead);
         }

      }
      public void CanProvideStageIDsInContext()
      {
         var pipeline = PipelineFactory.CreateEmptySendPipeline();
         var stages = new List<Guid>();
         pipeline.AddComponent(new SendStageTest(stages), PipelineStage.PreAssemble);
         pipeline.AddComponent(new SendStageTest(stages), PipelineStage.Assemble);
         pipeline.AddComponent(new SendStageTest(stages), PipelineStage.Encode);

         var inputMessage = MessageHelper.CreateFromString("<sample/>");
         var collection = new MessageCollection();
         collection.Add(inputMessage);

         var outputMessage = pipeline.Execute(collection);
         Assert.AreEqual(3, stages.Count);
         Assert.AreEqual(PipelineStage.PreAssemble.ID, stages[0]);
         Assert.AreEqual(PipelineStage.Assemble.ID, stages[1]);
         Assert.AreEqual(PipelineStage.Encode.ID, stages[2]);
      }
      public void CanExecutePipelineWithFlatFile()
      {
         SendPipelineWrapper pipeline =
            PipelineFactory.CreateSendPipeline(typeof(CSV_FF_SendPipeline));

         // Create the input message to pass through the pipeline
         Stream stream = DocLoader.LoadStream("CSV_XML_SendInput.xml");
         IBaseMessage inputMessage = MessageHelper.CreateFromStream(stream);
         inputMessage.BodyPart.Charset = "UTF-8";

         // Add the necessary schemas to the pipeline, so that
         // assembling works
         pipeline.AddDocSpec(typeof(Schema3_FF));

         MessageCollection inputMessages = new MessageCollection();
         inputMessages.Add(inputMessage);

         // Execute the pipeline, and check the output
         IBaseMessage outputMessage = pipeline.Execute(inputMessages);

         Assert.IsNotNull(outputMessage);
      }