コード例 #1
0
ファイル: User.cs プロジェクト: raudut/Infernet-asthme
        /// <summary>
        /// Anonymize the names.
        /// </summary>
        /// <param name="anonymizeMethod">The anonymize.</param>
        /// <exception cref="System.NotImplementedException">Unknown anonymize method</exception>
        internal void AnonymizeNames(Anonymize anonymizeMethod)
        {
            this.NameMapping = new Dictionary <string, string>();
            Func <bool> initFunc = null;
            Func <ContactDetails, string> anonymizeFunc = null;

            switch (anonymizeMethod)
            {
            case Anonymize.AnonymizeByRandomNames:
                var randomNames = new MBMLCommon.RandomNameGenerator().GetEnumerator();
                initFunc      = randomNames.MoveNext;
                anonymizeFunc = _ => randomNames.Current;
                break;

            case Anonymize.AnonymizeByCodes:
                var generator = new HashCodeNameGenerator("User{0}");
                anonymizeFunc = generator.GetValue;
                break;

            case Anonymize.DoNotAnonymize:
                break;

            default:
                throw new NotSupportedException("Unknown anonymize method");
            }

            foreach (Person person in this.Contacts.Where(p => p != UnknownPerson))
            {
                AnonymizeIdentities(person.Identities, initFunc, anonymizeFunc, this.NameMapping, anonymizeMethod);
            }

            AnonymizeIdentities(this.Identities, initFunc, anonymizeFunc, this.NameMapping, anonymizeMethod);
        }
コード例 #2
0
ファイル: Db.cs プロジェクト: TheIndra55/Sanara
 public bool IsAnonymized(ulong guildId)
 {
     if (!Anonymize.ContainsKey(guildId))
     {
         return(false);
     }
     return(Anonymize[guildId]);
 }
コード例 #3
0
ファイル: Db.cs プロジェクト: TheIndra55/Sanara
        public async Task InitGuild(IGuild guild)
        {
            if (Languages.ContainsKey(guild.Id)) // If somehow InitGuild is called 2 times for the same guild we ignore it
            {
                return;
            }
            string guildIdStr = guild.Id.ToString();

            if (await R.Db(dbName).Table("Guilds").GetAll(guildIdStr).Count().Eq(0).RunAsync <bool>(conn))
            {
                await R.Db(dbName).Table("Guilds").Insert(R.HashMap("id", guildIdStr)
                                                          .With("Prefix", "s.")
                                                          .With("Language", "en")
                                                          .With("Availability", defaultAvailability)
                                                          ).RunAsync(conn);
            }
            dynamic json = await R.Db(dbName).Table("Guilds").Get(guildIdStr).RunAsync(conn);

            Languages.Add(guild.Id, (string)json.Language);
            Prefixs.Add(guild.Id, (string)json.Prefix);
            string availability = (string)json.Availability;

            if (availability == null)
            {
                Availability.Add(guild.Id, defaultAvailability);
            }
            else
            {
                string newAvailability = availability;
                while (newAvailability.Length < defaultAvailability.Length)
                {
                    newAvailability += "1";
                }
                Availability.Add(guild.Id, newAvailability);
            }
            string anonymize = (string)json.Anonymize;

            if (anonymize != null)
            {
                Anonymize.Add(guild.Id, bool.Parse(anonymize));
            }
            else
            {
                Anonymize.Add(guild.Id, false);
            }
            string anime = (string)json.animeSubscription;

            if (anime != null && anime != "0")
            {
                AnimeSubscription.Add((await guild.GetTextChannelAsync(ulong.Parse(anime)), null));
            }
            string nhentai = (string)json.nhentaiSubscription;

            if (nhentai != null && nhentai != "0")
            {
                NHentaiSubscription.Add((await guild.GetTextChannelAsync(ulong.Parse(nhentai)), Subscription.SubscriptionTags.ParseSubscriptionTags(json.nhentaiSubscriptionTags.ToObject <string[]>(), false)));
            }
        }
コード例 #4
0
ファイル: Desensitize.cs プロジェクト: regisroy/docx4j.NET
        static void Main(string[] args)
        {
            // set up logging
            clog = LoggingConfigurator.configureLogging();
            clog.Info("Hello from Common Logging");

            // create a dir to save the output docx
            string projectDir = System.IO.Directory.GetParent(
                System.IO.Directory.GetParent(
                    Environment.CurrentDirectory.ToString()).ToString()).ToString() + "\\";

            System.IO.Directory.CreateDirectory(projectDir + "OUT");

            string fileIN  = projectDir + @"src\samples\resources\sample-docx.docx";
            string fileOUT = projectDir + @"OUT\Anon.docx";

            WordprocessingMLPackage pkg = Docx4J.load(new java.io.File(fileIN));
            // or
            // WordprocessingMLPackage pkg = Plutext.Docx4NET.WordprocessingMLPackageFactory.createWordprocessingMLPackage(fileIN);


            // Anonymize/densensitize it
            Anonymize       anon   = new Anonymize(pkg);
            AnonymizeResult result = anon.go();


            // Report
            clog.Info("\n\n REPORT for " + fileIN + "\n\n");
            if (result.isOK())
            {
                clog.Info("document successfully anonymised.");
            }
            else
            {
                clog.Info("document partially anonymised; please check " + fileOUT);

                if (result.getUnsafeParts().size() > 0)
                {
                    clog.Info("The following parts may leak info:");
                    foreach (Part p in result.getUnsafeParts())
                    {
                        clog.Info(p.getPartName().getName() + ", of type " + p.getClass().getName());
                    }
                }

                // unsafe objects
                clog.Info(result.reportUnsafeObjects());
            }

            clog.Info("\n\n .. end REPORT for " + fileIN + "\n\n");


            // save result to file
            Docx4J.save(pkg, new java.io.File(fileOUT));
            clog.Info("\n\n saved " + fileOUT + "\n\n");
        }
コード例 #5
0
        /// <summary>
        /// Loads the user from desktop search.
        /// </summary>
        /// <param name="months">The months.</param>
        /// <param name="anonymizeUserData">The anonymize user data.</param>
        public void LoadUserFromDesktopSearch(int months, Anonymize anonymizeUserData)
        {
            this.Inbox.ReplyToModelProgress.Status = "Loading data";
            this.User = this.LoadInputsFromDesktopFetcher(months);
            if (this.User == null)
            {
                var message = string.Format("\n* Please re-run with more months than {0} months, e.g.: *\n", this.Months)
                              + string.Format(
                    "{0} /m {1}\n",
                    AppDomain.CurrentDomain.FriendlyName,
                    Math.Min(this.Months + Program.DefaultMonths, Program.MaxMonths));
                throw new Exception(message);
            }

            this.Inbox.ReplyToModelProgress.PercentComplete = 25;

            this.User.Anonymize = anonymizeUserData;

            this.Inbox.ReplyToModelProgress.Status = "Computing Features";

            this.User.FeatureSetTypes = new[]
            {
                FeatureSetType.Initial,
                FeatureSetType.WithSubjectPrefix,
                FeatureSetType.WithRecipient,
                FeatureSetType.WithRecipient2
            };

            this.User.CurrentFeatureSetType = FeatureSetType.Initial;
            this.UserTrials.Clear();

            foreach (var featureSetType in this.User.FeatureSetTypes)
            {
                var trial = new ModelRunner.Trial {
                    Name = "CollectorUser"
                };
                this.UserTrials.Add(featureSetType, trial);
                trial.InputsCollection.Add(Inputs.FromUser(this.User, featureSetType));
                trial.TrainMessages      = this.User.TrainMessages;
                trial.ValidationMessages = this.User.ValidationMessages;
                trial.TestMessages       = this.User.TestMessages;
            }

            this.Inbox.ReplyToModelProgress.PercentComplete = 50;

            Console.WriteLine(Environment.NewLine + @"* Data collection complete *" + Environment.NewLine);

            this.Inbox.User = this.User;
        }
コード例 #6
0
ファイル: User.cs プロジェクト: raudut/Infernet-asthme
        /// <summary>
        /// Anonymize the identities.
        /// </summary>
        /// <param name="identities">The identities.</param>
        /// <param name="initAction">The initialize action.</param>
        /// <param name="anonymizeFunc">The anonymize function.</param>
        /// <param name="nameMapping">The name mapping.</param>
        /// <param name="anonymizeMethod">The anonymize method.</param>
        private static void AnonymizeIdentities(
            IList <ContactDetails> identities,
            Func <bool> initAction,
            Func <ContactDetails, string> anonymizeFunc,
            IDictionary <string, string> nameMapping,
            Anonymize anonymizeMethod)
        {
            if (anonymizeFunc == null)
            {
                identities.ForEach(ia => ia.Anonymize = Anonymize.DoNotAnonymize);
                return;
            }

            for (int i = 0; i < identities.Count; i++)
            {
                if (initAction != null)
                {
                    if (!initAction())
                    {
                        throw new InvalidOperationException("Initialization action failed");
                    }
                }

                ContactDetails identity = identities[i];
                if (identity == UnknownContactDetails)
                {
                    continue;
                }

                identity.Anonymize = Anonymize.DoNotAnonymize;

                string name = identity.Name.ToString();
                if (!nameMapping.ContainsKey(name))
                {
                    nameMapping[name] = anonymizeFunc(identity);
                }

                identity.AnonymizedName = new Uncertain <string> {
                    Value = nameMapping[name], Probability = 1.0
                };
                identity.AnonymizedEmail = new Uncertain <string>
                {
                    Value       = nameMapping[name].ToLower().Replace(".", string.Empty).Replace(' ', '.') + i + "@example.com",
                    Probability = 1.0
                };

                identity.Anonymize = anonymizeMethod;
            }
        }