XElement CreateWorkflowXElement(StringBuilder xaml) { XElement dataList = string.IsNullOrEmpty(DataList) ? new XElement("DataList") : XElement.Parse(DataList); XElement service = new XElement("Service", new XAttribute("ID", ID), new XAttribute("Version", (Version != null) ? Version.ToString() : "1.0"), new XAttribute("ServerID", ServerID.ToString()), new XAttribute("Name", ResourceName ?? string.Empty), new XAttribute("ResourceType", ResourceType), new XAttribute("IsValid", IsValid), new XElement("DisplayName", ResourceName ?? string.Empty), new XElement("Category", Category ?? string.Empty), new XElement("IsNewWorkflow", IsNewWorkflow), new XElement("AuthorRoles", string.Empty), new XElement("Comment", Comment ?? string.Empty), new XElement("Tags", Tags ?? string.Empty), new XElement("IconPath", IconPath ?? string.Empty), new XElement("HelpLink", HelpLink ?? string.Empty), new XElement("UnitTestTargetWorkflowService", UnitTestTargetWorkflowService ?? string.Empty), dataList, new XElement("Action", new XAttribute("Name", "InvokeWorkflow"), new XAttribute("Type", "Workflow"), new XElement("XamlDefinition", xaml)), new XElement("ErrorMessages", WriteErrors()) ); return(service); }
XElement CreateServiceXElement(StringBuilder xaml) { XElement dataList = string.IsNullOrEmpty(DataList) ? new XElement("DataList") : XElement.Parse(DataList); var content = xaml.Unescape(); content = content.Replace("&", "&"); var contentElement = content.ToXElement(); XElement service = new XElement("Service", new XAttribute("ID", ID), new XAttribute("Version", (Version != null) ? Version.ToString() : "1.0"), new XAttribute("ServerID", ServerID.ToString()), new XAttribute("Name", ResourceName ?? string.Empty), new XAttribute("ResourceType", ServerResourceType ?? ResourceType.ToString()), new XAttribute("IsValid", IsValid), new XElement("DisplayName", ResourceName ?? string.Empty), new XElement("Category", Category ?? string.Empty), new XElement("AuthorRoles", string.Empty), new XElement("Comment", Comment ?? string.Empty), new XElement("Tags", Tags ?? string.Empty), new XElement("IconPath", IconPath ?? string.Empty), new XElement("HelpLink", HelpLink ?? string.Empty), new XElement("UnitTestTargetWorkflowService", UnitTestTargetWorkflowService ?? string.Empty), dataList, new XElement("Actions", contentElement), new XElement("ErrorMessages", WriteErrors()) ); return(service); }
void SetServerID(XmlDocument doc) { if (doc.DocumentElement != null) { doc.DocumentElement.SetAttribute("ServerID", ServerID.ToString()); } }
private async void InitializeAsync() { foreach (var message in await App.DriverDaemon.InvokeAsync(d => d.GetCurrentLog())) { if (message != null) { this.Items.Add(Log.GetStringFormat(message)); } } ServerID = await App.DriverDaemon.InvokeAsync(d => d.SetLogOutput(true)); if (ServerID != Guid.Empty) { PipeClient = new NamedPipeClientStream(ServerID.ToString()); await PipeClient.ConnectAsync(); MainThread = new Thread(Main) { Name = "Log Client Thread" }; MainThread.Start(); } this.ParentWindow.Closing += async(sender, e) => await App.DriverDaemon.InvokeAsync(d => d.SetLogOutput(false)); }
public override void SetBasicPropertyValues() { base.SetBasicPropertyValues(); ResourceProperty propertyValue; for (int i = 0; i < ListProperties.Count; i++) { propertyValue = ListProperties[i]; switch (propertyValue.PropertyID) { case PRO_TYPE: propertyValue.Value = DeviceType.ToString(); break; case PRO_SERVERID: propertyValue.Value = ServerID.ToString(); break; case PRO_HOSTADDRESS: propertyValue.Value = HostAddress; break; case PRO_ROOTDIR: propertyValue.Value = RootDir; break; } } }
public CmmDataRecord(CmmServerConfig conf, bool active, ClientState state) { IsActived = active; ServerID = conf.ServerID; ServerName = "三坐标 " + ServerID.ToString(); IPAddress = conf.HostIPAddress; _state = state; IsFault = (state == ClientState.CS_Error) ? true : false; //State = cmmStateInfo[state]; }
public void ResumeConnection() { var cli = new TcpClient(); // TODO: try-catch: соединение не установлено, повторите позже cli.Connect(ServerIp); Reconnect(new RemoteClient(cli)); SendMessage(MsgType.RestoreSession, ServerID.ToString()); string g; ReadResponse(out g); }
/// <summary> /// Initializes config with the given values and optionally protects it. /// <remarks> /// If <paramref name="shouldProtectConfig"/> is <code>true</code>, then the config file must exist on disk. /// </remarks> /// </summary> /// <param name="settings">The settings to be loaded.</param> /// <param name="shouldProtectConfig"><code>true</code> if the configuration should be protected; <code>false</code> otherwise.</param> /// <exception cref="System.ArgumentNullException">settings</exception> protected void Initialize(NameValueCollection settings, bool shouldProtectConfig) { if (settings == null) { throw new ArgumentNullException("settings"); } SystemKey = CreateKey(settings["SystemKey"]); Guid serverID; if (Guid.TryParse(settings["ServerID"], out serverID) && serverID != Guid.Empty) { ServerID = serverID; ServerKey = CreateKey(settings["ServerKey"]); } else { // BUG 8395: settings is a ReadOnlyNameValueCollection so create a new collection instead var newSettings = new NameValueCollection(); #region New server installation so initialize config with new server id and key ServerID = Guid.NewGuid(); ServerKey = new RSACryptoServiceProvider(); newSettings["ServerID"] = ServerID.ToString(); newSettings["ServerKey"] = Convert.ToBase64String(ServerKey.ExportCspBlob(true)); newSettings["SystemKey"] = settings["SystemKey"]; #endregion SaveConfig(newSettings); if (shouldProtectConfig) { ProtectConfig(); } } }
public void WriteXml(XmlWriter writer) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(List <KeyEntry>)); List <KeyEntry> keyEntries = new List <KeyEntry>(); foreach (KeyValuePair <long, List <long> > thisColl in CharCollection) { keyEntries.Add(new KeyEntry() { Key = thisColl.Key, Item = thisColl.Value }); } writer.WriteStartElement("Character"); writer.WriteAttributeString("name", name); writer.WriteAttributeString("AdvLvl", AdvLvl.ToString()); writer.WriteAttributeString("AdvClass", AdvClass.ToString()); writer.WriteAttributeString("TimePlayed", TimePlayed.ToString()); writer.WriteAttributeString("DaybreakID", DaybreakID.ToString()); writer.WriteAttributeString("ServerID", ServerID.ToString()); xmlSerializer.Serialize(writer, keyEntries); writer.WriteFullEndElement(); keyEntries.Clear(); }
void SetServerID(XmlDocument doc) { doc.DocumentElement?.SetAttribute("ServerID", ServerID.ToString()); }
static void DownloadThreadRunner() { try { int Direction = -1; lock (FileLock) { if (FilesystemData.FileTransferStatus.ServerID == null) { return; } Direction = FilesystemData.FileTransferStatus.Direction; } #region Client to Server if (Direction == 1) { string LocalFilename = ""; string MD5; Int64 ServerID = 0; Int64 CurrentSZ; Int64 TotalSZ; bool OverrideMetered; bool ReqOnly; DateTime LastModified; try { lock (FileLock) { LocalFilename = FilesystemData.FileTransferStatus.RemoteFileLocation; ServerID = FilesystemData.FileTransferStatus.ServerID.Value; CurrentSZ = FilesystemData.FileTransferStatus.ProgressSize; TotalSZ = FilesystemData.FileTransferStatus.Size; MD5 = FilesystemData.FileTransferStatus.MD5CheckSum; OverrideMetered = FilesystemData.FileTransferStatus.OverrideMeteredConnection; ReqOnly = FilesystemData.FileTransferStatus.RequestOnly; LastModified = FilesystemData.FileTransferStatus.LastModfied; } //won't start when in metered connection! if (OverrideMetered == false) { try { if (MeteredConnection.IsMeteredConnection() == true) { FoxEventLog.VerboseWriteEventLog("Upload paused = metered connection detected", System.Diagnostics.EventLogEntryType.Information); return; } } catch { } } Int64 ReallyCurrentSZ = 0; try { if (File.Exists(LocalFilename) == true) { FileInfo fi = new FileInfo(LocalFilename); ReallyCurrentSZ = fi.Length; } else { FoxEventLog.WriteEventLog("File " + LocalFilename + " does not exist for upload.", System.Diagnostics.EventLogEntryType.Error); return; } } catch (Exception ee) { FoxEventLog.WriteEventLog("Checking upload file " + LocalFilename + " ID: " + ServerID.ToString() + " failed:\n" + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); return; } downloadnet = Utilities.ConnectNetwork(7); if (downloadnet == null) { return; } if (ReqOnly == true) { Status.UpdateMessage(7, "Checking " + LocalFilename); MD5 = MD5Utilities.CalcMD5File(LocalFilename); FileInfo fi = new FileInfo(LocalFilename); lock (FileLock) { FilesystemData.FileTransferStatus.MD5CheckSum = MD5; FilesystemData.FileTransferStatus.LastModfied = fi.LastWriteTimeUtc; FilesystemData.WriteFileTransferStatus(); } Int64?NewID = downloadnet.File_Agent_NewUploadReq(LocalFilename, OverrideMetered, MD5); if (NewID == null) { FoxEventLog.VerboseWriteEventLog("Cannot create a new upload req for " + LocalFilename, System.Diagnostics.EventLogEntryType.Warning); return; } if (downloadnet.File_Agent_CancelUpload(ServerID) == false) { FoxEventLog.VerboseWriteEventLog("Cannot delete temp upload req for " + LocalFilename + " ID: " + ServerID.ToString(), System.Diagnostics.EventLogEntryType.Warning); return; } lock (FileLock) { //wait for the new upload req ClearDataFSD(); FilesystemData.WriteFileTransferStatus(); UnlockTimer = true; return; } } else { FileStream fs = null; do { try { if (CancelAndDeleteDL == true) { return; } FileInfo fi = new FileInfo(LocalFilename); if (roughDT(fi.LastWriteTimeUtc, LastModified) == false || fi.Length != TotalSZ) { if (downloadnet.File_Agent_CancelUpload(ServerID) == false) { FoxEventLog.VerboseWriteEventLog("Cannot cancel upload req for " + LocalFilename + " ID: " + ServerID.ToString() + ", due file changes", System.Diagnostics.EventLogEntryType.Warning); lock (FileLock) { ClearDataFSD(); FilesystemData.WriteFileTransferStatus(); } return; } else { FoxEventLog.VerboseWriteEventLog("Cannot upload req for " + LocalFilename + " ID: " + ServerID.ToString() + ": File has been changed!", System.Diagnostics.EventLogEntryType.Warning); } return; } try { if (fs == null) { fs = File.Open(LocalFilename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); } } catch (Exception ee) { FoxEventLog.WriteEventLog("Cannot upload file " + LocalFilename + " ID: " + ServerID.ToString() + " failed:\n" + ee.ToString(), System.Diagnostics.EventLogEntryType.Warning); return; } try { fs.Seek(CurrentSZ, SeekOrigin.Begin); } catch { FoxEventLog.WriteEventLog("Cannot properly seek in file " + LocalFilename + " ID: " + ServerID.ToString() + " Pos: 0x" + CurrentSZ.ToString("X"), System.Diagnostics.EventLogEntryType.Warning); return; } byte[] data = null; try { int read = 1024 * 1024; data = new byte[read]; read = fs.Read(data, 0, read); if (data.Length != read) { byte[] ddd = new byte[read]; Array.Copy(data, ddd, read); data = ddd; } } catch { FoxEventLog.WriteEventLog("Cannot read file " + LocalFilename + " ID: " + ServerID.ToString() + " Pos: 0x" + CurrentSZ.ToString("X"), System.Diagnostics.EventLogEntryType.Warning); return; } Status.UpdateMessage(7, "Uploading " + LocalFilename + "\r\n" + CommonUtilities.NiceSize(CurrentSZ) + " of " + CommonUtilities.NiceSize(TotalSZ)); bool res = downloadnet.File_Agent_AppendUpload(ServerID, data); if (res == false) { FoxEventLog.VerboseWriteEventLog("Cannot upload append req for " + LocalFilename + " ID: " + ServerID.ToString(), System.Diagnostics.EventLogEntryType.Warning); return; } CurrentSZ += data.Length; lock (FileLock) { FilesystemData.FileTransferStatus.ProgressSize = CurrentSZ; FilesystemData.WriteFileTransferStatus(); } if (CurrentSZ == TotalSZ) { FoxEventLog.WriteEventLog("Upload file success " + LocalFilename + " ID: " + ServerID.ToString(), System.Diagnostics.EventLogEntryType.Information); lock (FileLock) { ClearDataFSD(); FilesystemData.WriteFileTransferStatus(); } UnlockTimer = true; return; } } finally { if (fs != null) { fs.Close(); fs = null; } } } while (true); } } catch (Exception ee) { FoxEventLog.WriteEventLog("Downloading file " + LocalFilename + " ID: " + ServerID.ToString() + " crashed:\n" + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); } finally { Status.UpdateMessage(7); } } #endregion #region Server to Client if (Direction == 0) { string LocalFilename; string MD5; Int64 ServerID; Int64 CurrentSZ; Int64 TotalSZ; bool OverrideMetered; lock (FileLock) { LocalFilename = FilesystemData.FileTransferStatus.RemoteFileLocation; ServerID = FilesystemData.FileTransferStatus.ServerID.Value; CurrentSZ = FilesystemData.FileTransferStatus.ProgressSize; TotalSZ = FilesystemData.FileTransferStatus.Size; MD5 = FilesystemData.FileTransferStatus.MD5CheckSum; OverrideMetered = FilesystemData.FileTransferStatus.OverrideMeteredConnection; } //won't start when in metered connection! if (OverrideMetered == false) { try { if (MeteredConnection.IsMeteredConnection() == true) { FoxEventLog.VerboseWriteEventLog("Download paused = metered connection detected", System.Diagnostics.EventLogEntryType.Information); return; } } catch { } } Int64 ReallyCurrentSZ = 0; try { string Dir = Path.GetDirectoryName(LocalFilename); if (Directory.Exists(Dir) == false) { Directory.CreateDirectory(Dir); } if (File.Exists(LocalFilename) == true) { FileInfo fi = new FileInfo(LocalFilename); ReallyCurrentSZ = fi.Length; } else { ReallyCurrentSZ = 0; } } catch (Exception ee) { FoxEventLog.WriteEventLog("Checking download file " + LocalFilename + " ID: " + ServerID.ToString() + " failed:\n" + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); } if (ReallyCurrentSZ != CurrentSZ) { FoxEventLog.WriteEventLog("File Size does not match: deleting the file " + LocalFilename, System.Diagnostics.EventLogEntryType.Warning); try { File.Delete(LocalFilename); } catch (Exception ee) { FoxEventLog.WriteEventLog("Cannot delete " + LocalFilename + "\n" + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); } lock (FileLock) { ClearDataFSD(); FilesystemData.WriteFileTransferStatus(); return; } } downloadnet = Utilities.ConnectNetwork(7); if (downloadnet == null) { return; } try { downloadnet.DownloadNotify += Downloadnet_DownloadNotify; if (downloadnet.DownloadFile("api/agent/filefiledownload/" + ServerID.ToString(), LocalFilename, TotalSZ) == false) { FileInfo fi = new FileInfo(LocalFilename); lock (FileLock) { FilesystemData.FileTransferStatus.ProgressSize = fi.Length; FilesystemData.WriteFileTransferStatus(); } } else { if (downloadnet.StopDownload == false) { Status.UpdateMessage(7, "Checking " + FilesystemData.FileTransferStatus.RemoteFileLocation + "..."); string CalcMD5 = MD5Utilities.CalcMD5File(LocalFilename); if (MD5.ToLower() != CalcMD5.ToLower()) { FoxEventLog.WriteEventLog("File MD5 does not match: deleting the file " + LocalFilename, System.Diagnostics.EventLogEntryType.Warning); try { File.Delete(LocalFilename); } catch (Exception ee) { FoxEventLog.WriteEventLog("Cannot delete " + LocalFilename + "\n" + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); } lock (FileLock) { ClearDataFSD(); FilesystemData.WriteFileTransferStatus(); return; } } else { //success! FoxEventLog.WriteEventLog("File download success: " + LocalFilename, System.Diagnostics.EventLogEntryType.Information); downloadnet.File_Agent_CancelUpload(ServerID); lock (FileLock) { ClearDataFSD(); FilesystemData.WriteFileTransferStatus(); } UnlockTimer = true; return; } } else { if (CancelAndDeleteDL == true) { FoxEventLog.VerboseWriteEventLog("File " + LocalFilename + " canceled by server req.", System.Diagnostics.EventLogEntryType.Information); try { File.Delete(LocalFilename); } catch (Exception ee) { FoxEventLog.WriteEventLog("Cannot delete " + LocalFilename + "\n" + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); } lock (FileLock) { ClearDataFSD(); FilesystemData.WriteFileTransferStatus(); return; } } } } } catch (Exception ee) { FoxEventLog.WriteEventLog("Downloading file " + LocalFilename + " ID: " + ServerID.ToString() + " crashed:\n" + ee.ToString(), System.Diagnostics.EventLogEntryType.Error); } finally { downloadnet.DownloadNotify -= Downloadnet_DownloadNotify; Status.UpdateMessage(7); } } #endregion } finally { try { if (downloadnet != null) { downloadnet.CloseConnection(); } } catch { } downloadnet = null; } }
public void WriteXml(XmlWriter writer) { //------Always log these for reconstruction------------ writer.WriteAttributeString("DisplayName", DisplayName); writer.WriteAttributeString("ID", ID.ToString()); writer.WriteAttributeString("OriginalInstanceID", OriginalInstanceID.ToString()); writer.WriteAttributeString("ParentID", ParentID.ToString()); writer.WriteAttributeString("ServerID", ServerID.ToString()); writer.WriteAttributeString("StateType", StateType.ToString()); writer.WriteElementString("HasError", HasError.ToString()); writer.WriteAttributeString("SessionID", SessionID.ToString()); if (HasError) { writer.WriteElementString("ErrorMessage", ErrorMessage); } //----------------------------- var settings = WorkflowLoggger.LoggingSettings; //Version if (settings.IsVersionLogged && !string.IsNullOrWhiteSpace(Version)) { writer.WriteElementString("Version", Version); } //Type if (settings.IsTypeLogged) { writer.WriteElementString("Name", Name); writer.WriteElementString("ActivityType", ActivityType.ToString()); } //Duration if (settings.IsDurationLogged) { if (Duration != default(TimeSpan)) { writer.WriteElementString("Duration", DurationString); } } //DateTime if (settings.IsDataAndTimeLogged) { if (StartTime != DateTime.MinValue) { writer.WriteElementString("StartTime", StartTime.ToString("G")); } if (EndTime != DateTime.MinValue) { writer.WriteElementString("EndTime", EndTime.ToString("G")); } } //Input if (settings.IsInputLogged && Inputs.Count > 0) { writer.WriteStartElement("Inputs"); writer.WriteAttributeString("Count", Inputs.Count.ToString(CultureInfo.InvariantCulture)); var inputSer = new XmlSerializer(typeof(DebugItem)); foreach (var other in Inputs) { inputSer.Serialize(writer, other); } writer.WriteEndElement(); } //Output if (settings.IsOutputLogged && Outputs.Count > 0) { writer.WriteStartElement("Outputs"); writer.WriteAttributeString("Count", Outputs.Count.ToString(CultureInfo.InvariantCulture)); var outputSer = new XmlSerializer(typeof(DebugItem)); foreach (var other in Outputs) { outputSer.Serialize(writer, other); } writer.WriteEndElement(); } //StartBlock if (IsFirstStep()) { if (ExecutionOrigin != ExecutionOrigin.Unknown) { writer.WriteElementString("ExecutionOrigin", ExecutionOrigin.ToString()); } if (!string.IsNullOrWhiteSpace(ExecutingUser)) { writer.WriteElementString("ExecutingUser", ExecutingUser); } } //EndBlock if (IsFinalStep()) { writer.WriteElementString("NumberOfSteps", NumberOfSteps.ToString(CultureInfo.InvariantCulture)); } }