Пример #1
0
 public ShiftsEntry(int month, int year, DateTime lastUpdate, string lastVersion, EntryAttachment shiftAttachment)
 {
     Key             = year.ToString("0000") + "#" + month.ToString("00");
     Month           = month; Year = year; LastUpdate = lastUpdate; LastVersion = lastVersion; MarkedRead = false;
     Title           = new DateTime(year, month, 1).ToString("MMMM yyyy");
     ShiftAttachment = shiftAttachment;
 }
Пример #2
0
        private void AttachmentAdapter_EntrySelected(object sender, Adapters.ListFeedAttachmentAdapterEntrySelected e)
        {
            EntryAttachment attachment = TBL.GetFeedEntry(e.EntryKey)?.GetAttachment(e.AttachmentKey);

            if (attachment.IsDownloadable)
            {
                bool success = Helper.FileOpen.Open(this, attachment.LocalFilePath);
                if (!success)
                {
                    AttachmentAdapter_AttachmentRetrieveError(null, new Adapters.AttachmentRetrieveErrorEventArgs(Adapters.AttachmentRetrieveErrorReason.RETRIEVE_ERROR));
                }
            }
            else
            {
                bool success = Helper.FileOpen.OpenWeb(this, attachment.RemoteURL);
                if (!success)
                {
                    AttachmentAdapter_AttachmentRetrieveError(null, new Adapters.AttachmentRetrieveErrorEventArgs(Adapters.AttachmentRetrieveErrorReason.RETRIEVE_ERROR));
                }
            }
        }
Пример #3
0
        public async void GetNewsFeedAttachment(EntryAttachment attachment, Action <Adapters.AttachmentRetrieveErrorReason> onError, Action <string> onDownloaded, bool relogin = true)
        {
            if (attachment.IsDownloaded)
            {
                onDownloaded(attachment.LocalFilePath);
                return;
            }
            int waitTimeout = (2 * REQUEST_TIMEOUT) / 200;

            //Dateinamen erstellen
            string filePath   = attachment.LocalFilePath;
            var    fileHandle = new Java.IO.File(filePath);

            if (!fileHandle.Exists())
            {
                string attachFilename  = Path.GetFileNameWithoutExtension(attachment.Title).Replace(" ", "_");
                string attachExtension = Path.GetExtension(attachment.RemoteURL);

                fileHandle = Java.IO.File.CreateTempFile(attachFilename, attachExtension, _context.CacheDir);
                filePath   = fileHandle.Path;
            }

            //Request erstellen
            if (!IsOnline())
            {
                onError(Adapters.AttachmentRetrieveErrorReason.CONNECTION_LOST); return;
            }
            while (State == SharepointAPIState.WORKING)
            {
                await Task.Delay(200);

                waitTimeout -= 1;
                if (waitTimeout < 0)
                {
                    fileHandle.Delete();

                    onError(Adapters.AttachmentRetrieveErrorReason.RETRIEVE_ERROR);
                    return;
                }
            }

            if (State == SharepointAPIState.SERVER_ERROR || State == SharepointAPIState.WRONG_LOGIN)
            {
                fileHandle.Delete();

                onError(Adapters.AttachmentRetrieveErrorReason.RETRIEVE_ERROR);
                return;
            }

            //schmutziger Path 3.11, weil die Uri bei Links nicht korrekt erstellt wurde.
            var patch = attachment.RemoteURL.Replace("https:/m", "https://m");

            var client = new DownloadClient(new Uri(patch), filePath, CreateOAuthCookie(), _bearer);

            client.DownloadProgressChanged += (ss, ee) => { };
            client.DownloadFinished        += async(ss, ee) =>
            {
                if (ee.DownloadFinished)
                {
                    if (State == SharepointAPIState.CONNECTION_LOST)
                    {
                        InvokeStateChanged(SharepointAPIState.LOGGED_IN);
                    }

                    attachment.UpdateAttachmentDownloaded(filePath);

                    onDownloaded(filePath);
                    return;
                }

                if (relogin)
                {
                    onError(Adapters.AttachmentRetrieveErrorReason.RELOGIN_REQUIRED);
                    var result = await CreateLogin();

                    InvokeStateChanged(result);

                    if (result == SharepointAPIState.LOGGED_IN)
                    {
                        GetNewsFeedAttachment(attachment, onError, onDownloaded, false);
                        return;
                    }
                    else
                    {
                        if (result == SharepointAPIState.CONNECTION_LOST)
                        {
                            onError(Adapters.AttachmentRetrieveErrorReason.CONNECTION_LOST);
                        }
                        else
                        {
                            onError(Adapters.AttachmentRetrieveErrorReason.RETRIEVE_ERROR);
                        }
                    }
                }
                else
                {
                    onError(Adapters.AttachmentRetrieveErrorReason.RETRIEVE_ERROR);
                }
                return;
            };
            client.StartDownloadCallback();
        }