Beispiel #1
0
        //###################################################################################

        protected override void OnCreate(Bundle savedInstanceState)
        {
            //Statischen Speicher wiederherstellen, wenn im Hintergrund vom System gelöscht
            if (TBL.SP_Object == null)
            {
                Activity_Init.InitRoutine(this);
            }

            SetTheme(Resource.Style.AppTheme);
            base.OnCreate(savedInstanceState);

            //entryFeed
            string entryID = Intent.GetStringExtra(BUNDLE_ENTRYKEY);

            if (savedInstanceState != null)
            {
                entryID = savedInstanceState.GetString(BUNDLE_ENTRYKEY, "");
            }
            _currentEntry = TBL.GetFeedEntry(entryID);

            if (_currentEntry == null)
            {
                Finish(); return;
            }

            //Layout füllen
            SetContentView(Resource.Layout.activity_feedEntry);

            CreateViewholder();
            CreateToolbar();
        }
Beispiel #2
0
        private async Task <SharepointAPIState> RetrieveNewsFeed(bool doNotify, bool relogin, string host)
        {
            InvokeStateChanged(SharepointAPIState.WORKING);

            if (!IsOnline())
            {
                return(SharepointAPIState.CONNECTION_LOST);
            }                                                               // InvokeStateChanged(SharepointAPIState.CONNECTION_LOST); return; }
            if (string.IsNullOrWhiteSpace(_username))
            {
                return(SharepointAPIState.WRONG_LOGIN);
            }                                                                                    // InvokeStateChanged(SharepointAPIState.WRONG_LOGIN); return; }
            if (string.IsNullOrWhiteSpace(_password))
            {
                return(SharepointAPIState.WRONG_LOGIN);
            }                                                                                    // InvokeStateChanged(SharepointAPIState.WRONG_LOGIN); return; }

            if (!string.IsNullOrWhiteSpace(_spOauth))
            {
                _cookieJar = CreateOAuthCookie();
            }
            else
            {
                _cookieJar = new CookieContainer();
            }

            var listFeed = new List <FeedEntry>();

            string query = host + "_api/SitePages/pages?$select=Id,Title,Modified,CanvasJson1,lastModifiedBy,promotedState,Url&$orderby=Modified%20desc&$expand=lastModifiedBy"; // "_api/web/lists/getbytitle('news_mei')/items?$select=ID,Title,Body,Modified,AttachmentFiles,Author/Name,Author/Title&$orderby=Modified%20desc&$expand=AttachmentFiles,Author/Id";

            try
            {
                HttpWebRequest request = GetRequest(new Uri(_url_endpoint + query));
                request.Headers.Add("X-RequestDigest", _bearer);
                request.Accept = "application/json; odata=verbose";

                ResponseObject response = await GetResponse(request);

                switch (response.StatusCode)
                {
                case ResponseObject.ResponseObjectStatusCode.CONNECTION_LOST:

                    return(SharepointAPIState.CONNECTION_LOST);    //InvokeStateChanged(SharepointAPIState.CONNECTION_LOST); return;

                case ResponseObject.ResponseObjectStatusCode.FORBIDDEN:

                    if (relogin)
                    {
                        var loginState = await CreateLogin();

                        if (loginState == SharepointAPIState.LOGGED_IN)
                        {
                            return(await RetrieveNewsFeed(doNotify, false, host));
                        }
                        return(loginState);    //InvokeStateChanged(loginState); return;
                    }

                    return(SharepointAPIState.WRONG_LOGIN);    // InvokeStateChanged(SharepointAPIState.WRONG_LOGIN); return;

                case ResponseObject.ResponseObjectStatusCode.ERROR:
                case ResponseObject.ResponseObjectStatusCode.UNSET:
                default:

                    return(SharepointAPIState.SERVER_ERROR);    //InvokeStateChanged(SharepointAPIState.SERVER_ERROR); return;

                case ResponseObject.ResponseObjectStatusCode.OK:

                    if (response.Response?.StatusCode == HttpStatusCode.OK)
                    {
                        string responseData = GetResponseData(response.Response); response.Close();

                        JSONObject feedDoc = new JSONObject(responseData);
                        var        results = feedDoc.GetJSONObject("d").GetJSONArray("results");

                        for (int i = 0; i < results.Length(); i++)
                        {
                            var c = results.GetJSONObject(i);

                            const string TITLE    = "Title";
                            const string ID       = "Id";
                            const string MODIFIED = "Modified";
                            const string AUTHOR   = "LastModifiedBy";
                            const string STATE    = "PromotedState";
                            const string CONTENT  = "CanvasJson1";
                            const string PAGEURL  = "Url";

                            if (!c.Has(TITLE) || !c.Has(ID) || !c.Has(MODIFIED) || !c.Has(AUTHOR) || !c.Has(STATE) || !c.Has(PAGEURL))
                            {
                                break;
                            }

                            string title = c.GetString(TITLE);
                            string key   = "#" + c.GetInt(ID).ToString() + "_" + title.Trim(' ').ToLower();

                            if (!DateTime.TryParse(c.GetString(MODIFIED), out DateTime date))
                            {
                                date = DateTime.Now;
                            }

                            string author = _context.GetString(Resource.String.feedentry_unknown);
                            if (c.GetJSONObject(AUTHOR).Has("Name"))
                            {
                                author = c.GetJSONObject(AUTHOR).GetString("Name");
                            }

                            string body = "";
                            //string body = _url_endpoint + "/" + host + c.GetString(PAGEURL);

                            bool isVisible = c.GetInt(STATE) == 2;     //Promoted, sonst ausgeblendet
                            if (isVisible && c.Has(CONTENT))
                            {
                                //Dokument parsen
                                string contentText = c.GetString(CONTENT);
                                var    contentJson = GetJsonArray(contentText);
                                if (contentJson == null)
                                {
                                    break;
                                }

                                var attachmentList = new List <EntryAttachment>();
                                for (int j = 0; j < contentJson.Length(); j++)
                                {
                                    const string WEBPARTS = "webPartData";
                                    if (contentJson.GetJSONObject(j).Has(WEBPARTS))
                                    {
                                        var webPartData = contentJson.GetJSONObject(j).GetJSONObject(WEBPARTS);
                                        if (webPartData != null)
                                        {
                                            string webPartId = webPartData.GetString("id");

                                            switch (webPartId)
                                            {
                                            case "b7dd04e1-19ce-4b24-9132-b60a1c2b910d":

                                                //Eingebettetes Dokument --> Als Anhang speichern
                                                if (!webPartData.Has("properties") || !webPartData.GetJSONObject("properties").Has("file"))
                                                {
                                                    break;
                                                }

                                                string fileUrl  = webPartData.GetJSONObject("properties").GetString("file");
                                                string fileName = Path.GetFileName(fileUrl);
                                                attachmentList.Add(new EntryAttachment(fileName, fileUrl, false));

                                                break;

                                            case "6410b3b6-d440-4663-8744-378976dc041e":

                                                //Link --> Wenn Datei als Anhang, sonst als Hyperlink
                                                if (!webPartData.Has("serverProcessedContent") ||
                                                    !webPartData.GetJSONObject("serverProcessedContent").Has("links") ||
                                                    !webPartData.GetJSONObject("serverProcessedContent").GetJSONObject("links").Has("url"))
                                                {
                                                    break;
                                                }
                                                if (!webPartData.GetJSONObject("serverProcessedContent").Has("searchablePlainTexts") ||
                                                    !webPartData.GetJSONObject("serverProcessedContent").GetJSONObject("searchablePlainTexts").Has("title"))
                                                {
                                                    break;
                                                }

                                                string url        = webPartData.GetJSONObject("serverProcessedContent").GetJSONObject("links").GetString("url");
                                                string link_title = webPartData.GetJSONObject("serverProcessedContent").GetJSONObject("searchablePlainTexts").GetString("title");

                                                if (url.StartsWith("/:"))
                                                {
                                                    url = _url_malteserHost + url;
                                                }

                                                attachmentList.Add(new EntryAttachment(link_title, url, true));

                                                break;

                                            case "d1d91016-032f-456d-98a4-721247c305e8":

                                                //Bild --> Bild als Anhang aufnehmen
                                                if (!webPartData.Has("serverProcessedContent") ||
                                                    !webPartData.GetJSONObject("serverProcessedContent").Has("imageSources") ||
                                                    !webPartData.GetJSONObject("serverProcessedContent").GetJSONObject("imageSources").Has("imageSource"))
                                                {
                                                    break;
                                                }

                                                string pic_url = webPartData.GetJSONObject("serverProcessedContent").GetJSONObject("imageSources").GetString("imageSource");
                                                if (pic_url.StartsWith("/"))
                                                {
                                                    pic_url = _url_malteserHost + pic_url;
                                                }

                                                string pic_filename = Path.GetFileName(pic_url);
                                                if (pic_filename.ToLower().StartsWith("visualtemplateimage"))
                                                {
                                                    break;
                                                }

                                                attachmentList.Add(new EntryAttachment(pic_filename, pic_url, false));

                                                break;

                                            default:

                                                string content = webPartData.ToString();
                                                Console.WriteLine(content);

                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (contentJson.GetJSONObject(j).Has("innerHTML") &&
                                            contentJson.GetJSONObject(j).Has("controlType") && contentJson.GetJSONObject(j).GetInt("controlType") == 4)
                                        {
                                            string bodytext = contentJson.GetJSONObject(j).GetString("innerHTML");
                                            bodytext = Helper.Converter.GetPlainOfHtml(bodytext);
                                            body    += bodytext;
                                        }
                                    }
                                }

                                FeedEntry entry = new FeedEntry(key, title, date, author, body, attachmentList);
                                if (!string.IsNullOrEmpty(body) || attachmentList.Count > 0)
                                {
                                    listFeed.Add(entry);
                                }
                            }
                        }

                        TBL.UpdateEntries(listFeed, doNotify);

                        return(SharepointAPIState.OK);    //InvokeStateChanged(SharepointAPIState.OK); return;
                    }

                    return(SharepointAPIState.SERVER_ERROR);    //InvokeStateChanged(SharepointAPIState.SERVER_ERROR); return;
                }
            }
            catch (Exception)
            {
                return(SharepointAPIState.SERVER_ERROR); //InvokeStateChanged(SharepointAPIState.SERVER_ERROR); return;
            }
        }
Beispiel #3
0
 public void AddFeedEntry(FeedEntry item)
 {
     _newFeed.Add(item.Title);
 }
Beispiel #4
0
        //###################################################################################

        private static bool IsShiftsEntry(FeedEntry item, out ShiftsEntry shiftEntry)
        {
            shiftEntry = null;
            if (item.Attachments.Count != 1)
            {
                return(false);
            }

            string title = item.Title.ToLower().Trim();

            string[] split = title.Split(' ');
            if (split.Count() == 5 && (split[0] == "dp" || split[0] == "dienstplan") && split[3].StartsWith("ver"))  //DP/MONAT/JAHR/VERSION/NUMMER
            {
                //Monat
                int month = -1;
                switch (split[1].Substring(0, 3))
                {
                case "jan":
                    month = 1;
                    break;

                case "feb":
                    month = 2;
                    break;

                case "mär":
                case "mae":
                    month = 3;
                    break;

                case "apr":
                    month = 4;
                    break;

                case "mai":
                    month = 5;
                    break;

                case "jun":
                    month = 6;
                    break;

                case "jul":
                    month = 7;
                    break;

                case "aug":
                    month = 8;
                    break;

                case "sep":
                    month = 9;
                    break;

                case "okt":
                    month = 10;
                    break;

                case "nov":
                    month = 11;
                    break;

                case "dez":
                    month = 12;
                    break;
                }
                if (month <= 0)
                {
                    return(false);
                }

                //Jahr
                if (Helper.Converter.IsTextInteger(split[2]) && split[2].Length == 4)
                {
                    int year = int.Parse(split[2]);
                    if (month == item.Date.Month && year != item.Date.Year)
                    {
                        year = item.Date.Year;
                    }                                                                                  //Tippfehler ausmerzen

                    string version = split[4].Trim('.').Trim(' ');

                    shiftEntry = new ShiftsEntry(month, year, item.Date, version, item.Attachments.First());
                    return(true);
                }
            }
            else if (split.Count() == 4 && (split[0] == "dp" || split[0] == "dienstplan") && split[2].StartsWith("ver") && split[3].Contains("."))
            {
                //Monat
                int month = -1;
                switch (split[1].Substring(0, 3))
                {
                case "jan":
                    month = 1;
                    break;

                case "feb":
                    month = 2;
                    break;

                case "mär":
                case "mae":
                    month = 3;
                    break;

                case "apr":
                    month = 4;
                    break;

                case "mai":
                    month = 5;
                    break;

                case "jun":
                    month = 6;
                    break;

                case "jul":
                    month = 7;
                    break;

                case "aug":
                    month = 8;
                    break;

                case "sep":
                    month = 9;
                    break;

                case "okt":
                    month = 10;
                    break;

                case "nov":
                    month = 11;
                    break;

                case "dez":
                    month = 12;
                    break;
                }
                if (month <= 0)
                {
                    return(false);
                }

                //Jahr
                int year = item.Date.Year;
                if ((item.Date.AddMonths(3) < new DateTime(year, month, item.Date.Day)))
                {
                    year -= 1;
                }

                string version = split[3].Trim('.').Trim(' ');

                shiftEntry = new ShiftsEntry(month, year, item.Date, version, item.Attachments.First());
                return(true);
            }

            return(false);
        }