示例#1
0
        public override Task Initialize()
        {
            ActivityUI.Header.Value = ActivityId.ToString();
            CrateSignaller.MarkAvailableAtRuntime <StandardTableDataCM>("Table");

            return(Task.FromResult(0));
        }
示例#2
0
 /// <summary>
 /// Called when the start header is serialized using the specified XML writer.
 /// </summary>
 /// <param name="writer">
 /// An <see cref="XmlDictionaryWriter"/> that is used to serialize the start header.
 /// </param>
 /// <param name="messageVersion">Unused.</param>
 /// <remarks>
 /// We override the default implementation in order to force a specific message
 /// layout, rather than relying on the default implementation which doesn't
 /// serialize in the expected manner.
 /// </remarks>
 protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
 {
     writer.WriteElementString("ActivityId", ActivityId.ToString());
     writer.WriteElementString("AccessToken", AccessToken);
     writer.WriteElementString("ExecutionId", ExecutionId.ToString());
     writer.WriteElementString("Action", Action);
     writer.WriteElementString("MomentStart", MomentStart.ToString("o", CultureInfo.InvariantCulture));
 }
示例#3
0
        public string GetLinkAddress()
        {
            if (ActivityId == null)
            {
                return("");
            }

            return(string.Format("/Activity/ViewActivity/{0}", ActivityId.ToString()));
        }
        public override async Task FollowUp()
        {
            await FillDropdowns();

            if (!ActivityUI.BuildSolutionButton.Clicked)
            {
                return;
            }
            ActivityPayload.ChildrenActivities.Clear();
            //We need to keep the versions we know how to work with. If later these child activities will be upgraded we probably won't be able to configure them properly
            var activityTemplates = await HubCommunicator.GetActivityTemplates();

            var configureMonitorActivityTask = ConfigureMonitorActivity(activityTemplates);
            var configureSetDelayTask        = ConfigureSetDelayActivity(activityTemplates);
            var configureQueryFr8Task        = ConfigureQueryFr8Activity(activityTemplates);
            var configureTestDataTask        = ConfigureFilterDataActivity(activityTemplates);
            await Task.WhenAll(configureMonitorActivityTask, configureSetDelayTask, configureQueryFr8Task, configureTestDataTask);

            //If solution was already built and  we should replace notifier action
            var previousNotifierId         = NotifierActivityId;
            var previousNotifierTemplateId = NotifierActivityTemplateId;
            var isInitialBuild             = previousNotifierId == Guid.Empty;

            if (isInitialBuild)
            {
                await ConfigureBuildMessageActivity(activityTemplates);
            }
            var currentNotifierTemplateId = NotifierActivityTemplateId = Guid.Parse(ActivityUI.NotifierSelector.Value);

            if (isInitialBuild || currentNotifierTemplateId != previousNotifierTemplateId)
            {
                //If it is not initial build we should remove existing notifier from plan
                var previousNotifierOrdering = 3;
                if (!isInitialBuild)
                {
                    var currentPlan      = (await HubCommunicator.GetPlansByActivity(ActivityId.ToString()));
                    var startingSubPlan  = currentPlan.SubPlans.First(x => x.SubPlanId == currentPlan.StartingSubPlanId);
                    var previousNotifier = startingSubPlan.Activities.FirstOrDefault(x => x.Id == previousNotifierId);
                    if (previousNotifier != null)
                    {
                        previousNotifierOrdering = previousNotifier.Ordering;
                        await HubCommunicator.DeleteActivity(previousNotifierId);
                    }
                }
                //And we should add new notifier anyway
                NotifierActivityId = await ConfigureNotifierActivity(activityTemplates, previousNotifierOrdering);
            }
            ;
            ActivityPayload.ChildrenActivities.Sort((x, y) => x.Ordering.CompareTo(y.Ordering));
            ActivityPayload.ChildrenActivities[0] = configureMonitorActivityTask.Result;
            ActivityPayload.ChildrenActivities[2] = configureQueryFr8Task.Result;
        }
示例#5
0
 public Dictionary <string, string> ToQueryStringDictionary()
 {
     return(new Dictionary <string, string>
     {
         { "userId", UserId?.ToString("D") },
         { "startDate", StartDate?.ToString("yyyy-MM-dd") },
         { "endDate", EndDate?.ToString("yyyy-MM-dd") },
         { "activityId", ActivityId?.ToString("D") },
         { "clientProjectId", ClientProjectId?.ToString("D") }
     }
            .Where(x => x.Value != null)
            .ToDictionary(x => x.Key, x => x.Value));
 }
示例#6
0
        private async Task ProcessCollectionControls(StandardConfigurationControlsCM collectionControls)
        {
            var fieldsPayloadCrate = Crate.FromContent(RuntimeFieldCrateLabelPrefix, new StandardPayloadDataCM(new KeyValueDTO[] { }));

            fieldsPayloadCrate.SourceActivityId = ActivityId.ToString();

            Payload.Add(fieldsPayloadCrate);
            foreach (var controlDefinitionDTO in collectionControls.Controls)
            {
                ProcessCollectionControl(controlDefinitionDTO);
            }

            await ProcessFilePickers(collectionControls.Controls.Where(a => a.Type == ControlTypes.FilePicker));
        }
示例#7
0
 public static void LogCpuMonitoringEvent(string message, string sessionId)
 {
     DaasEventSource.Instance.LogCpuMonitoringEvent(SiteName, _assemblyVersion, sessionId, ActivityId.ToString(), message);
     LogDiagnostic("CPUMonitoring [INF] {0} {1} {2}", sessionId, ActivityId.ToString(), message);
 }
示例#8
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        internal string ToQueryString()
        {
            var dictionary = new Dictionary <string, string>();

            if (Agent != null)
            {
                dictionary.Add("agent", Agent.ToJson());
            }

            if (VerbId != null)
            {
                dictionary.Add("verb", VerbId.ToString());
            }

            if (ActivityId != null)
            {
                dictionary.Add("activity", ActivityId.ToString());
            }

            if (Registration.HasValue)
            {
                dictionary.Add("registration", Registration.Value.ToString());
            }

            if (RelatedActivities.HasValue)
            {
                dictionary.Add("related_activities", RelatedActivities.Value ? "true" : "false");
            }

            if (RelatedAgents.HasValue)
            {
                dictionary.Add("related_agents", RelatedAgents.Value ? "true" : "false");
            }

            if (Since.HasValue)
            {
                dictionary.Add("since", Since.Value.ToString("o"));
            }

            if (Until.HasValue)
            {
                dictionary.Add("until", Until.Value.ToString("o"));
            }

            if (Limit.HasValue)
            {
                dictionary.Add("limit", Limit.Value.ToString());
            }

            if (Format.HasValue)
            {
                dictionary.Add("format", Format.ToString().ToLower());
            }

            if (Attachments.HasValue)
            {
                dictionary.Add("attachments", Attachments.Value ? "true" : "false");
            }

            if (Ascending.HasValue)
            {
                dictionary.Add("ascending", Ascending.Value ? "true" : "false");
            }

            if (!dictionary.Any())
            {
                return(string.Empty);
            }

            return(string.Concat("?", string.Join("&", dictionary.Select(x => $"{WebUtility.UrlEncode(x.Key)}={WebUtility.UrlEncode(x.Value)}"))));
        }
示例#9
0
 public override int GetHashCode()
 {
     return((ActivityId.ToString() + "|" + RoleId.ToString()).GetHashCode());
 }
示例#10
0
 public override Task Initialize()
 {
     ActivityUI.TextBlock.Value = ActivityId.ToString();
     return(Task.FromResult(0));
 }
示例#11
0
 /// <summary>
 /// Returns a <see cref="System.String"/> that represents this instance.
 /// </summary>
 /// <returns>
 /// A <see cref="System.String"/> that represents this instance.
 /// </returns>
 public override string ToString()
 {
     return(TaskName + ActivityId.ToString("D"));
 }
示例#12
0
 public static void LogDiagnoserErrorEvent(string message, Exception ex)
 {
     DaasEventSource.Instance.LogDiagnoserErrorEvent(SiteName, _assemblyVersion, DaasSessionId, ActivityId.ToString(), CallerComponent, message, ex.GetType().ToString(), ex.Message, ex.StackTrace);
     LogDiagnostic("Diagnoser [ERR] {0} {1} {2} {3} {4} {5} {6}", DaasSessionId, ActivityId.ToString(), CallerComponent, message, ex.GetType().ToString(), ex.Message, ex.StackTrace);
 }
示例#13
0
 public static void LogDiagnoserErrorEvent(string message, string exceptionMessage)
 {
     DaasEventSource.Instance.LogDiagnoserErrorEvent(SiteName, _assemblyVersion, DaasSessionId, ActivityId.ToString(), CallerComponent, message, string.Empty, exceptionMessage, string.Empty);
     LogDiagnostic("Diagnoser [ERR] {0} {1} {2} {3} {4}", DaasSessionId, ActivityId.ToString(), CallerComponent, message, exceptionMessage);
 }
示例#14
0
 public static void LogDiagnoserEvent(string message)
 {
     DaasEventSource.Instance.LogDiagnoserEvent(SiteName, _assemblyVersion, DaasSessionId, ActivityId.ToString(), CallerComponent, message);
     LogDiagnostic("Diagnoser [INF] {0} {1} {2} {3}", DaasSessionId, ActivityId.ToString(), CallerComponent, message);
 }
 /// <summary>
 /// Returns a <see cref="System.String"/> that represents this instance.
 /// </summary>
 /// <returns>
 /// A <see cref="System.String"/> that represents this instance.
 /// </returns>
 public override string ToString() => TaskName + ActivityId.ToString("D");
示例#16
0
 public static void LogSessionVerboseEvent(string message, string sessionId)
 {
     DaasEventSource.Instance.LogSessionVerboseEvent(SiteName, _assemblyVersion, sessionId, ActivityId.ToString(), message);
     LogDiagnostic("Session [VERB] {0} {1} {2}", sessionId, ActivityId.ToString(), message);
 }
示例#17
0
 public static void TraceStats(string message)
 {
     if (!KustoLoggingDisabled)
     {
         DaasEventSource.Instance.LogDiagnoserStats(SiteName, _assemblyVersion, DaasSessionId, ActivityId.ToString(), CallerComponent, message);
     }
 }
示例#18
0
        // ReSharper disable once ArrangeTypeMemberModifiers
        // ReSharper disable once UnusedParameter.Local
#pragma warning disable IDE0060 // Remove unused parameter
        private static void Main(string[] args)
#pragma warning restore IDE0060 // Remove unused parameter
        {
            var storedFiles = new Dictionary <string, string>();

            using (var stream = new FileStream(@"C:\Users\maraz\Desktop\moves\log.txt", FileMode.OpenOrCreate))
            {
                using (var logFile = new StreamReader(stream))
                {
                    var records = logFile.ReadToEnd().Split(Environment.NewLine);
                    if (records.Length > 1)
                    {
                        storedFiles = records.Where(e => e.Contains("|")).Select(e =>
                        {
                            var parts = e.Split("|");
                            return(new { Key = parts[0], Value = parts[1] });
                        })
                                      .ToDictionary(e => e.Key, e => e.Value);
                    }
                }
            }

            var configuration = SetupConfiguration();
            var client        = new Client(configuration, new ConsoleLogger <Client>());

            System.Console.WriteLine("Loading event types");

            client.Authenticate().Wait();
            var eventTypes = client.LoadEventTypes().Result;

            Task.Delay(Timeout).Wait();

            System.Console.WriteLine("Loading activity types");

            var activityTypes = client.LoadActivityTypes().Result;

            System.Console.WriteLine("-------------------------------------------------------------------------------");

            var allGpxFiles = Directory.GetFiles(@"C:\Users\maraz\Desktop\moves", "*.gpx*", SearchOption.AllDirectories);

            foreach (var gpxFile in allGpxFiles)
            {
                Move activityData = null;

                try
                {
                    var jsonDataFile = gpxFile.Replace("gps_data.gpx", "move_data.json");

                    using (var jsonDataStream = new StreamReader(jsonDataFile))
                    {
                        activityData = JsonConvert.DeserializeObject <Move>(jsonDataStream.ReadToEnd());
                    }

                    if (storedFiles.ContainsKey(activityData.MoveId.ToString()))
                    {
                        System.Console.WriteLine($"Garmin Connect move {activityData.MoveId} (Garmin activity {storedFiles[activityData.MoveId.ToString()]}) should be already stored or upload failed.");
                        System.Console.WriteLine("-------------------------------------------------------------------------------");
                        continue;
                    }

                    System.Console.WriteLine($"Uploading Garmin Connect move {activityData.MoveId}");
                    var(Success, ActivityId) = client.UploadActivity(gpxFile, new FileFormat {
                        FormatKey = "gpx"
                    }).Result;
                    if (!Success)
                    {
                        System.Console.WriteLine($"Error while uploading uploading Garmin Connect move {activityData.MoveId}.");
                        throw new Exception("Error while uploading uploading Garmin Connect move {activityData.MoveId}.");
                    }

                    var name = activityData.Notes != null
                ? activityData.Notes.Split('.').FirstOrDefault() ?? activityData.MoveId.ToString()
                : activityData.MoveId.ToString();

                    System.Console.WriteLine($"Setting name of Garmin Connect move {activityData.MoveId} (Garmin activity {ActivityId}) to '{name}'.");
                    client.SetActivityName(ActivityId, name).Wait();

                    Task.Delay(Timeout).Wait();

                    var description = CreateDescription(activityData);

                    System.Console.WriteLine($"Setting description of Garmin Connect move {activityData.MoveId} (Garmin activity {ActivityId}) to '{description}'.");
                    client.SetActivityDescription(ActivityId, description).Wait();

                    Task.Delay(Timeout).Wait();

                    var activityType = activityTypes.FirstOrDefault(e => string.Equals(e.TypeKey, ResolveActivityType(activityData.ActivityID).TypeKey, StringComparison.InvariantCultureIgnoreCase));
                    if (activityType != null)
                    {
                        System.Console.WriteLine($"Setting activity type of Garmin Connect move {activityData.MoveId} (Garmin activity {ActivityId}) to '{activityType.TypeKey}'.");
                        client.SetActivityType(ActivityId, activityType).Wait();
                        Task.Delay(Timeout).Wait();
                    }

                    var eventType = eventTypes.FirstOrDefault(e => string.Equals(e.TypeKey, activityType != null && activityType.TypeId == (int)ActivityTypeEnum.Running
                        ? EventTypeEnum.Training.ToString()
                        : EventTypeEnum.Fitness.ToString(), StringComparison.InvariantCultureIgnoreCase));

                    if (eventType != null)
                    {
                        System.Console.WriteLine($"Setting event type of Garmin Connect move {activityData.MoveId} (Garmin activity {ActivityId}) to '{eventType.TypeKey}'.");
                        client.SetEventType(ActivityId, eventType).Wait();
                        Task.Delay(Timeout).Wait();
                    }

                    storedFiles.Add(activityData.MoveId.ToString(), ActivityId.ToString());
                    UpdateLogFile(activityData.MoveId, ActivityId);

                    System.Console.WriteLine("-------------------------------------------------------------------------------");
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine($"Error while uploading Garmin Connect move {activityData?.MoveId}: {ex.Message}.");
                    System.Console.WriteLine($"Error while uploading move: {ex.StackTrace}.");
                    storedFiles.Add(activityData.MoveId.ToString(), "0");
                    UpdateLogFile(activityData.MoveId, 0);
                }
            }
        }