private void FetchServices(Timer obj)
        {
            var knownServices = RemoteServerManager.GetAllGroups().SelectMany(g => g.GetAllRemoteServers()).Select(s => s.ID);
            var joined        = registry.Keys.Except(knownServices);
            var left          = knownServices.Except(registry.Keys);

            foreach (ushort joinedID in joined)
            {
                if (joinedID != RemoteServerManager.ServerID)
                {
                    RegistryEntry service = registry[joinedID];
                    string        group   = service.Group;

                    Logger.Trace($"Discovered server {joinedID} from group '{group}'.");

                    HandleServerJoin(joinedID, group, service.Host, service.Port, new Dictionary <string, string>(service.Properties));
                }
            }

            //TODO consider just a set method instead of/as well as join/leave
            foreach (ushort leftID in left)
            {
                if (leftID != RemoteServerManager.ServerID)
                {
                    Logger.Trace($"Server {leftID} has left the cluster.");

                    HandleServerLeave(leftID);
                }
            }
        }
Пример #2
0
        public async Task <DeviceConfiguration> DetermineConfiguration(GetDeviceConfiguration query)
        {
            var device = await _deviceRepo.GetDevice(query.DeviceId);

            if (device == null)
            {
                return(DeviceConfiguration.DeviceNotFound);
            }

            var application = await _applicationRepo.GetApplication(device.ApplicationId);

            // Get the application level configurations and override with any device level
            // configuration settings.
            DeviceConfiguration appConfig    = application.BuildConfiguration();
            DeviceConfiguration deviceConfig = device.BuildConfiguration();

            var configuration = appConfig.OverrideWith(deviceConfig);

            // Based on the combined settings, set the corresponding application and
            // agent versions.
            RegistryEntry registry = await GetRegistryEntry(configuration);

            configuration.SetRegistry(registry);

            return(configuration);
        }
Пример #3
0
        /// <summary>
        /// Update skynet registry entry
        /// Gets the current version, updates the revision and stores the new data
        /// </summary>
        /// <param name="privateKey"></param>
        /// <param name="publicKey"></param>
        /// <param name="dataKey"></param>
        /// <param name="data"></param>
        /// <param name="revision">optional forced revision</param>
        /// <param name="timeout">Time you want to wait for getting a SkyDB entry</param>
        /// <returns></returns>
        public async Task <bool> UpdateRegistry(byte[] privateKey, byte[] publicKey, RegistryKey dataKey, string data, int?revision = null, TimeSpan?timeout = null)
        {
            //Get current document
            RegistryEntry?current = new RegistryEntry(dataKey);

            if (!revision.HasValue)
            {
                current = await GetRegistry(publicKey, dataKey, timeout);

                if (current == null)
                {
                    current = new RegistryEntry(dataKey);
                }
                else
                {
                    current.Revision += 1;
                }
            }
            else
            {
                //Do not get entry to save time, but set forced revision
                current.Revision = revision.Value;
            }

            current.SetData(data);

            //Set new version
            return(await SetRegistry(privateKey, publicKey, current));
        }
Пример #4
0
 public void ReturnsTrue_WhenInputIsValid(string input, string expected)
 {
     RegistryEntry.TryParseName(input, out var output)
     .Should()
     .BeTrue();
     output.Should().Be(expected);
 }
Пример #5
0
        public void TestDataKey()
        {
            var           encodedDK = "7c96a0537ab2aaac9cfe0eca217732f4e10791625b4ab4c17e4d91c8078713b9";
            RegistryEntry r         = new RegistryEntry(new RegistryKey("app"));
            var           hex       = r.Key.GetHexKey();

            Assert.AreEqual(encodedDK, hex.ToLowerInvariant());
        }
 private void removeByType(RegistryEntry entry)
 {
     Type type = entry.EventType;
     if (_byType.ContainsKey(type))
     {
         _byType[type].Remove(entry);
     }
 }
        private RegistryEntry GetRegistryEntry(RegistryEntry registryEntry)
        {
            var query = from o in EphorteContext.Query <RegistryEntry>()
                        where o.Id == registryEntry.Id
                        select o;

            return(query.FirstOrDefault());
        }
Пример #8
0
        private RegistryEntry GetProgramWithEstimatedSize(RegistryEntry program)
        {
            if ((program.EstimatedSize == null || program.EstimatedSize == 0) && !string.IsNullOrEmpty(program.InstallLocation))
            {
                program.EstimatedSize = CalculateInstallSize(program.InstallLocation);
            }

            return(program);
        }
Пример #9
0
        public void Register(Func <IDocumentHandler> handlerConstructor, int priority = 0)
        {
            var entry = new RegistryEntry <Func <IDocumentHandler> >()
            {
                Priority = priority,
                Value    = handlerConstructor
            };

            list.Add(entry);
        }
        private void indexByType(RegistryEntry entry)
        {
            Type type = entry.EventType;
            if (!_byType.ContainsKey(type))
            {
                _byType[type] = new List<RegistryEntry>();
            }

            _byType[type].Add(entry);
        }
Пример #11
0
    public void Register(RegistryEntry <T> entry)
    {
        string id = entry.GetId();

        if (entries.ContainsKey(id))
        {
            throw new System.Exception("Duplicate registry entry with id " + id + ".");
        }
        entries.Add(id, entry.GetRegistryObject());
    }
Пример #12
0
        public static byte[] Sign(this RegistryEntry entry, byte[] privateKey, byte[] publicKey)
        {
            var hashAll = entry.GetFullHash();

            var signature = Chaos.NaCl.Ed25519.Sign(hashAll, privateKey);

            //var validationResult = await Signer.ValidateAsync(signature, hashAll, publicKey);

            return(signature);
        }
Пример #13
0
        public void AddRegistryEntryDocument(RegistryEntry registryEntry, DocumentDescription documentDescription,
                                             string documentLinkTypeId)
        {
            var registryEntryDocument = _ephorteContext.Create <RegistryEntryDocument>();

            registryEntryDocument.RegistryEntry       = registryEntry;
            registryEntryDocument.DocumentDescription = documentDescription;
            registryEntryDocument.DocumentLinkTypeId  = documentLinkTypeId;
            _ephorteContext.Add(registryEntryDocument);
        }
Пример #14
0
 public RegistryEntryViewModel(RegistryEntry entry)
 {
     Uri           = entry.Uri;
     Name          = entry.Name;
     Database      = entry.Database;
     AuthorityUri  = entry.AuthorityUri;
     State         = entry.State.ToString();
     Tags          = string.Join(", ", entry.TagsAsArray);
     LastUpdated   = entry.LastUpdated;
     this.EndPoint = EndPoint.FromUri(entry.Uri);
 }
Пример #15
0
        private void MakeRegistryEntries(RegistryEntry entry, RegistryKey hKey)
        {
            var key = hKey.CreateSubKey(entry.Key);

            var value = ReplacePlaceholder(entry.Value, entry.Bitness);

            if (!(string.IsNullOrWhiteSpace(entry.Name) && string.IsNullOrWhiteSpace(value)))
            {
                key.SetValue(entry.Name, value);
            }
        }
Пример #16
0
 private RegistryEntryGridRow RegistryEntryToGridRow(RegistryEntry finalProgram)
 {
     return(new RegistryEntryGridRow
     {
         DisplayIcon = finalProgram.DisplayIcon,
         DisplayName = finalProgram.DisplayName,
         EstimatedSize = finalProgram.EstimatedSize,
         InstallLocation = finalProgram.InstallLocation,
         UninstallString = finalProgram.UninstallString,
         IsSelected = false
     });
 }
Пример #17
0
            public void AddEntry(FourCC inCode, string inName, string inDescription)
            {
                RegistryEntry entry;

                if (m_EntryMap.TryGetValue(inCode, out entry))
                {
                    throw new ArgumentException("FourCC with code " + inCode.ToString() + " has already been registered", "inCode");
                }

                entry = new RegistryEntry(inCode, inName, inDescription);
                m_EntryList.Add(entry);
                m_EntryMap.Add(inCode, entry);
            }
Пример #18
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            var entries = new RegistryEntry[]
            {
                //给所有类型的文件添加自定义的右键菜单
                new RegistryEntry()
                {
                    parentKey         = @"*\shell", name = "Wipe Content",
                    associatedProgram = this.GetType().Assembly.Location
                },
                //给所有文件夹添加自定义的右键菜单
                new RegistryEntry()
                {
                    parentKey         = @"directory\shell", name = "Wipe Directory",
                    associatedProgram = this.GetType().Assembly.Location
                }
            };

            try
            {
                foreach (var item in entries)
                {
                    //创建项:shell
                    RegistryKey shellKey = Registry.ClassesRoot.OpenSubKey(item.parentKey, true);
                    if (shellKey == null)
                    {
                        shellKey = Registry.ClassesRoot.CreateSubKey(item.parentKey);
                    }

                    //创建项:右键显示的菜单名称
                    using (var rightCmd = shellKey.CreateSubKey(item.name))
                    {
                        using (var associatedProgram = rightCmd.CreateSubKey("command"))
                        {
                            //创建默认值:关联的程序
                            associatedProgram.SetValue(string.Empty,
                                                       item.associatedProgram + " %1");
                        }
                    }

                    //刷新到磁盘并释放资源
                    shellKey.Close();
                }
                MessageBox.Show("Registered successfully!");
            }
            catch (System.Security.SecurityException se)
            {
                MessageBox.Show("Please start this program with Administrator and try again.");
            }
        }
        public void TestPathToDataKey()
        {
            //var path = "skyfeed.hns/preferences/ui.json";
            //var path = "crqa.hns/snew.hns/123";
            var path = "crqa.hns/snew.hns/newcontent/index.json";
            //var path = "crqa.hns/snew.hns/newcontent/page_0.json";

            var           bucket   = new DiscoverableBucket(path);
            RegistryEntry registry = new RegistryEntry(new RegistryKey(bucket));

            var hexKey = registry.Key.GetHexKey();

            Assert.IsNotNull(hexKey);
        }
        private DocumentDescription AddAttachment(RegistryEntry registryEntry)
        {
            //Add document description
            var documentDescription2 = _ephorte.AddDocumentDescription();

            documentDescription2.DocumentTitle = "Attachment " + DateTime.Now;
            //Add a document-object with the given document-description.
            var documentObject3 = _ephorte.AddDocumentObject(documentDescription2, 1, VariantFormatId.Production);

            //Add a registry-entry-document with the given registry-entry and document-description.
            _ephorte.AddRegistryEntryDocument(registryEntry, documentDescription2, DocumentLinkTypeId.Attachment);

            //The (attachment) document is uploded, and will be checked in when doing SaveChanges
            _ephorte.UploadTextDocument(documentObject3, SecondAttachmentFileName, TextFileContent + " - attachment");
            return(documentDescription2);
        }
        private bool CanReset(RegistryEntry entry)
        {
            if (entry is null)
            {
                return(false);
            }

            if (entry.IsUserSpecific() && !entry.IsHiveAvailable())
            {
                Logger.Log($"User hive is not available, cannot reset registry key '{entry}'!");

                return(false);
            }

            return(true);
        }
        private void AddMainDocument(RegistryEntry registryEntry,
                                     out DocumentDescription documentDescription1,
                                     out DocumentObject documentObject1)
        {
            //Add document description
            documentDescription1 = _ephorte.AddDocumentDescription();

            //Add a document-object with a given document-description
            documentObject1 = _ephorte.AddDocumentObject(documentDescription1, 1, VariantFormatId.Production);

            //Add a registry-entry-document with the given registry-entry and document-description. This is the main document (H
            _ephorte.AddRegistryEntryDocument(registryEntry, documentDescription1, DocumentLinkTypeId.MainDocument);

            //This first version of the (main) document is uploded before any the pending changes are saved, and will be checked in when doing SaveChanges
            _ephorte.UploadTextDocument(documentObject1, MainFileName, TextFileContent + " - v1");
        }
        public void Register(RegistryEntry entry)
        {
            /*_log.Debug(
                m => m(
                         "Registering subscriber {0} of type {1} to {2}.",
                         entry.Subscriber.DisplayName,
                         entry.Subscriber.GetType().GetDisplayName(),
                         entry.EventType.GetDisplayName()));*/

            lock (_registering)
            {
                _byGuid.Add(entry.Guid, entry);
                _bySubscriber.Add(entry.Subscriber, entry);
                indexByType(entry);
            }
        }
Пример #24
0
        public void SetValue <T>(string id, T value, bool overwrite = true)
        {
            Type t = typeof(RegistryEntry <T>);

            if (!objectFormatters.ContainsKey(t))
            {
                throw new MissingRegistryFormatterException(typeof(T));
            }
            if (objectStore.ContainsKey(id) && overwrite)
            {
                objectStore[id] = new RegistryEntry <T>(id, value, (RegistryFormatter <T>)objectFormatters[t]);
            }
            else
            {
                objectStore.Add(id, new RegistryEntry <T>(id, value, (RegistryFormatter <T>)objectFormatters[t]));
            }
        }
Пример #25
0
        public async Task TestSetRegistry()
        {
            string dataKey  = Guid.NewGuid().ToString();
            int    revision = 0;
            string data     = "IADUs8d9CQjUO34LmdaaNPK_STuZo24rpKVfYW3wPPM2uQ"; //Sia logo

            var key = SiaSkynetClient.GenerateKeys(_testSeed);

            RegistryEntry reg = new RegistryEntry(new RegistryKey(dataKey));

            reg.SetData(data);
            reg.Revision = revision;

            var success = await _client.SetRegistry(key.privateKey, key.publicKey, reg);

            Assert.IsTrue(success);
        }
Пример #26
0
        /// <summary>
        /// Save data to the Skynet Registry
        /// </summary>
        /// <param name="privateKey"></param>
        /// <param name="publicKey"></param>
        /// <param name="entry"></param>
        /// <returns></returns>
        public async Task <bool> SetRegistry(byte[] privateKey, byte[] publicKey, RegistryEntry entry)
        {
            string hexPublicKey = BitConverter.ToString(publicKey).Replace("-", "");

            var signature = entry.Sign(privateKey, publicKey);

            SetRegistryRequest req = new SetRegistryRequest();

            req.publickey.key = publicKey.Select(x => (int)x).ToArray();
            req.datakey       = entry.Key.GetHexKey();
            req.data          = entry.Data.Select(x => (int)x).ToArray();
            req.revision      = entry.Revision;
            req.signature     = signature.Select(x => (int)x).ToArray();
            var result = await _api.SetRegistry(req);

            return(result.IsSuccessStatusCode);
        }
Пример #27
0
        public SenderRecipient AddSenderRecipient(RegistryEntry registryEntry, string firstName, string lastName)
        {
            var senderRecipient = _ephorteContext.Create <SenderRecipient>();

            if (registryEntry.Id == 0)
            {
                senderRecipient.RegistryEntry = registryEntry;
            }
            else
            {
                senderRecipient.RegistryEntryId = registryEntry.Id;
            }

            senderRecipient.Email = firstName + "." + lastName + "@does-not-exist.no";
            senderRecipient.Name  = firstName + " " + lastName;
            _ephorteContext.Add(senderRecipient);
            return(senderRecipient);
        }
Пример #28
0
        /// <summary>
        /// Registers a content importer for the specified file extension.
        /// </summary>
        /// <typeparam name="T">The type of content importer to register.</typeparam>
        /// <param name="extension">The file extension for which to register the importer.</param>
        public void RegisterImporter <T>(String extension) where T : IContentImporter
        {
            Contract.RequireNotEmpty(extension, nameof(extension));

            var baseImporterType = GetBaseContentImporterType(typeof(T));

            if (baseImporterType == null)
            {
                throw new InvalidOperationException(UltravioletStrings.ImporterInvalidBaseClass.Format(typeof(T).FullName));
            }

            if (registeredImporters.ContainsKey(extension))
            {
                throw new InvalidOperationException(
                          UltravioletStrings.ImporterAlreadyRegistered.Format(typeof(T).FullName, extension));
            }
            registeredImporters[extension] = new RegistryEntry(CreateImporterInstance(typeof(T)));
        }
Пример #29
0
 public void Save()
 {
     foreach (KeyValuePair <OptionName, RegistryEntry> registryOption in registryOptions)
     {
         OptionName    option = registryOption.Key;
         RegistryEntry entry  = registryOption.Value;
         using (RegistryKey key = entry.Hive.OpenSubKey(entry.Key, true))
         {
             if ((bool)typeof(RegistryOptions).GetProperty(option.ToString()).GetValue(Options))
             {
                 key.SetValue(entry.Name, entry.Value);
             }
             else
             {
                 key.DeleteValue(entry.Name, false);
             }
         }
     }
 }
        private void Reset(RegistryEntry entry, object value)
        {
            if (value is null)
            {
                var deleted = entry.TryDelete();

                if (!deleted && entry.GetValue() != null)
                {
                    throw new IOException($"Failed to delete registry key '{entry}'!");
                }

                Logger.Log($"Deleted registry key '{entry}'.");
            }
            else
            {
                entry.SetValue(value);
                Logger.Log($"Set registry key '{entry}' to '{value}'.");
            }
        }
Пример #31
0
        private async Task <RegistryEntry> GetRegistryEntry(DeviceConfiguration configuration)
        {
            RegistryEntry registry = new RegistryEntry {
                Registry = _registrySettings.Host
            };

            if (configuration.ApplicationVersionId != null)
            {
                registry.ApplicationVersion = await _applicationRepo.GetApplicationVersion(
                    configuration.ApplicationVersionId.Value);
            }

            if (configuration.AgentVersionId != null)
            {
                registry.AgentVersion = await _deviceRepo.GetAgentVersion(
                    configuration.AgentVersionId.Value);
            }

            return(registry);
        }
Пример #32
0
 private static void Reset(RegistryEntry entry, object value)
 {
     try
     {
         if (entry.IsUserSpecific() && !entry.IsHiveAvailable())
         {
             OutputAndLog($"User hive is not available, cannot reset registry key '{entry}'!");
         }
         else
         {
             entry.SetValue(value);
             Console.ForegroundColor = ConsoleColor.Green;
             OutputAndLog($@"Successfully set '{entry}' to '{value}'");
         }
     }
     catch (Exception e)
     {
         Console.ForegroundColor = ConsoleColor.Red;
         OutputAndLog($@"Failed to set '{entry}' to '{value}'");
         Log(e);
     }
 }
Пример #33
0
        private static string PrepareRegistryKey(RegistryEntry key)
        {
            var root = key.Root;

            switch (root)
            {
            case RegistryRoot.HKEY_CLASSES_ROOT:
                return("REGISTRY\\MACHINE\\Classes\\" + key.Key);

            case RegistryRoot.HKEY_CURRENT_USER:
                return("REGISTRY\\USER\\[{CurrentUserSID}]\\" + key.Key);

            case RegistryRoot.HKEY_USERS:
                return("REGISTRY\\USER\\" + key.Key);

            case RegistryRoot.HKEY_LOCAL_MACHINE:
                return("REGISTRY\\MACHINE\\" + key.Key);

            default:
                return("REGISTRY\\MACHINE\\" + key.Key);
            }
        }
 public void AddRegistryEntryDocument(RegistryEntry registryEntry, DocumentDescription documentDescription,
                                      string documentLinkTypeId)
 {
     var registryEntryDocument = _ephorteContext.Create<RegistryEntryDocument>();
     registryEntryDocument.RegistryEntry = registryEntry;
     registryEntryDocument.DocumentDescription = documentDescription;
     registryEntryDocument.DocumentLinkTypeId = documentLinkTypeId;
     _ephorteContext.Add(registryEntryDocument);
 }
 public void AddRecipient(RegistryEntry registryEntry, string firstName, string lastName)
 {
     var senderRecipient = AddSenderRecipient(registryEntry, firstName, lastName);
     senderRecipient.IsRecipient = true;
 }
        private DocumentDescription AddAttachment(RegistryEntry registryEntry)
        {
            //Add document description
            var documentDescription2 = _ephorte.AddDocumentDescription();
            documentDescription2.DocumentTitle = "Attachment " + DateTime.Now;
            //Add a document-object with the given document-description. 
            var documentObject3 = _ephorte.AddDocumentObject(documentDescription2, 1, VariantFormatId.Production);

            //Add a registry-entry-document with the given registry-entry and document-description.
            _ephorte.AddRegistryEntryDocument(registryEntry, documentDescription2, DocumentLinkTypeId.Attachment);

            //The (attachment) document is uploded, and will be checked in when doing SaveChanges
            _ephorte.UploadTextDocument(documentObject3, SecondAttachmentFileName, TextFileContent + " - attachment");
            return documentDescription2;
        }
        public SenderRecipient AddSenderRecipient(RegistryEntry registryEntry, string firstName, string lastName)
        {
            var senderRecipient = _ephorteContext.Create<SenderRecipient>();
            if (registryEntry.Id == 0)
                senderRecipient.RegistryEntry = registryEntry;
            else
                senderRecipient.RegistryEntryId = registryEntry.Id;

            senderRecipient.Email = firstName + "." + lastName + "@does-not-exist.no";
            senderRecipient.Name = firstName + " " + lastName;
            _ephorteContext.Add(senderRecipient);
            return senderRecipient;
        }
        private void AddMainDocument(RegistryEntry registryEntry,
                                     out DocumentDescription documentDescription1,
                                     out DocumentObject documentObject1)
        {
            //Add document description
            documentDescription1 = _ephorte.AddDocumentDescription();

            //Add a document-object with a given document-description
            documentObject1 = _ephorte.AddDocumentObject(documentDescription1, 1, VariantFormatId.Production);

            //Add a registry-entry-document with the given registry-entry and document-description. This is the main document (H
            _ephorte.AddRegistryEntryDocument(registryEntry, documentDescription1, DocumentLinkTypeId.MainDocument);

            //This first version of the (main) document is uploded before any the pending changes are saved, and will be checked in when doing SaveChanges
            _ephorte.UploadTextDocument(documentObject1, MainFileName, TextFileContent + " - v1");
        }
 private RegistryEntry GetRegistryEntry(RegistryEntry registryEntry)
 {
     var query = from o in EphorteContext.Query<RegistryEntry>()
                 where o.Id == registryEntry.Id
                 select o;
     return query.FirstOrDefault();
 }
 //private const string EphorteUrl = "http://server.name/site-url";
 private static void LogEphorteWebLink(RegistryEntry registryEntry)
 {
     Console.WriteLine("Link to registry-entry in ephorteweb: " + EphorteUrl + "/locator/?SHOW=JP&JP_ID=" + registryEntry.Id);
 }