private ResultField FetchColumnDefinition()
        {
            var item     = new ResultField();
            var packet   = Connection.ReadPacket();
            var position = 0;

            item.Catalog  = PacketReader.ReadStringLengthEncoded(packet, ref position, Options.Encoding);
            item.Schema   = PacketReader.ReadStringLengthEncoded(packet, ref position, Options.Encoding);
            item.Table    = PacketReader.ReadStringLengthEncoded(packet, ref position, Options.Encoding);
            item.OrgTable = PacketReader.ReadStringLengthEncoded(packet, ref position, Options.Encoding);
            item.Name     = PacketReader.ReadStringLengthEncoded(packet, ref position, Options.Encoding);
            item.OrgName  = PacketReader.ReadStringLengthEncoded(packet, ref position, Options.Encoding);

            PacketReader.ReadIntLengthEncoded(packet, ref position);

            item.CharSet     = PacketReader.ReadInt2(packet, ref position);
            item.FieldLength = (int)PacketReader.ReadInt4(packet, ref position);
            item.DataType    = (RawFieldType)PacketReader.ReadInt1(packet, ref position);
            item.Flags       = (ColumnFlags)PacketReader.ReadInt2(packet, ref position);
            item.Decimals    = PacketReader.ReadInt1(packet, ref position);

            item.InternalType = ResultField.DataTypeToInternalType(item.DataType, item.Flags);
            item.FieldType    = ResultField.InternalTypeToType(item.InternalType);

            return(item);
        }
Beispiel #2
0
        private void DoDecimalPressed()
        {
            if (IsLoading)
            {
                return;
            }

            if (_shouldClearOnNumberPress)
            {
                _shouldClearOnNumberPress = false;
                ResultField = "0";
            }

            if (_hasPendingOperation)
            {
                _hasPendingOperation = false;
                ResultField          = "0";
            }

            if (ResultField.Contains("."))
            {
                return;
            }

            ResultField += ".";
        }
Beispiel #3
0
        private ResultField XpathSelectLatinName(HtmlDocument doc, FieldSelector latinSelector)
        {
            if (String.IsNullOrWhiteSpace(latinSelector.Selector))
            {
                return(null);
            }
            var node  = doc.DocumentNode.SelectSingleNode(latinSelector.Selector);
            var field = new ResultField {
                Name = latinSelector.Selector, Value = node == null ? null : node.InnerText.Trim()
            };

            return(field);
        }
Beispiel #4
0
        private void DoToggleSignPressed()
        {
            if (IsLoading)
            {
                return;
            }

            if (ResultField.StartsWith("-"))
            {
                ResultField = ResultField.Substring(1);
            }
            else if ("0" != ResultField)
            {
                ResultField = "-" + ResultField;
            }
        }
Beispiel #5
0
        public ResultForm(BindingList <Player> players)
        {
            this.players = players;
            InitializeComponent();
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            this.MaximizeBox     = false;
            this.MinimizeBox     = false;

            List <Player> sortedList = players.OrderBy(o => o.balance).ToList();

            sortedList.Reverse();

            for (int i = 0; i < sortedList.Count; i++)
            {
                ResultField temp = new ResultField(i + 1, sortedList[i].name, sortedList[i].balance);
                resultpanel.Controls.Add(temp);
            }
        }
Beispiel #6
0
        void ReleaseDesignerOutlets()
        {
            if (GenerateButton != null)
            {
                GenerateButton.Dispose();
                GenerateButton = null;
            }

            if (ResultField != null)
            {
                ResultField.Dispose();
                ResultField = null;
            }

            if (WordField != null)
            {
                WordField.Dispose();
                WordField = null;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Run macro
        /// </summary>
        public async Task RunAsync()
        {
            if (!Ok)
            {
                return;
            }

            try {
                InitGlobals();
                await Run();
                await SwitchToWorkerThreadAsync();

                Result = ResultField.GetValue(null) as string;
                if (string.IsNullOrEmpty(Result))
                {
                    Result = MACRO_OK;
                }
            } catch (Exception e) {
                ErrorException(e);
            }
            UpdateGlobals();
        }
Beispiel #8
0
        /// <summary>
        /// Run macro
        /// </summary>
        public async Task RunAsync()
        {
            if (!Ok)
            {
                return;
            }

            if (string.IsNullOrEmpty(CSharpMethodCode))
            {
                return;
            }

            try {
                InitGlobalVars();
                await Run();
                await SwitchToWorkerThreadAsync();

                Result = ResultField.GetValue(null) as string;
            } catch (Exception e) {
                ErrorException(e);
            }
        }
Beispiel #9
0
        private void TodoBindingSource_CurrentChanged(object sender, EventArgs e)
        {
            CurrentStateField.SetDataBinding(todoBindingSource.Current, "CurrentState");
            DescriptionField.SetDataBinding(todoBindingSource.Current, "Description");
            ResultField.SetDataBinding(todoBindingSource.Current, "Result");
            PublicTextField.SetDataBinding(todoBindingSource.Current, "PublicText");

            if (todoBindingSource.Current is Todo)
            {
                Todo todo = (Todo)todoBindingSource.Current;
                toolStripLabel1.Text = todo.ShortDescription.Truncate(50);


                toolStripButtonIst.ForeColor       = Color.FromArgb(62, 62, 66);
                toolStripButtonSoll.ForeColor      = Color.FromArgb(62, 62, 66);
                toolStripButtonRecherche.ForeColor = Color.FromArgb(62, 62, 66);
                toolStripButtonResult.ForeColor    = Color.FromArgb(62, 62, 66);

                if (!string.IsNullOrEmpty(todo.CurrentState))
                {
                    toolStripButtonIst.ForeColor = Color.White;
                }
                if (!string.IsNullOrEmpty(todo.Description))
                {
                    toolStripButtonSoll.ForeColor = Color.White;
                }
                if (!string.IsNullOrEmpty(todo.Result))
                {
                    toolStripButtonRecherche.ForeColor = Color.White;
                }
                if (!string.IsNullOrEmpty(todo.PublicText))
                {
                    toolStripButtonResult.ForeColor = Color.White;
                }
            }
        }
Beispiel #10
0
        internal void SetBindingSources(object projectDataSource, object sprintDataSource, object taskDataSource)
        {
            this.todoBindingSource.DataSource   = taskDataSource;
            this.sprintBindingSource.DataSource = sprintDataSource;

            this.projectBindingSource.DataSource = projectDataSource;

            CurrentStateField.CustomEditor.HeaderText = "Ist Zustand";
            CurrentStateField.SetDataBinding(todoBindingSource.Current, "CurrentState");
            CurrentStateField.HeaderClicked += CurrentStateField_HeaderClicked;

            DescriptionField.CustomEditor.HeaderText = "Soll Zustand";
            DescriptionField.SetDataBinding(todoBindingSource.Current, "Description");
            DescriptionField.HeaderClicked += DescriptionField_HeaderClicked;

            ResultField.CustomEditor.HeaderText = "Recherche";
            ResultField.SetDataBinding(todoBindingSource.Current, "Result");
            ResultField.HeaderClicked += ResultField_HeaderClicked;

            PublicTextField.CustomEditor.HeaderText = "Resultat";
            PublicTextField.SetDataBinding(todoBindingSource.Current, "PublicText");
            PublicTextField.HeaderClicked += PublicTextField_HeaderClicked;

            List <CompletionItem> comletionList = new List <CompletionItem>();

            foreach (object obj in todoBindingSource.List)
            {
                Todo           task            = (Todo)obj;
                CompletionItem completionItem2 = new CompletionItem()
                {
                    DisplayText = task.ShortDescription, PopUpText = task.Description, ReplacementText = task.Id
                };
                comletionList.Add(completionItem2);

                CompletionItem completionItem = new CompletionItem()
                {
                    DisplayText = task.Id, PopUpText = task.ShortDescription
                };
                comletionList.Add(completionItem);
            }

            foreach (object obj in projectBindingSource.List)
            {
                Project        project         = (Project)obj;
                CompletionItem completionItem2 = new CompletionItem()
                {
                    DisplayText = project.ShortDescription, PopUpText = project.Description, ReplacementText = project.Id
                };
                comletionList.Add(completionItem2);
            }

            foreach (object obj in sprintBindingSource.List)
            {
                Sprint         sprint          = (Sprint)obj;
                CompletionItem completionItem2 = new CompletionItem()
                {
                    DisplayText = sprint.ShortDescription, PopUpText = sprint.Description, ReplacementText = sprint.Id
                };
                comletionList.Add(completionItem2);
            }

            todoBindingSource.CurrentChanged += TodoBindingSource_CurrentChanged;

            CurrentStateField.FillComletionList(comletionList);
        }
Beispiel #11
0
        void ReleaseDesignerOutlets()
        {
            if (Clear != null)
            {
                Clear.Dispose();
                Clear = null;
            }

            if (Decimal != null)
            {
                Decimal.Dispose();
                Decimal = null;
            }

            if (Divise != null)
            {
                Divise.Dispose();
                Divise = null;
            }

            if (Eight != null)
            {
                Eight.Dispose();
                Eight = null;
            }

            if (Equals != null)
            {
                Equals.Dispose();
                Equals = null;
            }

            if (Five != null)
            {
                Five.Dispose();
                Five = null;
            }

            if (Four != null)
            {
                Four.Dispose();
                Four = null;
            }

            if (Minus != null)
            {
                Minus.Dispose();
                Minus = null;
            }

            if (Multiply != null)
            {
                Multiply.Dispose();
                Multiply = null;
            }

            if (Nine != null)
            {
                Nine.Dispose();
                Nine = null;
            }

            if (One != null)
            {
                One.Dispose();
                One = null;
            }

            if (Plus != null)
            {
                Plus.Dispose();
                Plus = null;
            }

            if (ResultField != null)
            {
                ResultField.Dispose();
                ResultField = null;
            }

            if (Seven != null)
            {
                Seven.Dispose();
                Seven = null;
            }

            if (Six != null)
            {
                Six.Dispose();
                Six = null;
            }

            if (Three != null)
            {
                Three.Dispose();
                Three = null;
            }

            if (ToggleSign != null)
            {
                ToggleSign.Dispose();
                ToggleSign = null;
            }

            if (Two != null)
            {
                Two.Dispose();
                Two = null;
            }

            if (Zero != null)
            {
                Zero.Dispose();
                Zero = null;
            }
        }
        public static object Invoke(object that)
        {
            var xType = that.GetType();

            var xTypeBase = xType.BaseType;
            var xMe       = typeof(__ClientBase <>);


            // enter __ClientBase Channel { xType = JVMCLRWSDLMID.sk.DigiDocServicePortTypeClient }
            // enter __ClientBase Channel { xType = JVMCLRWSDLMID.sk.DigiDocServicePortTypeClient, xTypeBase = ScriptCoreLibJava.BCLImplementation.System.ServiceModel.__ClientBase_1, xMe = ScriptCoreLibJava.BCLImplementation.System.ServiceModel.__ClientBase_1 }
            // enter __ClientBase Channel { xType = JVMCLRWSDLMID.sk.DigiDocServicePortTypeClient, xTypeBase = ScriptCoreLibJava.BCLImplementation.System.ServiceModel.__ClientBase_1, xMe = ScriptCoreLibJava.BCLImplementation.System.ServiceModel.__ClientBase_1, xTypeInterface = JVMCLRWSDLMID.sk.DigiDocServicePortType }

            // magic. we just inferred what TChannel is!

            var xTypeInterface = xType.GetInterfaces().FirstOrDefault();


            //Y:\staging\web\java\ScriptCoreLibJava\BCLImplementation\System\ServiceModel\__ClientBaseGetChannel.java:57: error: illegal generic type for instanceof
            //        base_14 = ((((Object)that) instanceof  ScriptCoreLibJava.BCLImplementation.System.ServiceModel.__ClientBase_1<Object>) ? (ScriptCoreLibJava.BCLI

            //var xClientBase = that as __ClientBase<object>;
            var xClientBase = that as __ClientBase__remoteAddress;

            // , xClientBase = __ClientBase { __remoteAddress = https://tsp.demo.sk.ee:443 } }

            Console.WriteLine("enter __ClientBase Channel " + new { xType, xTypeBase, xMe, xTypeInterface, xClientBase });


            // return __ClientBase_1<TChannel>._get_Channel_b__1(proxy, method, args);

            var invocationHandler = new xHandler
            {
                vinvoke = (proxy, method, args) =>
                {
                    // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201510/20151005

                    var xMethod = new __MethodInfo {
                        InternalMethod = method
                    };


                    //   at ScriptCoreLib.Shared.BCLImplementation.System.Linq.__Enumerable.FirstOrDefault(__Enumerable.java:2016)
                    var arg1          = xMethod.GetParameters().FirstOrDefault();
                    var arg1value     = args.FirstOrDefault();
                    var arg1valueType = args.FirstOrDefault().GetType();



                    //Console.WriteLine("enter Proxy invocationHandler " + new { method = method.getName() });
                    //Console.WriteLine("enter Proxy invocationHandler " + new { xMethod.Name, xMethod.ReturnType, proxy, args });
                    Console.WriteLine("enter Proxy invocationHandler " + new { xMethod.Name, xMethod.ReturnType, arg1, arg1value, arg1valueType });

                    // which wsdl is in use?

                    var xMessageContractAttribute = default(__MessageContractAttribute);

                    foreach (var xCustomAttribute in arg1valueType.GetCustomAttributes(false))
                    {
                        var locMessageContractAttribute = xCustomAttribute as __MessageContractAttribute;
                        if (locMessageContractAttribute != null)
                        {
                            xMessageContractAttribute = locMessageContractAttribute;

                            Console.WriteLine(new { xMessageContractAttribute.WrapperName, xMessageContractAttribute.WrapperNamespace });
                        }
                    }



                    #region Envelope
                    var data = new StringBuilder();


                    data.Append(@"<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">");
                    data.Append(@"<s:Body s:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">");


                    data.Append(@"<q1:" + xMessageContractAttribute.WrapperName + @" xmlns:q1=""" + xMessageContractAttribute.WrapperNamespace + @""">");

                    // <q1:MobileAuthenticate xmlns:q1=""http://www.sk.ee/DigiDocService/DigiDocService_2_3.wsdl"">

                    foreach (var field in arg1valueType.GetFields())
                    {
                        var fieldvalue = field.GetValue(arg1value);

                        Console.WriteLine(new { field.Name, field.FieldType, fieldvalue });

                        //var x = new XElement(field.Name, fieldvalue).ToString();
                        var x = new XElement(field.Name, "" + fieldvalue).ToString();

                        if (field.FieldType == typeof(string))
                        {
                            x = x.Replace(@"<" + field.Name, @"<" + field.Name + @" xsi:type=""xsd:string""");
                        }
                        else if (field.FieldType == typeof(int))
                        {
                            x = x.Replace(@"<" + field.Name, @"<" + field.Name + @" xsi:type=""xsd:int""");
                        }
                        else if (field.FieldType == typeof(bool))
                        {
                            x = x.Replace(@"<" + field.Name, @"<" + field.Name + @" xsi:type=""xsd:boolean""");
                        }

                        data.Append(x);
                    }

                    data.Append(@"</q1:" + xMessageContractAttribute.WrapperName + @">");

                    data.Append(@"</s:Body>");
                    data.Append(@"</s:Envelope>");
                    #endregion



                    // <s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/""><s:Body s:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">

                    // <q1:MobileAuthenticate xmlns:q1=""http://www.sk.ee/DigiDocService/DigiDocService_2_3.wsdl"">

                    // <IDCode xsi:type=""xsd:string"">14212128025</IDCode>
                    // <CountryCode xsi:type=""xsd:string"">EE</CountryCode>
                    // <PhoneNo xsi:type=""xsd:string"">37200007</PhoneNo>
                    // <Language xsi:type=""xsd:string"">EST</Language>
                    // <ServiceName xsi:type=""xsd:string"">Testimine</ServiceName>
                    // <MessageToDisplay xsi:type=""xsd:string"">Testimine</MessageToDisplay>
                    // <SPChallenge xsi:type=""xsd:string"">03010400000000000000</SPChallenge>
                    // <MessagingMode xsi:type=""xsd:string"">asynchClientServer</MessagingMode>
                    // <AsyncConfiguration xsi:type=""xsd:int"">0</AsyncConfiguration>
                    // <ReturnCertData xsi:type=""xsd:boolean"">true</ReturnCertData>
                    //<ReturnRevocationData xsi:type=""xsd:boolean"">false</ReturnRevocationData>
                    // </q1:MobileAuthenticate>

                    // </s:Body></s:Envelope>

                    Console.WriteLine(new { data });


                    //{ WrapperName = MobileAuthenticate, WrapperNamespace = http://www.sk.ee/DigiDocService/DigiDocService_2_3.wsdl }
                    //{ Name = IDCode, fieldvalue = 14212128025 }
                    //{ Name = CountryCode, fieldvalue = EE }
                    //{ Name = PhoneNo, fieldvalue = 37200007 }
                    //{ Name = Language, fieldvalue = EST }
                    //{ Name = ServiceName, fieldvalue = Testimine }
                    //{ Name = MessageToDisplay, fieldvalue = Testimine }
                    //{ Name = SPChallenge, fieldvalue = 03010400000000000000 }
                    //{ Name = MessagingMode, fieldvalue = asynchClientServer }
                    //{ Name = AsyncConfiguration, fieldvalue = 0 }
                    //{ Name = ReturnCertData, fieldvalue = true }
                    //{ Name = ReturnRevocationData, fieldvalue = false }

                    // arg1 = ScriptCoreLibJava.BCLImplementation.System.Reflection.__ParameterInfo@1bb9a58, args = [Ljava.lang.Object;@1922f46 }
                    // enter Proxy invocationHandler { Name = JVMCLRWSDLMID_sk_DigiDocServicePortType_MobileAuthenticateAsync, ReturnType = ScriptCoreLibJava.BCLImplementation.System.Threading.Tasks.__Task_1,
                    // arg1 = ParameterInfo { Name = arg0, ParameterType = JVMCLRWSDLMID.sk.MobileAuthenticateRequest }, arg1value = JVMCLRWSDLMID.sk.MobileAuthenticateRequest@770d2e }


                    // JVMCLRWSDLMID.sk.MobileAuthenticateRequest
                    //System.Threading.Tasks.Task<JVMCLRWSDLMID.sk.MobileAuthenticateResponse> MobileAuthenticateAsync(JVMCLRWSDLMID.sk.MobileAuthenticateRequest request);

                    var xResponseTypeName = arg1.ParameterType.FullName.Replace("Request", "Response");
                    var xResponseType     = Type.GetType(xResponseTypeName);

                    Console.WriteLine(new { xResponseType });
                    // { xResponseType = JVMCLRWSDLMID.sk.MobileAuthenticateResponse }


                    // lets assume this was async call and we also know what the response will be.

                    var c = new TaskCompletionSource <object>();



                    var xPOST = new __WebClient();

                    xPOST.Headers["Content-Type"] = "text/xml; charset=UTF-8";
                    xPOST.Headers["SOAPAction"]   = "\"\"";


                    var xPOSTresponse = xPOST.UploadStringTaskAsync(
                        xClientBase.__remoteAddress.uri,
                        "POST",
                        data.ToString()
                        );


                    xPOSTresponse.ContinueWith(
                        task =>
                    {
                        if (string.IsNullOrEmpty(task.Result))
                        {
                            // fault?


                            c.SetResult(
                                null
                                );

                            return;
                        }

                        var Envelope = XElement.Parse(task.Result);
                        var Body     = Envelope.Elements().Skip(1).FirstOrDefault();
                        var Response = Body.Elements().FirstOrDefault();
                        var fields   = Response.Elements();


                        var Result = Activator.CreateInstance(xResponseType);

                        var ResultFields = xResponseType.GetFields(
                            global::System.Reflection.BindingFlags.DeclaredOnly | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Public);

                        foreach (var ResultField in ResultFields)
                        {
                            var ResultValueElement = fields.FirstOrDefault(x => x.Name.LocalName == ResultField.Name);
                            if (ResultValueElement == null)
                            {
                                Console.WriteLine(new { ResultField.Name, ResultField.FieldType });
                            }
                            else
                            {
                                // { Name = Sesscode, FieldType = int, IsInt = false, Value = 158266114 }
                                var IsInt = ResultField.FieldType == typeof(int);
                                if (IsInt)
                                {
                                    ResultField.SetValue(Result, int.Parse(ResultValueElement.Value));
                                }
                                else if (ResultField.FieldType == typeof(string))
                                {
                                    ResultField.SetValue(Result, ResultValueElement.Value);
                                }

                                Console.WriteLine(new { ResultField.Name, ResultField.FieldType, IsInt, ResultValueElement.Value });
                            }
                        }

                        c.SetResult(
                            Result
                            );
                    }
                        );



                    //                    enter Proxy invocationHandler { method = JVMCLRWSDLMID_sk_DigiDocServicePortType_MobileAuthenticateAsync }
                    //{ Message = , StackTrace = java.lang.NullPointerException
                    //        at JVMCLRWSDLMID.Program.main(Program.java:55)

                    // enter Proxy invocationHandler { Name = JVMCLRWSDLMID_sk_DigiDocServicePortType_MobileAuthenticateAsync, ReturnType = ScriptCoreLibJava.BCLImplementation.System.Threading.Tasks.__Task_1 }

                    // task of what?

                    //var value = Activator.CreateInstance(xMethod.ReturnType);

                    return(c.Task);

                    //return null;
                }
            };


            // how would this work from js?
            var p = java.lang.reflect.Proxy.newProxyInstance(
                xTypeInterface.ToClass().getClassLoader(),

                interfaces: new[] { xTypeInterface.ToClass() },
                invocationHandler: invocationHandler
                );

            return(p);
        }
Beispiel #13
0
        private void FindError(ResultField field, object nedvigimost, string ScriptName, string Url)
        {
            var        val   = nedvigimost.GetPropValue(field.EngName);
            ErrorTable error = new ErrorTable()
            {
                TypeError = 3, Script = ScriptName, Url = Url, Field = field.Name, ValueScript = "", DateException = DateTime.Now, Counter = 1
            };

            error.TypeError = -1;
            switch (field.Type)
            {
            case "Целое число":
                if (val == null)
                {
                    error.TypeError = field.Important? 1: 3;
                }
                else
                {
                    var valInt = (int)val;
                    if (valInt == -10000001)
                    {
                        error.TypeError = field.Important ? 6 : 2;
                    }
                }
                break;

            case "Число с плавающей точкой":
                if (val == null)
                {
                    error.TypeError = field.Important ? 1 : 3;
                }
                else
                {
                    var valDouble = (double)nedvigimost.GetPropValue(field.EngName);

                    if (Math.Abs(valDouble - (-10000001.0)) == 0)
                    {
                        error.TypeError = field.Important ? 6 : 2;
                    }
                }

                break;

            case "Строка":
                if (val == null)
                {
                    val = "";
                }
                var reg = new Regex("[a-zA-Z0-9_а-яА-Я]+");
                if (reg.Matches(val.ToString()).Count > 1)
                {
                    error = (new ErrorTable()
                    {
                        TypeError = 4,
                        Script = ScriptName,
                        Url = Url,
                        Field = field.Name,
                        ValueScript = "",
                        DateException = DateTime.Now, Counter = 1
                    });
                }
                break;

            case "Дата время":
                if (val == null)
                {
                    error.TypeError = field.Important ? 1 : 3;
                }
                var date = DateTime.MinValue;
                DateTime.TryParse(nedvigimost.GetPropValue(field.EngName)?.ToString(), out date);
                if (date == DateTime.MinValue)
                {
                    error.TypeError = field.Important ? 6 : 2;
                }
                break;

            case "URL":
                break;
            }
            if (error.TypeError != -1)
            {
                var err = ctx.ErrorTables.FirstOrDefault(
                    s => s.Script == error.Script && s.Field == error.Field &&
                    !s.Corrected && s.TypeError == error.TypeError);
                if (err != null)
                {
                    err.Counter = err.Counter + 1;
                }
                else
                {
                    ctx.ErrorTables.Add(error);
                }
            }
        }
Beispiel #14
0
 internal ResultFieldAccess(ResultType resultType, ResultField field)
 {
     this.resultType = resultType;
     this.field      = field;
 }
        private void searchFerryButton_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor = Cursors.WaitCursor;
                ferryLayer.Shapes.Clear();
                routeLayer.Shapes.Clear();

                if (string.IsNullOrEmpty(combinedTransportDepartureTextBox.Text))
                {
                    MessageBox.Show("You must fill in the combined transport departure. Only the arrival is optional");
                    return;
                }
                using (var xlocate = XWSClientFactory.GetXLocateWSClient(Properties.Settings.Default.XLocate, token))
                {
                    //geocode both cities, even if destiantion is left blank, i rather keep call numbers low to avoid extra latency
                    var addresses = new Address[]
                    {
                        new Address()
                        {
                            city = combinedTransportDepartureTextBox.Text
                        },
                        new Address()
                        {
                            city = combinedTransportArrivalTextBox.Text
                        },
                    };
                    var addressResponse = xlocate.findAddresses(addresses, null, null, null, null);
                    // check if we have found a start city else abort
                    if (addressResponse[0].wrappedResultList == null || addressResponse[0].wrappedResultList.Length == 0)
                    {
                        MessageBox.Show("Departure city not found");
                        return;
                    }

                    // search for ferrie near departure, use a max range to prevent huge list
                    var departureLocation = new Location()
                    {
                        coordinate = addressResponse[0].wrappedResultList[0].coordinates
                    };
                    var searchOptions = new ReverseSearchOption[]
                    {
                        new ReverseSearchOption()
                        {
                            param = ReverseSearchParameter.ENGINE_SEARCHRANGE,
                            value = Properties.Settings.Default.SeachRange.ToString(),
                        },
                    };
                    var resultFields = new ResultField[]
                    {
                        ResultField.ISBLOCKEDFORTRUCKS,
                        ResultField.ISBLOCKEDFORHAZARDOUSGOODS,
                        ResultField.ISBLOCKEDFORCOMBUSTIBLEGOODS,
                    };
                    var combinedTransportResponse = xlocate.findCombinedTransportByLocation(departureLocation, searchOptions, null, null);

                    var resultCombinedTransports = combinedTransportResponse.wrappedResultList.ToList();

                    // by default xlocate return all ferrie that have a start or end near the location
                    // we are only using the ones near the start, so filter on max range airline distance
                    resultCombinedTransports = resultCombinedTransports.Where(r =>
                                                                              Geotools.AirLineDistanceCalculator.CalculateUsingMercator(
                                                                                  r.start.coordinate.point,
                                                                                  addressResponse[0].wrappedResultList[0].coordinates.point)
                                                                              <= Properties.Settings.Default.SeachRange).ToList();

                    // if we have found a destination city, filter on ferries that have destination within max range airline
                    if (addressResponse[1].wrappedResultList != null && addressResponse[1].wrappedResultList.Length != 0)
                    {
                        resultCombinedTransports = resultCombinedTransports.Where(r =>
                                                                                  Geotools.AirLineDistanceCalculator.CalculateUsingMercator(
                                                                                      r.destination.coordinate.point,
                                                                                      addressResponse[1].wrappedResultList[0].coordinates.point)
                                                                                  <= Properties.Settings.Default.SeachRange).ToList();
                    }
                    // show the result
                    resultCombinedTransportBindingSource.DataSource = resultCombinedTransports;

                    // paint the results on the map
                    #region visualise
                    foreach (var resultCombinedTransport in resultCombinedTransports)
                    {
                        System.Windows.Point startPoint = new System.Windows.Point(
                            resultCombinedTransport.start.coordinate.point.x,
                            resultCombinedTransport.start.coordinate.point.y
                            );
                        System.Windows.Point endPoint = new System.Windows.Point(
                            resultCombinedTransport.destination.coordinate.point.x,
                            resultCombinedTransport.destination.coordinate.point.y
                            );

                        var line = new Ptv.XServer.Controls.Map.Layers.Shapes.MapPolyline()
                        {
                            MapStrokeThickness = 6,
                            Stroke             = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Blue),
                            Points             = new System.Windows.Media.PointCollection(),
                            ToolTip            = $"{resultCombinedTransport.name}\n{resultCombinedTransport.type}\n{resultCombinedTransport.duration}\n{resultCombinedTransport.distance}\n{resultCombinedTransport.id}",
                        };
                        line.Points.Add(startPoint);
                        line.Points.Add(endPoint);
                        ferryLayer.Shapes.Add(line);

                        var startBall = new Ptv.XServer.Controls.Map.Symbols.Ball()
                        {
                            Height  = 15,
                            Width   = 15,
                            Color   = System.Windows.Media.Colors.Green,
                            ToolTip = $"{resultCombinedTransport.start.country} - {resultCombinedTransport.start.name}",
                        };
                        Ptv.XServer.Controls.Map.Layers.Shapes.ShapeCanvas.SetLocation(startBall, startPoint);
                        ferryLayer.Shapes.Add(startBall);

                        var endBall = new Ptv.XServer.Controls.Map.Symbols.Ball()
                        {
                            Height  = 15,
                            Width   = 15,
                            Color   = System.Windows.Media.Colors.Red,
                            ToolTip = $"{resultCombinedTransport.destination.country} - {resultCombinedTransport.destination.name}",
                        };
                        Ptv.XServer.Controls.Map.Layers.Shapes.ShapeCanvas.SetLocation(endBall, endPoint);
                        ferryLayer.Shapes.Add(endBall);
                    }
                    map.WrappedMap.ZoomToAll();
                    #endregion
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, exception.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor = null;
            }
        }