示例#1
0
        public SparkleFetcher(string server, string required_fingerprint, string remote_path,
            string target_folder, bool fetch_prior_history, string canonical_name, string repository, string path,
            string user, string password, ActivityListener activityListener)
            : base(server, required_fingerprint,
                remote_path, target_folder, fetch_prior_history, repository, path, user, password)
        {
            Console.WriteLine("Cmis SparkleFetcher constructor");
            TargetFolder = target_folder;
            RemoteUrl    = new Uri (server);

            Directory.CreateDirectory(Path.Combine(SparkleFolder.ROOT_FOLDER, canonical_name));

            CmisDirectory cmis = new CmisDirectory(canonical_name, path, remote_path, server, user, password, repository, activityListener);
            cmis.Sync();
        }
示例#2
0
 public SparkleRepo(string path, SparkleConfig config, ActivityListener activityListener)
     : base(path, config)
 {
     cmis = new Cmis(path, config, activityListener);
     SparkleLogger.LogInfo("Sync", "Cmis:" + cmis);
 }
示例#3
0
        /**
         * Constructor for SparkleFetcher (when a new CMIS folder is first added)
         */
        public CmisDirectory(string canonical_name, string localPath, string remoteFolderPath,
            string url, string user, string password, string repositoryId,
            ActivityListener activityListener)
        {
            this.activityListener = activityListener;
            this.remoteFolderPath = remoteFolderPath;

            // Set local root folder.
            this.localRootFolder = Path.Combine(SparkleFolder.ROOT_FOLDER, canonical_name);

            database = new CmisDatabase(localRootFolder);

            cmisParameters = new Dictionary<string, string>();
            cmisParameters[SessionParameter.BindingType] = BindingType.AtomPub;
            cmisParameters[SessionParameter.AtomPubUrl] = url;
            cmisParameters[SessionParameter.User] = user;
            cmisParameters[SessionParameter.Password] = password;
            cmisParameters[SessionParameter.RepositoryId] = repositoryId;

            syncing = false;
        }
示例#4
0
        /**
         * Constructor for SparkleRepo (at every launch of CmisSync)
         */
        public CmisDirectory(string localPath, SparkleConfig config,
            ActivityListener activityListener)
        {
            this.activityListener = activityListener;

            // Set local root folder.
            this.localRootFolder = Path.Combine(SparkleFolder.ROOT_FOLDER, localPath);

            database = new CmisDatabase(localRootFolder);

            // Get path on remote repository.
            remoteFolderPath = config.GetFolderOptionalAttribute(Path.GetFileName(localRootFolder), "remoteFolder");

            cmisParameters = new Dictionary<string, string>();
            cmisParameters[SessionParameter.BindingType] = BindingType.AtomPub;
            cmisParameters[SessionParameter.AtomPubUrl] = config.GetUrlForFolder(Path.GetFileName(localRootFolder));
            cmisParameters[SessionParameter.User] = config.GetFolderOptionalAttribute(Path.GetFileName(localRootFolder), "user");
            cmisParameters[SessionParameter.Password] = config.GetFolderOptionalAttribute(Path.GetFileName(localRootFolder), "password");
            cmisParameters[SessionParameter.RepositoryId] = config.GetFolderOptionalAttribute(Path.GetFileName(localRootFolder), "repository");

            syncing = false;
        }
 public ActivityListenerAggregator(ActivityListener overall)
 {
     this.overall = overall;
 }
        public SparkleControllerBase ()
        {
            activityListenerAggregator = new ActivityListenerAggregator(this);

            string app_data_path = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
            string config_path   = Path.Combine (app_data_path, "cmissync");
            
            this.config                 = new SparkleConfig (config_path, "config.xml");
            SparkleConfig.DefaultConfig = this.config;
            FoldersPath                 = this.config.FoldersPath;
        }
        internal TracerProviderSdk(
            Resource resource,
            IEnumerable <string> sources,
            IEnumerable <TracerProviderBuilder.InstrumentationFactory> instrumentationFactories,
            Sampler sampler,
            List <BaseProcessor <Activity> > processors)
        {
            this.resource = resource;
            this.sampler  = sampler;

            foreach (var processor in processors)
            {
                this.AddProcessor(processor);
            }

            if (instrumentationFactories.Any())
            {
                this.adapter = new ActivitySourceAdapter(sampler, this.processor, resource);
                foreach (var instrumentationFactory in instrumentationFactories)
                {
                    this.instrumentations.Add(instrumentationFactory.Factory(this.adapter));
                }
            }

            var listener = new ActivityListener
            {
                // Callback when Activity is started.
                ActivityStarted = (activity) =>
                {
                    OpenTelemetrySdkEventSource.Log.ActivityStarted(activity);

                    if (!activity.IsAllDataRequested)
                    {
                        return;
                    }

                    if (SuppressInstrumentationScope.IncrementIfTriggered() == 0)
                    {
                        activity.SetResource(this.resource);
                        this.processor?.OnStart(activity);
                    }
                },

                // Callback when Activity is stopped.
                ActivityStopped = (activity) =>
                {
                    OpenTelemetrySdkEventSource.Log.ActivityStopped(activity);

                    if (!activity.IsAllDataRequested)
                    {
                        return;
                    }

                    if (SuppressInstrumentationScope.DecrementIfTriggered() == 0)
                    {
                        this.processor?.OnEnd(activity);
                    }
                },
            };

            if (sampler is AlwaysOnSampler)
            {
                listener.Sample = (ref ActivityCreationOptions <ActivityContext> options) =>
                                  !Sdk.SuppressInstrumentation ? ActivitySamplingResult.AllDataAndRecorded : ActivitySamplingResult.None;
            }
            else if (sampler is AlwaysOffSampler)
            {
                listener.Sample = (ref ActivityCreationOptions <ActivityContext> options) =>
                                  !Sdk.SuppressInstrumentation ? PropagateOrIgnoreData(options.Parent.TraceId) : ActivitySamplingResult.None;
            }
            else
            {
                // This delegate informs ActivitySource about sampling decision when the parent context is an ActivityContext.
                listener.Sample = (ref ActivityCreationOptions <ActivityContext> options) =>
                                  !Sdk.SuppressInstrumentation ? ComputeActivitySamplingResult(options, sampler) : ActivitySamplingResult.None;
            }

            if (sources.Any())
            {
                // Sources can be null. This happens when user
                // is only interested in InstrumentationLibraries
                // which do not depend on ActivitySources.

                var wildcardMode = false;

                // Validation of source name is already done in builder.
                foreach (var name in sources)
                {
                    if (name.Contains('*'))
                    {
                        wildcardMode = true;
                    }
                }

                if (wildcardMode)
                {
                    var pattern = "^(" + string.Join("|", from name in sources select '(' + Regex.Escape(name).Replace("\\*", ".*") + ')') + ")$";
                    var regex   = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);

                    // Function which takes ActivitySource and returns true/false to indicate if it should be subscribed to
                    // or not.
                    listener.ShouldListenTo = (activitySource) => regex.IsMatch(activitySource.Name);
                }
                else
                {
                    var activitySources = new Dictionary <string, bool>(StringComparer.OrdinalIgnoreCase);

                    foreach (var name in sources)
                    {
                        activitySources[name] = true;
                    }

                    // Function which takes ActivitySource and returns true/false to indicate if it should be subscribed to
                    // or not.
                    listener.ShouldListenTo = (activitySource) => activitySources.ContainsKey(activitySource.Name);
                }
            }

            ActivitySource.AddActivityListener(listener);
            this.listener = listener;
        }
示例#8
0
        public void TestExpectedListenersReturnValues()
        {
            RemoteExecutor.Invoke(() => {
                int activityStartCount = 0;
                int activityStopCount  = 0;

                ActivitySource source         = new ActivitySource("MultipleListenerSource");
                ActivityListener [] listeners = new ActivityListener[4];

                listeners[0] = new ActivityListener
                {
                    ActivityStarted     = (activity) => { activityStartCount++; Assert.NotNull(activity); },
                    ActivityStopped     = (activity) => { activityStopCount++; Assert.NotNull(activity); },
                    ShouldListenTo      = (activitySource) => true,
                    SampleUsingParentId = (ref ActivityCreationOptions <string> activityOptions) => ActivitySamplingResult.None,
                    Sample = (ref ActivityCreationOptions <ActivityContext> activityOptions) => ActivitySamplingResult.None
                };
                ActivitySource.AddActivityListener(listeners[0]);

                Assert.Null(source.StartActivity("a1"));

                Assert.Equal(0, activityStartCount);
                Assert.Equal(0, activityStopCount);

                listeners[1] = new ActivityListener
                {
                    ActivityStarted     = (activity) => { activityStartCount++; Assert.NotNull(activity); },
                    ActivityStopped     = (activity) => { activityStopCount++; Assert.NotNull(activity); },
                    ShouldListenTo      = (activitySource) => true,
                    SampleUsingParentId = (ref ActivityCreationOptions <string> activityOptions) => ActivitySamplingResult.PropagationData,
                    Sample = (ref ActivityCreationOptions <ActivityContext> activityOptions) => ActivitySamplingResult.PropagationData
                };
                ActivitySource.AddActivityListener(listeners[1]);

                using (Activity a2 = source.StartActivity("a2"))
                {
                    Assert.False(a2.IsAllDataRequested);
                    Assert.True((a2.ActivityTraceFlags & ActivityTraceFlags.Recorded) == 0);

                    Assert.Equal(2, activityStartCount);
                    Assert.Equal(0, activityStopCount);
                }

                Assert.Equal(activityStartCount, activityStopCount);
                Assert.Equal(2, activityStopCount);

                listeners[2] = new ActivityListener
                {
                    ActivityStarted     = (activity) => { activityStartCount++; Assert.NotNull(activity); },
                    ActivityStopped     = (activity) => { activityStopCount++; Assert.NotNull(activity); },
                    ShouldListenTo      = (activitySource) => true,
                    SampleUsingParentId = (ref ActivityCreationOptions <string> activityOptions) => ActivitySamplingResult.AllData,
                    Sample = (ref ActivityCreationOptions <ActivityContext> activityOptions) => ActivitySamplingResult.AllData
                };
                ActivitySource.AddActivityListener(listeners[2]);

                using (Activity a3 = source.StartActivity("a3"))
                {
                    Assert.True(a3.IsAllDataRequested);
                    Assert.True((a3.ActivityTraceFlags & ActivityTraceFlags.Recorded) == 0);

                    Assert.Equal(5, activityStartCount);
                    Assert.Equal(2, activityStopCount);
                }

                Assert.Equal(activityStartCount, activityStopCount);
                Assert.Equal(5, activityStopCount);

                listeners[3] = new ActivityListener
                {
                    ActivityStarted     = (activity) => { activityStartCount++; Assert.NotNull(activity); },
                    ActivityStopped     = (activity) => { activityStopCount++; Assert.NotNull(activity); },
                    ShouldListenTo      = (activitySource) => true,
                    SampleUsingParentId = (ref ActivityCreationOptions <string> activityOptions) => ActivitySamplingResult.AllDataAndRecorded,
                    Sample = (ref ActivityCreationOptions <ActivityContext> activityOptions) => ActivitySamplingResult.AllDataAndRecorded
                };
                ActivitySource.AddActivityListener(listeners[3]);

                using (Activity a4 = source.StartActivity("a4"))
                {
                    Assert.True(a4.IsAllDataRequested);
                    Assert.True((a4.ActivityTraceFlags & ActivityTraceFlags.Recorded) != 0, $"a4.ActivityTraceFlags failed: {a4.ActivityTraceFlags}");

                    Assert.Equal(9, activityStartCount);
                    Assert.Equal(5, activityStopCount);
                }

                foreach (IDisposable listener in listeners)
                {
                    listener.Dispose();
                }

                Assert.Equal(activityStartCount, activityStopCount);
                Assert.Equal(9, activityStopCount);
                Assert.Null(source.StartActivity("a5"));
            }).Dispose();
        }