Exemplo n.º 1
0
        public ActionResult <GetContentResponse> GetContent(int contentId)
        {
            try
            {
                var userId = Int32.Parse(User.Identity.Name);
                _userManagementService.CheckUserExists(userId);

                var content = _contentManagementService.GetContent(contentId);

                GetContentResponse response = new GetContentResponse()
                {
                    Content = ApiContentMapper.MapContentData(content)
                };

                return(Ok(response));
            }
            catch (UserNotExistError)
            {
                return(StatusCode(StatusCodes.Status404NotFound, new
                {
                    message = "Пользователь не найден"
                }));
            }
            catch (ContentNotExistError)
            {
                return(StatusCode(StatusCodes.Status404NotFound, new
                {
                    message = "Материал не найден"
                }));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new { message = e.Message }));
            }
        }
Exemplo n.º 2
0
        private void performChainContainer(string document_id, Dictionary <string, byte[]> additionalTicketsToBeChained)
        {
            APICon.Container.ChainContainer container = new APICon.Container.ChainContainer();

            Event[] e = controller.getAllBindedEventsInChain(document_id);
            foreach (Event ev in e)
            {
                //Console.WriteLine(ev.ToString());

                GetContentResponse cr   = controller.getUPDDocumentContent(ev.document_id);
                string             name = GetTextFromXml(cr.body, "Файл[@*]/@ИдФайл");
                container.AddEntry(name + ".xml", Utils.Base64DecodeToBytes(cr.body, "windows-1251"));
                container.AddEntry(name + GetSignExtensionForContainer(), GetSignEncodedBodyForContainer(cr.sign));
                if (ev.event_status.StartsWith("УПД"))
                {
                    byte[] pdf = Utils.Base64DecodeToBytes(controller.GetPdf(ev.document_id), "UTF-8");
                    container.AddEntry(name + ".pdf", pdf);
                    container.docFunction = GetTextFromXml(cr.body, "Файл/Документ/@Функция");
                    string[] s = { "КСЧФ", "КСЧФДИС", "ДИС" };
                    container.docNumber = GetTextFromXml(cr.body, s.Contains(container.docFunction) ? "Файл/Документ/СвКСчФ/@НомерКСчФ" : "Файл/Документ/СвСчФакт/@НомерСчФ");
                    container.docDate   = GetTextFromXml(cr.body, s.Contains(container.docFunction) ? "Файл/Документ/СвКСчФ/@ДатаКСчФ" : "Файл/Документ/СвСчФакт/@ДатаСчФ");
                    container.SetContainerName();
                }
            }
            foreach (string key in additionalTicketsToBeChained.Keys)
            {
                container.AddEntry(key, additionalTicketsToBeChained[key]);
            }
            DFSHelper.saveContainer(container);
        }
Exemplo n.º 3
0
        public ApiDocument getDocInfoByEvent(Event e)
        {
            GetDocInfoRequest  req     = null;
            GetDocInfoResponse resp    = null;
            GetContentResponse content = null;

            try
            {
                req  = new GetDocInfoRequest(authToken, e.document_id);
                resp = (GetDocInfoResponse)Http2.post <GetDocInfoResponse>("https://api-service.edi.su/Api/Dixy/TimeLine/GetDocData", req);
                if (resp.intCode == 200)
                {
                    content = getDocumentContent(e);
                    resp.document.file_body = content.body;
                    resp.document.sign_body = content.sign;
                    return(resp.document);
                }
                return(null);
            }
            catch (Exception ex)
            {
                Logger.log("error while processing [" + e.document_id + "]");
                Logger.log(resp.varMessage);
                Logger.log(ex.Message);
                return(null);
            }
        }
Exemplo n.º 4
0
        public GetContentResponse getDocumentContent(Event e)
        {
            GetContentResponse response = null;

            try
            {
                response = (GetContentResponse)Http2.post <GetContentResponse>("https://api-service.edi.su/Api/Dixy/Content/GetBoth", new GetContentRequest(authToken, e.document_id));
            }
            catch (Exception ex)
            {
                Logger.log("error while processing [" + e.document_id + "]");
                Logger.log(response.varMessage);
                Logger.log(ex.Message);
            }
            return(response);
        }
Exemplo n.º 5
0
        private void OnCommandComplete(GetContentResponse response, object cookie)
        {
            this.response = response;
            FMS fMS = new FMS();

            fMS.Init(new FmsOptions
            {
                CodeName        = response.AppCode,
                Env             = StringUtils.ParseEnum <FmsEnvironment>(response.Environment),
                ManifestVersion = response.ManifestVersion,
                Mode            = FmsMode.Versioned,
                LocalRootUrl    = "http://localhost/",
                RemoteRootUrl   = response.CdnRoots[0],
                Engine          = Service.Get <Engine>()
            }, new FmsCallback(this.OnFmsComplete), new FmsCallback(this.OnFmsError));
            Service.Get <CurrentPlayer>().Patches = response.Patches;
        }
Exemplo n.º 6
0
 private void OnCommandComplete(GetContentResponse response, object cookie)
 {
     this.response = response;
     this.options  = new ContentManagerOptions();
     if (response.CdnRoots.Count > 0 && !string.IsNullOrEmpty(response.CdnRoots[0]) && !string.IsNullOrEmpty(response.ManifestVersion) && !string.IsNullOrEmpty(response.ManifestPath))
     {
         this.options.ManifestVersion = int.Parse(response.ManifestVersion);
         this.options.ManifestPath    = response.ManifestPath;
         this.options.ContentBaseUrl  = response.CdnRoots[0];
         this.options.Env             = response.Environment;
         ContentManagerMode mode = ContentManagerMode.Remote;
         this.options.Mode = mode;
         this.LoadContentManager();
         Service.CurrentPlayer.Patches = response.Patches;
         return;
     }
     Service.Logger.Error("Content is not initialized");
     AlertScreen.ShowModalWithBI(true, null, "The server was unable to deliver content initialization data. Please try again soon.", "Connection error!");
 }
Exemplo n.º 7
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetContentResponse response = new GetContentResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("content", targetDepth))
                {
                    var unmarshaller = ContentDataUnmarshaller.Instance;
                    response.Content = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Exemplo n.º 8
0
        public GetContentResponse getUPDDocumentContent(string docGUID)
        {
            GetUPDContentResponse response = null;
            GetContentResponse    contResp = null;

            try
            {
                response            = (GetUPDContentResponse)Http2.post <GetUPDContentResponse>("https://api-service.edi.su/Api/Dixy/Content/GetDocWithSignContent", new GetContentRequest(authToken, docGUID));
                contResp            = new GetContentResponse();
                contResp.intCode    = response.intCode;
                contResp.varMessage = response.varMessage;
                contResp.body       = response.body;
                contResp.sign       = response.sign[0].body;
            }
            catch (Exception ex)
            {
                Logger.log("error while processing [" + docGUID + "]");
                Logger.log(response.varMessage);
                Logger.log(ex.Message);
            }
            return(contResp);
        }
Exemplo n.º 9
0
        public GetContentResponse GetContent(Event e)
        {
            GetContentResponse response = null;

            if (e.soapFileName.Contains("DP_OTORG"))
            {
                response = getDocumentContent(e);
                if (response.intCode != 200)
                {
                    response = getUPDDocumentContent(e);
                }
            }
            else
            {
                response = getUPDDocumentContent(e);
                if (response.intCode != 200)
                {
                    response = getDocumentContent(e);
                }
            }
            return(response);
        }
Exemplo n.º 10
0
        public bool signAndConfirmEvent(Event e)
        {
            try
            {
                GetContentResponse content = controller.GetContent(e);

                string   eventName   = controller.GetIDFileFromTicket(content.body, e);
                string   docType     = eventName.Split('_')[0] + "_" + eventName.Split('_')[1];
                Document docSettings = conf.GetCustomEDOTicketSettings(docType);
                if (docSettings != null)
                {
                    string signExt = ".bin";
                    if (docSettings.custom_sign_extension != null)
                    {
                        signExt = docSettings.custom_sign_extension;
                    }

                    Dictionary <string, byte[]> additionalTicketsToBeChained = new Dictionary <string, byte[]>();
                    if (!docSettings.TicketsGenerate)
                    {
                        /*
                         *         just saving incoming ticket
                         */
                        DFSHelper.saveTicket(docSettings.LocalPath, eventName + ".xml", Utils.Base64DecodeToBytes(content.body, "windows-1251"));
                        DFSHelper.saveTicket(docSettings.LocalPath, eventName + signExt, Utils.StringToBytes(content.sign, "UTF-8"));

                        /*
                         * when configured -> creating xml status
                         */
                        DFSHelper.saveStatus(controller, content.body, docSettings, null);
                    }
                    else
                    {
                        string thumbPrint = docSettings.Thumpprint != null ? docSettings.Thumpprint : conf.Thumpprint;
                        Ticket ticket     = controller.Ticket(thumbPrint, eventName);
                        if (ticket != null)
                        {
                            string body = Utils.Base64Encode(ticket.body, "windows-1251");
                            string sign = controller.Sign(thumbPrint, body);
                            if (controller.confirmEvent(e, body, sign))
                            {
                                if (eventName.Contains(".xml"))
                                {
                                    eventName = eventName.Replace(".xml", string.Empty);
                                }

                                /*
                                 *  saving incoming ticket
                                 */
                                DFSHelper.saveTicket(docSettings.LocalPath, eventName + ".xml", Utils.Base64DecodeToBytes(content.body, "windows-1251"));
                                DFSHelper.saveTicket(docSettings.LocalPath, eventName + signExt, Utils.StringToBytes(content.sign, "UTF-8"));

                                /*
                                 *  saving outgoing ticket
                                 */
                                additionalTicketsToBeChained.Add(ticket.fileName, ticket.body);
                                additionalTicketsToBeChained.Add(ticket.fileName.Replace(".xml", GetSignExtensionForContainer()), GetSignEncodedBodyForContainer(sign));
                                DFSHelper.saveTicket(docSettings.TicketPath, ticket.fileName, ticket.body);
                                DFSHelper.saveTicket(docSettings.TicketPath, ticket.fileName.Replace(".xml", signExt), Utils.StringToBytes(sign, "UTF-8"));

                                /*
                                 * when configured -> creating xml status
                                 */
                                DFSHelper.saveStatus(controller, content.body, docSettings, null);
                            }
                        }
                    }

                    /*
                     * check if need to be contained
                     */
                    if (e.performChainContainer)
                    {
                        performChainContainer(e.document_id, additionalTicketsToBeChained);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Logger.log(ex.Message);
                return(false);
            }
        }
        async private void HodClient_requestCompletedWithContent(string response)
        {
            await messageDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                mJobID               = "";
                String text          = "";
                indicator.Visibility = Visibility.Collapsed;
                if (mHodApp == HODApps.GET_CONTENT)
                {
                    mContentResponse = (GetContentResponse)mParser.ParseCustomResponse <GetContentResponse>(ref response);
                    if (mContentResponse != null)
                    {
                        // purify word array
                        if (mPunctuation == true)
                        {
                            var words     = mContentResponse.documents[0].text;
                            var timestamp = mContentResponse.documents[0].offset;

                            int count = mContentResponse.documents[0].text.Count;
                            int start = (mContentResponse.documents[0].text.Count > 10) ? 10 : 0;
                            int end   = (mContentResponse.documents[0].text.Count > 200) ? 150 : mContentResponse.documents[0].text.Count;
                            var total = 0.0;
                            for (int i = start; i < end; i++)
                            {
                                total += timestamp[i] - timestamp[i - 1];
                            }
                            var average   = total / end - 1;
                            double para   = average + 1500;
                            double dot    = average + 800;
                            double commas = average + 400;
                            count         = words.Count;
                            words[0]      = FirstCharToUpper(words[0]);
                            var len       = 0;
                            for (int i = 1; i < count; i++)
                            {
                                if (!words[i].Equals("<Music/Noise>") && !words[i - 1].Equals("<Music/Noise>"))
                                {
                                    var diff = timestamp[i] - timestamp[i - 1];
                                    if (diff > para && len > 1) // 2000
                                    {
                                        words[i - 1] += ".\n";
                                        words[i]      = FirstCharToUpper(words[i]);
                                        len           = 0;
                                    }
                                    else if (diff > dot && len > 1) // 1500
                                    {
                                        words[i - 1] += ".";
                                        words[i]      = FirstCharToUpper(words[i]);
                                        len           = 0;
                                    }
                                    else if (diff > commas && len > 1) // 1000
                                    {
                                        words[i - 1] += ",";
                                        len           = 0;
                                    }
                                    else
                                    {
                                        len++;
                                    }
                                }
                            }
                            mContentResponse.documents[0].text    = words;
                            mContentResponse.documents[0].offset  = timestamp;
                            mContentResponse.documents[0].content = String.Join(" ", words);

                            mTextItem.UnreadText = mContentResponse.documents[0].content;
                            mIsReading           = false;
                            if (mplayer.CurrentState != MediaElementState.Playing)
                            {
                                mplayer.Play();
                            }
                        }
                        else
                        {
                            mTextItem.UnreadText += mContentResponse.documents[0].content;
                        }
                        mIndex = 0;
                    }
                }
                else if (mHodApp == HODApps.FIND_SIMILAR)
                {
                    var result = (FindSimilarResponse)mParser.ParseCustomResponse <FindSimilarResponse>(ref response);
                    if (result != null)
                    {
                        text = "<html><head/><body><div style=\"font-size:1.0em\">";
                        mUrlList.Clear();
                        text += "<div style=\"text-align:right\"><a href=\"hod_home\">Back to Concepts</a></div>";
                        foreach (var document in result.documents)
                        {
                            text += String.Format("<div><b>Title: </b>{0} </div>", document.title);
                            text += String.Format("<div><b>Relevance: </b>{0}%</div>", document.weight.ToString("0.00"));
                            if (document.summary != null)
                            {
                                text += String.Format("<div><b>Summary: </b>{0}</div>", document.summary);
                            }
                            if (document.reference != null)
                            {
                                text += String.Format("<div><b>Content: </b><a href=\"{0}\">website</a></div>", document.reference);
                                mUrlList.Add(document.reference);
                            }
                            text += "</br>";
                        }
                        text += "</div></body></html>";
                        processedcontent.NavigateToString(text);
                    }
                }
                else if (mHodApp == HODApps.QUERY_TEXT_INDEX)
                {
                    mInprogress = false;
                    mMediaList  = (QueryTextIndexResponse)mParser.ParseCustomResponse <QueryTextIndexResponse>(ref response);
                    if (mMediaList != null)
                    {
                        mListViewModel.ClearData();
                        foreach (QueryTextIndexResponse.Document doc in mMediaList.documents)
                        {
                            ContentModel item = new ContentModel();
                            item.Type         = doc.mediatype[0];
                            item.Title        = doc.medianame[0];
                            if (doc.filename != null)
                            {
                                item.filename = doc.filename[0];
                            }
                            item.reference = doc.reference;
                            item.index     = doc.index;

                            var type = item.Type.Split('/');
                            if (type[0] == "video")
                            {
                                item.Icon = "Assets/video_icon.png";
                            }
                            else
                            {
                                item.Icon = "Assets/audio_icon.png";
                            }

                            mListViewModel.Items.Add(item);
                        }
                    }
                }
                else if (mHodApp == HODApps.ANALYZE_SENTIMENT)
                {
                    mSaResponse = mParser.ParseSentimentAnalysisResponse(ref response);
                    if (mSaResponse != null)
                    {
                        parseSentimentAnalysis();
                    }
                }
                else if (mHodApp == HODApps.ENTITY_EXTRACTION)
                {
                    mEeResponse = (EntityExtractionResponse)mParser.ParseCustomResponse <EntityExtractionResponse>(ref response);
                    if (mEeResponse != null)
                    {
                        parseEntityExtraction();
                    }
                    else
                    {
                        text += "Error!</div></body></html>";
                        processedcontent.NavigateToString(text);
                    }
                }
            });
        }