public Chart() { ChartBox = CreateChartBox(); ChartBox.Bounds = DisplayRectangle; ChartBox.Paint += new PaintEventHandler(ChartBox_Paint); ChartBox.MouseDown += new MouseEventHandler(ChartBox_MouseDown); ChartBox.MouseUp += new MouseEventHandler(ChartBox_MouseUp); ChartBox.MouseMove += new MouseEventHandler(ChartBox_MouseMove); ChartBox.MouseLeave += new EventHandler(ChartBox_MouseLeave); ChartBox.MouseWheel += new MouseEventHandler(ChartBox_MouseWheel); ChartBox.DoubleClick += new EventHandler(ChartBox_DoubleClick); ChartBox.KeyDown += new KeyEventHandler(ChartBox_KeyDown); ChartBox.KeyUp += new KeyEventHandler(ChartBox_KeyUp); ChartBox.KeyPress += new KeyPressEventHandler(ChartBox_KeyPress); ChartBox.Resize += new EventHandler(ChartBox_Resize); Controls.Add(ChartBox); SetPaintStyles(); Labels = new XList <ChartLabel>(); Layers = new XList <ChartLayer>(); Selector = new SelectionLayer(this); Layers.Add(Selector); MinimumChartSize = DefaultMinimumChartSize; }
public void TestXListAdd() { var list = new XList <int>(); for (int i = 0; i < LoopLength; i++) { list.Add(i); } }
public void TestXListAdd() { var list = new XList <MyStruct>(); for (int i = 0; i < LoopLength; i++) { list.Add(_sample); } }
public TestsOnIntegers() { _intTestXList = new XList <int>(); _intTestList = new List <int>(); for (int i = 0; i < LoopLength; i++) { _intTestList.Add(i); _intTestXList.Add(i); } }
public TestsOnStructs() { _intTestXList = new XList <MyStruct>(); _intTestList = new List <MyStruct>(); for (int i = 0; i < LoopLength; i++) { var s = new MyStruct(i); _intTestList.Add(s); _intTestXList.Add(s); } }
public override void Execute() { var results = new XList <GetConfigResult>(); Request.xForEach(item => { var doc = Collection.FindOne($"$.key='{item.Key}'"); results.Add(new GetConfigResult { Key = item.Key, Content = doc["value"].AsString }); }); Result = results; }
public static XList <Expression <Func <T, T> > > Then <T>(this XList <Expression <Func <T, T> > > first, Expression <Func <T, T> > second) { if (null == first) { return(new XList <Expression <Func <T, T> > > { second }); } if (null != second) { first.Add(second); } return(first); }
public void InitializeButtons() { LeftButtons = new XList <TabBarButton>(); LeftButtons.ItemAdded += new XListEventHandler <TabBarButton>(Buttons_ItemAdded); RightButtons = new XList <TabBarButton>(); RightButtons.ItemAdded += new XListEventHandler <TabBarButton>(Buttons_ItemAdded); DropDownButton = new TabBarButton(); //DropDownButton.OwnerDraw = false; DropDownButton.Icon = Properties.Resources.chevron; DropDownButton.Visible = ShowDropDownButton; DropDownButton.Click += new EventHandler(DropDownButton_Click); //DropDownButton.Paint += new UIPaintEventHandler(DropDownButton_Paint); RightButtons.Add(DropDownButton); // InitializeSpecialTabs(); }
public void DownloadFile(string url, string destination) { var response = Event <GetResponseInterface> .RaiseFirst(); if (response == null) { return; } _downloadQueue = _downloadQueue ?? new XList <Task <string> >(); _downloadQueue.Add(SessionData.Current.RequireRemoteFile(url, new Uri(url).SingleItemAsEnumerable(), PackageManagerSettings.CoAppCacheDirectory, false, rrfState => { if (rrfState == null || string.IsNullOrEmpty(rrfState.LocalLocation) || !File.Exists(rrfState.LocalLocation)) { // didn't fill in the local location? -- this happens when the client can't download. return(null); } if (!rrfState.LocalLocation.Equals(destination, StringComparison.CurrentCultureIgnoreCase)) { File.Copy(rrfState.LocalLocation, destination); } return(destination); }) as Task <string>); }
protected PropertySheet Parse() { var tokenStream = PropertySheetTokenizer.Tokenize(_propertySheetText); var state = ParseState.Global; var enumerator = tokenStream.GetEnumerator(); var importFilename = string.Empty; var startFolder = System.Environment.CurrentDirectory; // first, check for a .user file to auto-import if(!string.IsNullOrEmpty(_filename) ) { var fullPath = _filename.GetFullPath(); startFolder = Path.GetDirectoryName(fullPath) + "\\"; Import(Path.GetFileName(fullPath) + ".user", startFolder); } Token token; Rule rule = null; string ruleName = "*"; string ruleParameter = null; string ruleClass = null; string ruleId = null; PropertyRule property = null; var sourceLocation = new SourceLocation { Row=0, Column = 0, SourceFile = null, }; string propertyName = null; string propertyLabelText = null; string presentlyUnknownValue = null; // string collectionName = null; List<string> multidimensionalLambda = null; enumerator.MoveNext(); do { token = enumerator.Current; switch (token.Type) { // regardless where we are, skip over whitespace, etc. case TokenType.WhiteSpace: case TokenType.LineComment: case TokenType.MultilineComment: continue; } // System.Console.WriteLine("Token : {0} == [{1}]", token.Type, token.Data); switch (state) { case ParseState.Global: sourceLocation = new SourceLocation { // will be the start of the next new rule. Row = token.Row, Column = token.Column, SourceFile = _filename, }; switch (token.Type) { case TokenType.Identifier: // look for identifier as the start of a selector if( token.Data == "@import" ) { // special case to handle @import rules state = ParseState.Import; continue; } state = ParseState.Selector; ruleName = token.Data; continue; case TokenType.Dot: state = ParseState.SelectorDot; ruleName = "*"; // take next identifier as the classname continue; case TokenType.Pound: state = ParseState.SelectorPound; ruleName = "*"; // take next identifier as the id continue; case TokenType.Semicolon: // tolerate extra semicolons. continue; default: throw new EndUserParseException(token, _filename, "PSP 100", "Expected one of '.' , '#' or identifier"); } case ParseState.Import : switch (token.Type) { case TokenType.StringLiteral: case TokenType.Identifier: state = ParseState.ImportFilename; importFilename = token.Data; continue; default: throw new EndUserParseException(token, _filename, "PSP 121", "Expected a string literal for filename (Missing semicolon?)"); } case ParseState.ImportFilename: switch (token.Type) { case TokenType.Semicolon: if( !Import(importFilename, startFolder)) { throw new EndUserParseException(token, _filename, "PSP 122", "Imported file '{0}' not found", importFilename); } state = ParseState.Global; continue; default: throw new EndUserParseException(token, _filename, "PSP 121", "Expected a string literal for filename"); } case ParseState.Selector: switch (token.Type) { case TokenType.Dot: state = ParseState.SelectorDot; continue; case TokenType.Pound: state = ParseState.SelectorPound; continue; case TokenType.SelectorParameter: ruleParameter = token.Data; if( ruleParameter.IndexOfAny("\r\n".ToCharArray()) >= 0) { throw new EndUserParseException(token, _filename, "PSP 123", "Selector parameter may not contain CR/LFs (missing close bracket?): {0} ", Rule.CreateSelectorString(ruleName, ruleParameter,ruleClass, ruleId )); } continue; case TokenType.OpenBrace: state = ParseState.InRule; // property sheets now merge rules when redefined. // if( _propertySheet.HasRule(ruleName, ruleParameter, ruleClass, ruleId) ) { // throw new EndUserParseException(token, _filename, "PSP 113", "Duplicate rule with identical selector not allowed: {0} ", Rule.CreateSelectorString(ruleName, ruleParameter,ruleClass, ruleId )); // } rule = _propertySheet.GetRule(ruleName, ruleParameter, ruleClass, ruleId); ruleName = null; ruleParameter = null; ruleClass = null; ruleId = null; rule.SourceLocation = sourceLocation; continue; default: throw new EndUserParseException(token, _filename, "PSP 101", "Expected one of '.' , '#' , '[' or '{{' ." ); } case ParseState.SelectorDot: switch (token.Type) { case TokenType.Identifier: ruleClass = token.Data; state = ParseState.Selector; continue; default: throw new EndUserParseException(token, _filename, "PSP 102", "Expected identifier"); } case ParseState.SelectorPound: switch (token.Type) { case TokenType.Identifier: ruleId = token.Data; state = ParseState.Selector; continue; default: throw new EndUserParseException(token, _filename, "PSP 103", "Expected identifier"); } case ParseState.InRule: switch (token.Type) { case TokenType.Semicolon: // extra semicolons are tolerated. continue; case TokenType.StringLiteral: case TokenType.Identifier: propertyName = token.Data; state = ParseState.HavePropertyName; sourceLocation = new SourceLocation { Row = token.Row, Column = token.Column, SourceFile = _filename, }; continue; case TokenType.CloseBrace: // this rule is DONE. rule = null; // set this to null, so that we don't accidentally add new stuff to this rule. state = ParseState.Global; continue; default: throw new EndUserParseException(token, _filename, "PSP 104", "In rule, expected semi-colon ';', close-brace '}}' or value." ); } case ParseState.HavePropertyName: switch (token.Type) { case TokenType.Colon: state = ParseState.HavePropertySeparator; property = rule.GetRuleProperty(propertyName); continue; default: throw new EndUserParseException(token, _filename, "PSP 105", "Found rule property name, expected colon ':'." ); } case ParseState.HavePropertySeparator: switch (token.Type) { case TokenType.StringLiteral: case TokenType.NumericLiteral: state = ParseState.HavePropertyLabel; if ("@Literal" == token.RawData) { propertyLabelText = token.Data; } else { propertyLabelText = token.Data; } continue; case TokenType.Identifier: state = ParseState.HavePropertyLabel; propertyLabelText = token.Data; continue; case TokenType.OpenBrace: state = ParseState.InPropertyCollectionWithoutLabel; continue; default: throw new EndUserParseException(token, _filename, "PSP 106", "After rule property name, expected value, open-brace '{{' or open-parenthesis '('." ); } case ParseState.InPropertyCollectionWithoutLabel: switch (token.Type) { case TokenType.StringLiteral: case TokenType.NumericLiteral: case TokenType.Identifier: // at this point it could be a collection, a label, or a value. presentlyUnknownValue = token.Data; state = ParseState.InPropertyCollectionWithoutLabelButHaveSomething; continue; case TokenType.CloseBrace: // state = ParseState.HavePropertyCompleted; // this makes the semicolon optional. state = ParseState.InRule; continue; case TokenType.OpenParenthesis: state = ParseState.OpenBraceExpectingMultidimesionalLamda; multidimensionalLambda = new XList<string>(); continue; default: throw new EndUserParseException(token, _filename, "PSP 107", "In property collection, expected value or close brace '}}'"); } case ParseState.OpenBraceExpectingMultidimesionalLamda: switch( token.Type) { case TokenType.StringLiteral: case TokenType.NumericLiteral: case TokenType.Identifier: // looks like we have the name of a collection for a multidimensional lambda multidimensionalLambda.Add( token.Data); state = ParseState.HasMultidimensionalLambdaIdentifier; continue; default: throw new EndUserParseException(token, _filename, "PSP 124", "In multidimensional lambda declaration, expected identifier, found '{0}'", token.Data); } case ParseState.HasMultidimensionalLambdaIdentifier: switch( token.Type) { case TokenType.Comma: state = ParseState.OpenBraceExpectingMultidimesionalLamda; continue; case TokenType.CloseParenthesis: state = ParseState.NextTokenBetterBeLambda; continue; default: throw new EndUserParseException(token, _filename, "PSP 125", "In multidimensional lambda declaration, expected close parenthesis or comma, found '{0}'", token.Data); } case ParseState.NextTokenBetterBeLambda: switch( token.Type ) { case TokenType.Lambda: // we already knew that it was going to be this. // the collection has all the appropriate values. presentlyUnknownValue = null; state = ParseState.HasLambda; continue; default: throw new EndUserParseException(token, _filename, "PSP 125", "Expected lambda '=>' found '{0}'", token.Data); } case ParseState.InPropertyCollectionWithoutLabelButHaveSomething: switch (token.Type) { case TokenType.Lambda: multidimensionalLambda = new XList<string> {presentlyUnknownValue}; presentlyUnknownValue = null; state = ParseState.HasLambda; continue; case TokenType.Equal: // looks like it's gonna be a label = value type. propertyLabelText = presentlyUnknownValue; presentlyUnknownValue = null; state = ParseState.HasEqualsInCollection; continue; case TokenType.Comma: { // turns out its a simple collection item. var pv = property.GetPropertyValue(string.Empty); pv.Add(presentlyUnknownValue); pv.SourceLocation = sourceLocation; presentlyUnknownValue = null; state = ParseState.InPropertyCollectionWithoutLabel; } continue; case TokenType.CloseBrace: { // turns out its a simple collection item. var pv = property.GetPropertyValue(string.Empty); pv.Add(presentlyUnknownValue); pv.SourceLocation = sourceLocation; presentlyUnknownValue = null; // state = ParseState.HavePropertyCompleted; // this makes the semicolon optional. state = ParseState.InRule; } continue; default: throw new EndUserParseException(token, _filename, "PSP 114", "after an value or identifier in a collection expected a '=>' or '=' or ',' ."); } case ParseState.HasEqualsInCollection : switch (token.Type) { case TokenType.StringLiteral: case TokenType.NumericLiteral: case TokenType.Identifier: { var pv = property.GetPropertyValue(propertyLabelText); pv.Add(token.Data); pv.SourceLocation = sourceLocation; state = ParseState.InPropertyCollectionWithoutLabelWaitingForComma; } continue; case TokenType.OpenBrace: state = ParseState.InPropertyCollectionWithLabel; continue; default: throw new EndUserParseException(token, _filename, "PSP 119", "after an equals '=' in a collection, expected a value or identifier."); } case ParseState.HasLambda: switch (token.Type) { case TokenType.StringLiteral: case TokenType.NumericLiteral: case TokenType.Identifier: propertyLabelText = token.Data; state = ParseState.HasLambdaAndLabel; continue; default: throw new EndUserParseException(token, _filename, "PSP 115", "After the '=>' in a collection, expected value or identifier."); } case ParseState.HasLambdaAndLabel: switch (token.Type) { case TokenType.Equal: state = ParseState.HasLambdaAndLabelAndEquals; continue; case TokenType.Semicolon: case TokenType.Comma : case TokenType.CloseBrace: { // assumes "${DEFAULTLAMBDAVALUE}" for the lamda value /* ORIG: var pv = property.GetPropertyValue(propertyLabelText, multidimensionalLambda); pv.Add("${DEFAULTLAMBDAVALUE}"); */ var pv = property.GetPropertyValue("", multidimensionalLambda); pv.Add(propertyLabelText); pv.SourceLocation = sourceLocation; propertyLabelText = null; multidimensionalLambda = null; state = ParseState.InPropertyCollectionWithoutLabelWaitingForComma; } if (token.Type == TokenType.CloseBrace) { // and, we're closing out this property. // state = ParseState.HavePropertyCompleted; // this makes the semicolon optional. state = ParseState.InRule; } continue; default: throw new EndUserParseException(token, _filename, "PSP 116", "After the '{0} => {1}' in collection, expected '=' ", multidimensionalLambda.Aggregate("(", (current,each) => current+", "+each)+")" , propertyLabelText); } case ParseState.HasLambdaAndLabelAndEquals: switch (token.Type) { case TokenType.StringLiteral: case TokenType.NumericLiteral: case TokenType.Identifier: { var pv = property.GetPropertyValue(propertyLabelText, multidimensionalLambda); pv.Add(token.Data); pv.SourceLocation = sourceLocation; propertyLabelText = null; multidimensionalLambda = null; state = ParseState.InPropertyCollectionWithoutLabelWaitingForComma; } continue; default: throw new EndUserParseException(token, _filename, "PSP 117", "After the '{0} => {1} = ' in collection, expected a value or identifier", multidimensionalLambda.Aggregate("(", (current, each) => current + ", " + each) + ")", propertyLabelText); } case ParseState.InPropertyCollectionWithoutLabelWaitingForComma: switch (token.Type) { case TokenType.Comma: case TokenType.Semicolon: state = ParseState.InPropertyCollectionWithoutLabel; continue; case TokenType.CloseBrace: // state = ParseState.HavePropertyCompleted; // this makes the semicolon optional. state = ParseState.InRule; continue; default: throw new EndUserParseException(token, _filename, "PSP 118", "After complete expression or value in a collection, expected ',' or '}}'."); } case ParseState.InPropertyCollectionWithLabel: switch (token.Type) { case TokenType.StringLiteral: case TokenType.NumericLiteral: case TokenType.Identifier: presentlyUnknownValue = token.Data; state = ParseState.HaveCollectionValue; continue; case TokenType.CloseBrace: //state = ParseState.HavePropertyCompleted; // this makes the semicolon optional. state = ParseState.InPropertyCollectionWithoutLabelWaitingForComma; continue; default: throw new EndUserParseException(token, _filename, "PSP 107", "In property collection, expected value or close brace '}}'" ); } case ParseState.HaveCollectionValue: switch (token.Type) { case TokenType.Semicolon: case TokenType.Comma: { var pv = property.GetPropertyValue(propertyLabelText); pv.Add(presentlyUnknownValue); pv.SourceLocation = sourceLocation; // propertyLabelText = null; state = ParseState.InPropertyCollectionWithLabel; } continue; case TokenType.CloseBrace: { var pv = property.GetPropertyValue(propertyLabelText); pv.Add(presentlyUnknownValue); pv.SourceLocation = sourceLocation; propertyLabelText = null; // state = ParseState.HavePropertyCompleted; // this makes the semicolon optional. state = ParseState.InRule; } continue; default: throw new EndUserParseException(token, _filename, "PSP 108", "With property collection value, expected comma ',' or close-brace '}}'."); } case ParseState.HavePropertyLabel: switch (token.Type) { case TokenType.Equal: state = ParseState.HavePropertyEquals; continue; case TokenType.Dot: var t = SkipToNext(ref enumerator); if( !t.HasValue ) { throw new EndUserParseException(token, _filename, "PSP 109", "Unexpected end of Token stream [HavePropertyLabel]"); } token = t.Value; if (token.Type == TokenType.Identifier || token.Type == TokenType.NumericLiteral) { propertyLabelText += "." + token.Data; } else throw new EndUserParseException(token, _filename, "PSP 110", "Expected identifier or numeric literal after Dot '.'."); continue; case TokenType.Semicolon: { // it turns out that what we thought the label was, is really the property value, // the label is an empty string var pv = property.GetPropertyValue(string.Empty); pv.Add(propertyLabelText); pv.SourceLocation = sourceLocation; propertyName = propertyLabelText = null; state = ParseState.InRule; } continue; default: throw new EndUserParseException(token, _filename, "PSP 111", "After property value, expected semi-colon ';' or equals '='." ); } case ParseState.HavePropertyEquals: switch (token.Type) { case TokenType.Identifier: case TokenType.StringLiteral: case TokenType.NumericLiteral: { // found our property-value. add it, and move along. var pv = property.GetPropertyValue(propertyLabelText); pv.Add(token.Data); pv.SourceLocation = sourceLocation; propertyName = propertyLabelText = null; state = ParseState.HavePropertyCompleted; } continue; case TokenType.OpenBrace: // we're starting a new collection (where we have the label already). state = ParseState.InPropertyCollectionWithLabel; continue; default: throw new EndUserParseException(token, _filename, "PSP 112", "After equals in property, expected value or close-brace '{B{'." ); } case ParseState.HavePropertyCompleted: switch (token.Type) { case TokenType.CloseBrace: case TokenType.Semicolon: state = ParseState.InRule; continue; default: throw new EndUserParseException(token, _filename, "PSP 113", "After property completed, expected semi-colon ';'."); } default: throw new EndUserParseException(token, _filename, "PSP 120", "CATS AND DOGS, LIVINGTOGETHER..."); } } while (enumerator.MoveNext()); return _propertySheet; }
protected PropertySheet Parse() { var tokenStream = PropertySheetTokenizer.Tokenize(_propertySheetText); var state = ParseState.Global; var enumerator = tokenStream.GetEnumerator(); var importFilename = string.Empty; // var startFolder = System.Environment.CurrentDirectory; var startFolder = Path.GetDirectoryName(_filename.GetFullPath()); // first, check for a .user file to auto-import if (!string.IsNullOrEmpty(_filename)) { var userSheetFilename = Path.Combine(startFolder, Path.GetFileName(_filename.GetFullPath()) + ".user"); if (File.Exists(userSheetFilename)) { _propertySheet.UserOverride = ParseIncludedSheet(null, userSheetFilename, File.ReadAllText(userSheetFilename)); } } Token token; Rule rule = null; string ruleName = "*"; string ruleParameter = null; string ruleClass = null; string ruleId = null; // PropertyRule property = null; var sourceLocation = new SourceLocation { Row = 0, Column = 0, SourceFile = null, }; string propertyName = null; string propertyLabelText = null; string presentlyUnknownValue = null; // string collectionName = null; List <string> multidimensionalLambda = null; enumerator.MoveNext(); do { token = enumerator.Current; switch (token.Type) { // regardless where we are, skip over whitespace, etc. case TokenType.WhiteSpace: case TokenType.LineComment: case TokenType.MultilineComment: continue; } switch (state) { case ParseState.Global: sourceLocation = new SourceLocation { // will be the start of the next new rule. Row = token.Row, Column = token.Column, SourceFile = _filename, }; switch (token.Type) { case TokenType.Identifier: // look for identifier as the start of a selector if (token.Data == "@import") { // special case to handle @import rules state = ParseState.Import; continue; } state = ParseState.Selector; ruleName = token.Data; continue; case TokenType.Dot: state = ParseState.SelectorDot; ruleName = "*"; // take next identifier as the classname continue; case TokenType.Pound: state = ParseState.SelectorPound; ruleName = "*"; // take next identifier as the id continue; case TokenType.Semicolon: // tolerate extra semicolons. continue; default: throw new EndUserParseException(token, _filename, "PSP 100", "Expected one of '.' , '#' or identifier"); } case ParseState.Import: switch (token.Type) { case TokenType.StringLiteral: case TokenType.Identifier: state = ParseState.ImportFilename; importFilename = token.Data; continue; default: throw new EndUserParseException(token, _filename, "PSP 121", "Expected a string literal for filename (Missing semicolon?)"); } case ParseState.ImportFilename: switch (token.Type) { case TokenType.Semicolon: if (!Import(importFilename, startFolder)) { throw new EndUserParseException(token, _filename, "PSP 122", "Imported file '{0}' not found", importFilename); } state = ParseState.Global; continue; default: throw new EndUserParseException(token, _filename, "PSP 121", "Expected a string literal for filename"); } case ParseState.Selector: switch (token.Type) { case TokenType.Dot: state = ParseState.SelectorDot; continue; case TokenType.Pound: state = ParseState.SelectorPound; continue; case TokenType.SelectorParameter: ruleParameter = token.Data; if (ruleParameter.IndexOfAny("\r\n".ToCharArray()) >= 0) { throw new EndUserParseException(token, _filename, "PSP 123", "Selector parameter may not contain CR/LFs (missing close bracket?): {0} ", Rule.CreateSelectorString(ruleName, ruleParameter, ruleClass, ruleId)); } continue; case TokenType.OpenBrace: state = ParseState.InRule; rule = _propertySheet[ruleName, ruleParameter, ruleClass, ruleId]; ruleName = null; ruleParameter = null; ruleClass = null; ruleId = null; rule.SourceLocation = sourceLocation; continue; default: throw new EndUserParseException(token, _filename, "PSP 101", "Expected one of '.' , '#' , '[' or '{{' ."); } case ParseState.SelectorDot: switch (token.Type) { case TokenType.Identifier: ruleClass = token.Data; state = ParseState.Selector; continue; default: throw new EndUserParseException(token, _filename, "PSP 102", "Expected identifier"); } case ParseState.SelectorPound: switch (token.Type) { case TokenType.Identifier: ruleId = token.Data; state = ParseState.Selector; continue; default: throw new EndUserParseException(token, _filename, "PSP 103", "Expected identifier"); } case ParseState.InRule: switch (token.Type) { case TokenType.Semicolon: // extra semicolons are tolerated. continue; case TokenType.StringLiteral: case TokenType.Identifier: propertyName = token.Data; state = ParseState.HavePropertyName; sourceLocation = new SourceLocation { Row = token.Row, Column = token.Column, SourceFile = _filename, }; continue; case TokenType.CloseBrace: // this rule is DONE. rule = null; // set this to null, so that we don't accidentally add new stuff to this rule. state = ParseState.Global; continue; default: throw new EndUserParseException(token, _filename, "PSP 104", "In rule, expected semi-colon ';', close-brace '}}' or value."); } case ParseState.HavePropertyName: switch (token.Type) { case TokenType.Colon: state = ParseState.HavePropertySeparator; // property = rule.GetPropertyRule(propertyName); continue; default: throw new EndUserParseException(token, _filename, "PSP 105", "Found rule property name, expected colon ':'."); } case ParseState.HavePropertySeparator: switch (token.Type) { case TokenType.StringLiteral: case TokenType.NumericLiteral: state = ParseState.HavePropertyLabel; if ("@Literal" == token.RawData) { propertyLabelText = token.Data; } else { propertyLabelText = token.Data; } continue; case TokenType.Identifier: state = ParseState.HavePropertyLabel; propertyLabelText = token.Data; continue; case TokenType.OpenBrace: state = ParseState.InPropertyCollectionWithoutLabel; continue; default: throw new EndUserParseException(token, _filename, "PSP 106", "After rule property name, expected value, open-brace '{{' or open-parenthesis '('."); } case ParseState.InPropertyCollectionWithoutLabel: switch (token.Type) { case TokenType.StringLiteral: case TokenType.NumericLiteral: case TokenType.Identifier: { // at this point it could be a collection, a label, or a value. presentlyUnknownValue = token.Data; state = ParseState.InPropertyCollectionWithoutLabelButHaveSomething; // we're going to peek ahead and see if there is any characters we want to accept. (#.-+) var peek = enumerator; var cont = true; var okToTakeIdentifierOrNumeric = false; do { if (!peek.MoveNext()) { break; } // if we find a character that we consider to be ok for labels here, we're going to add it in, and consume the token. switch (peek.Current.Type) { case TokenType.Pound: case TokenType.Dot: case TokenType.Minus: case TokenType.MinusMinus: case TokenType.Plus: case TokenType.PlusPlus: enumerator.MoveNext(); presentlyUnknownValue = presentlyUnknownValue + enumerator.Current.Data; okToTakeIdentifierOrNumeric = true; break; case TokenType.NumericLiteral: case TokenType.Identifier: if (!okToTakeIdentifierOrNumeric) { cont = false; break; } enumerator.MoveNext(); presentlyUnknownValue = presentlyUnknownValue + enumerator.Current.Data; okToTakeIdentifierOrNumeric = false; break; default: cont = false; break; } } while (cont); } continue; case TokenType.CloseBrace: state = ParseState.HavePropertyCompleted; // this makes the semicolon optional. //state = ParseState.InRule; continue; case TokenType.OpenParenthesis: state = ParseState.OpenBraceExpectingMultidimesionalLamda; multidimensionalLambda = new XList <string>(); continue; default: throw new EndUserParseException(token, _filename, "PSP 107", "In property collection, expected value or close brace '}}'"); } case ParseState.OpenBraceExpectingMultidimesionalLamda: switch (token.Type) { case TokenType.StringLiteral: case TokenType.NumericLiteral: case TokenType.Identifier: // looks like we have the name of a collection for a multidimensional lambda multidimensionalLambda.Add(token.Data); state = ParseState.HasMultidimensionalLambdaIdentifier; continue; default: throw new EndUserParseException(token, _filename, "PSP 124", "In multidimensional lambda declaration, expected identifier, found '{0}'", token.Data); } case ParseState.HasMultidimensionalLambdaIdentifier: switch (token.Type) { case TokenType.Comma: state = ParseState.OpenBraceExpectingMultidimesionalLamda; continue; case TokenType.CloseParenthesis: state = ParseState.NextTokenBetterBeLambda; continue; default: throw new EndUserParseException(token, _filename, "PSP 125", "In multidimensional lambda declaration, expected close parenthesis or comma, found '{0}'", token.Data); } case ParseState.NextTokenBetterBeLambda: switch (token.Type) { case TokenType.Lambda: // we already knew that it was going to be this. // the collection has all the appropriate values. presentlyUnknownValue = null; state = ParseState.HasLambda; continue; default: throw new EndUserParseException(token, _filename, "PSP 125", "Expected lambda '=>' found '{0}'", token.Data); } case ParseState.InPropertyCollectionWithoutLabelButHaveSomething: switch (token.Type) { case TokenType.Lambda: multidimensionalLambda = new XList <string> { presentlyUnknownValue }; presentlyUnknownValue = null; state = ParseState.HasLambda; continue; case TokenType.Equal: // looks like it's gonna be a label = value type. propertyLabelText = presentlyUnknownValue; presentlyUnknownValue = null; state = ParseState.HasEqualsInCollection; continue; case TokenType.Comma: { // turns out its a simple collection item. var pv = rule.GetPropertyRule(propertyName).GetPropertyValue(string.Empty); pv.Add(presentlyUnknownValue); pv.SourceLocation = sourceLocation; presentlyUnknownValue = null; state = ParseState.InPropertyCollectionWithoutLabel; } continue; case TokenType.CloseBrace: { // turns out its a simple collection item. var pv = rule.GetPropertyRule(propertyName).GetPropertyValue(string.Empty); pv.Add(presentlyUnknownValue); pv.SourceLocation = sourceLocation; presentlyUnknownValue = null; // state = ParseState.HavePropertyCompleted; // this makes the semicolon optional. state = ParseState.InRule; } continue; case TokenType.OpenBracket: case TokenType.OpenBrace: case TokenType.OpenParenthesis: case TokenType.LessThan: // starting a new script block // presentlyUnknownValue is the script type // the content goes until the matching close token. continue; case TokenType.Identifier: case TokenType.NumericLiteral: case TokenType.StringLiteral: // starting a new script block // presentlyUnknownValue is the script type // the content of the string literal is the script content rule.AddScriptedPropertyRule(propertyName, presentlyUnknownValue, token.Data, token.Data); continue; default: string tokentext = token.RawData.ToString(); if (tokentext.Length == 1) { // starting a new script block // presentlyUnknownValue is the script type // the content goes until we see that same token again. continue; } throw new EndUserParseException(token, _filename, "PSP 114", "after an value or identifier in a collection expected a '=>' or '=' or ',' ."); } case ParseState.HasEqualsInCollection: switch (token.Type) { case TokenType.StringLiteral: case TokenType.NumericLiteral: case TokenType.Identifier: { var pv = rule.GetPropertyRule(propertyName).GetPropertyValue(propertyLabelText); pv.Add(token.Data); pv.SourceLocation = sourceLocation; state = ParseState.InPropertyCollectionWithoutLabelWaitingForComma; } continue; case TokenType.OpenBrace: state = ParseState.InPropertyCollectionWithLabel; continue; default: throw new EndUserParseException(token, _filename, "PSP 119", "after an equals '=' in a collection, expected a value or identifier."); } case ParseState.HasLambda: switch (token.Type) { case TokenType.StringLiteral: case TokenType.NumericLiteral: case TokenType.Identifier: propertyLabelText = token.Data; state = ParseState.HasLambdaAndLabel; continue; default: throw new EndUserParseException(token, _filename, "PSP 115", "After the '=>' in a collection, expected value or identifier."); } case ParseState.HasLambdaAndLabel: switch (token.Type) { case TokenType.Equal: state = ParseState.HasLambdaAndLabelAndEquals; continue; case TokenType.Semicolon: case TokenType.Comma: case TokenType.CloseBrace: { // assumes "${DEFAULTLAMBDAVALUE}" for the lamda value /* ORIG: * var pv = property.GetPropertyValue(propertyLabelText, multidimensionalLambda); * pv.Add("${DEFAULTLAMBDAVALUE}"); */ var pv = rule.GetPropertyRule(propertyName).GetPropertyValue("", multidimensionalLambda); pv.Add(propertyLabelText); pv.SourceLocation = sourceLocation; propertyLabelText = null; multidimensionalLambda = null; state = ParseState.InPropertyCollectionWithoutLabelWaitingForComma; } if (token.Type == TokenType.CloseBrace) { // and, we're closing out this property. // state = ParseState.HavePropertyCompleted; // this makes the semicolon optional. state = ParseState.InRule; } continue; default: throw new EndUserParseException(token, _filename, "PSP 116", "After the '{0} => {1}' in collection, expected '=' ", multidimensionalLambda.Aggregate("(", (current, each) => current + ", " + each) + ")", propertyLabelText); } case ParseState.HasLambdaAndLabelAndEquals: switch (token.Type) { case TokenType.StringLiteral: case TokenType.NumericLiteral: case TokenType.Identifier: { var pv = rule.GetPropertyRule(propertyName).GetPropertyValue(propertyLabelText, multidimensionalLambda); pv.Add(token.Data); pv.SourceLocation = sourceLocation; propertyLabelText = null; multidimensionalLambda = null; state = ParseState.InPropertyCollectionWithoutLabelWaitingForComma; } continue; default: throw new EndUserParseException(token, _filename, "PSP 117", "After the '{0} => {1} = ' in collection, expected a value or identifier", multidimensionalLambda.Aggregate("(", (current, each) => current + ", " + each) + ")", propertyLabelText); } case ParseState.InPropertyCollectionWithoutLabelWaitingForComma: switch (token.Type) { case TokenType.Comma: case TokenType.Semicolon: state = ParseState.InPropertyCollectionWithoutLabel; continue; case TokenType.CloseBrace: // state = ParseState.HavePropertyCompleted; // this makes the semicolon optional. state = ParseState.InRule; continue; default: throw new EndUserParseException(token, _filename, "PSP 118", "After complete expression or value in a collection, expected ',' or '}}'."); } case ParseState.InPropertyCollectionWithLabel: switch (token.Type) { case TokenType.StringLiteral: case TokenType.NumericLiteral: case TokenType.Identifier: presentlyUnknownValue = token.Data; state = ParseState.HaveCollectionValue; continue; case TokenType.CloseBrace: //state = ParseState.HavePropertyCompleted; // this makes the semicolon optional. state = ParseState.InPropertyCollectionWithoutLabelWaitingForComma; continue; default: throw new EndUserParseException(token, _filename, "PSP 107", "In property collection, expected value or close brace '}}'"); } case ParseState.HaveCollectionValue: switch (token.Type) { case TokenType.Semicolon: case TokenType.Comma: { var pv = rule.GetPropertyRule(propertyName).GetPropertyValue(propertyLabelText); pv.Add(presentlyUnknownValue); pv.SourceLocation = sourceLocation; // propertyLabelText = null; state = ParseState.InPropertyCollectionWithLabel; } continue; case TokenType.CloseBrace: { var pv = rule.GetPropertyRule(propertyName).GetPropertyValue(propertyLabelText); pv.Add(presentlyUnknownValue); pv.SourceLocation = sourceLocation; propertyLabelText = null; state = ParseState.HavePropertyCompleted; // this makes the semicolon optional. // state = ParseState.InRule; } continue; default: throw new EndUserParseException(token, _filename, "PSP 108", "With property collection value, expected comma ',' or close-brace '}}'."); } case ParseState.HavePropertyLabel: switch (token.Type) { case TokenType.Equal: state = ParseState.HavePropertyEquals; continue; case TokenType.Dot: var t = SkipToNext(ref enumerator); if (!t.HasValue) { throw new EndUserParseException(token, _filename, "PSP 109", "Unexpected end of Token stream [HavePropertyLabel]"); } token = t.Value; if (token.Type == TokenType.Identifier || token.Type == TokenType.NumericLiteral) { propertyLabelText += "." + token.Data; } else { throw new EndUserParseException(token, _filename, "PSP 110", "Expected identifier or numeric literal after Dot '.'."); } continue; case TokenType.Semicolon: { // it turns out that what we thought the label was, is really the property value, // the label is an empty string var pv = rule.GetPropertyRule(propertyName).GetPropertyValue(string.Empty); pv.Add(propertyLabelText); pv.SourceLocation = sourceLocation; propertyName = propertyLabelText = null; state = ParseState.InRule; } continue; default: throw new EndUserParseException(token, _filename, "PSP 111", "After property value, expected semi-colon ';' or equals '='."); } case ParseState.HavePropertyEquals: switch (token.Type) { case TokenType.Identifier: case TokenType.StringLiteral: case TokenType.NumericLiteral: { // found our property-value. add it, and move along. var pv = rule.GetPropertyRule(propertyName).GetPropertyValue(propertyLabelText); pv.Add(token.Data); pv.SourceLocation = sourceLocation; propertyName = propertyLabelText = null; state = ParseState.HavePropertyCompleted; } continue; case TokenType.OpenBrace: // we're starting a new collection (where we have the label already). state = ParseState.InPropertyCollectionWithLabel; continue; default: throw new EndUserParseException(token, _filename, "PSP 112", "After equals in property, expected value or close-brace '{B{'."); } case ParseState.HavePropertyCompleted: switch (token.Type) { case TokenType.CloseBrace: case TokenType.Semicolon: state = ParseState.InRule; continue; default: throw new EndUserParseException(token, _filename, "PSP 113", "After property completed, expected semi-colon ';'."); } default: throw new EndUserParseException(token, _filename, "PSP 120", "CATS AND DOGS, LIVINGTOGETHER..."); } } while (enumerator.MoveNext()); return(_propertySheet); }
public void DownloadFile(string url, string destination) { var response = Event<GetResponseInterface>.RaiseFirst(); if (response == null) { return; } _downloadQueue = _downloadQueue ?? new XList<Task<string>>(); _downloadQueue.Add(SessionData.Current.RequireRemoteFile(url, new Uri(url).SingleItemAsEnumerable(), PackageManagerSettings.CoAppCacheDirectory, false, rrfState => { if (rrfState == null || string.IsNullOrEmpty(rrfState.LocalLocation) || !File.Exists(rrfState.LocalLocation)) { // didn't fill in the local location? -- this happens when the client can't download. return null; } if (!rrfState.LocalLocation.Equals(destination, StringComparison.CurrentCultureIgnoreCase)) { File.Copy(rrfState.LocalLocation, destination); } return destination; }) as Task<string>); }
/// <summary> /// Starts the listener. /// </summary> /// <remarks> /// </remarks> private void StartListener() { if (_cancellationTokenSource.Token.IsCancellationRequested) { return; } try { if (IsRunning) { Logger.Message("Starting New Listener {0}", listenerCount++); var serverPipe = new NamedPipeServerStream(PipeName, PipeDirection.InOut, Instances, PipeTransmissionMode.Message, PipeOptions.Asynchronous, BufferSize, BufferSize, _pipeSecurity); nonConnectedListeners.Add(serverPipe); var listenTask = Task.Factory.FromAsync(serverPipe.BeginWaitForConnection, serverPipe.EndWaitForConnection, serverPipe); listenTask.ContinueWith(t => { nonConnectedListeners.Remove(serverPipe); if (t.IsCanceled || _cancellationTokenSource.Token.IsCancellationRequested || Signals.ShutdownRequested || Signals.ShuttingDown) { return; } StartListener(); // spawn next one! if (serverPipe.IsConnected) { var serverInput = new byte[BufferSize]; serverPipe.ReadAsync(serverInput, 0, serverInput.Length).AutoManage().ContinueWith(antecedent => { var rawMessage = Encoding.UTF8.GetString(serverInput, 0, antecedent.Result); if (string.IsNullOrEmpty(rawMessage)) { return; } var requestMessage = new UrlEncodedMessage(rawMessage); // first command must be "startsession" if (!requestMessage.Command.Equals("StartSession", StringComparison.CurrentCultureIgnoreCase)) { return; } // verify that user is allowed to connect. try { var hasAccess = false; serverPipe.RunAsClient(() => { hasAccess = PermissionPolicy.Connect.HasPermission; }); if (!hasAccess) { return; } } catch { return; } // check for the required parameters. // close the session if they are not here. if (string.IsNullOrEmpty(requestMessage["id"]) || string.IsNullOrEmpty(requestMessage["client"])) { return; } var isSync = requestMessage["async"].IsFalse(); if (isSync) { StartResponsePipeAndProcessMessages(requestMessage["client"], requestMessage["id"], serverPipe); } else { Session.Start(requestMessage["client"], requestMessage["id"], serverPipe, serverPipe); } }).Wait(); } }, _cancellationTokenSource.Token, TaskContinuationOptions.AttachedToParent, TaskScheduler.Current); } } catch /* (Exception e) */ { RequestStop(); } }
protected override XList <TopicLine> CreateTopicLines(MindMapLayoutArgs e, Topic beginTopic, Topic endTopic, Vector4 beginSide, Vector4 endSide) { XList <TopicLine> lines = new XList <TopicLine>(); var beginRect = beginTopic.Bounds; var endRect = endTopic.Bounds; if (e.ShowLineArrowCap) { endRect.Inflate(LineAnchorSize, LineAnchorSize); } if (beginTopic != null && !beginTopic.IsRoot) { int foldBtnSize = endTopic.FoldingButton.Width; switch (beginSide) { case Vector4.Left: break; case Vector4.Right: break; case Vector4.Top: beginRect.Y -= foldBtnSize; beginRect.Height += foldBtnSize; break; case Vector4.Bottom: beginRect.Height += foldBtnSize; break; } } if (beginTopic != null && endTopic != null && beginTopic.Type == TopicType.Barrier && beginTopic.IsParentOf(endTopic)) { beginRect.Y = beginTopic.ContentBounds.Bottom; beginRect.Height = 0; } if (endTopic != null) { if (endTopic.Type == TopicType.Threat || endTopic.Type == TopicType.Consequence || endTopic.Type == TopicType.Escalation) { endRect.Height = 60; // 60 is barrier height } else if (endTopic.Style.Shape == TopicShape.BaseLine) { endRect.Y = endRect.Bottom; endRect.Height = 0; } } TopicLine line; if (endTopic != null && beginTopic != null && endTopic.Type == TopicType.Barrier && (beginTopic.IsRoot || beginTopic.Type == TopicType.Barrier)) { endRect = endTopic.ContentBounds; endRect.Height = endTopic.Bounds.Height; line = new TopicLine(endTopic, beginSide, endSide, beginRect, endRect); lines.Add(line); beginRect = endRect; int left = beginRect.Left; if (beginSide == Vector4.Left) { left += beginRect.Width; } else if (beginSide == Vector4.Right) { left -= beginRect.Width; } beginRect.Location = new Point(left, beginRect.Y); endRect = endTopic.Bounds; } line = new TopicLine(endTopic, beginSide, endSide, beginRect, endRect); lines.Add(line); return(lines); }
XList <int> CalculateColumn(Topic parent, Topic[] children) { XList <int> listWidth = new XList <int>(); if (parent.Type == TopicType.Barrier) { listWidth.Add(parent.ContentBounds.Width); } int index = 0; for (int i = 0, count = children.Length; i <= count; ++i) { Topic subTopic = null; XList <int> subListWidth = new XList <int>(); if (i == count) { if (parent.Type != TopicType.Barrier && !parent.IsRoot) { subTopic = parent; subListWidth.Add(subTopic.ContentBounds.Width); } else { break; } } else { subTopic = children[i]; subListWidth = CalculateColumn(subTopic); } if (parent.Type == TopicType.Barrier) { index = 1; } if (parent.IsRoot) { index = 0; } for (int k = index, n = listWidth.Count; k < n; ++k) { if (k < subListWidth.Count) { listWidth[k] = Math.Max(subListWidth[k], listWidth[k]); } else { break; } } if (listWidth.Count < subListWidth.Count + index) { for (int k = listWidth.Count - index, n = subListWidth.Count; k < n; ++k) { listWidth.Add(subListWidth[k]); } } ++index; } return(listWidth); }
XList <int> CalculateRow(Topic parent, Topic[] children, MindMapLayoutArgs e) { XList <int> listHeight = new XList <int>(); if (!parent.IsRoot) { parent.TextSize = CalculateTextSize(parent, e); listHeight.Add(parent.ContentBounds.Height); } XList <int> prevSubListHeight = new XList <int>(); bool isIncrease = parent.IsRoot || parent.Type == TopicType.Barrier; int i = isIncrease ? 0 : children.Length - 1; while (i > -1 && i < children.Length) { Topic subTopic = children[i]; XList <int> subListHeight = CalculateRow(subTopic, e); if (subTopic.Type == TopicType.Barrier && prevSubListHeight.Count > 1) { prevSubListHeight.RemoveAt(0); if (subListHeight.IsEmpty) { subListHeight.AddRange(prevSubListHeight); } else { XList <int> savedList = subListHeight; subListHeight = new XList <int>(); subListHeight.Add(savedList[0]); subListHeight.AddRange(prevSubListHeight); savedList.RemoveAt(0); subListHeight.AddRange(savedList); } } if (parent.Type == TopicType.Barrier || parent.IsRoot) { // Append row listHeight.AddRange(subListHeight); } else { // Merge rows for (int k = 0, n = listHeight.Count; k < n; ++k) { if (k < subListHeight.Count) { listHeight[k] = Math.Max(subListHeight[k], listHeight[k]); } else { break; } } if (listHeight.Count < subListHeight.Count) { for (int k = listHeight.Count, n = subListHeight.Count; k < n; ++k) { listHeight.Add(subListHeight[k]); } } } prevSubListHeight = subListHeight; if (isIncrease) { ++i; } else { --i; } } return(listHeight); }
public void Add(float x, float y) { content.Add(new Vector2f((int)x / 30, (int)y / 30)); XList.Add((int)x / 30); YList.Add((int)y / 30); }