Пример #1
0
        public bool debugAssertIsValid(InformationCollector informationCollector = null)
        {
            D.assert(() => {
                var verify = new Action <bool, string>((bool check, string message) => {
                    if (check)
                    {
                        return;
                    }
                    var information = new StringBuilder();
                    if (informationCollector != null)
                    {
                        informationCollector(information);
                    }

                    throw new UIWidgetsError($"{this.GetType()} is not valid: {message}\n{information}");
                });

                verify(this.scrollExtent >= 0.0, "The \"scrollExtent\" is negative.");
                verify(this.paintExtent >= 0.0, "The \"paintExtent\" is negative.");
                verify(this.layoutExtent >= 0.0, "The \"layoutExtent\" is negative.");
                verify(this.cacheExtent >= 0.0, "The \"cacheExtent\" is negative.");
                if (this.layoutExtent > this.paintExtent)
                {
                    verify(false,
                           "The \"layoutExtent\" exceeds the \"paintExtent\".\n" +
                           _debugCompareFloats("paintExtent", this.paintExtent, "layoutExtent",
                                               this.layoutExtent)
                           );
                }

                if (this.maxPaintExtent < this.paintExtent)
                {
                    verify(false,
                           "The \"maxPaintExtent\" is less than the \"paintExtent\".\n" +
                           _debugCompareFloats("maxPaintExtent", this.maxPaintExtent, "paintExtent",
                                               this.paintExtent) +
                           "By definition, a sliver can\"t paint more than the maximum that it can paint!"
                           );
                }

                verify(this.hitTestExtent >= 0.0, "The \"hitTestExtent\" is negative.");
                verify(this.scrollOffsetCorrection != 0.0, "The \"scrollOffsetCorrection\" is zero.");
                return(true);
            });
            return(true);
        }
        public MultiFrameImageStreamCompleter(
            IPromise <Codec> codec,
            float scale,
            InformationCollector informationCollector = null
            )
        {
            D.assert(codec != null);

            this._scale = scale;
            this._informationCollector = informationCollector;

            codec.Then((Action <Codec>) this._handleCodecReady, ex => {
                this.reportError(
                    context: "resolving an image codec",
                    exception: ex,
                    informationCollector: informationCollector,
                    silent: true
                    );
            });
        }
Пример #3
0
        /*
         * 6. Затем идет поиск вхождения в строку из specwords
         * совпадение: 1 любое слово из паттерна, знаки препинания: на конце, заглавные буквы: нет
         * я меня мне мной.
         * Ты все время говоришь о себе.
         * уже.
         * Уже?
         */
        private string Stage_6(string str)
        {
            string results = Formatting(str, true);

            string[] split = results.Split(new Char[] { ' ' });

            foreach (string word in split)
            {
                string str_ = _sqlHand.GetBoltunData(Mode.LIKE, results, "specwords", word);

                string results_ = Formatting(str_).ToLower();

                if (results_ != string.Empty)
                {
                    InformationCollector.Log("stage: 6\ninput: " + str + "\noutput: " + str_);
                    return(str_);
                }
            }
            return(Stage_7(str));
        }
Пример #4
0
        protected void reportError(
            DiagnosticsNode context = null,
            Exception exception     = null,
            InformationCollector informationCollector = null,
            bool silent = false)
        {
            _currentError = new UIWidgetsErrorDetails(
                exception: exception,
                library: "image resource service",
                context: context,
                informationCollector: informationCollector,
                silent: silent
                );

            var localErrorListeners = LinqUtils <ImageErrorListener> .WhereList(
                LinqUtils <ImageErrorListener, ImageStreamListener> .SelectList(_listeners, (l => l.onError)),
                (l => l != null));

            if (localErrorListeners.isEmpty())
            {
                UIWidgetsError.reportError(_currentError);
            }
            else
            {
                foreach (var errorListener in localErrorListeners)
                {
                    try {
                        errorListener(exception);
                    }
                    catch (Exception ex) {
                        UIWidgetsError.reportError(
                            new UIWidgetsErrorDetails(
                                context: new ErrorDescription("when reporting an error to an image listener"),
                                library: "image resource service",
                                exception: ex
                                )
                            );
                    }
                }
            }
        }
Пример #5
0
        public MultiFrameImageStreamCompleter(
            Future <Codec> codec,
            float scale,
            InformationCollector informationCollector = null
            )
        {
            D.assert(codec != null);

            _scale = scale;
            _informationCollector = informationCollector;

            codec.then_((Action <Codec>)_handleCodecReady, ex => {
                reportError(
                    context: new ErrorDescription("resolving an image codec"),
                    exception: ex,
                    informationCollector: informationCollector,
                    silent: true
                    );
                return(FutureOr.nil);
            });
        }
        protected void reportError(
            string context      = null,
            Exception exception = null,
            InformationCollector informationCollector = null,
            bool silent = false)
        {
            this.currentError = new UIWidgetsErrorDetails(
                exception: exception,
                library: "image resource service",
                context: context,
                informationCollector: informationCollector,
                silent: silent
                );

            var localErrorListeners = this._listeners.Select(l => l.errorListener).Where(l => l != null).ToList();

            if (localErrorListeners.isEmpty())
            {
                UIWidgetsError.reportError(this.currentError);
            }
            else
            {
                foreach (var errorListener in localErrorListeners)
                {
                    try {
                        errorListener(exception);
                    }
                    catch (Exception ex) {
                        UIWidgetsError.reportError(
                            new UIWidgetsErrorDetails(
                                context: "when reporting an error to an image listener",
                                library: "image resource service",
                                exception: ex
                                )
                            );
                    }
                }
            }
        }
Пример #7
0
        public override bool debugAssertIsValid(
            bool isAppliedConstraint = false,
            InformationCollector informationCollector = null
            )
        {
            D.assert(() => {
                var verify = new Action <bool, string>((bool check, string message) => {
                    if (check)
                    {
                        return;
                    }

                    var information = new StringBuilder();
                    if (informationCollector != null)
                    {
                        informationCollector(information);
                    }

                    throw new UIWidgetsError(
                        $"{this.GetType()} is not valid: {message}\n{information}The offending constraints were: \n  {this}");
                });

                verify(this.scrollOffset >= 0.0f, "The \"scrollOffset\" is negative.");
                verify(this.crossAxisExtent >= 0.0f, "The \"crossAxisExtent\" is negative.");
                verify(
                    AxisUtils.axisDirectionToAxis(this.axisDirection) !=
                    AxisUtils.axisDirectionToAxis(this.crossAxisDirection),
                    "The \"axisDirection\" and the \"crossAxisDirection\" are along the same axis.");
                verify(this.viewportMainAxisExtent >= 0.0f, "The \"viewportMainAxisExtent\" is negative.");
                verify(this.remainingPaintExtent >= 0.0f, "The \"remainingPaintExtent\" is negative.");
                verify(this.remainingCacheExtent >= 0.0f, "The \"remainingCacheExtent\" is negative.");
                verify(this.cacheOrigin <= 0.0f, "The \"cacheOrigin\" is positive.");
                verify(this.isNormalized, "The constraints are not normalized.");
                return(true);
            });

            return(true);
        }
Пример #8
0
        public string GetVideo(string chatId)
        {
            try
            {
                WebClient web = new WebClient();
                web.Encoding = Encoding.GetEncoding(1251);

                string source = web.DownloadString(_urlList[chatId][RNG.Next(0, _urlList[chatId].Count)]);

                var arr = Regex.Matches(source, @"href=""(/.+)""\s*class=""(?:.+)""\s*data-sessionlink=""(?:.+)""\s*dir=""(?:.+)"">(?:.+)</a>", RegexOptions.IgnoreCase)
                          .Cast <Match>()
                          .Select(m => "http://www.youtube.com" + m.Groups[1].Value)
                          .ToArray();

                for (int i = 0; ; i++)
                {
                    string url = arr[RNG.Next(1, arr.Length)];

                    if (!CheckBlacklist(url, chatId) && url.Length < 50)   // && защита от случая, когда парсер вместе с ссылкой хватает кусок кода
                    {
                        AddBlacklist(url, chatId);

                        return(GetText(url, chatId));
                    }
                    else if (i == arr.Length)   // если все ролики из выдачи поиска на первой внезапно окажутся в блэклисте, дропаем цикл
                    {
                        return(string.Empty);
                    }
                }
            }
            catch (Exception e)
            {
                InformationCollector.Error(this, e.Message);
                return(string.Empty);
            }
        }
Пример #9
0
        void _executeTimingsCallbacks(List <FrameTiming> timings)
        {
            var clonedCallbacks =
                new List <TimingsCallback>(collection: _timingsCallbacks);

            foreach (var callback in clonedCallbacks)
            {
                try {
                    if (_timingsCallbacks.Contains(item: callback))
                    {
                        callback(timings: timings);
                    }
                }
                catch (Exception ex) {
                    InformationCollector collector = null;
                    D.assert(() => {
                        IEnumerable <DiagnosticsNode> infoCollect()
                        {
                            yield return(new DiagnosticsProperty <TimingsCallback>(
                                             "The TimingsCallback that gets executed was",
                                             value: callback,
                                             style: DiagnosticsTreeStyle.errorProperty));
                        }

                        collector = infoCollect;
                        return(true);
                    });

                    UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                                   exception: ex,
                                                   context: new ErrorDescription("while executing callbacks for FrameTiming"),
                                                   informationCollector: collector
                                                   ));
                }
            }
        }
Пример #10
0
        public override bool Connect(SkyBot handle)
        {
            Status = APIStatus.Connecting;
            base.Connect(handle);

            token = Config.Read("Discord", "token");

            bool result = false;

            api = new DiscordClient(new DiscordConfig()
            {
                AutoReconnect = true,
                Token         = token,
            });

            try
            {
                api.MessageCreated += new EventHandler <MessageCreateEventArgs>(ReceiveMessages);
                api.Connect();
                result = true;
            }
            catch (Exception ex)
            {
                InformationCollector.Error(this, ex.Message);
                return(false);
            }

            if (result)
            {
                Status = APIStatus.Connected;
                Parent.UI.discordStatus.Text      = Status.ToString();
                Parent.UI.discordStatus.ForeColor = System.Drawing.Color.Green;
            }

            return(result);
        }
Пример #11
0
        public void notifyStatusListeners(AnimationStatus status)
        {
            var localListeners = new List <AnimationStatusListener>(_statusListeners);

            foreach (AnimationStatusListener listener in localListeners)
            {
                try {
                    if (_statusListeners.Contains(listener))
                    {
                        listener(status);
                    }
                } catch (Exception exception) {
                    InformationCollector collector = null;
                    D.assert(() => {
                        IEnumerable <DiagnosticsNode> infoCollector()
                        {
                            yield return(new DiagnosticsProperty <AnimationLocalStatusListenersMixinAnimationLocalListenersMixinAnimationEagerListenerMixinAnimation <T> >(
                                             "The " + GetType() + " notifying status listeners was",
                                             this,
                                             style: DiagnosticsTreeStyle.errorProperty
                                             ));
                        }

                        collector = infoCollector;
                        return(true);
                    });

                    UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                                   exception: exception,
                                                   library: "animation library",
                                                   context: new ErrorDescription("while notifying status listeners for " + GetType()),
                                                   informationCollector: collector
                                                   ));
                }
            }
        }
Пример #12
0
        public override bool debugAssertIsValid(
            bool isAppliedConstraint = false,
            InformationCollector informationCollector = null
            )
        {
            D.assert(() => {
                bool hasErrors             = false;
                StringBuilder errorMessage = new StringBuilder("\n");
                var verify = new Action <bool, string>((bool check, string message) => {
                    if (check)
                    {
                        return;
                    }
                    hasErrors = true;
                    errorMessage.AppendLine($"  {message}");
                });
                void verifyFloat(float?property, string name, bool mustBePositive = false, bool mustBeNegative = false)
                {
                    verify(property != null, $"The \"{name}\" is null.");
                    if (property.Value.isNaN())
                    {
                        string additional = ".";
                        if (mustBePositive)
                        {
                            additional = ", expected greater than or equal to zero.";
                        }
                        else if (mustBeNegative)
                        {
                            additional = ", expected less than or equal to zero.";
                        }
                        verify(false, $"The \"{name}\" is NaN" + $"{additional}");
                    }
                    else if (mustBePositive)
                    {
                        verify(property >= 0.0f, $"The \"{name}\" is negative.");
                    }
                    else if (mustBeNegative)
                    {
                        verify(property <= 0.0f, $"The \"{name}\" is positive.");
                    }
                }
                verify(axis != null, "The \"axis\" is null.");
                verify(growthDirection != null, "The \"growthDirection\" is null.");
                verifyFloat(scrollOffset, "scrollOffset");
                verifyFloat(overlap, "overlap");
                verifyFloat(crossAxisExtent, "crossAxisExtent");
                verifyFloat(scrollOffset, "scrollOffset", mustBePositive: true);
                verify(crossAxisDirection != null, "The \"crossAxisDirection\" is null.");
                verify(AxisUtils.axisDirectionToAxis(axisDirection) != AxisUtils.axisDirectionToAxis(crossAxisDirection), "The \"axisDirection\" and the \"crossAxisDirection\" are along the same axis.");
                verifyFloat(viewportMainAxisExtent, "viewportMainAxisExtent", mustBePositive: true);
                verifyFloat(remainingPaintExtent, "remainingPaintExtent", mustBePositive: true);
                verifyFloat(remainingCacheExtent, "remainingCacheExtent", mustBePositive: true);
                verifyFloat(cacheOrigin, "cacheOrigin", mustBeNegative: true);
                verifyFloat(precedingScrollExtent, "precedingScrollExtent", mustBePositive: true);
                verify(isNormalized, "The constraints are not normalized."); // should be redundant with earlier checks


                if (hasErrors)
                {
                    List <DiagnosticsNode> diagnosticInfo = new List <DiagnosticsNode>();
                    diagnosticInfo.Add(new ErrorSummary($"{GetType()} is not valid: {errorMessage}"));
                    if (informationCollector != null)
                    {
                        diagnosticInfo.AddRange(informationCollector.Invoke());
                    }
                    diagnosticInfo.Add(new DiagnosticsProperty <SliverConstraints>("The offending constraints were", this, style: DiagnosticsTreeStyle.errorProperty));

                    throw new UIWidgetsError(diagnosticInfo);
                }
                return(true);
            });

            return(true);
        }
Пример #13
0
        public override bool Connect(SkyBot handle)
        {
            base.Connect(handle);
            Status = APIStatus.Connecting;
            Parent.UI.tgStatus.Text      = Status.ToString();
            Parent.UI.tgStatus.ForeColor = System.Drawing.Color.Yellow;

            token = Config.Read("Telegram", "token");

            try
            {
                // its outside of constructor to make creating child tg bots easier
                api = new TelegramBotClient(token);

                api.OnMessage             += ReceiveMessage;
                api.OnReceiveError        += OnError;
                api.OnReceiveGeneralError += OnError;
            }
            catch (Exception ex)
            {
                InformationCollector.Error(this, ex.Message);
            }

            receiveThread = new Thread(delegate()
            {
                try
                {
                    api.TestApiAsync();
                    api.StartReceiving();

                    if (api.IsReceiving)
                    {
                        InformationCollector.Info(this, "Receiving...");
                    }
                    else
                    {
                        InformationCollector.Error(this, "NOT receiving...");
                    }
                }
                catch (Exception ex)
                {
                    InformationCollector.Error(this, ex.Message);
                }
            });
            receiveThread.Start();

            bool result = receiveThread.IsAlive;

            if (result)
            {
                Status = APIStatus.Connected;
                Parent.UI.tgStatus.Text      = Status.ToString();
                Parent.UI.tgStatus.ForeColor = System.Drawing.Color.Green;
            }
            else
            {
                InformationCollector.Error(this, "receiveThread is NOT alive!");
                Disconnect();
            }

            return(result);
        }
Пример #14
0
 private void OnError(object sender, ReceiveGeneralErrorEventArgs receiveEventArgs)
 {
     InformationCollector.Error(this, receiveEventArgs.Exception.Message);
 }