private XElement GetReportSection(SectionTypeEnum sectionType, int sectionGroupIndex)
 {
     return(this.dataSections
            .Values
            .FirstOrDefault(si => si.Attribute("SectionType").Value.ToInt32() == (int)sectionType &&
                            si.Attribute("SectionGroupIndex").Value.ToInt32() == sectionGroupIndex));
 }
        private void CreateSinglePageCanvas(XElement canvasXml, SectionTypeEnum sectionType)
        {
            PrintCanvas result = new PrintCanvas
            {
                Width  = this.PageWidth,
                Height = this.PageHeight
            };

            foreach (XElement item in canvasXml.GetReportObjects())
            {
READD:
                double bottom = 0;

                string textOverflow = string.Empty;

                result.AddObject(item, sectionType, out bottom, out textOverflow);

                if (!textOverflow.IsNullEmptyOrWhiteSpace())
                {
                    item.Attribute("Text").Value = textOverflow;

                    this.AddCanvas(result);

                    result = new PrintCanvas
                    {
                        Width  = this.PageWidth,
                        Height = this.PageHeight
                    };

                    goto READD;
                }
            }

            this.AddCanvas(result);
        }
示例#3
0
 /// <summary>
 /// Вызов перелистывания scroll view к разделу с недостающей валютой
 /// </summary>
 /// <param name="sectionType"></param>
 public void StartMovement(SectionTypeEnum sectionType)
 {
     if (sectionNames.TryGetValue(sectionType, out string sectionName))
     {
         StartMovement(sectionName);
     }
     else
     {
         log.Error($"Не удалось начать перелистывание к секции sectionType {sectionType}. " +
                   $"Возможно секция не была инициализирована");
     }
 }
        public bool AddObject(XElement item, SectionTypeEnum sectionType, out double elementBottom, out string textOverflow)
        {
            UIElement element = ObjectCreator.CreateReportObject(item, false);

            double itemHeight = 0;

            if (item.IsDataObject())
            {
                this.MeasureDataElement(element, out itemHeight);
            }
            else
            {
                itemHeight = element.GetPropertyValue("TextHeight").ToDouble();
            }

            textOverflow = string.Empty;

            Canvas.SetLeft(element, element.GetPropertyValue("Left").ToDouble());

            Canvas.SetTop(element, (element.GetPropertyValue("Top").ToDouble() + this.TopOffset));

            this.Children.Add(element);

            elementBottom = Canvas.GetTop(element) + itemHeight;

            if (elementBottom > this.BottomOffset)
            {
                if (item.IsDataObject() && !this.TryTrimWrapedText(element, elementBottom, out textOverflow))
                {
                    this.Children.Remove(element);

                    elementBottom = 0;

                    return(false);
                }
                else if (!item.IsDataObject())
                {
                    this.Children.Remove(element);

                    elementBottom = 0;

                    return(false);
                }
            }

            this.HaveElements = true;

            return(true);
        }
示例#5
0
        public void ShowError(SectionTypeEnum sectionTypeEnum)
        {
            //скрыть меню подтверждения покупки
            lobbyEcsController.ClosePurchaseConfirmationWindow();
            //начать перелистывать на раздел с валютой
            scrollViewSmoothMovementBehaviour.StartMovement(sectionTypeEnum);
            //todo показать всплывающий текст ошибки

            switch (sectionTypeEnum)
            {
            case SectionTypeEnum.SoftCurrency:
                textTooltip.Show("Not enough coins.");
                break;

            case SectionTypeEnum.HardCurrency:
                textTooltip.Show("Not enough gems.");
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(sectionTypeEnum), sectionTypeEnum, null);
            }
        }
示例#6
0
 public Section(string id, SectionTypeEnum sectionType, int delayInMs)
 {
     this._id         = id;
     this.SectionType = sectionType;
     this.DelayInMs   = delayInMs;
 }
        public async void ProcessNode(JToken node, JToken section = null)
        {
            if (node == null)
            {
                return;
            }
            ClearButtonTimer();

            //Replaceing verbs
            node = JToken.Parse(VerbProcessor.Process(node.ToString()));

            var parsedNode = node.ToObject <ChatNode>();

            if (parsedNode.Buttons != null && parsedNode.Buttons.Count > 0)
            {
                ClearButtons();
            }

            if (parsedNode.NodeType == NodeTypeEnum.ApiCall)
            {
                ToggleTyping(true);
                try
                {
                    var paramDict = new Dictionary <string, object>();
                    foreach (var reqParam in parsedNode.RequiredVariables)
                    {
                        if (reqParam == "HISTORY") //Custom Variable
                        {
                            paramDict[reqParam] = ChatThread.Where(x => x.SectionType != SectionTypeEnum.Typing).ToArray();
                        }
                        else
                        {
                            paramDict[reqParam] = ButtonActionHelper.GetSavedValue(reqParam);
                        }
                    }
                    var nextNodeId = parsedNode.NextNodeId; //Default
                    switch (parsedNode.ApiMethod.ToUpper())
                    {
                    case "GET":
                    {
                        var query = string.Join("&", paramDict.Select(x => $"{x.Key}={Uri.EscapeDataString(x.Value + "")}"));
                        var api   = string.IsNullOrWhiteSpace(query) ? parsedNode.ApiUrl : parsedNode.ApiUrl + "?" + query;

                        var resp = await APIHelper.HitAsync <Dictionary <string, object> >(api);

                        if (resp.ContainsKey("NextNodeId"))
                        {
                            nextNodeId = resp["NextNodeId"] + "";
                        }
                        ButtonActionHelper.HandleSaveMultiple(resp);
                    }
                    break;

                    case "POST":
                    {
                        var resp = await APIHelper.HitPostAsync <Dictionary <string, object>, Dictionary <string, object> >(parsedNode.ApiUrl, paramDict);

                        if (resp.ContainsKey("NextNodeId"))
                        {
                            nextNodeId = resp["NextNodeId"] + "";
                        }
                    }
                    break;

                    default:
                        Utils.ShowDialog($"{parsedNode.ApiMethod} ApiType Unknown!");
                        break;
                    }
                    NavigateToNode(nextNodeId);
                }
                catch (HttpRequestException ex)
                {
                    ToggleTyping(false);
                    Utils.ShowDialog(ex.ToString());
                    NavigateToNode(parsedNode.NextNodeId);
                }
                catch (Exception ex)
                {
                    ToggleTyping(false);
                    Utils.ShowDialog(ex.ToString());
                    NavigateToNode(parsedNode.NextNodeId);
                }
            }
            else if (node["Sections"] == null || node["Sections"].Children().Count() == 0)
            {
                ToggleTyping(false);
                await ProcessButtonsAsync(node);
            }
            else if (node["Sections"] != null && node["Sections"].Children().Count() > 0)
            {
                var sectionsSource       = node["Sections"];
                var currentSectionSource = section ?? sectionsSource.First;

                //Replaceing verbs
                currentSectionSource = JToken.Parse(VerbProcessor.Process(currentSectionSource.ToString()));

                SectionTypeEnum secType       = (SectionTypeEnum)Enum.Parse(typeof(SectionTypeEnum), currentSectionSource["SectionType"].ToString());
                Section         parsedSection = null;
                bool            showTyping    = false;
                switch (secType)
                {
                case SectionTypeEnum.Image:
                    parsedSection = currentSectionSource.ToObject <ImageSection>();
                    showTyping    = true;
                    break;

                case SectionTypeEnum.Text:
                    parsedSection = currentSectionSource.ToObject <TextSection>();
                    break;

                case SectionTypeEnum.Gif:
                    parsedSection = currentSectionSource.ToObject <GifSection>();
                    showTyping    = true;
                    break;

                case SectionTypeEnum.Video:
                    parsedSection = currentSectionSource.ToObject <VideoSection>();
                    break;

                case SectionTypeEnum.Audio:
                    parsedSection = currentSectionSource.ToObject <AudioSection>();
                    break;

                case SectionTypeEnum.EmbeddedHtml:
                    parsedSection = currentSectionSource.ToObject <EmbeddedHtmlSection>();
                    break;

                case SectionTypeEnum.Link:
                case SectionTypeEnum.Graph:
                case SectionTypeEnum.Carousel:
                    Utils.ShowDialog($"{secType} Coming soon!");
                    break;

                default:
                    break;
                }
                if (parsedSection != null)
                {
                    if (parsedSection.DelayInMs > 50 || showTyping) //Add 'typing' bubble if delay is grather than 50 ms
                    {
                        ToggleTyping(true);
                    }

                    //Wait for delay MilliSeconds and then continue with chat
                    Dispatcher.Dispatch(async() =>
                    {
                        var precacheSucess = await PrecacheSection(parsedSection);
                        //Remove 'typing' bubble
                        ToggleTyping(false);
                        var sectionIndex = (sectionsSource.Children().ToList().FindIndex(x => x["_id"].ToString() == parsedSection._id));
                        if (precacheSucess)
                        {
                            if (sectionIndex == 0) //First section in node, send View Event
                            {
                                await Task.Run(async() =>
                                {
                                    try
                                    {
                                        await APIHelper.TrackEvent(Utils.GetViewEvent(parsedNode.Id, Utils.DeviceId));
                                    }
                                    catch (Exception ex)
                                    {
                                        await Utils.ShowDialogAsync(ex.ToString());
                                    }
                                });
                            }
                            AddIncommingSection(parsedSection);
                        }
                        var remainingSections = sectionsSource.Children().Count() - (sectionIndex + 1);
                        if (remainingSections > 0)
                        {
                            var nextSection = sectionsSource.ElementAt(sectionIndex + 1);
                            ProcessNode(node, nextSection);
                        }
                        else
                        {
                            await ProcessButtonsAsync(node);
                        }
                    }, parsedSection.DelayInMs);
                }
            }
        }
示例#8
0
        public async void ProcessNode(JToken node, JToken section = null)
        {
            if (node == null)
            {
                Utils.ShowDialog("Node not found!");
                return;
            }
            ClearButtonTimer();

            //Replacing verbs
            node = JToken.Parse(VerbProcessor.Process(node.ToString()));

            var parsedNode = node.ToObject <ChatNode>();

            if (parsedNode.Buttons != null && parsedNode.Buttons.Count > 0)
            {
                ClearButtons();
            }

            if (parsedNode.NodeType == NodeTypeEnum.HandoffToAgent)
            {
                await Utils.ShowDialogAsync("'HandoffToAgent' not supported in simulator");
            }
            else if (parsedNode.NodeType == NodeTypeEnum.ApiCall)
            {
                ToggleTyping(true);
                try
                {
                    var paramDict = new Dictionary <string, object>();
                    if (parsedNode.RequiredVariables != null)
                    {
                        foreach (var reqParam in parsedNode.RequiredVariables)
                        {
                            if (reqParam == "HISTORY")                             //Custom Variable
                            {
                                paramDict[reqParam] = ChatThread.Where(x => x.SectionType != SectionTypeEnum.Typing).ToArray();
                            }
                            else
                            {
                                paramDict[reqParam] = ButtonActionHelper.GetSavedValue(reqParam);
                            }
                        }
                    }
                    var nextNodeId = parsedNode.NextNodeId;                     //Default
                    switch (parsedNode.ApiMethod.ToUpper())
                    {
                    case "GET":
                    {
                        var query = string.Join("&", paramDict.Select(x => $"{x.Key}={Uri.EscapeDataString(x.Value + "")}"));
                        var api   = string.IsNullOrWhiteSpace(query) ? parsedNode.ApiUrl : parsedNode.ApiUrl + (parsedNode.ApiUrl?.Contains("?") == true ? "&" : "?") + query;

                        var resp = await APIHelper.HitAsync <JObject>(api);

                        if (!string.IsNullOrWhiteSpace(resp["NextNodeId"] + ""))
                        {
                            nextNodeId = resp["NextNodeId"] + "";
                        }

                        ButtonActionHelper.HandleSaveMultiple(resp.ToObject <Dictionary <string, object> >());
                        var apiNextNodeId = ExtractNextNodeIdFromAPIResp(parsedNode, resp);
                        if (!string.IsNullOrWhiteSpace(apiNextNodeId))
                        {
                            nextNodeId = apiNextNodeId;
                        }
                    }
                    break;

                    case "POST":
                    {
                        var resp = await APIHelper.HitPostAsync <Dictionary <string, object>, JObject>(parsedNode.ApiUrl, paramDict);

                        if (!string.IsNullOrWhiteSpace(resp["NextNodeId"] + ""))
                        {
                            nextNodeId = resp["NextNodeId"] + "";
                        }
                        var apiNextNodeId = ExtractNextNodeIdFromAPIResp(parsedNode, resp);
                        if (!string.IsNullOrWhiteSpace(apiNextNodeId))
                        {
                            nextNodeId = apiNextNodeId;
                        }
                    }
                    break;

                    default:
                        Utils.ShowDialog($"{parsedNode.ApiMethod} ApiMethod Unsupported!");
                        break;
                    }
                    NavigateToNode(nextNodeId);
                }
                catch (Exception ex)
                {
                    ToggleTyping(false);
                    Utils.ShowDialog($"API[{parsedNode.ApiMethod}]: {parsedNode.ApiUrl }\r\nRequired Vars: {(parsedNode.RequiredVariables == null ? "" : string.Join(",", parsedNode.RequiredVariables))}\r\nError: " + ex.Message);
                    NavigateToNode(parsedNode.NextNodeId);
                }
            }
            else if (node["Sections"] == null || node["Sections"].Children().Count() == 0)
            {
                ToggleTyping(false);
                await ProcessButtonsAsync(node);
            }
            else if (node["Sections"] != null && node["Sections"].Children().Count() > 0)
            {
                var sectionsSource       = node["Sections"];
                var currentSectionSource = section ?? sectionsSource.First;

                //Replacing verbs
                currentSectionSource = JToken.Parse(VerbProcessor.Process(currentSectionSource.ToString()));

                SectionTypeEnum secType       = (SectionTypeEnum)Enum.Parse(typeof(SectionTypeEnum), currentSectionSource["SectionType"].ToString());
                Section         parsedSection = null;
                bool            showTyping    = false;
                switch (secType)
                {
                case SectionTypeEnum.Image:
                    parsedSection = currentSectionSource.ToObject <ImageSection>();
                    showTyping    = true;
                    break;

                case SectionTypeEnum.Text:
                    parsedSection = currentSectionSource.ToObject <TextSection>();
                    break;

                case SectionTypeEnum.Gif:
                    parsedSection = currentSectionSource.ToObject <GifSection>();
                    showTyping    = true;
                    break;

                case SectionTypeEnum.Video:
                    parsedSection = currentSectionSource.ToObject <VideoSection>();
                    break;

                case SectionTypeEnum.Audio:
                    parsedSection = currentSectionSource.ToObject <AudioSection>();
                    break;

                case SectionTypeEnum.EmbeddedHtml:
                    parsedSection = currentSectionSource.ToObject <EmbeddedHtmlSection>();
                    break;

                case SectionTypeEnum.PrintOTP:
                    parsedSection = currentSectionSource.ToObject <PrintOTPSection>();
                    break;

                case SectionTypeEnum.Carousel:
                {
                    parsedSection = currentSectionSource.ToObject <CarouselSection>();
                    (parsedSection as CarouselSection).Items = VerbProcessor.ProcessCarousalItems((parsedSection as CarouselSection).Items, parsedNode);
                }
                break;

                case SectionTypeEnum.Link:
                case SectionTypeEnum.Graph:
                    Utils.ShowDialog($"{secType} Coming soon!");
                    break;

                default:
                    break;
                }
#if DEBUG
                if (Debugger.IsAttached)
                {
                    if (parsedSection != null)
                    {
                        parsedSection.DelayInMs = 0;
                    }
                }
                else
                {
                    if (parsedSection != null && parsedSection.DelayInMs <= 0)
                    {
                        parsedSection.DelayInMs = 2000;
                    }
                }
#endif
                if (parsedSection != null)
                {
                    if (parsedSection.DelayInMs > 50 || showTyping)                     //Add 'typing' bubble if delay is greater than 50 ms
                    {
                        ToggleTyping(true);
                    }

                    //Wait for delay MilliSeconds and then continue with chat
                    Dispatcher.Dispatch(async() =>
                    {
                        var precacheSucess = await PrecacheSection(parsedSection);
                        //Remove 'typing' bubble
                        ToggleTyping(false);
                        var sectionIndex = (sectionsSource.Children().ToList().FindIndex(x => x["_id"].ToString() == parsedSection._id));
                        if (precacheSucess)
                        {
                            if (parsedNode.NodeType == NodeTypeEnum.Card)
                            {
                                parsedSection.Title   = VerbProcessor.Process(parsedNode.CardHeader);
                                parsedSection.Caption = VerbProcessor.Process(parsedNode.CardFooter);

                                if (parsedNode.Placement == null || parsedNode.Placement == Placement.Incoming)
                                {
                                    AddIncommingSection(parsedSection);
                                }
                                else if (parsedNode.Placement == Placement.Outgoing)
                                {
                                    AddOutgoingSection(parsedSection);
                                }
                                else if (parsedNode.Placement == Placement.Center)
                                {
                                    AddCenterSection(parsedSection);
                                }
                            }
                            else
                            {
                                AddIncommingSection(parsedSection);
                            }
                        }
                        var remainingSections = sectionsSource.Children().Count() - (sectionIndex + 1);
                        if (remainingSections > 0)
                        {
                            var nextSection = sectionsSource.ElementAt(sectionIndex + 1);
                            ProcessNode(node, nextSection);
                        }
                        else
                        {
                            await ProcessButtonsAsync(node);
                        }
                    }, parsedSection.DelayInMs);
                }
            }
        }
示例#9
0
 public static bool IsSectionTypePresentInNode(JToken node, SectionTypeEnum secType)
 {
     return(node?["Sections"]?.Any(x => x.ToObject <Section>()?.SectionType == secType) == true);
 }
        /// <summary>
        /// Gets the ReportSection from the ReportSettings XML
        /// </summary>
        /// <param name="element">The report ReportSettings the get the result XML from</param>
        /// <param name="sectionIndex">The int section index to retreive</param>
        /// <returns>Returns the ReportSection at the selected section index </returns>
        internal static XElement GetReportSection(this XElement element, int sectionIndex, out SectionTypeEnum sectionTypeEnum)
        {
            XElement result = element
                              .Descendants("ReportSection")
                              .FirstOrDefault(si => si.Attribute("SectionIndex").Value.ToInt32() == sectionIndex);

            sectionTypeEnum = (SectionTypeEnum)result.Attribute("SectionType").Value.ToInt32();

            return(result);
        }
        public void PrintDocument(XDocument report)
        {
            #region GATHER PAGE SETUP INFORMATION

            XElement pageSetup = report.Root.Element("PageSetup");

            this.paperKind = (PaperKind)pageSetup.Attribute("PaperKindEnum").Value.ToInt32();

            this.pageOrientation = (PageOrientationEnum)pageSetup.Attribute("PageOrientationEnum").Value.ToInt32();

            this.pageSize = PageSetupOptions.GetPageMediaSize(this.paperKind);

            this.pageMarginTop = pageSetup.Attribute("PageMarginTop").Value.ToInt32();

            this.pageMarginBottom = pageSetup.Attribute("PageMarginBottom").Value.ToInt32();

            XElement coverPage = report.GetReportSettings(ReportTypeEnum.CoverPage);

            if (coverPage != null)
            {
                SectionTypeEnum sectionType = SectionTypeEnum.None;

                XElement reportSection = coverPage.GetReportSection(0, out sectionType);

                this.CreateSinglePageCanvas(reportSection.GetCanvasXml(), sectionType);
            }

            XElement headersAndFooters = report.GetReportSettings(ReportTypeEnum.PageHeaderAndFooter);

            if (headersAndFooters != null)
            {
                SectionTypeEnum sectionType = SectionTypeEnum.None;

                this.pageHeader = headersAndFooters.GetReportSection(0, out sectionType);

                this.pageFooter = headersAndFooters.GetReportSection(1, out sectionType);
            }

            #endregion

            #region START BUILD DATA REPORT

            this.dataSections = report.GetDataReportSections();

            if (this.dataSections.Count > 0)
            {
                this.isSingleTable = this.dataSections.Count == 3;

                this.CreateDataPageCanvas();

                this.reportData = report.Root.Element("ReportData");

                foreach (XElement table in this.reportData.Elements())
                {
                    foreach (XElement row in table.Elements())
                    {
                        int rowIndex = this.tableRowIndex = table.Attribute("TableRowIndex").Value.ToInt32();

                        if (!this.isSingleTable)
                        {
                            this.SetSectionHeader(0);
                        }

                        this.BuildReportData(row);

                        this.tableRowIndex = rowIndex;

                        if (!this.isSingleTable)
                        {
                            this.SetSectionFooter(0);
                        }
                    }

                    if (this.isSingleTable)
                    {
                        this.SetSectionFooter(0);
                    }
                }
            }

            if (this.activeCanvas != null && this.activeCanvas.HaveElements)
            {
                this.CompleteDataPageCanvas();
            }

            #endregion

            #region FINALIZE PAGES

            XElement finalPage = report.GetReportSettings(ReportTypeEnum.FinalPage);

            if (finalPage != null)
            {
                SectionTypeEnum sectionType = SectionTypeEnum.None;

                XElement reportSection = finalPage.GetReportSection(0, out sectionType);

                this.CreateSinglePageCanvas(reportSection.GetCanvasXml(), sectionType);
            }

            #endregion
        }
示例#12
0
 /// <summary>
 /// This method returns all created sections of the given type.
 /// </summary>
 /// <param name="sectionType">This is the type of the section.</param>
 /// <returns>Section List.</returns>
 public static List <Section> GetAll(SectionTypeEnum sectionType)
 {
     return(InMemoryDatabaseSingleton.DatabaseInstance.SelectMany <Section>(
                x => x.SectionType == sectionType).OrderByDescending(
                x => x.CreationDate).ToList());
 }
示例#13
0
 /// <summary>
 /// This method returns last creatd section.
 /// </summary>
 public static Section Get(SectionTypeEnum sectionType, string courseName)
 {
     return
         (InMemoryDatabaseSingleton.DatabaseInstance.SelectMany <Section>(x => x.SectionType ==
                                                                          sectionType && x.CourseName == courseName && x.IsCreated).OrderByDescending(x => x.CreationDate).First());
 }