Exemple #1
0
        }         // func TryGetLogEvent

        public static async Task GetLogLinesAsync(DEHttpClient http, string path, int start, int count, Action <string, LogLine> process)
        {
            var xLines = await http.GetXmlAsync(Program.MakeUri(path,
                                                                new PropertyValue("action", "listget"),
                                                                new PropertyValue("id", "tw_lines"),
                                                                new PropertyValue("desc", false),
                                                                new PropertyValue("start", start),
                                                                new PropertyValue("count", count)
                                                                ), rootName : "list");

            var lines = xLines.Element("items")?.Elements("line");

            if (lines != null)
            {
                foreach (var x in lines)
                {
                    process(
                        path,
                        new LogLine(
                            FromMsgTypeString(x.GetAttribute("typ", "I")),
                            GetDateTime(x.GetAttribute("stamp", null)),
                            x.Value
                            )
                        );
                }
            }
        } // func GetLogLinesAsync
        public ConsoleDebugSocket(ConsoleApplication app, DEHttpClient http)
            : base(http)
        {
            this.app = app ?? throw new ArgumentNullException(nameof(app));

            DefaultTimeout = 0;
        }         // ctor
Exemple #3
0
        }         // func GetLogPropertyInfo

        public static async Task GetLogPropertiesAsync(DEHttpClient http, string path, Action <string, LogProperty> process = null)
        {
            var xProperties = await http.GetXmlAsync(Program.MakeUri(path,
                                                                     new PropertyValue("action", "listget"),
                                                                     new PropertyValue("id", "tw_properties")
                                                                     ), rootName : "list");

            var properties = xProperties.Element("items")?.Elements("property");

            if (properties != null)
            {
                foreach (var x in properties)
                {
                    var name = x.GetAttribute("name", null);
                    if (name == null)
                    {
                        continue;
                    }

                    // parse info
                    var propertyInfo = new LogPropertyInfo(name,
                                                           x.GetAttribute("displayname", name),
                                                           LuaType.GetType(x.GetAttribute("type", "string"), lateAllowed: true).Type,
                                                           x.GetAttribute("description", name),
                                                           x.GetAttribute("format", null)
                                                           );
                    UpdatePropertyInfo(propertyInfo);

                    // process value
                    process?.Invoke(path, new LogProperty(propertyInfo, x.Value));
                }
            }
        } // func GetLogProperties
Exemple #4
0
        }         // func GetExcelAddinVersion

        public void ClearCredentials()
        {
            request  = null;
            fullName = null;

            IsAuthentificatedChanged?.Invoke(this, EventArgs.Empty);
        }         // proc ClearCredentials
Exemple #5
0
        public LogHttpLines(DEHttpClient http, string path)
        {
            this.http = http ?? throw new ArgumentNullException(nameof(http));
            this.path = path ?? throw new ArgumentNullException(nameof(path));

            queue.OnException = e => ConsoleApplication.Current.Invoke(() => ConsoleApplication.Current.WriteError(e, "Log not parsed."));
            queue.Enqueue(FetchLinesAsync);
        }         // ctor
        public ActivityOverlay(DEHttpClient http, int height)
        {
            this.http = http ?? throw new ArgumentNullException(nameof(http));

            // create buffer
            lastLogs       = new LastLogLine[height];
            lastProperties = new LastProperty[height];

            // set position
            Left     = 0;
            Top     -= height;
            Position = ConsoleOverlayPosition.Window;
        }         // ctor
Exemple #7
0
        }         // func GetLogPropertyInfosAsync

        public static Task <LogPropertyInfo> GetLogPropertyInfoAsync(DEHttpClient http, string path, string name)
        {
            if (propertyStore.TryGetValue(name, out var propertyInfo))
            {
                return(Task.FromResult(propertyInfo));
            }

            // register wait info
            var w = new WaitForPropertyInfo(name);

            waits.Add(w);

            // fork fetch properties
            GetLogPropertyInfosAsync(http, path).Spawn();

            return(w.Task);
        }         // func GetLogPropertyInfo
Exemple #8
0
        }         // proc UpdatePropertyInfo

        private static async Task GetLogPropertyInfosAsync(DEHttpClient http, string path)
        {
            // lock property fetch
            if (currentPropertiesFetching.IndexOf(path) >= 0)
            {
                return;
            }
            currentPropertiesFetching.Add(path);
            try
            {
                await GetLogPropertiesAsync(http, path);
            }
            finally
            {
                currentPropertiesFetching.Remove(path);
            }
        }         // func GetLogPropertyInfosAsync
Exemple #9
0
        private async Task <bool> UpdateApplicationAsync(DEHttpClient client, string src)
        {
            if (formsApplication.ShowMessage(String.Format("Eine neue Anwendung steht bereit.\nInstallieren und {0} neustarten?", formsApplication.Title), MessageBoxIcon.Question, MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return(false);
            }

            var sourceUri = client.CreateFullUri(src);
            var msiExe    = Path.Combine(Environment.SystemDirectory, "msiexec.exe");
            var psi       = new ProcessStartInfo(msiExe, "/i " + sourceUri.ToString() + " /q");

            using (var bar = CreateProgress(true))
                using (var ps = Process.Start(psi))
                {
                    bar.Text = "Installation wird ausgeführt...";
                    await Task.Run(new Action(ps.WaitForExit));

                    // ps.ExitCode
                }

            return(true);
        }         // proc UpdateApplicationAsync
Exemple #10
0
 public ConsoleEventSocket(ConsoleApplication app, DEHttpClient http)
     : base(http)
 {
     this.app = app ?? throw new ArgumentNullException(nameof(app));
 }         // ctor
Exemple #11
0
        }         // func LoginAsync

        #endregion

        #region -- Http ---------------------------------------------------------------

        public override DEHttpClient CreateHttp(Uri uri = null)
        {
            return(uri == null
                                ? request
                                : DEHttpClient.Create(new Uri(request.BaseAddress, uri), request.Credentials, request.DefaultEncoding));
        }         // func CreateHttp
Exemple #12
0
        }         // proc ClearCredentials

        public async Task <PpsLoginResult> LoginAsync(IWin32Window parent)
        {
            var newRequest = DEHttpClient.Create(info.Uri, null, Encoding);

            try
            {
                // get app-info
                var xInfo = await newRequest.GetXmlAsync("info.xml?app=" + formsApplication.ApplicationId);

                // check version
                var clientVersion  = GetExcelAddinVersion();
                var assemblyVesion = GetExcelAssemblyVersion();
                var serverVersion  = new Version(xInfo.GetAttribute("version", "1.0.0.0"));

#if DEBUG
                assemblyVesion = serverVersion = clientVersion;
#endif

                if (clientVersion < serverVersion)                 // new version is provided
                {
                    return(await UpdateApplicationAsync(newRequest, xInfo.GetAttribute("src", null))
                                                ? PpsLoginResult.Restart
                                                : PpsLoginResult.Canceled);
                }
                else if (assemblyVesion < clientVersion)                 // new version is installed, but not active
                {
                    return(AskForRestart()
                                                ? PpsLoginResult.Restart
                                                : PpsLoginResult.Canceled);
                }

                // update mime type mappings
                PpsShellExtensions.UpdateMimeTypesFromInfo(xInfo);

                // open trust stroe
                using (var login = new PpsClientLogin("ppsn_env:" + info.Uri.ToString(), info.Name, false))
                {
                    var loginCounter = 0;                     // first time, do not show login dialog
                    while (true)
                    {
                        // show login dialog
                        if (loginCounter > 0)
                        {
                            if (!await InvokeAsync(() => login.ShowWindowsLogin(parent.Handle)))
                            {
                                return(PpsLoginResult.Canceled);
                            }
                        }

                        // create new client request
                        loginCounter++;
                        newRequest?.Dispose();
                        newRequest = DEHttpClient.Create(info.Uri, login.GetCredentials(true), Encoding);

                        // try login with user
                        try
                        {
                            // execute login
                            var xLogin = await newRequest.GetXmlAsync("login.xml");

                            request = newRequest;
                            IsAuthentificatedChanged?.Invoke(this, EventArgs.Empty);
                            fullName = xLogin.GetAttribute("FullName", (string)null);

                            login.Commit();
                            return(PpsLoginResult.Sucess);
                        }
                        catch (HttpResponseException e)
                        {
                            switch (e.StatusCode)
                            {
                            case HttpStatusCode.Unauthorized:
                                if (loginCounter > 1)
                                {
                                    ShowMessage("Passwort oder Nutzername falsch.");
                                }
                                break;

                            default:
                                formsApplication.ShowMessage(String.Format("Verbindung mit fehlgeschlagen.\n{0} ({2} {1})", e.Message, e.StatusCode, (int)e.StatusCode), MessageBoxIcon.Error);
                                return(PpsLoginResult.Canceled);
                            }
                        }
                    }
                }
            }
            catch (HttpRequestException e)
            {
                newRequest?.Dispose();
                if (e.InnerException is WebException we)
                {
                    switch (we.Status)
                    {
                    case WebExceptionStatus.Timeout:
                    case WebExceptionStatus.ConnectFailure:
                        ShowMessage("Server nicht erreichbar.");
                        return(PpsLoginResult.Canceled);
                    }
                }
                else
                {
                    ShowException(ExceptionShowFlags.None, e, "Verbindung fehlgeschlagen.");
                }
                return(PpsLoginResult.Canceled);
            }
            catch
            {
                newRequest?.Dispose();
                throw;
            }
        }         // func LoginAsync